1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-10 04:07:18 +02:00
lazygit/pkg/gui/controllers/vertical_scroll_controller.go

83 lines
2.3 KiB
Go
Raw Normal View History

package controllers
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
2022-12-20 15:25:49 +02:00
"github.com/jesseduffield/lazygit/pkg/tasks"
)
// given we have no fields here, arguably we shouldn't even need this factory
// struct, but we're maintaining consistency with the other files.
type VerticalScrollControllerFactory struct {
2023-03-23 09:47:29 +02:00
c *ControllerCommon
2022-12-20 15:25:49 +02:00
viewBufferManagerMap *map[string]*tasks.ViewBufferManager
}
2023-03-23 09:47:29 +02:00
func NewVerticalScrollControllerFactory(c *ControllerCommon, viewBufferManagerMap *map[string]*tasks.ViewBufferManager) *VerticalScrollControllerFactory {
2022-12-20 15:25:49 +02:00
return &VerticalScrollControllerFactory{
2023-03-23 09:47:29 +02:00
c: c,
2022-12-20 15:25:49 +02:00
viewBufferManagerMap: viewBufferManagerMap,
}
}
func (self *VerticalScrollControllerFactory) Create(context types.Context) types.IController {
return &VerticalScrollController{
2022-12-20 15:25:49 +02:00
baseController: baseController{},
2023-03-23 09:47:29 +02:00
c: self.c,
2022-12-20 15:25:49 +02:00
context: context,
viewBufferManagerMap: self.viewBufferManagerMap,
}
}
type VerticalScrollController struct {
baseController
2023-03-23 09:47:29 +02:00
c *ControllerCommon
2022-12-20 15:25:49 +02:00
context types.Context
viewBufferManagerMap *map[string]*tasks.ViewBufferManager
}
func (self *VerticalScrollController) Context() types.Context {
return self.context
}
func (self *VerticalScrollController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
return []*types.Binding{}
}
func (self *VerticalScrollController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
return []*gocui.ViewMouseBinding{
{
ViewName: self.context.GetViewName(),
Key: gocui.MouseWheelUp,
Handler: func(gocui.ViewMouseBindingOpts) error {
return self.HandleScrollUp()
},
},
{
ViewName: self.context.GetViewName(),
Key: gocui.MouseWheelDown,
Handler: func(gocui.ViewMouseBindingOpts) error {
return self.HandleScrollDown()
},
},
}
}
func (self *VerticalScrollController) HandleScrollUp() error {
self.context.GetViewTrait().ScrollUp(self.c.UserConfig.Gui.ScrollHeight)
return nil
}
func (self *VerticalScrollController) HandleScrollDown() error {
2022-12-20 15:25:49 +02:00
scrollHeight := self.c.UserConfig.Gui.ScrollHeight
self.context.GetViewTrait().ScrollDown(scrollHeight)
if manager, ok := (*self.viewBufferManagerMap)[self.context.GetViewName()]; ok {
manager.ReadLines(scrollHeight)
}
return nil
}