Remove modifiers from keybinding (#5588)

Followup to #5563; I forgot to do this there.
This commit is contained in:
Stefan Haller 2026-05-06 09:55:46 +02:00 committed by GitHub
commit 434abc7994
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 39 additions and 104 deletions

View file

@ -54,7 +54,7 @@ Views can also be created using relative coordinates:
Configure keybindings:
if err := g.SetKeybinding("viewname", gocui.KeyEnter, gocui.ModNone, fcn); err != nil {
if err := g.SetKeybinding("viewname", gocui.KeyEnter, fcn); err != nil {
// handle error
}
@ -64,7 +64,7 @@ gocui implements full mouse support that can be enabled with:
Mouse events are handled like any other keybinding:
if err := g.SetKeybinding("viewname", gocui.MouseLeft, gocui.ModNone, fcn); err != nil {
if err := g.SetKeybinding("viewname", gocui.MouseLeft, fcn); err != nil {
// handle error
}

View file

@ -544,28 +544,12 @@ func (g *Gui) CurrentView() *View {
// SetKeybinding creates a new keybinding. If viewname equals to ""
// (empty string) then the keybinding will apply to all views. key must
// be a rune or a Key.
//
// When mouse keys are used (MouseLeft, MouseRight, ...), modifier might not work correctly.
// It behaves differently on different platforms. Somewhere it doesn't register Alt key press,
// on others it might report Ctrl as Alt. It's not consistent and therefore it's not recommended
// to use with mouse keys.
func (g *Gui) SetKeybinding(viewname string, key Key, mod Modifier, handler func(*Gui, *View) error) error {
kb := newKeybinding(viewname, key, mod, handler)
func (g *Gui) SetKeybinding(viewname string, key Key, handler func(*Gui, *View) error) error {
kb := newKeybinding(viewname, key, handler)
g.keybindings = append(g.keybindings, kb)
return nil
}
// DeleteKeybinding deletes a keybinding.
func (g *Gui) DeleteKeybinding(viewname string, key Key, mod Modifier) error {
for i, kb := range g.keybindings {
if kb.viewName == viewname && kb.key.keyName == key.KeyName() && kb.key.str == key.str && kb.mod == mod {
g.keybindings = append(g.keybindings[:i], g.keybindings[i+1:]...)
return nil
}
}
return errors.New("keybinding not found")
}
// DeleteKeybindings deletes all keybindings of view.
func (g *Gui) DeleteAllKeybindings() {
g.keybindings = []*keybinding{}

View file

@ -19,16 +19,14 @@ type Modifier tcell.ModMask
type keybinding struct {
viewName string
key Key
mod Modifier
handler func(*Gui, *View) error
}
// newKeybinding returns a new Keybinding object.
func newKeybinding(viewname string, key Key, mod Modifier, handler func(*Gui, *View) error) (kb *keybinding) {
func newKeybinding(viewname string, key Key, handler func(*Gui, *View) error) (kb *keybinding) {
kb = &keybinding{
viewName: viewname,
key: key,
mod: mod,
handler: handler,
}
return kb

View file

@ -3,7 +3,6 @@ package controllers
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -69,7 +68,6 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
},
{
Key: opts.GetKey(opts.Config.Universal.Return),
Modifier: gocui.ModNone,
Handler: self.escape,
Description: self.c.Tr.Cancel,
DescriptionFunc: self.escapeDescription,
@ -85,7 +83,6 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.OptionMenuAlt1),
Modifier: gocui.ModNone,
// we have the description on the alt key and not the main key for legacy reasons
// (the original main key was 'x' but we've reassigned that to other purposes)
Description: self.c.Tr.OpenKeybindingsMenu,
@ -118,23 +115,19 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
},
{
Key: opts.GetKey(opts.Config.Universal.Quit),
Modifier: gocui.ModNone,
Description: self.c.Tr.Quit,
Handler: self.quit,
},
{
Key: opts.GetKey(opts.Config.Universal.QuitAlt1),
Modifier: gocui.ModNone,
Handler: self.quit,
Key: opts.GetKey(opts.Config.Universal.QuitAlt1),
Handler: self.quit,
},
{
Key: opts.GetKey(opts.Config.Universal.QuitWithoutChangingDirectory),
Modifier: gocui.ModNone,
Handler: self.quitWithoutChangingDirectory,
Key: opts.GetKey(opts.Config.Universal.QuitWithoutChangingDirectory),
Handler: self.quitWithoutChangingDirectory,
},
{
Key: opts.GetKey(opts.Config.Universal.SuspendApp),
Modifier: gocui.ModNone,
Handler: self.c.Helpers().SuspendResume.SuspendApp,
Description: self.c.Tr.SuspendApp,
GetDisabledReason: func() *types.DisabledReason {

View file

@ -3,7 +3,6 @@ package controllers
import (
"log"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
)
@ -40,9 +39,8 @@ func (self *JumpToSideWindowController) GetKeybindings(opts types.KeybindingsOpt
return &types.Binding{
ViewName: "",
// by default the keys are 1, 2, 3, etc
Key: opts.GetKey(opts.Config.Universal.JumpToBlock[index]),
Modifier: gocui.ModNone,
Handler: opts.Guards.NoPopupPanel(self.goToSideWindow(window)),
Key: opts.GetKey(opts.Config.Universal.JumpToBlock[index]),
Handler: opts.Guards.NoPopupPanel(self.goToSideWindow(window)),
}
})
}

View file

@ -24,24 +24,20 @@ func NewSearchPromptController(
func (self *SearchPromptController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
return []*types.Binding{
{
Key: gocui.NewKeyName(gocui.KeyEnter),
Modifier: gocui.ModNone,
Handler: self.confirm,
Key: gocui.NewKeyName(gocui.KeyEnter),
Handler: self.confirm,
},
{
Key: opts.GetKey(opts.Config.Universal.Return),
Modifier: gocui.ModNone,
Handler: self.cancel,
Key: opts.GetKey(opts.Config.Universal.Return),
Handler: self.cancel,
},
{
Key: opts.GetKey(opts.Config.Universal.PrevItem),
Modifier: gocui.ModNone,
Handler: self.prevHistory,
Key: opts.GetKey(opts.Config.Universal.PrevItem),
Handler: self.prevHistory,
},
{
Key: opts.GetKey(opts.Config.Universal.NextItem),
Modifier: gocui.ModNone,
Handler: self.nextHistory,
Key: opts.GetKey(opts.Config.Universal.NextItem),
Handler: self.nextHistory,
},
}
}

View file

@ -1,7 +1,6 @@
package controllers
import (
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -36,12 +35,12 @@ func NewSideWindowController(
func (self *SideWindowController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
return []*types.Binding{
{Key: opts.GetKey(opts.Config.Universal.PrevBlock), Modifier: gocui.ModNone, Handler: self.previousSideWindow},
{Key: opts.GetKey(opts.Config.Universal.NextBlock), Modifier: gocui.ModNone, Handler: self.nextSideWindow},
{Key: opts.GetKey(opts.Config.Universal.PrevBlockAlt), Modifier: gocui.ModNone, Handler: self.previousSideWindow},
{Key: opts.GetKey(opts.Config.Universal.NextBlockAlt), Modifier: gocui.ModNone, Handler: self.nextSideWindow},
{Key: opts.GetKey(opts.Config.Universal.PrevBlockAlt2), Modifier: gocui.ModNone, Handler: self.previousSideWindow},
{Key: opts.GetKey(opts.Config.Universal.NextBlockAlt2), Modifier: gocui.ModNone, Handler: self.nextSideWindow},
{Key: opts.GetKey(opts.Config.Universal.PrevBlock), Handler: self.previousSideWindow},
{Key: opts.GetKey(opts.Config.Universal.NextBlock), Handler: self.nextSideWindow},
{Key: opts.GetKey(opts.Config.Universal.PrevBlockAlt), Handler: self.previousSideWindow},
{Key: opts.GetKey(opts.Config.Universal.NextBlockAlt), Handler: self.nextSideWindow},
{Key: opts.GetKey(opts.Config.Universal.PrevBlockAlt2), Handler: self.previousSideWindow},
{Key: opts.GetKey(opts.Config.Universal.NextBlockAlt2), Handler: self.nextSideWindow},
}
}

View file

@ -102,25 +102,21 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.ScrollUpMainAlt1),
Modifier: gocui.ModNone,
Handler: gui.scrollUpMain,
},
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.ScrollDownMainAlt1),
Modifier: gocui.ModNone,
Handler: gui.scrollDownMain,
},
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.ScrollUpMainAlt2),
Modifier: gocui.ModNone,
Handler: gui.scrollUpMain,
},
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.ScrollDownMainAlt2),
Modifier: gocui.ModNone,
Handler: gui.scrollDownMain,
},
{
@ -181,7 +177,6 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin
{
ViewName: "information",
Key: gocui.NewKeyName(gocui.MouseLeft),
Modifier: gocui.ModNone,
Handler: gui.handleInfoClick,
},
{
@ -216,37 +211,31 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin
{
ViewName: "secondary",
Key: gocui.NewKeyName(gocui.MouseWheelDown),
Modifier: gocui.ModNone,
Handler: gui.scrollDownSecondary,
},
{
ViewName: "secondary",
Key: gocui.NewKeyName(gocui.MouseWheelUp),
Modifier: gocui.ModNone,
Handler: gui.scrollUpSecondary,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.PrevItem),
Modifier: gocui.ModNone,
Handler: gui.scrollUpConfirmationPanel,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.NextItem),
Modifier: gocui.ModNone,
Handler: gui.scrollDownConfirmationPanel,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.PrevItemAlt),
Modifier: gocui.ModNone,
Handler: gui.scrollUpConfirmationPanel,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.NextItemAlt),
Modifier: gocui.ModNone,
Handler: gui.scrollDownConfirmationPanel,
},
{
@ -262,37 +251,31 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.NextPage),
Modifier: gocui.ModNone,
Handler: gui.pageDownConfirmationPanel,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.PrevPage),
Modifier: gocui.ModNone,
Handler: gui.pageUpConfirmationPanel,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.GotoTop),
Modifier: gocui.ModNone,
Handler: gui.goToConfirmationPanelTop,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.GotoTopAlt),
Modifier: gocui.ModNone,
Handler: gui.goToConfirmationPanelTop,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.GotoBottom),
Modifier: gocui.ModNone,
Handler: gui.goToConfirmationPanelBottom,
},
{
ViewName: "confirmation",
Key: opts.GetKey(opts.Config.Universal.GotoBottomAlt),
Modifier: gocui.ModNone,
Handler: gui.goToConfirmationPanelBottom,
},
{
@ -316,71 +299,60 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin
ViewName: "extras",
Tag: "navigation",
Key: opts.GetKey(opts.Config.Universal.PrevItemAlt),
Modifier: gocui.ModNone,
Handler: gui.scrollUpExtra,
},
{
ViewName: "extras",
Tag: "navigation",
Key: opts.GetKey(opts.Config.Universal.PrevItem),
Modifier: gocui.ModNone,
Handler: gui.scrollUpExtra,
},
{
ViewName: "extras",
Tag: "navigation",
Key: opts.GetKey(opts.Config.Universal.NextItem),
Modifier: gocui.ModNone,
Handler: gui.scrollDownExtra,
},
{
ViewName: "extras",
Tag: "navigation",
Key: opts.GetKey(opts.Config.Universal.NextItemAlt),
Modifier: gocui.ModNone,
Handler: gui.scrollDownExtra,
},
{
ViewName: "extras",
Key: opts.GetKey(opts.Config.Universal.NextPage),
Modifier: gocui.ModNone,
Handler: gui.pageDownExtrasPanel,
},
{
ViewName: "extras",
Key: opts.GetKey(opts.Config.Universal.PrevPage),
Modifier: gocui.ModNone,
Handler: gui.pageUpExtrasPanel,
},
{
ViewName: "extras",
Key: opts.GetKey(opts.Config.Universal.GotoTop),
Modifier: gocui.ModNone,
Handler: gui.goToExtrasPanelTop,
},
{
ViewName: "extras",
Key: opts.GetKey(opts.Config.Universal.GotoTopAlt),
Modifier: gocui.ModNone,
Handler: gui.goToExtrasPanelTop,
},
{
ViewName: "extras",
Key: opts.GetKey(opts.Config.Universal.GotoBottom),
Modifier: gocui.ModNone,
Handler: gui.goToExtrasPanelBottom,
},
{
ViewName: "extras",
Key: opts.GetKey(opts.Config.Universal.GotoBottomAlt),
Modifier: gocui.ModNone,
Handler: gui.goToExtrasPanelBottom,
},
{
ViewName: "extras",
Tag: "navigation",
Key: gocui.NewKeyName(gocui.MouseLeft),
Modifier: gocui.ModNone,
Handler: gui.handleFocusCommandLog,
},
}
@ -478,7 +450,7 @@ func (gui *Gui) SetKeybinding(binding *types.Binding) error {
return gui.callKeybindingHandler(binding)
}
return gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, handler)
return gui.g.SetKeybinding(binding.ViewName, binding.Key, handler)
}
func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error {

View file

@ -2,7 +2,6 @@ package custom_commands
import (
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
@ -47,7 +46,6 @@ func (self *Client) GetCustomCommandKeybindings() ([]*types.Binding, error) {
bindings = append(bindings, &types.Binding{
ViewName: "", // custom commands menus are global; we filter the commands inside by context
Key: config.GetValidatedKeyBindingKey(customCommand.Key),
Modifier: gocui.ModNone,
Handler: handler,
Description: getCustomCommandsMenuDescription(customCommand, self.c.Tr),
OpensMenu: true,

View file

@ -5,7 +5,6 @@ import (
"strings"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@ -37,7 +36,6 @@ func (self *KeybindingCreator) call(customCommand config.CustomCommand, handler
return &types.Binding{
ViewName: viewName,
Key: config.GetValidatedKeyBindingKey(customCommand.Key),
Modifier: gocui.ModNone,
Handler: handler,
Description: customCommand.GetDescription(),
}

View file

@ -12,7 +12,6 @@ type Binding struct {
ViewName string
Handler func() error
Key gocui.Key
Modifier gocui.Modifier
Description string
// DescriptionFunc is used instead of Description if non-nil, and is useful for dynamic
// descriptions that change depending on context. Important: this must not be an expensive call.

View file

@ -43,7 +43,7 @@ func RunTUI(raceDetector bool) {
g.SetManagerFunc(app.layout)
if err := g.SetKeybinding("list", gocui.NewKeyName(gocui.KeyArrowUp), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyName(gocui.KeyArrowUp), func(*gocui.Gui, *gocui.View) error {
if app.itemIdx > 0 {
app.itemIdx--
}
@ -57,7 +57,7 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyName(gocui.KeyArrowDown), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyName(gocui.KeyArrowDown), func(*gocui.Gui, *gocui.View) error {
if app.itemIdx < len(app.filteredTests)-1 {
app.itemIdx++
}
@ -72,15 +72,15 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyStrMod("c", gocui.ModCtrl), gocui.ModNone, quit); err != nil {
if err := g.SetKeybinding("list", gocui.NewKeyStrMod("c", gocui.ModCtrl), quit); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyRune('q'), gocui.ModNone, quit); err != nil {
if err := g.SetKeybinding("list", gocui.NewKeyRune('q'), quit); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyRune('s'), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyRune('s'), func(*gocui.Gui, *gocui.View) error {
currentTest := app.getCurrentTest()
if currentTest == nil {
return nil
@ -93,7 +93,7 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyName(gocui.KeyEnter), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyName(gocui.KeyEnter), func(*gocui.Gui, *gocui.View) error {
currentTest := app.getCurrentTest()
if currentTest == nil {
return nil
@ -106,7 +106,7 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyRune('t'), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyRune('t'), func(*gocui.Gui, *gocui.View) error {
currentTest := app.getCurrentTest()
if currentTest == nil {
return nil
@ -119,7 +119,7 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyRune('d'), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyRune('d'), func(*gocui.Gui, *gocui.View) error {
currentTest := app.getCurrentTest()
if currentTest == nil {
return nil
@ -132,7 +132,7 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyRune('o'), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyRune('o'), func(*gocui.Gui, *gocui.View) error {
currentTest := app.getCurrentTest()
if currentTest == nil {
return nil
@ -148,7 +148,7 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyRune('O'), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyRune('O'), func(*gocui.Gui, *gocui.View) error {
currentTest := app.getCurrentTest()
if currentTest == nil {
return nil
@ -164,7 +164,7 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("list", gocui.NewKeyRune('/'), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("list", gocui.NewKeyRune('/'), func(*gocui.Gui, *gocui.View) error {
app.filtering = true
if _, err := g.SetCurrentView("editor"); err != nil {
return err
@ -181,7 +181,7 @@ func RunTUI(raceDetector bool) {
}
// not using the editor yet, but will use it to help filter the list
if err := g.SetKeybinding("editor", gocui.NewKeyName(gocui.KeyEsc), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("editor", gocui.NewKeyName(gocui.KeyEsc), func(*gocui.Gui, *gocui.View) error {
app.filtering = false
if _, err := g.SetCurrentView("list"); err != nil {
return err
@ -198,7 +198,7 @@ func RunTUI(raceDetector bool) {
log.Panicln(err)
}
if err := g.SetKeybinding("editor", gocui.NewKeyName(gocui.KeyEnter), gocui.ModNone, func(*gocui.Gui, *gocui.View) error {
if err := g.SetKeybinding("editor", gocui.NewKeyName(gocui.KeyEnter), func(*gocui.Gui, *gocui.View) error {
app.filtering = false
if _, err := g.SetCurrentView("list"); err != nil {