From b46623ebef3c897e0bb20bd4dcdd0832b349f2af Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 22 Jul 2023 13:04:39 +1000 Subject: Use fuzzy search when filtering a view This adds fuzzy filtering instead of exact match filtering, which is more forgiving of typos and allows more efficiency. --- pkg/integration/components/view_driver.go | 1 + .../tests/filter_and_search/filter_fuzzy.go | 35 ++++++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 37 insertions(+) create mode 100644 pkg/integration/tests/filter_and_search/filter_fuzzy.go (limited to 'pkg/integration') diff --git a/pkg/integration/components/view_driver.go b/pkg/integration/components/view_driver.go index d1d1571c7..d3216bb91 100644 --- a/pkg/integration/components/view_driver.go +++ b/pkg/integration/components/view_driver.go @@ -539,6 +539,7 @@ func (self *ViewDriver) FilterOrSearch(text string) *ViewDriver { self.Press(self.t.keys.Universal.StartSearch). Tap(func() { self.t.ExpectSearch(). + Clear(). Type(text). Confirm() diff --git a/pkg/integration/tests/filter_and_search/filter_fuzzy.go b/pkg/integration/tests/filter_and_search/filter_fuzzy.go new file mode 100644 index 000000000..198020afa --- /dev/null +++ b/pkg/integration/tests/filter_and_search/filter_fuzzy.go @@ -0,0 +1,35 @@ +package filter_and_search + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var FilterFuzzy = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Verify that fuzzy filtering works (not just exact matches)", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.NewBranch("this-is-my-branch") + shell.EmptyCommit("first commit") + shell.NewBranch("other-branch") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Lines( + Contains(`other-branch`).IsSelected(), + Contains(`this-is-my-branch`), + ). + FilterOrSearch("timb"). // using first letters of words + Lines( + Contains(`this-is-my-branch`).IsSelected(), + ). + FilterOrSearch("brnch"). // allows missing letter + Lines( + Contains(`other-branch`).IsSelected(), + Contains(`this-is-my-branch`), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 5eab827b7..aa43dd2c1 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -98,6 +98,7 @@ var tests = []*components.IntegrationTest{ file.RememberCommitMessageAfterFail, filter_and_search.FilterCommitFiles, filter_and_search.FilterFiles, + filter_and_search.FilterFuzzy, filter_and_search.FilterMenu, filter_and_search.FilterRemoteBranches, filter_and_search.NestedFilter, -- cgit v1.2.3