Open
Description
It was quite hard to reproduce this, so the following might seem a bit artificial, but isn't. The following piece of code is, on purpose, very similar to the autocomplete demo:
package main
import (
"strings"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
// 1,000 most common English words.
const wordList = "a/cl,c."
func main() {
words := strings.Split(wordList, ",")
app := tview.NewApplication()
inputField := tview.NewInputField().
SetLabel("Enter a word: ").
SetFieldWidth(30).
SetDoneFunc(func(key tcell.Key) {
app.Stop()
})
inputField.SetAutocompleteFunc(func(currentText string) (entries []string) {
if len(currentText) == 0 {
return
}
for _, word := range words {
for _, part := range strings.Split(word, "/") {
if strings.HasPrefix(strings.ToLower(part), strings.ToLower(currentText)) {
entries = append(entries, word)
break
}
}
}
if len(entries) == 0 {
entries = nil
}
return
})
inputField.SetAutocompletedFunc(func(text string, index, source int) bool {
if source != tview.AutocompletedNavigate {
inputField.SetText(text)
}
return source == tview.AutocompletedEnter || source == tview.AutocompletedClick
})
if err := app.EnableMouse(true).SetRoot(inputField, true).Run(); err != nil {
panic(err)
}
}
If you type "c", "l" and "Backspace", you'll get this:
I hope this little reproducer can help find and fix the bug. If you have any further questions, please let me know!
As a side note, thank you very much for your awesome work on this lib. It's very useful!
Metadata
Assignees
Labels
No labels