Insert emoji at cursor location
Closed this issue · 2 comments
Hello @woody180! Thank you for this awesome emoji picker! Amazing job! It's very useful if you don't won't to hide the input field.
I have a question, is this possible to insert the emoji at cursor position? Thank you!
Found this solution. Thank you anyway :)
function insertAtCursor(myField, myValue) { //IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } //MOZILLA and others else if (myField.selectionStart || myField.selectionStart == "0") { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); } else { myField.value += myValue; } } new FgEmojiPicker({ trigger: [".emoji-launch"], position: ["bottom", "right"], emit(obj, triggerElement) { const emoji = obj.emoji; let textarea = triggerElement.parentElement.querySelector("textarea"); insertAtCursor(textarea, emoji); }, });
Thank you for nice response. That's correct note. I'll update code for inserting emoji in cursor position