Files
lazygit/pkg/gui/controllers/jump_to_side_window_controller.go
T
Stefan Haller 3ecca88bd8 Convert JumpToBlock to a list of multi-key bindings
JumpToBlock is special: each of its 5 elements is the binding for one side
window (status / files / branches / commits / stash), not an alternate for a
single command. Change the field from []string to []Keybinding so each window
slot can have alternates of its own.

The schema becomes "an array of 5 keybindings, each itself a string or array of
strings", which falls out cleanly from how the Keybinding type inlines into the
generated schema. Existing configs (a flat array of 5 strings) keep validating
because each element is unmarshalled through Keybinding's scalar-or-sequence
decoder.
2026-05-25 15:32:47 +02:00

61 lines
1.6 KiB
Go

package controllers
import (
"log"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
)
type JumpToSideWindowController struct {
baseController
c *ControllerCommon
nextTabFunc func() error
}
func NewJumpToSideWindowController(
c *ControllerCommon,
nextTabFunc func() error,
) *JumpToSideWindowController {
return &JumpToSideWindowController{
baseController: baseController{},
c: c,
nextTabFunc: nextTabFunc,
}
}
func (self *JumpToSideWindowController) Context() types.Context {
return nil
}
func (self *JumpToSideWindowController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
windows := self.c.Helpers().Window.SideWindows()
if len(opts.Config.Universal.JumpToBlock) != len(windows) {
log.Fatal("Jump to block keybindings cannot be set. Exactly 5 keybindings must be supplied.")
}
return lo.Map(windows, func(window string, index int) *types.Binding {
return &types.Binding{
ViewName: "",
// by default the keys are 1, 2, 3, etc
Keys: opts.GetKeys(opts.Config.Universal.JumpToBlock[index]),
Handler: opts.Guards.NoPopupPanel(self.goToSideWindow(window)),
}
})
}
func (self *JumpToSideWindowController) goToSideWindow(window string) func() error {
return func() error {
sideWindowAlreadyActive := self.c.Helpers().Window.CurrentWindow() == window
if sideWindowAlreadyActive && self.c.UserConfig().Gui.SwitchTabsWithPanelJumpKeys {
return self.nextTabFunc()
}
context := self.c.Helpers().Window.GetContextForWindow(window)
self.c.Context().Push(context, types.OnFocusOpts{})
return nil
}
}