Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ gui:
# Map of file extensions (including the dot) to icon properties (icon and color)
extensions: {}

# The number of lines you scroll by when scrolling the main window
# The number of lines you scroll by when scrolling the main window. When using a number between 0 and 1, scrools that percentag of a whole page.
scrollHeight: 2

# If true, allow scrolling past the bottom of the content in the main window
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ type GuiConfig struct {
// Custom icons for filenames and file extensions
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-files-icon--color
CustomIcons CustomIconsConfig `yaml:"customIcons"`
// The number of lines you scroll by when scrolling the main window
ScrollHeight int `yaml:"scrollHeight" jsonschema:"minimum=1"`
// The number of lines you scroll by when scrolling the main window. When using a number between 0 and 1, scrools that percentag of a whole page.
ScrollHeight float64 `yaml:"scrollHeight" jsonschema:"minimum=0.01"`
// If true, allow scrolling past the bottom of the content in the main window
ScrollPastBottom bool `yaml:"scrollPastBottom"`
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#scroll-off-margin
Expand Down
7 changes: 5 additions & 2 deletions pkg/gui/controllers/list_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)

type ListControllerFactory struct {
Expand Down Expand Up @@ -51,7 +52,8 @@ func (self *ListController) HandleScrollRight() error {
}

func (self *ListController) HandleScrollUp() error {
scrollHeight := self.c.UserConfig().Gui.ScrollHeight
var _, windowHeight int = self.context.GetViewTrait().ViewPortYBounds()
scrollHeight := utils.ScrollHeight(windowHeight, self.c.UserConfig().Gui.ScrollHeight)
self.context.GetViewTrait().ScrollUp(scrollHeight)
if self.context.RenderOnlyVisibleLines() {
self.context.HandleRender()
Expand All @@ -61,7 +63,8 @@ func (self *ListController) HandleScrollUp() error {
}

func (self *ListController) HandleScrollDown() error {
scrollHeight := self.c.UserConfig().Gui.ScrollHeight
var _, windowHeight int = self.context.GetViewTrait().ViewPortYBounds()
scrollHeight := utils.ScrollHeight(windowHeight, self.c.UserConfig().Gui.ScrollHeight)
self.context.GetViewTrait().ScrollDown(scrollHeight)
if self.context.RenderOnlyVisibleLines() {
self.context.HandleRender()
Expand Down
7 changes: 5 additions & 2 deletions pkg/gui/controllers/merge_conflicts_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)

type MergeConflictsController struct {
Expand Down Expand Up @@ -167,14 +168,16 @@ func (self *MergeConflictsController) GetOnFocusLost() func(types.OnFocusLostOpt

func (self *MergeConflictsController) HandleScrollUp() error {
self.context().SetUserScrolling(true)
self.context().GetViewTrait().ScrollUp(self.c.UserConfig().Gui.ScrollHeight)
_, windowHeight := self.context().GetViewTrait().ViewPortYBounds()
self.context().GetViewTrait().ScrollUp(utils.ScrollHeight(windowHeight, self.c.UserConfig().Gui.ScrollHeight))

return nil
}

func (self *MergeConflictsController) HandleScrollDown() error {
self.context().SetUserScrolling(true)
self.context().GetViewTrait().ScrollDown(self.c.UserConfig().Gui.ScrollHeight)
_, windowHeight := self.context().GetViewTrait().ViewPortYBounds()
self.context().GetViewTrait().ScrollDown(utils.ScrollHeight(windowHeight, self.c.UserConfig().Gui.ScrollHeight))

return nil
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/gui/controllers/vertical_scroll_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)

// given we have no fields here, arguably we shouldn't even need this factory
Expand Down Expand Up @@ -60,13 +61,16 @@ func (self *VerticalScrollController) GetMouseKeybindings(opts types.Keybindings
}

func (self *VerticalScrollController) HandleScrollUp() error {
self.context.GetViewTrait().ScrollUp(self.c.UserConfig().Gui.ScrollHeight)
heightInLines := self.context.GetView().Height()
scrollHeight := self.c.UserConfig().Gui.ScrollHeight
self.context.GetViewTrait().ScrollUp(utils.ScrollHeight(heightInLines, scrollHeight))

return nil
}

func (self *VerticalScrollController) HandleScrollDown() error {
scrollHeight := self.c.UserConfig().Gui.ScrollHeight
heightInLines := self.context.GetView().Height()
scrollHeight := utils.ScrollHeight(heightInLines, self.c.UserConfig().Gui.ScrollHeight)
self.context.GetViewTrait().ScrollDown(scrollHeight)

if manager := self.c.GetViewBufferManagerForView(self.context.GetView()); manager != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/global_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
const HORIZONTAL_SCROLL_FACTOR = 3

func (gui *Gui) scrollUpView(view *gocui.View) {
view.ScrollUp(gui.c.UserConfig().Gui.ScrollHeight)
view.ScrollUp(utils.ScrollHeight(view.Height(), gui.c.UserConfig().Gui.ScrollHeight))
}

func (gui *Gui) scrollDownView(view *gocui.View) {
scrollHeight := gui.c.UserConfig().Gui.ScrollHeight
scrollHeight := utils.ScrollHeight(view.Height(), gui.c.UserConfig().Gui.ScrollHeight)
view.ScrollDown(scrollHeight)

if manager := gui.getViewBufferManagerForView(view); manager != nil {
Expand Down
24 changes: 24 additions & 0 deletions pkg/utils/scroll_lines.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package utils

import "math"

// The configuration option for scrollheight uses partial pages when it is
// between (-1,1). This function calculates the scroll height based based of
// the window height.
func ScrollHeight(windowHeight int, scrollHeight float64) int {
if scrollHeight == 0 || windowHeight <= 0 {
// non-sensical value
return 2
} else if math.Abs(scrollHeight) <= 1 {
// scroll partial pages
var linesToScroll float64 = math.RoundToEven(math.Abs(scrollHeight) * float64(windowHeight))
linesToScroll = math.Max(1, linesToScroll)
if scrollHeight < 0 {
return -1 * int(linesToScroll)
} else {
return int(linesToScroll)
}
} else {
return int(math.Round(scrollHeight))
}
}
67 changes: 67 additions & 0 deletions pkg/utils/scroll_lines_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package utils

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestScrollHeight(t *testing.T) {
type scenario struct {
windowHeight int
scrollHeightFromConfig float64
expected int
}

scenarios := []scenario{
{
10,
5,
5,
},
{
1000,
-5,
-5,
},
{
10,
-5.2,
-5,
},
{
10,
0.5,
5,
},
{
12,
-0.25,
-3,
},
{
9,
0.5,
4,
},
{
9,
-0.5,
-4,
},
{
1,
-0.5,
-1,
},
{
1,
0.5,
1,
},
}

for _, s := range scenarios {
assert.EqualValues(t, s.expected, ScrollHeight(s.windowHeight, s.scrollHeightFromConfig))
}
}
6 changes: 3 additions & 3 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@
"description": "Custom icons for filenames and file extensions\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#custom-files-icon--color"
},
"scrollHeight": {
"type": "integer",
"minimum": 1,
"description": "The number of lines you scroll by when scrolling the main window",
"type": "number",
"minimum": 0.01,
"description": "The number of lines you scroll by when scrolling the main window. When using a number between 0 and 1, scrools that percentag of a whole page.",
"default": 2
},
"scrollPastBottom": {
Expand Down