1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-06-07 19:56:50 +02:00
Files
lazygit/pkg/gui/controllers/side_window_controller.go
Stefan Haller ee94e215e7 Remove dead Modifier field from keybindings
Modifiers were moved into Key in 22169e22f, but the separate Modifier field
on types.Binding and gocui.keybinding was left behind. The keypress matcher
already compares modifiers via Key.Equals, so the old field is never read on
the dispatch path; it just got passed through SetKeybinding and stored.

Drop it from gocui.keybinding, types.Binding, and the SetKeybinding /
DeleteKeybinding signatures, and remove every now-redundant Modifier:
gocui.ModNone struct field. Mouse bindings keep their own Modifier (on
ViewMouseBinding) since that path still consults it.
2026-05-06 09:51:23 +02:00

98 lines
2.6 KiB
Go

package controllers
import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type SideWindowControllerFactory struct {
c *ControllerCommon
}
func NewSideWindowControllerFactory(c *ControllerCommon) *SideWindowControllerFactory {
return &SideWindowControllerFactory{c: c}
}
func (self *SideWindowControllerFactory) Create(context types.Context) types.IController {
return NewSideWindowController(self.c, context)
}
type SideWindowController struct {
baseController
c *ControllerCommon
context types.Context
}
func NewSideWindowController(
c *ControllerCommon,
context types.Context,
) *SideWindowController {
return &SideWindowController{
baseController: baseController{},
c: c,
context: context,
}
}
func (self *SideWindowController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
return []*types.Binding{
{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},
}
}
func (self *SideWindowController) Context() types.Context {
return nil
}
func (self *SideWindowController) previousSideWindow() error {
windows := self.c.Helpers().Window.SideWindows()
currentWindow := self.c.Helpers().Window.CurrentWindow()
var newWindow string
if currentWindow == "" || currentWindow == windows[0] {
newWindow = windows[len(windows)-1]
} else {
for i := range windows {
if currentWindow == windows[i] {
newWindow = windows[i-1]
break
}
if i == len(windows)-1 {
return nil
}
}
}
context := self.c.Helpers().Window.GetContextForWindow(newWindow)
self.c.Context().Push(context, types.OnFocusOpts{})
return nil
}
func (self *SideWindowController) nextSideWindow() error {
windows := self.c.Helpers().Window.SideWindows()
currentWindow := self.c.Helpers().Window.CurrentWindow()
var newWindow string
if currentWindow == "" || currentWindow == windows[len(windows)-1] {
newWindow = windows[0]
} else {
for i := range windows {
if currentWindow == windows[i] {
newWindow = windows[i+1]
break
}
if i == len(windows)-1 {
return nil
}
}
}
context := self.c.Helpers().Window.GetContextForWindow(newWindow)
self.c.Context().Push(context, types.OnFocusOpts{})
return nil
}