From cded067bc3919a77b17feedd877e4590e7c95f4a Mon Sep 17 00:00:00 2001 From: Jeffas Date: Fri, 26 Jul 2019 14:29:40 +0100 Subject: Add tab completion to textinputs This adds tab completion to textinput components. They can be configured with a completion function. This function is called when the user presses . The first completion is initially shown to the user inserted into the text. Repeated presses of or cycle through the completions list. The completions list is invalidated when any other non-tab-like key is pressed. Also changed is some logic for current completion generation so that all available commands are returned when is pressed with no current text and similarly for arguments of commands. --- widgets/exline.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'widgets') diff --git a/widgets/exline.go b/widgets/exline.go index b7b4e3d..4791ae9 100644 --- a/widgets/exline.go +++ b/widgets/exline.go @@ -20,7 +20,7 @@ func NewExLine(commit func(cmd string), cancel func(), tabcomplete func(cmd string) []string, cmdHistory lib.History) *ExLine { - input := ui.NewTextInput("").Prompt(":") + input := ui.NewTextInput("").Prompt(":").TabComplete(tabcomplete) exline := &ExLine{ cancel: cancel, commit: commit, @@ -64,12 +64,6 @@ func (ex *ExLine) Event(event tcell.Event) bool { ex.input.Focus(false) ex.cmdHistory.Reset() ex.cancel() - case tcell.KeyTab: - complete := ex.tabcomplete(ex.input.StringLeft()) - if len(complete) == 1 { - ex.input.Set(complete[0] + " " + ex.input.StringRight()) - } - ex.Invalidate() default: return ex.input.Event(event) } -- cgit v1.2.3