Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete rendering bug? #1059

Open
alfa-alex opened this issue Nov 29, 2024 · 0 comments
Open

Autocomplete rendering bug? #1059

alfa-alex opened this issue Nov 29, 2024 · 0 comments

Comments

@alfa-alex
Copy link

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:
image

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant