diff options
| author | jared <jaredrmain@gmail.com> | 2019-04-08 11:10:26 -0400 |
|---|---|---|
| committer | jared <jaredrmain@gmail.com> | 2019-04-08 11:10:26 -0400 |
| commit | 820a6543c7dc4e99d2a193c5ce05cc0c9453a8d8 (patch) | |
| tree | f7c0ad0f1652be029e6904599e850c5f0c06c97f /src/components/emoji-input/emoji-input.js | |
| parent | b4e53576f29d247bd890e890316d2ed026a3d057 (diff) | |
#101 - update caret pos after emoji's inserted
Diffstat (limited to 'src/components/emoji-input/emoji-input.js')
| -rw-r--r-- | src/components/emoji-input/emoji-input.js | 19 |
1 files changed, 19 insertions, 0 deletions
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() + } + } } } } |
