mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-28 10:15:32 -05:00
When scrolling a lazy-loaded view (a diff in the main view, the command log, etc.), we top up the view's line buffer by reading more lines from the still-running task. This was driven by asking the task to read a fixed number of *additional* lines on every scroll event, which had two problems: - It was decoupled from the scroll position. Scrolling down, back up, and down again re-read lines that had already been read, so the buffer crept towards the end of the input regardless of where the user actually scrolled. - A single wheel notch only bought a single notch worth of runway, so fast scrolling constantly outran the reader and had to wait for the next read (and re-render) on every notch. Make ReadLines take an absolute target total instead of a delta: the task tracks how many lines it has read and only reads the shortfall, so requests are idempotent. Callers now ask to fill the viewport at the current scroll position plus a few screenfuls of read-ahead, which gives scrolling enough runway to stay smooth. The four call sites all wanted the same "fill this view" computation, so consolidate them into a single ReadLinesToFillView helper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/gocui"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
// 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 {
|
|
c *ControllerCommon
|
|
}
|
|
|
|
func NewVerticalScrollControllerFactory(c *ControllerCommon) *VerticalScrollControllerFactory {
|
|
return &VerticalScrollControllerFactory{
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
func (self *VerticalScrollControllerFactory) Create(context types.Context) types.IController {
|
|
return &VerticalScrollController{
|
|
baseController: baseController{},
|
|
c: self.c,
|
|
context: context,
|
|
}
|
|
}
|
|
|
|
type VerticalScrollController struct {
|
|
baseController
|
|
c *ControllerCommon
|
|
|
|
context types.Context
|
|
}
|
|
|
|
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 {
|
|
self.context.GetViewTrait().ScrollDown(self.c.UserConfig().Gui.ScrollHeight)
|
|
self.c.ReadLinesToFillView(self.context.GetView())
|
|
|
|
return nil
|
|
}
|