From 07a9b9204eced8a26f24af3ad022e869a5632f88 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Sat, 4 Jan 2020 12:54:48 -0500 Subject: Don't select completions until tab has been pressed Before, pressing when completions were visible would execute the selected completion. As soon as completions were provided, the first item would be selected. This could cause issues e.g. when changing folders: :cf Previously, this would have selected the first folder in the list. Now, since , , etc have not been pressed to select the first completion, the command above simply executes `:cf `. To accomplish this, a "no-op completion" has been added at index -1. --- lib/ui/textinput.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib/ui') diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index de7557a..b0af21f 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -276,7 +276,7 @@ func (ti *TextInput) updateCompletions() { func (ti *TextInput) showCompletions() { ti.completions = ti.tabcomplete(ti.StringLeft()) - ti.completeIndex = 0 + ti.completeIndex = -1 ti.Invalidate() } @@ -410,7 +410,7 @@ func (c *completions) next() { idx := c.idx idx++ if idx > len(c.options)-1 { - idx = 0 + idx = -1 } c.onSelect(idx) } @@ -418,7 +418,7 @@ func (c *completions) next() { func (c *completions) prev() { idx := c.idx idx-- - if idx < 0 { + if idx < -1 { idx = len(c.options) - 1 } c.onSelect(idx) @@ -429,7 +429,7 @@ func (c *completions) Event(e tcell.Event) bool { case *tcell.EventKey: switch e.Key() { case tcell.KeyTab: - if len(c.options) == 1 { + if len(c.options) == 1 && c.idx >= 0 { c.onExec() } else { stem := findStem(c.options) @@ -447,8 +447,10 @@ func (c *completions) Event(e tcell.Event) bool { c.prev() return true case tcell.KeyEnter: - c.onExec() - return true + if c.idx >= 0 { + c.onExec() + return true + } } } return false -- cgit v1.2.3