mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-23 22:24:51 +02:00
Start on supporting auto-suggestions when checking out a branch
switch to other fuzzy package with no dependencies
This commit is contained in:
28
pkg/utils/fuzzy_search.go
Normal file
28
pkg/utils/fuzzy_search.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user