aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui/textinput.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-05-10 23:56:26 +0200
committerRobin Jarry <robin@jarry.cc>2023-05-16 13:41:13 +0200
commit74c6544aec2b2d7da0ba80f2e62c1b0effb50d5d (patch)
tree0089941851dfbb827e2185f11e93be032c1c6aeb /lib/ui/textinput.go
parent42cd415756bff13acd306db21eff5f4439665270 (diff)
downloadaerc-74c6544aec2b2d7da0ba80f2e62c1b0effb50d5d.tar.gz
textinput: improve stemming
Fix cursor index after stemming and reset it to the position where the completion should occur. Only stem to add more information and not remove any user input. Stemming is activated on the textinput line when the user presses the Tab key. The idea of stemming is to adjust the textinput line to the common ground (="the stem") of the completions options. When the stemmed input line is set, however, the cursor will be moved to the end of the line if there is a text part on the right side of the cursor where the completion should occur. Another Tab press will activate the onStem function again, which then removes the right part of the text input leading to the loss of the user input. This can be prevented by moving the cursor to the place of the completion after stemming. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/ui/textinput.go')
-rw-r--r--lib/ui/textinput.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index 2b23f15d..65570e8b 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -132,6 +132,7 @@ func (ti *TextInput) drawPopover(ctx *Context) {
options: ti.completions,
idx: ti.completeIndex,
stringLeft: ti.StringLeft(),
+ prefix: ti.prefix,
onSelect: func(idx int) {
ti.completeIndex = idx
ti.Invalidate()
@@ -143,6 +144,7 @@ func (ti *TextInput) drawPopover(ctx *Context) {
},
onStem: func(stem string) {
ti.Set(ti.prefix + stem + ti.StringRight())
+ ti.index = len(ti.prefix + stem)
ti.Invalidate()
},
uiConfig: ti.uiConfig,
@@ -391,6 +393,7 @@ func (ti *TextInput) Event(event tcell.Event) bool {
type completions struct {
options []string
stringLeft string
+ prefix string
idx int
onSelect func(int)
onExec func()
@@ -479,11 +482,11 @@ func (c *completions) Event(e tcell.Event) bool {
c.onExec()
} else {
stem := findStem(c.options)
- if stem != "" && stem != c.stringLeft {
+ if stem != "" && c.idx < 0 &&
+ len(stem)+len(c.prefix) > len(c.stringLeft) {
c.onStem(stem)
- } else {
- c.next()
}
+ c.next()
}
return true
case tcell.KeyCtrlN, tcell.KeyDown: