fixed several bugs

This commit is contained in:
Henry Jameson 2019-06-09 20:40:46 +03:00
parent a3cc8cc5d8
commit 76b9a66e98
2 changed files with 16 additions and 14 deletions

View file

@ -64,6 +64,7 @@ const EmojiInput = {
if (!input) return if (!input) return
this.input = input this.input = input
this.resize() this.resize()
input.elm.addEventListener('transitionend', this.onTransition)
input.elm.addEventListener('blur', this.onBlur) input.elm.addEventListener('blur', this.onBlur)
input.elm.addEventListener('focus', this.onFocus) input.elm.addEventListener('focus', this.onFocus)
input.elm.addEventListener('paste', this.onPaste) input.elm.addEventListener('paste', this.onPaste)
@ -73,6 +74,7 @@ const EmojiInput = {
unmounted () { unmounted () {
const { input } = this const { input } = this
if (input) { if (input) {
input.elm.removeEventListener('transitionend', this.onTransition)
input.elm.removeEventListener('blur', this.onBlur) input.elm.removeEventListener('blur', this.onBlur)
input.elm.removeEventListener('focus', this.onFocus) input.elm.removeEventListener('focus', this.onFocus)
input.elm.removeEventListener('paste', this.onPaste) input.elm.removeEventListener('paste', this.onPaste)
@ -86,8 +88,8 @@ const EmojiInput = {
this.$emit('input', newValue) this.$emit('input', newValue)
this.caret = 0 this.caret = 0
}, },
replaceText () { replaceText (e) {
const len = this.suggestions.length || 0 const len = (this.suggestions && this.suggestions.length) || 0
if (this.textAtCaret.length === 1) { return } if (this.textAtCaret.length === 1) { return }
if (len > 0) { if (len > 0) {
const suggestion = this.suggestions[this.highlighted] const suggestion = this.suggestions[this.highlighted]
@ -96,9 +98,10 @@ const EmojiInput = {
this.$emit('input', newValue) this.$emit('input', newValue)
this.caret = 0 this.caret = 0
this.highlighted = 0 this.highlighted = 0
e.preventDefault()
} }
}, },
cycleBackward () { cycleBackward (e) {
const len = this.suggestions.length || 0 const len = this.suggestions.length || 0
if (len > 0) { if (len > 0) {
this.highlighted -= 1 this.highlighted -= 1
@ -109,7 +112,7 @@ const EmojiInput = {
this.highlighted = 0 this.highlighted = 0
} }
}, },
cycleForward () { cycleForward (e) {
const len = this.suggestions.length || 0 const len = this.suggestions.length || 0
if (len > 0) { if (len > 0) {
this.highlighted += 1 this.highlighted += 1
@ -120,6 +123,9 @@ const EmojiInput = {
this.highlighted = 0 this.highlighted = 0
} }
}, },
onTransition (e) {
this.resize(e)
},
onBlur (e) { onBlur (e) {
this.focused = false this.focused = false
this.setCaret(e) this.setCaret(e)
@ -145,24 +151,20 @@ const EmojiInput = {
const { ctrlKey, shiftKey, key } = e const { ctrlKey, shiftKey, key } = e
if (key === 'Tab') { if (key === 'Tab') {
if (shiftKey) { if (shiftKey) {
this.cycleBackward() this.cycleBackward(e)
e.preventDefault()
} else { } else {
this.cycleForward() this.cycleForward(e)
e.preventDefault()
} }
} }
if (key === 'ArrowUp') { if (key === 'ArrowUp') {
this.cycleBackward() this.cycleBackward(e)
e.preventDefault() e.preventDefault()
} else if (key === 'ArrowDown') { } else if (key === 'ArrowDown') {
this.cycleForward() this.cycleForward(e)
e.preventDefault()
} }
if (key === 'Enter') { if (key === 'Enter') {
if (!ctrlKey) { if (!ctrlKey) {
this.replaceText() this.replaceText(e)
e.preventDefault()
} }
} }
}, },

View file

@ -105,7 +105,7 @@ const PostStatusForm = {
}) })
}, },
emojiSuggestor () { emojiSuggestor () {
suggestor({ emoji: [ return suggestor({ emoji: [
...this.$store.state.instance.emoji, ...this.$store.state.instance.emoji,
...this.$store.state.instance.customEmoji ...this.$store.state.instance.customEmoji
]}) ]})