@@ -193,23 +193,43 @@ func (self *MenuViewModel) GetNonModelItems() []*NonModelItem {
193193}
194194
195195func (self * MenuContext ) GetKeybindings (opts types.KeybindingsOpts ) []* types.Binding {
196- basicBindings := self .ListContextTrait .GetKeybindings (opts )
197- menuItemsWithKeys := lo .Filter (self .menuItems , func (item * types.MenuItem , _ int ) bool {
198- return item .Key != nil
196+ allBindings := self .ListContextTrait .GetKeybindings (opts )
197+
198+ // Define essential keys that should always work (select, confirm, escape, and prev/next item navigation)
199+ essentialKeys := []types.Key {
200+ opts .GetKey (opts .Config .Universal .Select ),
201+ opts .GetKey (opts .Config .Universal .ConfirmMenu ),
202+ opts .GetKey (opts .Config .Universal .Return ),
203+ opts .GetKey (opts .Config .Universal .PrevItem ),
204+ opts .GetKey (opts .Config .Universal .PrevItemAlt ),
205+ opts .GetKey (opts .Config .Universal .NextItem ),
206+ opts .GetKey (opts .Config .Universal .NextItemAlt ),
207+ }
208+
209+ // Group bindings by whether they're essential or not
210+ bindingsByPriority := lo .GroupBy (allBindings , func (binding * types.Binding ) bool {
211+ return lo .Contains (essentialKeys , binding .Key )
199212 })
200213
201- menuItemBindings := lo .Map (menuItemsWithKeys , func (item * types.MenuItem , _ int ) * types.Binding {
214+ essentialBindings := bindingsByPriority [true ]
215+ navigationBindings := bindingsByPriority [false ]
216+
217+ // Create bindings for menu items
218+ menuItemBindings := lo .FilterMap (self .menuItems , func (item * types.MenuItem , _ int ) (* types.Binding , bool ) {
219+ if item .Key == nil {
220+ return nil , false
221+ }
202222 return & types.Binding {
203223 Key : item .Key ,
204224 Handler : func () error { return self .OnMenuPress (item ) },
205- }
225+ }, true
206226 })
207227
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 .
212- return append (basicBindings , menuItemBindings ... )
228+ // Precedence order: essential bindings (select/confirm/escape/up/down) have highest priority,
229+ // then menu item bindings, then other navigation bindings (page up/down/scroll/etc) have lowest priority.
230+ // This allows menu items to override non-essential navigation keys while keeping core menu
231+ // operations (like escape to close, enter to select, up/down to navigate) always available .
232+ return append (append ( essentialBindings , menuItemBindings ... ), navigationBindings ... )
213233}
214234
215235func (self * MenuContext ) OnMenuPress (selectedItem * types.MenuItem ) error {
0 commit comments