Merge branch 'fix/inputfield-suggestion' into 'master'

fix(inputfield): Display suggestion correctly

Closes #37

See merge request tslocum/cview!6
This commit is contained in:
Trevor Slocum 2020-10-01 19:51:55 +00:00
commit f83115be61
1 changed files with 5 additions and 4 deletions

View File

@ -501,12 +501,13 @@ func (i *InputField) Autocomplete() *InputField {
// autocompleteChanged gets called when another item in the
// autocomplete list has been selected.
func (i *InputField) autocompleteChanged(_ int, item *ListItem) {
if len(i.text) >= len(item.mainText) {
if len(item.secondaryText) > 0 && len(i.text) < len(item.secondaryText) {
i.autocompleteListSuggestion = item.secondaryText[len(i.text):]
} else if len(item.mainText) > len(i.text)+1 {
i.autocompleteListSuggestion = item.mainText[len(i.text)+1:]
} else {
i.autocompleteListSuggestion = ""
return
}
i.autocompleteListSuggestion = item.mainText[len(i.text):]
}
// SetAcceptanceFunc sets a handler which may reject the last character that was