lazygit/pkg/utils/fuzzy_search.go
Jesse Duffield da3b0bf7c8 Start on supporting auto-suggestions when checking out a branch
switch to other fuzzy package with no dependencies
2020-11-28 20:48:17 +11:00

28 lines
454 B
Go

package utils
import (
"sort"
"github.com/sahilm/fuzzy"
)
func FuzzySearch(needle string, haystack []string) []string {
if needle == "" {
return []string{}
}
myHaystack := make([]string, len(haystack))
for i := range haystack {
myHaystack[i] = haystack[i]
}
matches := fuzzy.Find(needle, haystack)
sort.Sort(matches)
result := make([]string, len(matches))
for i, match := range matches {
result[i] = match.Str
}
return result
}