mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
move side window actions to controllers package
This commit is contained in:
53
pkg/gui/controllers/jump_to_side_window_controller.go
Normal file
53
pkg/gui/controllers/jump_to_side_window_controller.go
Normal file
@ -0,0 +1,53 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type JumpToSideWindowController struct {
|
||||
baseController
|
||||
c *ControllerCommon
|
||||
}
|
||||
|
||||
func NewJumpToSideWindowController(
|
||||
common *ControllerCommon,
|
||||
) *JumpToSideWindowController {
|
||||
return &JumpToSideWindowController{
|
||||
baseController: baseController{},
|
||||
c: common,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
Key: opts.GetKey(opts.Config.Universal.JumpToBlock[index]),
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: self.goToSideWindow(window),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (self *JumpToSideWindowController) goToSideWindow(window string) func() error {
|
||||
return func() error {
|
||||
context := self.c.Helpers().Window.GetContextForWindow(window)
|
||||
|
||||
return self.c.PushContext(context)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user