@@ -2,6 +2,7 @@ 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"
@@ -48,11 +49,12 @@ func NewMenuContext(
4849}
4950
5051type MenuViewModel struct {
51- c * ContextCommon
52- menuItems []* types.MenuItem
53- prompt string
54- promptLines []string
55- columnAlignment []utils.Alignment
52+ c * ContextCommon
53+ menuItems []* types.MenuItem
54+ prompt string
55+ promptLines []string
56+ columnAlignment []utils.Alignment
57+ allowFilteringKeybindings bool
5658 * FilteredListViewModel [* types.MenuItem ]
5759}
5860
@@ -62,11 +64,29 @@ func NewMenuViewModel(c *ContextCommon) *MenuViewModel {
6264 c : c ,
6365 }
6466
67+ filterKeybindings := false
68+
6569 self .FilteredListViewModel = NewFilteredListViewModel (
6670 func () []* types.MenuItem { return self .menuItems },
67- func (item * types.MenuItem ) []string { return item .LabelColumns },
71+ func (item * types.MenuItem ) []string {
72+ if filterKeybindings {
73+ return []string {keybindings .LabelFromKey (item .Key )}
74+ }
75+
76+ return item .LabelColumns
77+ },
6878 )
6979
80+ self .FilteredListViewModel .SetPreprocessFilterFunc (func (filter string ) string {
81+ if self .allowFilteringKeybindings && strings .HasPrefix (filter , "@" ) {
82+ filterKeybindings = true
83+ return filter [1 :]
84+ }
85+
86+ filterKeybindings = false
87+ return filter
88+ })
89+
7090 return self
7191}
7292
@@ -92,6 +112,10 @@ func (self *MenuViewModel) SetPromptLines(promptLines []string) {
92112 self .promptLines = promptLines
93113}
94114
115+ func (self * MenuViewModel ) SetAllowFilteringKeybindings (allow bool ) {
116+ self .allowFilteringKeybindings = allow
117+ }
118+
95119// TODO: move into presentation package
96120func (self * MenuViewModel ) GetDisplayStrings (_ int , _ int ) [][]string {
97121 menuItems := self .FilteredListViewModel .GetItems ()
0 commit comments