aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--config/aerc.conf6
-rw-r--r--config/config.go2
-rw-r--r--doc/aerc-config.5.scd6
-rw-r--r--lib/ui/textinput.go10
-rw-r--r--widgets/compose.go18
-rw-r--r--widgets/exline.go18
6 files changed, 52 insertions, 8 deletions
diff --git a/config/aerc.conf b/config/aerc.conf
index e290525c..688f2ca1 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -169,6 +169,12 @@ styleset-name=default
# Default: 250ms
completion-delay=250ms
+# The minimum required characters to allow auto-completion to be triggered after
+# completion-delay.
+#
+# Default: 1
+#completion-min-chars=1
+
#
# Global switch for completion popovers
#
diff --git a/config/config.go b/config/config.go
index a15e1d51..5e5b49bc 100644
--- a/config/config.go
+++ b/config/config.go
@@ -71,6 +71,7 @@ type UIConfig struct {
Sort []string `delim:" "`
NextMessageOnDelete bool `ini:"next-message-on-delete"`
CompletionDelay time.Duration `ini:"completion-delay"`
+ CompletionMinChars int `ini:"completion-min-chars"`
CompletionPopovers bool `ini:"completion-popovers"`
StyleSetDirs []string `ini:"stylesets-dirs" delim:":"`
StyleSetName string `ini:"styleset-name"`
@@ -811,6 +812,7 @@ func LoadConfigFromFile(root *string, accts []string) (*AercConfig, error) {
DirListDelay: 200 * time.Millisecond,
NextMessageOnDelete: true,
CompletionDelay: 250 * time.Millisecond,
+ CompletionMinChars: 1,
CompletionPopovers: true,
StyleSetDirs: []string{},
StyleSetName: "default",
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 94dfb593..5483ee93 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -256,6 +256,12 @@ These options are configured in the *[ui]* section of aerc.conf.
Default: 250ms
+*completion-min-chars*
+ The minimum required characters to allow auto-completion to be triggered
+ after *completion-delay*.
+
+ Default: 1
+
*border-char-vertical*
*border-char-horizontal*
Set stylable characters (via the 'border' element) for vertical and
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 {
diff --git a/widgets/compose.go b/widgets/compose.go
index 6e34365a..14a75bb6 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -214,7 +214,11 @@ func (c *Composer) buildComposeHeader(aerc *Aerc, cmpl *completer.Completer) {
c.layout[i][j] = h // normalize to lowercase
e := newHeaderEditor(h, c.header, uiConfig)
if aerc.conf.Ui.CompletionPopovers {
- e.input.TabComplete(cmpl.ForHeader(h), uiConfig.CompletionDelay)
+ e.input.TabComplete(
+ cmpl.ForHeader(h),
+ uiConfig.CompletionDelay,
+ uiConfig.CompletionMinChars,
+ )
}
c.editors[h] = e
switch h {
@@ -233,7 +237,11 @@ func (c *Composer) buildComposeHeader(aerc *Aerc, cmpl *completer.Completer) {
if _, ok := c.editors[h]; !ok {
e := newHeaderEditor(h, c.header, uiConfig)
if aerc.conf.Ui.CompletionPopovers {
- e.input.TabComplete(cmpl.ForHeader(h), uiConfig.CompletionDelay)
+ e.input.TabComplete(
+ cmpl.ForHeader(h),
+ uiConfig.CompletionDelay,
+ uiConfig.CompletionMinChars,
+ )
}
c.editors[h] = e
c.focusable = append(c.focusable, e)
@@ -1005,7 +1013,11 @@ func (c *Composer) AddEditor(header string, value string, appendHeader bool) {
uiConfig := c.acct.UiConfig()
e := newHeaderEditor(header, c.header, uiConfig)
if uiConfig.CompletionPopovers {
- e.input.TabComplete(c.completer.ForHeader(header), uiConfig.CompletionDelay)
+ e.input.TabComplete(
+ c.completer.ForHeader(header),
+ uiConfig.CompletionDelay,
+ uiConfig.CompletionMinChars,
+ )
}
c.editors[header] = e
c.layout = append(c.layout, []string{header})
diff --git a/widgets/exline.go b/widgets/exline.go
index 789ccde8..5cf4338d 100644
--- a/widgets/exline.go
+++ b/widgets/exline.go
@@ -23,7 +23,11 @@ func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), fin
) *ExLine {
input := ui.NewTextInput("", &conf.Ui).Prompt(":").Set(cmd)
if conf.Ui.CompletionPopovers {
- input.TabComplete(tabcomplete, conf.Ui.CompletionDelay)
+ input.TabComplete(
+ tabcomplete,
+ conf.Ui.CompletionDelay,
+ conf.Ui.CompletionMinChars,
+ )
}
exline := &ExLine{
commit: commit,
@@ -37,7 +41,11 @@ func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), fin
}
func (x *ExLine) TabComplete(tabComplete func(string) ([]string, string)) {
- x.input.TabComplete(tabComplete, x.conf.Ui.CompletionDelay)
+ x.input.TabComplete(
+ tabComplete,
+ x.conf.Ui.CompletionDelay,
+ x.conf.Ui.CompletionMinChars,
+ )
}
func NewPrompt(conf *config.AercConfig, prompt string, commit func(text string),
@@ -45,7 +53,11 @@ func NewPrompt(conf *config.AercConfig, prompt string, commit func(text string),
) *ExLine {
input := ui.NewTextInput("", &conf.Ui).Prompt(prompt)
if conf.Ui.CompletionPopovers {
- input.TabComplete(tabcomplete, conf.Ui.CompletionDelay)
+ input.TabComplete(
+ tabcomplete,
+ conf.Ui.CompletionDelay,
+ conf.Ui.CompletionMinChars,
+ )
}
exline := &ExLine{
commit: commit,