summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-09-25 15:34:15 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-09-25 16:37:59 +1000
commitc74448f00ddcfc8327bcd4f9d37281015899000f (patch)
treea5c56172c3760d74dee6b51ab87db9630ba1e28b /pkg
parent41ab7c44a06c128c993fc69a6a4b421b5e2e9405 (diff)
Don't select current search result when showing search status
Previously there was no way to render a view's search status without also moving the cursor to the current search match. This caused issues where we wanted to display the status after leaving the view and coming back, or when beginning a new search from within the view. This commit separates the two use cases so we only move the cursor when we're actually selecting the next search match
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/context/search_trait.go40
-rw-r--r--pkg/gui/controllers/helpers/search_helper.go3
-rw-r--r--pkg/gui/types/context.go1
-rw-r--r--pkg/integration/tests/filter_and_search/new_search.go39
-rw-r--r--pkg/integration/tests/test_list.go1
5 files changed, 67 insertions, 17 deletions
diff --git a/pkg/gui/context/search_trait.go b/pkg/gui/context/search_trait.go
index 264c8217d..b8faf0757 100644
--- a/pkg/gui/context/search_trait.go
+++ b/pkg/gui/context/search_trait.go
@@ -37,20 +37,32 @@ func (self *SearchTrait) ClearSearchString() {
func (self *SearchTrait) IsSearchableContext() {}
func (self *SearchTrait) onSelectItemWrapper(innerFunc func(int) error) func(int, int, int) error {
- keybindingConfig := self.c.UserConfig.Keybinding
+ return func(selectedLineIdx int, index int, total int) error {
+ self.RenderSearchStatus(index, total)
- return func(y int, index int, total int) error {
- if total == 0 {
- self.c.SetViewContent(
- self.c.Views().Search,
- fmt.Sprintf(
- self.c.Tr.NoMatchesFor,
- self.searchString,
- theme.OptionsFgColor.Sprintf(self.c.Tr.ExitSearchMode, keybindings.Label(keybindingConfig.Universal.Return)),
- ),
- )
- return nil
+ if total != 0 {
+ if err := innerFunc(selectedLineIdx); err != nil {
+ return err
+ }
}
+
+ return nil
+ }
+}
+
+func (self *SearchTrait) RenderSearchStatus(index int, total int) {
+ keybindingConfig := self.c.UserConfig.Keybinding
+
+ if total == 0 {
+ self.c.SetViewContent(
+ self.c.Views().Search,
+ fmt.Sprintf(
+ self.c.Tr.NoMatchesFor,
+ self.searchString,
+ theme.OptionsFgColor.Sprintf(self.c.Tr.ExitSearchMode, keybindings.Label(keybindingConfig.Universal.Return)),
+ ),
+ )
+ } else {
self.c.SetViewContent(
self.c.Views().Search,
fmt.Sprintf(
@@ -66,10 +78,6 @@ func (self *SearchTrait) onSelectItemWrapper(innerFunc func(int) error) func(int
),
),
)
- if err := innerFunc(y); err != nil {
- return err
- }
- return nil
}
}
diff --git a/pkg/gui/controllers/helpers/search_helper.go b/pkg/gui/controllers/helpers/search_helper.go
index 8764337b1..c036bda3d 100644
--- a/pkg/gui/controllers/helpers/search_helper.go
+++ b/pkg/gui/controllers/helpers/search_helper.go
@@ -84,7 +84,8 @@ func (self *SearchHelper) DisplaySearchStatus(context types.ISearchableContext)
state.Context = context
self.searchPrefixView().SetContent(self.c.Tr.SearchPrefix)
- _ = context.GetView().SelectCurrentSearchResult()
+ index, totalCount := context.GetView().GetSearchStatus()
+ context.RenderSearchStatus(index, totalCount)
}
func (self *SearchHelper) searchState() *types.SearchState {
diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go
index fbc38df82..df16cf2bd 100644
--- a/pkg/gui/types/context.go
+++ b/pkg/gui/types/context.go
@@ -115,6 +115,7 @@ type ISearchableContext interface {
ClearSearchString()
IsSearching() bool
IsSearchableContext()
+ RenderSearchStatus(int, int)
}
type DiffableContext interface {
diff --git a/pkg/integration/tests/filter_and_search/new_search.go b/pkg/integration/tests/filter_and_search/new_search.go
new file mode 100644
index 000000000..9186dc085
--- /dev/null
+++ b/pkg/integration/tests/filter_and_search/new_search.go
@@ -0,0 +1,39 @@
+package filter_and_search
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+// This is a regression test to ensure https://github.com/jesseduffield/lazygit/issues/2971
+// doesn't happen again
+
+var NewSearch = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Start a new search and verify the search begins from the current cursor position, not from the current search match",
+ ExtraCmdArgs: []string{},
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ // need to create some branches, each with their own commits
+ shell.EmptyCommit("Add foo")
+ shell.EmptyCommit("Remove foo")
+ shell.EmptyCommit("Add bar")
+ shell.EmptyCommit("Remove bar")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Commits().
+ Focus().
+ Lines(
+ Contains(`Remove bar`).IsSelected(),
+ Contains(`Add bar`),
+ Contains(`Remove foo`),
+ Contains(`Add foo`),
+ ).
+ FilterOrSearch("Add").
+ SelectedLine(Contains(`Add bar`)).
+ SelectPreviousItem().
+ SelectedLine(Contains(`Remove bar`)).
+ FilterOrSearch("Remove").
+ SelectedLine(Contains(`Remove bar`))
+ },
+})
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index f3b57a5dd..89019719a 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -134,6 +134,7 @@ var tests = []*components.IntegrationTest{
filter_and_search.FilterSearchHistory,
filter_and_search.NestedFilter,
filter_and_search.NestedFilterTransient,
+ filter_and_search.NewSearch,
filter_by_path.CliArg,
filter_by_path.SelectFile,
filter_by_path.TypeFile,