mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-24 19:39:16 +02:00
Allow filterable contexts to customize the filter label
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package context
|
||||
|
||||
import "github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
|
||||
type FilteredListViewModel[T HasID] struct {
|
||||
*FilteredList[T]
|
||||
*ListViewModel[T]
|
||||
@@ -33,3 +35,8 @@ func (self *FilteredListViewModel[T]) ClearFilter() {
|
||||
|
||||
self.SetSelection(unfilteredIndex)
|
||||
}
|
||||
|
||||
// Default implementation of most filterable contexts. Can be overridden if needed.
|
||||
func (self *FilteredListViewModel[T]) FilterPrefix(tr *i18n.TranslationSet) string {
|
||||
return tr.FilterPrefix
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
@@ -238,3 +239,11 @@ func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error {
|
||||
func (self *MenuContext) RangeSelectEnabled() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *MenuContext) FilterPrefix(tr *i18n.TranslationSet) string {
|
||||
if self.allowFilteringKeybindings {
|
||||
return tr.FilterPrefixMenu
|
||||
}
|
||||
|
||||
return self.FilteredListViewModel.FilterPrefix(tr)
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) err
|
||||
|
||||
state.Context = context
|
||||
|
||||
self.searchPrefixView().SetContent(self.c.Tr.FilterPrefix)
|
||||
self.searchPrefixView().SetContent(context.FilterPrefix(self.c.Tr))
|
||||
promptView := self.promptView()
|
||||
promptView.ClearTextArea()
|
||||
self.OnPromptContentChanged("")
|
||||
@@ -69,7 +69,7 @@ func (self *SearchHelper) DisplayFilterStatus(context types.IFilterableContext)
|
||||
state.Context = context
|
||||
searchString := context.GetFilter()
|
||||
|
||||
self.searchPrefixView().SetContent(self.c.Tr.FilterPrefix)
|
||||
self.searchPrefixView().SetContent(context.FilterPrefix(self.c.Tr))
|
||||
|
||||
promptView := self.promptView()
|
||||
keybindingConfig := self.c.UserConfig().Keybinding
|
||||
|
@@ -79,10 +79,10 @@ func (self *WindowArrangementHelper) GetWindowDimensions(informationStr string,
|
||||
repoState := self.c.State().GetRepoState()
|
||||
|
||||
var searchPrefix string
|
||||
if repoState.GetSearchState().SearchType() == types.SearchTypeSearch {
|
||||
searchPrefix = self.c.Tr.SearchPrefix
|
||||
if filterableContext, ok := repoState.GetSearchState().Context.(types.IFilterableContext); ok {
|
||||
searchPrefix = filterableContext.FilterPrefix(self.c.Tr)
|
||||
} else {
|
||||
searchPrefix = self.c.Tr.FilterPrefix
|
||||
searchPrefix = self.c.Tr.SearchPrefix
|
||||
}
|
||||
|
||||
args := WindowArrangementArgs{
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/sasha-s/go-deadlock"
|
||||
)
|
||||
@@ -130,6 +131,7 @@ type IFilterableContext interface {
|
||||
ReApplyFilter(bool)
|
||||
IsFiltering() bool
|
||||
IsFilterableContext()
|
||||
FilterPrefix(tr *i18n.TranslationSet) string
|
||||
}
|
||||
|
||||
type ISearchableContext interface {
|
||||
|
@@ -816,6 +816,7 @@ type TranslationSet struct {
|
||||
SearchKeybindings string
|
||||
SearchPrefix string
|
||||
FilterPrefix string
|
||||
FilterPrefixMenu string
|
||||
ExitSearchMode string
|
||||
ExitTextFilterMode string
|
||||
Switch string
|
||||
@@ -1881,6 +1882,7 @@ func EnglishTranslationSet() *TranslationSet {
|
||||
SearchKeybindings: "%s: Next match, %s: Previous match, %s: Exit search mode",
|
||||
SearchPrefix: "Search: ",
|
||||
FilterPrefix: "Filter: ",
|
||||
FilterPrefixMenu: "Filter (prepend '@' to filter keybindings): ",
|
||||
WorktreesTitle: "Worktrees",
|
||||
WorktreeTitle: "Worktree",
|
||||
Switch: "Switch",
|
||||
|
Reference in New Issue
Block a user