From 820a6543c7dc4e99d2a193c5ce05cc0c9453a8d8 Mon Sep 17 00:00:00 2001 From: jared Date: Mon, 8 Apr 2019 11:10:26 -0400 Subject: #101 - update caret pos after emoji's inserted --- src/components/emoji-input/emoji-input.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/components/emoji-input/emoji-input.js') diff --git a/src/components/emoji-input/emoji-input.js b/src/components/emoji-input/emoji-input.js index 8f7598ca..99dba1cb 100644 --- a/src/components/emoji-input/emoji-input.js +++ b/src/components/emoji-input/emoji-input.js @@ -110,6 +110,25 @@ const EmojiInput = { const newValue = this.value.substr(0, this.caret) + emoji + this.value.substr(this.caret) this.$refs.input.focus() this.$emit('input', newValue) + this.caret += emoji.length + setTimeout(() => { + this.updateCaretPos() + }) + }, + updateCaretPos () { + const elem = this.$refs.input + if (elem.createTextRange) { + const range = elem.createTextRange() + range.move('character', this.caret) + range.select() + } else { + if (elem.selectionStart) { + elem.focus() + elem.setSelectionRange(this.caret, this.caret) + } else { + elem.focus() + } + } } } } -- cgit v1.2.3-70-g09d2