Skip to content

Commit 9e85017

Browse files
committed
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.
1 parent 97ccb45 commit 9e85017

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pkg/gui/menu_panel.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
77
"github.com/jesseduffield/lazygit/pkg/gui/types"
88
"github.com/jesseduffield/lazygit/pkg/theme"
9+
"github.com/samber/lo"
910
)
1011

1112
// note: items option is mutated by this function
@@ -21,7 +22,13 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
2122
}
2223

2324
maxColumnSize := 1
24-
confirmKey := keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.ConfirmMenu)
25+
26+
essentialKeys := []types.Key{
27+
keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.ConfirmMenu),
28+
keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.Return),
29+
keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.PrevItem),
30+
keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.NextItem),
31+
}
2532

2633
for _, item := range opts.Items {
2734
if item.LabelColumns == nil {
@@ -34,8 +41,8 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
3441

3542
maxColumnSize = max(maxColumnSize, len(item.LabelColumns))
3643

37-
// Remove all item keybindings that are the same as the confirm binding
38-
if item.Key == confirmKey && !opts.KeepConfirmKeybindings {
44+
// Remove all item keybindings that are the same as one of the essential bindings
45+
if !opts.KeepConfirmKeybindings && lo.Contains(essentialKeys, item.Key) {
3946
item.Key = nil
4047
}
4148
}

pkg/integration/tests/custom_commands/custom_commands_submenu_with_special_keybindings.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,10 @@ var CustomCommandsSubmenuWithSpecialKeybindings = NewIntegrationTest(NewIntegrat
5454
t.ExpectPopup().Menu().
5555
Title(Equals("My Custom Commands")).
5656
Lines(
57-
/* EXPECTED:
5857
Contains("j echo j"),
5958
Contains("H echo H"),
6059
Contains(" echo y"),
6160
Contains(" echo down"),
62-
ACTUAL: */
63-
Contains("j echo j"),
64-
Contains("H echo H"),
65-
Contains(" echo y"),
66-
Contains("<down> echo down"),
6761
)
6862
t.GlobalPress("j")
6963
/* EXPECTED:

0 commit comments

Comments
 (0)