about summary refs log tree commit diff stats
path: root/lib/ui
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2020-01-04 12:54:48 -0500
committerDrew DeVault <sir@cmpwn.com>2020-01-05 16:01:50 -0500
commit07a9b9204eced8a26f24af3ad022e869a5632f88 (patch)
tree10f459d08051358e71704ef513041ac56c2f5b71 /lib/ui
parentb2dc624dbff6b9028ee7ab883f817166a610c9e3 (diff)
downloadaerc-07a9b9204eced8a26f24af3ad022e869a5632f88.tar.gz
Don't select completions until tab has been pressed
Before, pressing <Enter> 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 <Enter>

Previously, this would have selected the first folder in the list. Now,
since <Tab>, <C-n>, 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.
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/textinput.go14
1 files changed, 8 insertions, 6 deletions
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