1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-17 12:06:38 +02:00

Show filter status similar to what we show with search

This commit is contained in:
Jesse Duffield 2023-06-03 13:50:26 +10:00
parent 13c1103815
commit 3ca1292fb4
3 changed files with 16 additions and 15 deletions

View File

@ -235,7 +235,7 @@ func (self *ContextMgr) ActivateContext(c types.Context, opts types.OnFocusOpts)
return err return err
} }
self.gui.helpers.Search.DisplaySearchInfoIfSearching(c) self.gui.helpers.Search.DisplaySearchStatusIfSearching(c)
desiredTitle := c.Title() desiredTitle := c.Title()
if desiredTitle != "" { if desiredTitle != "" {

View File

@ -1,8 +1,12 @@
package helpers package helpers
import ( import (
"fmt"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/theme"
) )
// NOTE: this helper supports both filtering and searching. Filtering is when // NOTE: this helper supports both filtering and searching. Filtering is when
@ -60,31 +64,26 @@ func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) err
return nil return nil
} }
func (self *SearchHelper) DisplayFilterPrompt(context types.IFilterableContext) { func (self *SearchHelper) DisplayFilterStatus(context types.IFilterableContext) {
state := self.searchState() state := self.searchState()
state.Context = context state.Context = context
searchString := context.GetFilter() searchString := context.GetFilter()
self.searchPrefixView().SetContent(self.c.Tr.FilterPrefix) self.searchPrefixView().SetContent(self.c.Tr.FilterPrefix)
promptView := self.promptView() promptView := self.promptView()
promptView.ClearTextArea() keybindingConfig := self.c.UserConfig.Keybinding
promptView.TextArea.TypeString(searchString) promptView.SetContent(fmt.Sprintf("matches for '%s' ", searchString) + theme.OptionsFgColor.Sprintf(self.c.Tr.ExitTextFilterMode, keybindings.Label(keybindingConfig.Universal.Return)))
promptView.RenderTextArea()
} }
func (self *SearchHelper) DisplaySearchPrompt(context types.ISearchableContext) { func (self *SearchHelper) DisplaySearchStatus(context types.ISearchableContext) {
state := self.searchState() state := self.searchState()
state.Context = context state.Context = context
searchString := context.GetSearchString()
self.searchPrefixView().SetContent(self.c.Tr.SearchPrefix)
_ = context.GetView().SelectCurrentSearchResult() _ = context.GetView().SelectCurrentSearchResult()
promptView := self.promptView()
promptView.ClearTextArea()
promptView.TextArea.TypeString(searchString)
promptView.RenderTextArea()
} }
func (self *SearchHelper) searchState() *types.SearchState { func (self *SearchHelper) searchState() *types.SearchState {
@ -199,15 +198,15 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) {
} }
} }
func (self *SearchHelper) DisplaySearchInfoIfSearching(c types.Context) { func (self *SearchHelper) DisplaySearchStatusIfSearching(c types.Context) {
if searchableContext, ok := c.(types.ISearchableContext); ok { if searchableContext, ok := c.(types.ISearchableContext); ok {
if searchableContext.IsSearching() { if searchableContext.IsSearching() {
self.DisplaySearchPrompt(searchableContext) self.DisplaySearchStatus(searchableContext)
} }
} }
if filterableContext, ok := c.(types.IFilterableContext); ok { if filterableContext, ok := c.(types.IFilterableContext); ok {
if filterableContext.IsFiltering() { if filterableContext.IsFiltering() {
self.DisplayFilterPrompt(filterableContext) self.DisplayFilterStatus(filterableContext)
} }
} }
} }

View File

@ -539,6 +539,7 @@ type TranslationSet struct {
SearchPrefix string SearchPrefix string
FilterPrefix string FilterPrefix string
ExitSearchMode string ExitSearchMode string
ExitTextFilterMode string
Actions Actions Actions Actions
Bisect Bisect Bisect Bisect
} }
@ -1226,6 +1227,7 @@ func EnglishTranslationSet() TranslationSet {
CopyPatchToClipboard: "Copy patch to clipboard", CopyPatchToClipboard: "Copy patch to clipboard",
NoMatchesFor: "No matches for '%s' %s", NoMatchesFor: "No matches for '%s' %s",
ExitSearchMode: "%s: Exit search mode", ExitSearchMode: "%s: Exit search mode",
ExitTextFilterMode: "%s: Exit filter mode",
MatchesFor: "matches for '%s' (%d of %d) %s", // lowercase because it's after other text MatchesFor: "matches for '%s' (%d of %d) %s", // lowercase because it's after other text
SearchKeybindings: "%s: Next match, %s: Previous match, %s: Exit search mode", SearchKeybindings: "%s: Next match, %s: Previous match, %s: Exit search mode",
SearchPrefix: "Search: ", SearchPrefix: "Search: ",