mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-12-24 00:21:22 +02:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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("<down> echo down"),
|
||||
)
|
||||
t.GlobalPress("j")
|
||||
/* EXPECTED:
|
||||
|
||||
Reference in New Issue
Block a user