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/context | |
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/context')
-rw-r--r-- | pkg/gui/context/search_trait.go | 40 |
1 files changed, 24 insertions, 16 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 } } |