From 561afa990186ce6bdf7f62ce6e0114e6430eda8b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 17 Mar 2024 09:11:00 +0100 Subject: [PATCH] Rename FuzzySearch to FilterStrings It isn't necessarily fuzzy any more. --- pkg/gui/controllers/helpers/suggestions_helper.go | 6 +++--- pkg/utils/search.go | 2 +- pkg/utils/search_test.go | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/gui/controllers/helpers/suggestions_helper.go b/pkg/gui/controllers/helpers/suggestions_helper.go index 91f42df8c..b31a19f7a 100644 --- a/pkg/gui/controllers/helpers/suggestions_helper.go +++ b/pkg/gui/controllers/helpers/suggestions_helper.go @@ -83,7 +83,7 @@ func (self *SuggestionsHelper) GetBranchNameSuggestionsFunc() func(string) []*ty if input == "" { matchingBranchNames = branchNames } else { - matchingBranchNames = utils.FuzzySearch(input, branchNames, self.c.UserConfig.Gui.UseFuzzySearch()) + matchingBranchNames = utils.FilterStrings(input, branchNames, self.c.UserConfig.Gui.UseFuzzySearch()) } return lo.Map(matchingBranchNames, func(branchName string, _ int) *types.Suggestion { @@ -136,7 +136,7 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type }) // doing another fuzzy search for good measure - matchingNames = utils.FuzzySearch(input, matchingNames, true) + matchingNames = utils.FilterStrings(input, matchingNames, true) } else { substrings := strings.Fields(input) _ = self.c.Model().FilesTrie.Visit(func(prefix patricia.Prefix, item patricia.Item) error { @@ -205,7 +205,7 @@ func FuzzySearchFunc(options []string, useFuzzySearch bool) func(string) []*type if input == "" { matches = options } else { - matches = utils.FuzzySearch(input, options, useFuzzySearch) + matches = utils.FilterStrings(input, options, useFuzzySearch) } return matchesToSuggestions(matches) diff --git a/pkg/utils/search.go b/pkg/utils/search.go index 7abe8c85d..4ec26bc22 100644 --- a/pkg/utils/search.go +++ b/pkg/utils/search.go @@ -7,7 +7,7 @@ import ( "github.com/samber/lo" ) -func FuzzySearch(needle string, haystack []string, useFuzzySearch bool) []string { +func FilterStrings(needle string, haystack []string, useFuzzySearch bool) []string { if needle == "" { return []string{} } diff --git a/pkg/utils/search_test.go b/pkg/utils/search_test.go index fef10ed59..ad5dd1225 100644 --- a/pkg/utils/search_test.go +++ b/pkg/utils/search_test.go @@ -7,8 +7,7 @@ import ( "github.com/stretchr/testify/assert" ) -// TestFuzzySearch is a function. -func TestFuzzySearch(t *testing.T) { +func TestFilterStrings(t *testing.T) { type scenario struct { needle string haystack []string @@ -68,7 +67,7 @@ func TestFuzzySearch(t *testing.T) { } for _, s := range scenarios { - assert.EqualValues(t, s.expected, FuzzySearch(s.needle, s.haystack, s.useFuzzySearch)) + assert.EqualValues(t, s.expected, FilterStrings(s.needle, s.haystack, s.useFuzzySearch)) } }