@@ -56,6 +56,7 @@ type MenuViewModel struct {
5656 promptLines []string
5757 columnAlignment []utils.Alignment
5858 allowFilteringKeybindings bool
59+ keybindingsTakePrecedence bool
5960 * FilteredListViewModel [* types.MenuItem ]
6061}
6162
@@ -117,6 +118,10 @@ func (self *MenuViewModel) SetAllowFilteringKeybindings(allow bool) {
117118 self .allowFilteringKeybindings = allow
118119}
119120
121+ func (self * MenuViewModel ) SetKeybindingsTakePrecedence (value bool ) {
122+ self .keybindingsTakePrecedence = value
123+ }
124+
120125// TODO: move into presentation package
121126func (self * MenuViewModel ) GetDisplayStrings (_ int , _ int ) [][]string {
122127 menuItems := self .FilteredListViewModel .GetItems ()
@@ -205,10 +210,19 @@ func (self *MenuContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Bin
205210 }
206211 })
207212
208- // appending because that means the menu item bindings have lower precedence.
209- // So if a basic binding is to escape from the menu, we want that to still be
210- // what happens when you press escape. This matters when we're showing the menu
211- // for all keybindings of say the files context.
213+ if self .keybindingsTakePrecedence {
214+ // This is used for all normal menus except the keybindings menu. In this case we want the
215+ // bindings of the menu items to have higher precedence than the builtin bindings; this
216+ // allows assigning a keybinding to a menu item that overrides a non-essential binding such
217+ // as 'j', 'k', 'H', 'L', etc. This is safe to do because the essential bindings such as
218+ // confirm and return have already been removed from the menu items in this case.
219+ return append (menuItemBindings , basicBindings ... )
220+ }
221+
222+ // For the keybindings menu we didn't remove the essential bindings from the menu items, because
223+ // it is important to see all bindings (as a cheat sheet for what the keys are when the menu is
224+ // not open). Therefore we want the essential bindings to have higher precedence than the menu
225+ // item bindings.
212226 return append (basicBindings , menuItemBindings ... )
213227}
214228
0 commit comments