1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

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.
This commit is contained in:
Stefan Haller
2023-08-17 16:27:38 +02:00
parent 527a1596f3
commit 125d4fa9dc
3 changed files with 9 additions and 8 deletions

View File

@ -83,9 +83,9 @@ func (self *ListController) handleLineChange(change int) error {
// we're not constantly re-rendering the main view. // we're not constantly re-rendering the main view.
if before != after { if before != after {
if change == -1 { 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 { } 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{}) return self.context.HandleFocus(types.OnFocusOpts{})

View File

@ -164,7 +164,7 @@ func (self *PatchExplorerController) HandlePrevLine() error {
after := self.context.GetState().GetSelectedLineIdx() after := self.context.GetState().GetSelectedLineIdx()
if self.context.GetState().SelectingLine() { 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 return nil
@ -176,7 +176,7 @@ func (self *PatchExplorerController) HandleNextLine() error {
after := self.context.GetState().GetSelectedLineIdx() after := self.context.GetState().GetSelectedLineIdx()
if self.context.GetState().SelectingLine() { 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 return nil

View File

@ -1,17 +1,18 @@
package controllers package controllers
import ( import (
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
// To be called after pressing up-arrow; checks whether the cursor entered the // 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 // 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() viewPortStart, viewPortHeight := view.ViewPortYBounds()
linesToScroll := calculateLinesToScrollUp( linesToScroll := calculateLinesToScrollUp(
viewPortStart, viewPortHeight, scrollOffMargin, lineIdxBefore, lineIdxAfter) viewPortStart, viewPortHeight, userConfig.Gui.ScrollOffMargin, lineIdxBefore, lineIdxAfter)
if linesToScroll != 0 { if linesToScroll != 0 {
view.ScrollUp(linesToScroll) 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 // 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 // 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() viewPortStart, viewPortHeight := view.ViewPortYBounds()
linesToScroll := calculateLinesToScrollDown( linesToScroll := calculateLinesToScrollDown(
viewPortStart, viewPortHeight, scrollOffMargin, lineIdxBefore, lineIdxAfter) viewPortStart, viewPortHeight, userConfig.Gui.ScrollOffMargin, lineIdxBefore, lineIdxAfter)
if linesToScroll != 0 { if linesToScroll != 0 {
view.ScrollDown(linesToScroll) view.ScrollDown(linesToScroll)
} }