diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-09-25 15:34:15 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-09-25 16:37:59 +1000 |
commit | c74448f00ddcfc8327bcd4f9d37281015899000f (patch) | |
tree | a5c56172c3760d74dee6b51ab87db9630ba1e28b /pkg/gui | |
parent | 41ab7c44a06c128c993fc69a6a4b421b5e2e9405 (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/gui')
-rw-r--r-- | pkg/gui/context/search_trait.go | 40 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/search_helper.go | 3 | ||||
-rw-r--r-- | pkg/gui/types/context.go | 1 |
3 files changed, 27 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 { |