diff options
author | kt programs <ktprograms@gmail.com> | 2022-03-06 10:58:07 +0800 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-03-07 10:18:50 +0100 |
commit | cc172970a079bb78847f2276db8bfae375cda185 (patch) | |
tree | 143f9f049d7faf01e6ab1b07aac5017c516efbb2 /commands/account/sort.go | |
parent | 55ae3d2cab8489609a1b11c169c28306730a71ea (diff) | |
download | aerc-cc172970a079bb78847f2276db8bfae375cda185.zip |
commands: implement fuzzy completion for commands and options
Change the option to enable fuzzy completion to be fuzzy-complete, since
it's no longer only used for folders
Signed-off-by: Kt Programs <ktprograms@gmail.com>
Acked-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'commands/account/sort.go')
-rw-r--r-- | commands/account/sort.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/commands/account/sort.go b/commands/account/sort.go index 89a5e38..15ecbc0 100644 --- a/commands/account/sort.go +++ b/commands/account/sort.go @@ -4,6 +4,7 @@ import ( "errors" "strings" + "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/lib/sort" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -19,6 +20,11 @@ func (Sort) Aliases() []string { } func (Sort) Complete(aerc *widgets.Aerc, args []string) []string { + acct := aerc.SelectedAccount() + if acct == nil { + return make([]string, 0) + } + supportedCriteria := []string{ "arrival", "cc", @@ -35,7 +41,7 @@ func (Sort) Complete(aerc *widgets.Aerc, args []string) []string { last := args[len(args)-1] var completions []string currentPrefix := strings.Join(args, " ") + " " - // if there is a completed criteria then suggest all again or an option + // if there is a completed criteria or option then suggest all again for _, criteria := range append(supportedCriteria, "-r") { if criteria == last { for _, criteria := range supportedCriteria { @@ -54,11 +60,8 @@ func (Sort) Complete(aerc *widgets.Aerc, args []string) []string { return []string{currentPrefix + "-r"} } // the last item is not complete - for _, criteria := range supportedCriteria { - if strings.HasPrefix(criteria, last) { - completions = append(completions, currentPrefix+criteria) - } - } + completions = commands.FilterList(supportedCriteria, last, currentPrefix, + acct.UiConfig().FuzzyComplete) return completions } |