@@ -2,10 +2,12 @@ package context
22
33import (
44 "errors"
5+ "strings"
56
67 "github.com/jesseduffield/lazygit/pkg/gui/keybindings"
78 "github.com/jesseduffield/lazygit/pkg/gui/style"
89 "github.com/jesseduffield/lazygit/pkg/gui/types"
10+ "github.com/jesseduffield/lazygit/pkg/i18n"
911 "github.com/jesseduffield/lazygit/pkg/utils"
1012 "github.com/samber/lo"
1113)
@@ -48,11 +50,12 @@ func NewMenuContext(
4850}
4951
5052type MenuViewModel struct {
51- c * ContextCommon
52- menuItems []* types.MenuItem
53- prompt string
54- promptLines []string
55- columnAlignment []utils.Alignment
53+ c * ContextCommon
54+ menuItems []* types.MenuItem
55+ prompt string
56+ promptLines []string
57+ columnAlignment []utils.Alignment
58+ allowFilteringKeybindings bool
5659 * FilteredListViewModel [* types.MenuItem ]
5760}
5861
@@ -62,11 +65,29 @@ func NewMenuViewModel(c *ContextCommon) *MenuViewModel {
6265 c : c ,
6366 }
6467
68+ filterKeybindings := false
69+
6570 self .FilteredListViewModel = NewFilteredListViewModel (
6671 func () []* types.MenuItem { return self .menuItems },
67- func (item * types.MenuItem ) []string { return item .LabelColumns },
72+ func (item * types.MenuItem ) []string {
73+ if filterKeybindings {
74+ return []string {keybindings .LabelFromKey (item .Key )}
75+ }
76+
77+ return item .LabelColumns
78+ },
6879 )
6980
81+ self .FilteredListViewModel .SetPreprocessFilterFunc (func (filter string ) string {
82+ if self .allowFilteringKeybindings && strings .HasPrefix (filter , "@" ) {
83+ filterKeybindings = true
84+ return filter [1 :]
85+ }
86+
87+ filterKeybindings = false
88+ return filter
89+ })
90+
7091 return self
7192}
7293
@@ -92,6 +113,10 @@ func (self *MenuViewModel) SetPromptLines(promptLines []string) {
92113 self .promptLines = promptLines
93114}
94115
116+ func (self * MenuViewModel ) SetAllowFilteringKeybindings (allow bool ) {
117+ self .allowFilteringKeybindings = allow
118+ }
119+
95120// TODO: move into presentation package
96121func (self * MenuViewModel ) GetDisplayStrings (_ int , _ int ) [][]string {
97122 menuItems := self .FilteredListViewModel .GetItems ()
@@ -214,3 +239,11 @@ func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error {
214239func (self * MenuContext ) RangeSelectEnabled () bool {
215240 return false
216241}
242+
243+ func (self * MenuContext ) FilterPrefix (tr * i18n.TranslationSet ) string {
244+ if self .allowFilteringKeybindings {
245+ return tr .FilterPrefixMenu
246+ }
247+
248+ return self .FilteredListViewModel .FilterPrefix (tr )
249+ }
0 commit comments