aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-01-29 23:32:19 +0100
committerRobin Jarry <robin@jarry.cc>2024-01-29 23:59:23 +0100
commit4998406cce859791013880ec5f8f402007a2d1bd (patch)
treeafb25d41867db0e3fcdd5fe080cb23ed60f68a56
parent50705608bb39108ab7b6627c6a4146e66a2facf5 (diff)
downloadaerc-4998406cce859791013880ec5f8f402007a2d1bd.tar.gz
listbox: send some key events to textinput
Send some key events directly to the textinput widget when the filter line is shown. There's no need to have duplicated code in listbox and textinput for the same keys, e.g. CtrlW. This also fixes a panic when CtrlW is used on the filter line. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--app/listbox.go33
1 files changed, 13 insertions, 20 deletions
diff --git a/app/listbox.go b/app/listbox.go
index 54ced1e8..7d1a4f27 100644
--- a/app/listbox.go
+++ b/app/listbox.go
@@ -229,41 +229,34 @@ func (lb *ListBox) Invalidate() {
}
func (lb *ListBox) Event(event tcell.Event) bool {
+ showFilter := lb.showFilterField()
if event, ok := event.(*tcell.EventKey); ok {
switch event.Key() {
case tcell.KeyLeft:
+ if showFilter {
+ break
+ }
lb.moveHorizontal(-1)
lb.Invalidate()
return true
case tcell.KeyRight:
- lb.moveHorizontal(+1)
- lb.Invalidate()
- return true
- case tcell.KeyCtrlB:
- line := lb.selected[:lb.horizPos]
- fds := strings.Fields(line)
- if len(fds) > 1 {
- lb.moveHorizontal(
- strings.LastIndex(line,
- fds[len(fds)-1]) - lb.horizPos - 1)
- } else {
- lb.horizPos = 0
- }
- lb.Invalidate()
- return true
- case tcell.KeyCtrlW:
- line := lb.selected[lb.horizPos+1:]
- fds := strings.Fields(line)
- if len(fds) > 1 {
- lb.moveHorizontal(strings.Index(line, fds[1]))
+ if showFilter {
+ break
}
+ lb.moveHorizontal(+1)
lb.Invalidate()
return true
case tcell.KeyCtrlA, tcell.KeyHome:
+ if showFilter {
+ break
+ }
lb.horizPos = 0
lb.Invalidate()
return true
case tcell.KeyCtrlE, tcell.KeyEnd:
+ if showFilter {
+ break
+ }
lb.horizPos = len(lb.selected)
lb.Invalidate()
return true