diff --git a/pkg/gui/controllers/list_controller.go b/pkg/gui/controllers/list_controller.go index cdaea413a..6094561f4 100644 --- a/pkg/gui/controllers/list_controller.go +++ b/pkg/gui/controllers/list_controller.go @@ -83,9 +83,9 @@ func (self *ListController) handleLineChange(change int) error { // we're not constantly re-rendering the main view. if before != after { if change == -1 { - checkScrollUp(self.context.GetViewTrait(), self.c.UserConfig.Gui.ScrollOffMargin, before, after) + checkScrollUp(self.context.GetViewTrait(), self.c.UserConfig, before, after) } else if change == 1 { - checkScrollDown(self.context.GetViewTrait(), self.c.UserConfig.Gui.ScrollOffMargin, before, after) + checkScrollDown(self.context.GetViewTrait(), self.c.UserConfig, before, after) } return self.context.HandleFocus(types.OnFocusOpts{}) diff --git a/pkg/gui/controllers/patch_explorer_controller.go b/pkg/gui/controllers/patch_explorer_controller.go index 83c8633a7..6f193cf2d 100644 --- a/pkg/gui/controllers/patch_explorer_controller.go +++ b/pkg/gui/controllers/patch_explorer_controller.go @@ -164,7 +164,7 @@ func (self *PatchExplorerController) HandlePrevLine() error { after := self.context.GetState().GetSelectedLineIdx() if self.context.GetState().SelectingLine() { - checkScrollUp(self.context.GetViewTrait(), self.c.UserConfig.Gui.ScrollOffMargin, before, after) + checkScrollUp(self.context.GetViewTrait(), self.c.UserConfig, before, after) } return nil @@ -176,7 +176,7 @@ func (self *PatchExplorerController) HandleNextLine() error { after := self.context.GetState().GetSelectedLineIdx() if self.context.GetState().SelectingLine() { - checkScrollDown(self.context.GetViewTrait(), self.c.UserConfig.Gui.ScrollOffMargin, before, after) + checkScrollDown(self.context.GetViewTrait(), self.c.UserConfig, before, after) } return nil diff --git a/pkg/gui/controllers/scroll_off_margin.go b/pkg/gui/controllers/scroll_off_margin.go index 119f30090..fe3e2cfc5 100644 --- a/pkg/gui/controllers/scroll_off_margin.go +++ b/pkg/gui/controllers/scroll_off_margin.go @@ -1,17 +1,18 @@ package controllers import ( + "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" ) // To be called after pressing up-arrow; checks whether the cursor entered the // top scroll-off margin, and so the view needs to be scrolled up one line -func checkScrollUp(view types.IViewTrait, scrollOffMargin int, lineIdxBefore int, lineIdxAfter int) { +func checkScrollUp(view types.IViewTrait, userConfig *config.UserConfig, lineIdxBefore int, lineIdxAfter int) { viewPortStart, viewPortHeight := view.ViewPortYBounds() linesToScroll := calculateLinesToScrollUp( - viewPortStart, viewPortHeight, scrollOffMargin, lineIdxBefore, lineIdxAfter) + viewPortStart, viewPortHeight, userConfig.Gui.ScrollOffMargin, lineIdxBefore, lineIdxAfter) if linesToScroll != 0 { view.ScrollUp(linesToScroll) } @@ -19,11 +20,11 @@ func checkScrollUp(view types.IViewTrait, scrollOffMargin int, lineIdxBefore int // To be called after pressing down-arrow; checks whether the cursor entered the // bottom scroll-off margin, and so the view needs to be scrolled down one line -func checkScrollDown(view types.IViewTrait, scrollOffMargin int, lineIdxBefore int, lineIdxAfter int) { +func checkScrollDown(view types.IViewTrait, userConfig *config.UserConfig, lineIdxBefore int, lineIdxAfter int) { viewPortStart, viewPortHeight := view.ViewPortYBounds() linesToScroll := calculateLinesToScrollDown( - viewPortStart, viewPortHeight, scrollOffMargin, lineIdxBefore, lineIdxAfter) + viewPortStart, viewPortHeight, userConfig.Gui.ScrollOffMargin, lineIdxBefore, lineIdxAfter) if linesToScroll != 0 { view.ScrollDown(linesToScroll) }