#101 - update caret pos after emoji's inserted

This commit is contained in:
jared 2019-04-08 11:10:26 -04:00
parent b4e53576f2
commit 820a6543c7
3 changed files with 22 additions and 1 deletions

View file

@ -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()
}
}
}
}
}