Closed Epistol closed 5 years ago
This is why this method is on the client side, not baked into the package. If you want to write the logic that handles inserting at the cursor position, go ahead 😉
For the record, I came up with this method :
append(emoji) {
const textArea = document.getElementsByName(this.label + '-emoji')[0];
this.cursorPosition = textArea.selectionEnd;
const start = this.input.substring(0, textArea.selectionStart);
const end = this.input.substring(textArea.selectionStart);
this.input = start + emoji + end;
textArea.focus();
this.$nextTick(() => {
textArea.selectionEnd = this.cursorPosition + emoji.length
})
},
Don't mind the getElementsByName, it's temporary, but it's a good start to get your input.
The method :
is mostly wrong due to the fact that when we put back the cursor on the end of the input, it will continue to add emojis at the end of the text, and not where we position our cursor.