refs #352 Close suggest popover when text is not match

This commit is contained in:
AkiraFukushima 2018-08-07 21:40:29 +09:00
parent d4d3514990
commit bdfd0beb29
1 changed files with 7 additions and 1 deletions

View File

@ -82,16 +82,23 @@ export default {
// e.target.value: current value of the textarea
const [start, word] = suggestText(e.target.value, e.target.selectionStart, '@')
if (!start || !word) {
this.closeSuggest()
return false
}
this.filteredAccounts = this.accounts.filter((a) => a.startsWith(word))
if (this.filteredAccounts.length === 0) {
this.closeSuggest()
return false
}
this.openSuggest = true
this.startIndex = start
this.matchWord = word
},
closeSuggest () {
this.openSuggest = false
this.startIndex = null
this.matchWord = null
},
suggestHighlight (index) {
if (index < 0) {
this.highlightedIndex = 0
@ -102,7 +109,6 @@ export default {
}
},
insertAccount (account) {
console.log(account)
const str = `${this.status.slice(0, this.startIndex - 1)}${account} ${this.status.slice(this.startIndex + this.matchWord.length)}`
this.status = str
this.openSuggest = false