[GH-ISSUE #1059] Autocomplete rendering bug? #767

Closed
opened 2026-03-04 01:07:35 +03:00 by kerem · 1 comment
Owner

Originally created by @alfa-alex on GitHub (Nov 29, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/1059

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!

Originally created by @alfa-alex on GitHub (Nov 29, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/1059 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](https://github.com/rivo/tview/blob/master/demos/inputfield/autocomplete/main.go) demo: ```go 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](https://github.com/user-attachments/assets/26f65687-5d1b-4c11-b1f9-07e9bbeae98b) 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!
kerem closed this issue 2026-03-04 01:07:36 +03:00
Author
Owner

@rivo commented on GitHub (Mar 30, 2025):

Thanks for reporting this. The latest commit should fix this.

<!-- gh-comment-id:2764769561 --> @rivo commented on GitHub (Mar 30, 2025): Thanks for reporting this. The latest commit should fix this.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#767
No description provided.