mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-10-08 22:52:12 +02:00
In all other menus besides the keybindings menu it makes sense to hide
keybindings that match the confirmMenu binding. This is important to make it
clear which action will be triggered when you press the key.
In the keybindings menu this is different; the main purpose of that menu is not
to allow triggering commands by their key while the menu is open, but to serve
as a reference for what the keybindings are when it is not open. Because of
this, it is more important to show all bindings in this menu, even if they
conflict with the confirmMenu key.
This fixes a regression introduced in b3a3410a1a
.
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
|
)
|
|
|
|
// note: items option is mutated by this function
|
|
func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
|
|
if !opts.HideCancel {
|
|
// this is mutative but I'm okay with that for now
|
|
opts.Items = append(opts.Items, &types.MenuItem{
|
|
LabelColumns: []string{gui.c.Tr.Cancel},
|
|
OnPress: func() error {
|
|
return nil
|
|
},
|
|
})
|
|
}
|
|
|
|
maxColumnSize := 1
|
|
confirmKey := keybindings.GetKey(gui.c.UserConfig().Keybinding.Universal.ConfirmMenu)
|
|
|
|
for _, item := range opts.Items {
|
|
if item.LabelColumns == nil {
|
|
item.LabelColumns = []string{item.Label}
|
|
}
|
|
|
|
if item.OpensMenu {
|
|
item.LabelColumns[0] = fmt.Sprintf("%s...", item.LabelColumns[0])
|
|
}
|
|
|
|
maxColumnSize = max(maxColumnSize, len(item.LabelColumns))
|
|
|
|
// Remove all item keybindings that are the same as the confirm binding
|
|
if item.Key == confirmKey && !opts.KeepConfirmKeybindings {
|
|
item.Key = nil
|
|
}
|
|
}
|
|
|
|
for _, item := range opts.Items {
|
|
if len(item.LabelColumns) < maxColumnSize {
|
|
// we require that each item has the same number of columns so we're padding out with blank strings
|
|
// if this item has too few
|
|
item.LabelColumns = append(item.LabelColumns, make([]string, maxColumnSize-len(item.LabelColumns))...)
|
|
}
|
|
}
|
|
|
|
gui.State.Contexts.Menu.SetMenuItems(opts.Items, opts.ColumnAlignment)
|
|
gui.State.Contexts.Menu.SetPrompt(opts.Prompt)
|
|
gui.State.Contexts.Menu.SetAllowFilteringKeybindings(opts.AllowFilteringKeybindings)
|
|
gui.State.Contexts.Menu.SetSelection(0)
|
|
|
|
gui.Views.Menu.Title = opts.Title
|
|
gui.Views.Menu.FgColor = theme.GocuiDefaultTextColor
|
|
|
|
gui.Views.Tooltip.Wrap = true
|
|
gui.Views.Tooltip.FgColor = theme.GocuiDefaultTextColor
|
|
gui.Views.Tooltip.Visible = true
|
|
|
|
// resetting keybindings so that the menu-specific keybindings are registered
|
|
if err := gui.resetKeybindings(); err != nil {
|
|
return err
|
|
}
|
|
|
|
gui.c.PostRefreshUpdate(gui.State.Contexts.Menu)
|
|
|
|
// TODO: ensure that if we're opened a menu from within a menu that it renders correctly
|
|
gui.c.Context().Push(gui.State.Contexts.Menu, types.OnFocusOpts{})
|
|
return nil
|
|
}
|