Improve emoji autocompletion when the same emoji has many names

This commit is contained in:
Tulir Asokan 2019-06-16 19:54:54 +03:00
parent 7f917f0271
commit 691708a76e

View File

@ -333,13 +333,23 @@ func (view *RoomView) autocompleteEmoji(word string) (completions []string) {
if len(word) == 0 || word[0] != ':' {
return
}
var valueCompletion1 string
var manyValues bool
for name, value := range emoji.CodeMap() {
if name == word {
return []string{value}
} else if strings.HasPrefix(name, word) {
completions = append(completions, name)
if valueCompletion1 == "" {
valueCompletion1 = value
} else if valueCompletion1 != value {
manyValues = true
}
}
}
if !manyValues && len(completions) > 0 {
return []string{emoji.CodeMap()[completions[0]]}
}
return
}