summaryrefslogtreecommitdiffstats
path: root/pkg/gui/controllers/jump_to_side_window_controller.go
blob: a3985968fe17ff0145a9153c9a3202b41adc2448 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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(
	c *ControllerCommon,
) *JumpToSideWindowController {
	return &JumpToSideWindowController{
		baseController: baseController{},
		c:              c,
	}
}

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)
	}
}