aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui/textinput.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-11-01 12:37:16 +0100
committerRobin Jarry <robin@jarry.cc>2022-11-06 23:16:08 +0100
commit6b0b5596dee5dda9fb367cbf8c82e52b9e6125a3 (patch)
tree9aeabf8ce24009bbdf28829647827951f21e425e /lib/ui/textinput.go
parent14ceca320065656ea31994191f9e74d254a72e04 (diff)
downloadaerc-6b0b5596dee5dda9fb367cbf8c82e52b9e6125a3.tar.gz
auto-completion: add option to require a min number of chars
When doing address completion via commands that take a while to run, having the completion trigger even with a single character can be non-optimal. Add an option to allow requiring a minimum number of characters to actually run the completion command. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib/ui/textinput.go')
-rw-r--r--lib/ui/textinput.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index 2a8b7c73..c2acd546 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -34,6 +34,7 @@ type TextInput struct {
completeIndex int
completeDelay time.Duration
completeDebouncer *time.Timer
+ completeMinChars int
uiConfig *config.UIConfig
}
@@ -60,10 +61,13 @@ func (ti *TextInput) Prompt(prompt string) *TextInput {
}
func (ti *TextInput) TabComplete(
- tabcomplete func(s string) ([]string, string), d time.Duration,
+ tabcomplete func(s string) ([]string, string),
+ d time.Duration,
+ minChars int,
) *TextInput {
ti.tabcomplete = tabcomplete
ti.completeDelay = d
+ ti.completeMinChars = minChars
return ti
}
@@ -296,7 +300,9 @@ func (ti *TextInput) updateCompletions() {
ti.completeDebouncer = time.AfterFunc(ti.completeDelay, func() {
defer logging.PanicHandler()
ti.Lock()
- ti.showCompletions()
+ if len(ti.StringLeft()) >= ti.completeMinChars {
+ ti.showCompletions()
+ }
ti.Unlock()
})
} else {