aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-08-12 00:51:41 +0200
committerRobin Jarry <robin@jarry.cc>2023-11-02 16:30:47 +0100
commit44a55d41ad6b5c61c75456414e13aec94b367b02 (patch)
tree8c82e4a02cda4210d39af99d63865e260f01992d /lib
parentc4e6de9d59cc534171fd0ef9fa51995e70a8b32e (diff)
downloadaerc-44a55d41ad6b5c61c75456414e13aec94b367b02.tar.gz
complete: allow setting the completion key binding
Until now, if less than complete-min-chars were entered or if completion-delay had not expired yet, the only way to force trigger completion was to press <tab>. In some cases, <tab> is already bound to another action (for example :next-field in the compose::editor context). This makes forcing the completion impossible. Allow defining a key to trigger manual completion via the new $complete special entry in binds.conf. Leave the default binding to <tab>. Set it to <C-o> in the [compose::editor] to avoid conflicting with the existing <tab> binding. Changelog-added: Customize key to trigger completion with `$complete` in `binds.conf`. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ui/textinput.go30
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index dd946aec..4b051d88 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -35,6 +35,7 @@ type TextInput struct {
completeDelay time.Duration
completeDebouncer *time.Timer
completeMinChars int
+ completeKey *config.KeyStroke
uiConfig *config.UIConfig
}
@@ -62,12 +63,12 @@ func (ti *TextInput) Prompt(prompt string) *TextInput {
func (ti *TextInput) TabComplete(
tabcomplete func(s string) ([]string, string),
- d time.Duration,
- minChars int,
+ d time.Duration, minChars int, key *config.KeyStroke,
) *TextInput {
ti.tabcomplete = tabcomplete
ti.completeDelay = d
ti.completeMinChars = minChars
+ ti.completeKey = key
return ti
}
@@ -344,55 +345,48 @@ func (ti *TextInput) Event(event tcell.Event) bool {
ti.Lock()
defer ti.Unlock()
if event, ok := event.(*tcell.EventKey); ok {
+ c := ti.completeKey
+ if c != nil && c.Key == event.Key() && c.Modifiers == event.Modifiers() {
+ ti.showCompletions()
+ return true
+ }
+
+ ti.invalidateCompletions()
+
switch event.Key() {
case tcell.KeyBackspace, tcell.KeyBackspace2:
- ti.invalidateCompletions()
ti.backspace()
case tcell.KeyCtrlD, tcell.KeyDelete:
- ti.invalidateCompletions()
ti.deleteChar()
case tcell.KeyCtrlB, tcell.KeyLeft:
- ti.invalidateCompletions()
if ti.index > 0 {
ti.index--
ti.ensureScroll()
ti.Invalidate()
}
case tcell.KeyCtrlF, tcell.KeyRight:
- ti.invalidateCompletions()
if ti.index < len(ti.text) {
ti.index++
ti.ensureScroll()
ti.Invalidate()
}
case tcell.KeyCtrlA, tcell.KeyHome:
- ti.invalidateCompletions()
ti.index = 0
ti.ensureScroll()
ti.Invalidate()
case tcell.KeyCtrlE, tcell.KeyEnd:
- ti.invalidateCompletions()
ti.index = len(ti.text)
ti.ensureScroll()
ti.Invalidate()
case tcell.KeyCtrlK:
- ti.invalidateCompletions()
ti.deleteLineForward()
case tcell.KeyCtrlW:
- ti.invalidateCompletions()
ti.deleteWord()
case tcell.KeyCtrlU:
- ti.invalidateCompletions()
ti.deleteLineBackward()
case tcell.KeyESC:
- if ti.completions != nil {
- ti.invalidateCompletions()
- ti.Invalidate()
- }
- case tcell.KeyTab:
- ti.showCompletions()
+ ti.Invalidate()
case tcell.KeyRune:
- ti.invalidateCompletions()
ti.insert(event.Rune())
}
}