diff options
author | Parasrah <dev@parasrah.com> | 2022-01-06 21:54:28 -0700 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-01-07 13:54:10 +0100 |
commit | 71eda7d37c8ef38502c360b518fcbf5960497eea (patch) | |
tree | 07b9383865f65934001378f170c942242bc0f054 /lib/ui | |
parent | b19b844a6326793f078b4a03eaf63ca96528796e (diff) | |
download | aerc-master.tar.gz |
as per the discussion https://lists.sr.ht/~sircmpwn/aerc/patches/15367 this handles completions in `completer/completer.go` by enabling the completer to return a `prefix` that will be prepended to the selected completion candidate.
Diffstat (limited to 'lib/ui')
-rw-r--r-- | lib/ui/textinput.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index 9daae3a..cd31d26 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -24,8 +24,9 @@ type TextInput struct { scroll int text []rune change []func(ti *TextInput) - tabcomplete func(s string) []string + tabcomplete func(s string) ([]string, string) completions []string + prefix string completeIndex int completeDelay time.Duration completeDebouncer *time.Timer @@ -55,7 +56,7 @@ func (ti *TextInput) Prompt(prompt string) *TextInput { } func (ti *TextInput) TabComplete( - tabcomplete func(s string) []string, d time.Duration) *TextInput { + tabcomplete func(s string) ([]string, string), d time.Duration) *TextInput { ti.tabcomplete = tabcomplete ti.completeDelay = d return ti @@ -129,7 +130,7 @@ func (ti *TextInput) drawPopover(ctx *Context) { ti.Invalidate() }, onStem: func(stem string) { - ti.Set(stem + ti.StringRight()) + ti.Set(ti.prefix + stem + ti.StringRight()) ti.Invalidate() }, uiConfig: ti.uiConfig, @@ -251,7 +252,7 @@ func (ti *TextInput) backspace() { func (ti *TextInput) executeCompletion() { if len(ti.completions) > 0 { - ti.Set(ti.completions[ti.completeIndex] + ti.StringRight()) + ti.Set(ti.prefix + ti.completions[ti.completeIndex] + ti.StringRight()) } } @@ -286,7 +287,7 @@ func (ti *TextInput) showCompletions() { // no completer return } - ti.completions = ti.tabcomplete(ti.StringLeft()) + ti.completions, ti.prefix = ti.tabcomplete(ti.StringLeft()) ti.completeIndex = -1 ti.Invalidate() } |