aboutsummaryrefslogtreecommitdiff
path: root/src/components/emoji-input/emoji-input.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-06-25 21:31:43 +0300
committerHenry Jameson <me@hjkos.com>2019-06-25 21:31:43 +0300
commit01bda605a7897a35e8e68f44d70edb804eeb417c (patch)
treeb36b305ee36fe6fd72b2c49a0fdcf2ae2e29f9b3 /src/components/emoji-input/emoji-input.js
parenta6bcd56c9f731e28e5da1dd334c7f3564000e638 (diff)
fix all known problems with clicks on autocomplete emojis
Diffstat (limited to 'src/components/emoji-input/emoji-input.js')
-rw-r--r--src/components/emoji-input/emoji-input.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/components/emoji-input/emoji-input.js b/src/components/emoji-input/emoji-input.js
index 0955a37e..f81669b9 100644
--- a/src/components/emoji-input/emoji-input.js
+++ b/src/components/emoji-input/emoji-input.js
@@ -59,7 +59,8 @@ const EmojiInput = {
input: undefined,
highlighted: 0,
caret: 0,
- focused: false
+ focused: false,
+ blurTimeout: false,
}
},
computed: {
@@ -122,12 +123,12 @@ const EmojiInput = {
this.$emit('input', newValue)
this.caret = 0
},
- replaceText (e) {
+ replaceText (e, suggestion) {
const len = this.suggestions.length || 0
if (this.textAtCaret.length === 1) { return }
- if (len > 0) {
- const suggestion = this.suggestions[this.highlighted]
- const replacement = suggestion.replacement
+ if (len > 0 || suggestion) {
+ const chosenSuggestion = suggestion || this.suggestions[this.highlighted]
+ const replacement = chosenSuggestion.replacement
const newValue = Completion.replaceWord(this.value, this.wordAtCaret, replacement)
this.$emit('input', newValue)
this.highlighted = 0
@@ -173,13 +174,20 @@ const EmojiInput = {
onBlur (e) {
// Clicking on any suggestion removes focus from autocomplete,
// preventing click handler ever executing.
- setTimeout(() => {
+ this.blurTimeout = setTimeout(() => {
this.focused = false
this.setCaret(e)
this.resize()
}, 200)
},
+ onClick (e, suggestion) {
+ this.replaceText(e, suggestion)
+ },
onFocus (e) {
+ if (this.blurTimeout) {
+ clearTimeout(this.blurTimeout)
+ }
+
this.focused = true
this.setCaret(e)
this.resize()