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/util.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/util.go')
-rw-r--r-- | commands/util.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/commands/util.go b/commands/util.go index f3f9bc8..92b851a 100644 --- a/commands/util.go +++ b/commands/util.go @@ -10,6 +10,8 @@ import ( "strings" "time" + "github.com/lithammer/fuzzysearch/fuzzy" + "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -194,3 +196,21 @@ func MsgInfoFromUids(store *lib.MessageStore, uids []uint32) ([]*models.MessageI } return infos, nil } + +// FilterList takes a list of valid completions and filters it, either +// by case smart prefix, or by fuzzy matching, prepending "prefix" to each completion +func FilterList(valid []string, search, prefix string, isFuzzy bool) []string { + out := make([]string, 0) + if isFuzzy { + for _, v := range fuzzy.RankFindFold(search, valid) { + out = append(out, prefix+v.Target) + } + } else { + for _, v := range valid { + if hasCaseSmartPrefix(v, search) { + out = append(out, prefix+v) + } + } + } + return out +} |