From 6b0b5596dee5dda9fb367cbf8c82e52b9e6125a3 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 1 Nov 2022 12:37:16 +0100 Subject: 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 Tested-by: Tim Culverhouse --- lib/ui/textinput.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/ui/textinput.go') 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 { -- cgit