Skip to content

Commit

Permalink
command name matches by checking subsequence, fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
LucienZhang committed Dec 19, 2021
1 parent 96aa481 commit 4cf0185
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ Complete documentation is available at https://github.com/LucienZhang/goto`,
Items: conf.Commands,
Templates: &templates,
Searcher: func(input string, index int) bool {
// todo: check for sub sequence
name := strings.Replace(strings.ToLower(conf.Commands[index].Name), " ", "", -1)
input = strings.Replace(strings.ToLower(input), " ", "", -1)
return strings.Contains(name, input)
// This algorithm is to check if input is a subsequence of command name, case insensitively.
input = strings.ToLower(input)
name := strings.ToLower(conf.Commands[index].Name)
i, j := 0, 0
for i < len(input) && j < len(name) {
if input[i] == name[j] {
i++
}
j++
}
return i == len(input)
},
StartInSearchMode: conf.StartInSearchMode,
}
Expand Down

0 comments on commit 4cf0185

Please sign in to comment.