~sircmpwn/aerc

Don't select completions until tab has been pressed v1 PROPOSED

Ben Burwell: 1
 Don't select completions until tab has been pressed

 1 files changed, 8 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/9444/mbox | git am -3
Learn more about email & git

[PATCH] Don't select completions until tab has been pressed Export this patch

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.
---
 lib/ui/textinput.go | 14 ++++++++------
 1 file 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
-- 
2.24.1
Thanks!

To git.sr.ht:~sircmpwn/aerc
   b2dc624..da6fb1a  master -> master
View this thread in the archives