diff --git a/pkg/gocui/doc.go b/pkg/gocui/doc.go index b2f8250b1..cd5416da9 100644 --- a/pkg/gocui/doc.go +++ b/pkg/gocui/doc.go @@ -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 } diff --git a/pkg/gocui/gui.go b/pkg/gocui/gui.go index 644045572..dded5dd4a 100644 --- a/pkg/gocui/gui.go +++ b/pkg/gocui/gui.go @@ -544,13 +544,8 @@ 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 } diff --git a/pkg/gocui/keybinding.go b/pkg/gocui/keybinding.go index b80cb5df6..85707a292 100644 --- a/pkg/gocui/keybinding.go +++ b/pkg/gocui/keybinding.go @@ -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 diff --git a/pkg/gui/controllers/global_controller.go b/pkg/gui/controllers/global_controller.go index 079ad24b5..d7f18fcb4 100644 --- a/pkg/gui/controllers/global_controller.go +++ b/pkg/gui/controllers/global_controller.go @@ -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 { diff --git a/pkg/gui/controllers/jump_to_side_window_controller.go b/pkg/gui/controllers/jump_to_side_window_controller.go index 25eb2c137..6a08e3758 100644 --- a/pkg/gui/controllers/jump_to_side_window_controller.go +++ b/pkg/gui/controllers/jump_to_side_window_controller.go @@ -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)), } }) } diff --git a/pkg/gui/controllers/search_prompt_controller.go b/pkg/gui/controllers/search_prompt_controller.go index e141ca42a..d5c2f5c3c 100644 --- a/pkg/gui/controllers/search_prompt_controller.go +++ b/pkg/gui/controllers/search_prompt_controller.go @@ -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, }, } } diff --git a/pkg/gui/controllers/side_window_controller.go b/pkg/gui/controllers/side_window_controller.go index ddf0f97bd..94706eb8f 100644 --- a/pkg/gui/controllers/side_window_controller.go +++ b/pkg/gui/controllers/side_window_controller.go @@ -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}, } } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 74e68d818..082d99ecc 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -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 { diff --git a/pkg/gui/services/custom_commands/client.go b/pkg/gui/services/custom_commands/client.go index d1479d7c8..4b927cf68 100644 --- a/pkg/gui/services/custom_commands/client.go +++ b/pkg/gui/services/custom_commands/client.go @@ -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, diff --git a/pkg/gui/services/custom_commands/keybinding_creator.go b/pkg/gui/services/custom_commands/keybinding_creator.go index a89beb287..644e6af45 100644 --- a/pkg/gui/services/custom_commands/keybinding_creator.go +++ b/pkg/gui/services/custom_commands/keybinding_creator.go @@ -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(), } diff --git a/pkg/gui/types/keybindings.go b/pkg/gui/types/keybindings.go index cc5fa2cf5..63079ccc7 100644 --- a/pkg/gui/types/keybindings.go +++ b/pkg/gui/types/keybindings.go @@ -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. diff --git a/pkg/integration/clients/tui.go b/pkg/integration/clients/tui.go index 90f02cc32..c4f8f94ab 100644 --- a/pkg/integration/clients/tui.go +++ b/pkg/integration/clients/tui.go @@ -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 {