summaryrefslogtreecommitdiff
path: root/commands/commands.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/commands.go')
-rw-r--r--commands/commands.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/commands/commands.go b/commands/commands.go
index 3777835..cb5b63b 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -121,7 +121,7 @@ func GetFolders(aerc *widgets.Aerc, args []string) []string {
return aerc.SelectedAccount().Directories().List()
}
for _, dir := range aerc.SelectedAccount().Directories().List() {
- if hasCaseSmartPrefix(dir, args[0]) {
+ if foundInString(dir, args[0], aerc.SelectedAccount().UiConfig().FuzzyFolderComplete) {
out = append(out, dir)
}
}
@@ -177,6 +177,14 @@ func GetLabels(aerc *widgets.Aerc, args []string) []string {
return out
}
+func foundInString(s, substring string, fuzzy bool) bool {
+ if fuzzy {
+ return caseInsensitiveContains(s, substring)
+ } else {
+ return hasCaseSmartPrefix(s, substring)
+ }
+}
+
// hasCaseSmartPrefix checks whether s starts with prefix, using a case
// sensitive match if and only if prefix contains upper case letters.
func hasCaseSmartPrefix(s, prefix string) bool {
@@ -186,6 +194,11 @@ func hasCaseSmartPrefix(s, prefix string) bool {
return strings.HasPrefix(strings.ToLower(s), strings.ToLower(prefix))
}
+func caseInsensitiveContains(s, substr string) bool {
+ s, substr = strings.ToUpper(s), strings.ToUpper(substr)
+ return strings.Contains(s, substr)
+}
+
func hasUpper(s string) bool {
for _, r := range s {
if unicode.IsUpper(r) {