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
|
package context
|
||||||
|
|
||||||
|
import "github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
|
|
||||||
type FilteredListViewModel[T HasID] struct {
|
type FilteredListViewModel[T HasID] struct {
|
||||||
*FilteredList[T]
|
*FilteredList[T]
|
||||||
*ListViewModel[T]
|
*ListViewModel[T]
|
||||||
@@ -33,3 +35,8 @@ func (self *FilteredListViewModel[T]) ClearFilter() {
|
|||||||
|
|
||||||
self.SetSelection(unfilteredIndex)
|
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/keybindings"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
@@ -238,3 +239,11 @@ func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error {
|
|||||||
func (self *MenuContext) RangeSelectEnabled() bool {
|
func (self *MenuContext) RangeSelectEnabled() bool {
|
||||||
return false
|
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
|
state.Context = context
|
||||||
|
|
||||||
self.searchPrefixView().SetContent(self.c.Tr.FilterPrefix)
|
self.searchPrefixView().SetContent(context.FilterPrefix(self.c.Tr))
|
||||||
promptView := self.promptView()
|
promptView := self.promptView()
|
||||||
promptView.ClearTextArea()
|
promptView.ClearTextArea()
|
||||||
self.OnPromptContentChanged("")
|
self.OnPromptContentChanged("")
|
||||||
@@ -69,7 +69,7 @@ func (self *SearchHelper) DisplayFilterStatus(context types.IFilterableContext)
|
|||||||
state.Context = context
|
state.Context = context
|
||||||
searchString := context.GetFilter()
|
searchString := context.GetFilter()
|
||||||
|
|
||||||
self.searchPrefixView().SetContent(self.c.Tr.FilterPrefix)
|
self.searchPrefixView().SetContent(context.FilterPrefix(self.c.Tr))
|
||||||
|
|
||||||
promptView := self.promptView()
|
promptView := self.promptView()
|
||||||
keybindingConfig := self.c.UserConfig().Keybinding
|
keybindingConfig := self.c.UserConfig().Keybinding
|
||||||
|
@@ -79,10 +79,10 @@ func (self *WindowArrangementHelper) GetWindowDimensions(informationStr string,
|
|||||||
repoState := self.c.State().GetRepoState()
|
repoState := self.c.State().GetRepoState()
|
||||||
|
|
||||||
var searchPrefix string
|
var searchPrefix string
|
||||||
if repoState.GetSearchState().SearchType() == types.SearchTypeSearch {
|
if filterableContext, ok := repoState.GetSearchState().Context.(types.IFilterableContext); ok {
|
||||||
searchPrefix = self.c.Tr.SearchPrefix
|
searchPrefix = filterableContext.FilterPrefix(self.c.Tr)
|
||||||
} else {
|
} else {
|
||||||
searchPrefix = self.c.Tr.FilterPrefix
|
searchPrefix = self.c.Tr.SearchPrefix
|
||||||
}
|
}
|
||||||
|
|
||||||
args := WindowArrangementArgs{
|
args := WindowArrangementArgs{
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/sasha-s/go-deadlock"
|
"github.com/sasha-s/go-deadlock"
|
||||||
)
|
)
|
||||||
@@ -130,6 +131,7 @@ type IFilterableContext interface {
|
|||||||
ReApplyFilter(bool)
|
ReApplyFilter(bool)
|
||||||
IsFiltering() bool
|
IsFiltering() bool
|
||||||
IsFilterableContext()
|
IsFilterableContext()
|
||||||
|
FilterPrefix(tr *i18n.TranslationSet) string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ISearchableContext interface {
|
type ISearchableContext interface {
|
||||||
|
@@ -816,6 +816,7 @@ type TranslationSet struct {
|
|||||||
SearchKeybindings string
|
SearchKeybindings string
|
||||||
SearchPrefix string
|
SearchPrefix string
|
||||||
FilterPrefix string
|
FilterPrefix string
|
||||||
|
FilterPrefixMenu string
|
||||||
ExitSearchMode string
|
ExitSearchMode string
|
||||||
ExitTextFilterMode string
|
ExitTextFilterMode string
|
||||||
Switch string
|
Switch string
|
||||||
@@ -1881,6 +1882,7 @@ func EnglishTranslationSet() *TranslationSet {
|
|||||||
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: ",
|
||||||
FilterPrefix: "Filter: ",
|
FilterPrefix: "Filter: ",
|
||||||
|
FilterPrefixMenu: "Filter (prepend '@' to filter keybindings): ",
|
||||||
WorktreesTitle: "Worktrees",
|
WorktreesTitle: "Worktrees",
|
||||||
WorktreeTitle: "Worktree",
|
WorktreeTitle: "Worktree",
|
||||||
Switch: "Switch",
|
Switch: "Switch",
|
||||||
|
Reference in New Issue
Block a user