diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-08-17 16:27:38 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-08-21 08:10:28 +0200 |
commit | 125d4fa9dc31931d2ff752316449b0a3a7a6d8df (patch) | |
tree | 4995f3c3b621cc8916ba064271b66448c6dcd9f2 | |
parent | 527a1596f3afa8a43659a518147bf10107e7ee47 (diff) |
Pass UserConfig to checkScrollUp/Down instead of just the scrollOffMargin
This will allow us to add a scrollOffEnabled config and have the functions
respect it without changes to clients.
-rw-r--r-- | pkg/gui/controllers/list_controller.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/patch_explorer_controller.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/scroll_off_margin.go | 9 |
3 files changed, 9 insertions, 8 deletions
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) } |