From 7e3b24d496bef10b86b0a8bf73d33ef623746da8 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 21 Dec 2025 11:22:02 +0100 Subject: [PATCH] In menus, remove not just the confirm binding, but also esc and up/down This is not really super important because we are very unlikely to assign a key such as esc or up/down to a menu item. However, users might do this in a custom commands menu, and in that case it is important that the builtin keys still work; or they might remap those builtin commands to other keys, in which case they might conflict with single-letter keys in normal menus. --- pkg/gui/menu_panel.go | 13 ++++++++++--- ...tom_commands_submenu_with_special_keybindings.go | 6 ------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index 324c171c0..da1f45d09 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -6,6 +6,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/theme" + "github.com/samber/lo" ) // note: items option is mutated by this function @@ -21,7 +22,13 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error { } maxColumnSize := 1 - confirmKey := keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.ConfirmMenu) + + essentialKeys := []types.Key{ + keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.ConfirmMenu), + keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.Return), + keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.PrevItem), + keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.NextItem), + } for _, item := range opts.Items { if item.LabelColumns == nil { @@ -34,8 +41,8 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error { maxColumnSize = max(maxColumnSize, len(item.LabelColumns)) - // Remove all item keybindings that are the same as the confirm binding - if item.Key == confirmKey && !opts.KeepConfirmKeybindings { + // Remove all item keybindings that are the same as one of the essential bindings + if !opts.KeepConfirmKeybindings && lo.Contains(essentialKeys, item.Key) { item.Key = nil } } diff --git a/pkg/integration/tests/custom_commands/custom_commands_submenu_with_special_keybindings.go b/pkg/integration/tests/custom_commands/custom_commands_submenu_with_special_keybindings.go index cc23b297d..7790a3785 100644 --- a/pkg/integration/tests/custom_commands/custom_commands_submenu_with_special_keybindings.go +++ b/pkg/integration/tests/custom_commands/custom_commands_submenu_with_special_keybindings.go @@ -54,16 +54,10 @@ var CustomCommandsSubmenuWithSpecialKeybindings = NewIntegrationTest(NewIntegrat t.ExpectPopup().Menu(). Title(Equals("My Custom Commands")). Lines( - /* EXPECTED: Contains("j echo j"), Contains("H echo H"), Contains(" echo y"), Contains(" echo down"), - ACTUAL: */ - Contains("j echo j"), - Contains("H echo H"), - Contains(" echo y"), - Contains(" echo down"), ) t.GlobalPress("j") /* EXPECTED: