Skip to content

Commit

Permalink
scrolling does not go beyond the displayed text jesseduffield#31
Browse files Browse the repository at this point in the history
  • Loading branch information
winhung committed Jul 16, 2019
1 parent f384e57 commit 956ba40
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions pkg/gui/main_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@ func (gui *Gui) scrollDownMain(g *gocui.Gui, v *gocui.View) error {
_, sy := mainView.Size()
y += sy
}

_, sizeY := mainView.Size()
scrollCount := gui.Config.UserConfig.Gui.ScrollHeight
totalLines := mainView.LinesHeight()
if oy+sizeY >= totalLines {
if newOy := totalLines - sizeY; newOy > 0 {
oy = newOy
} else {
scrollCount = 0
}
}

// for some reason we can't work out whether we've hit the bottomq
// there is a large discrepancy in the origin's y value and the length of BufferLines
return mainView.SetOrigin(ox, oy+gui.Config.UserConfig.Gui.ScrollHeight)
return mainView.SetOrigin(ox, oy+scrollCount)
}

func (gui *Gui) scrollLeftMain(g *gocui.Gui, v *gocui.View) error {
Expand All @@ -39,7 +51,25 @@ func (gui *Gui) scrollRightMain(g *gocui.Gui, v *gocui.View) error {
mainView := gui.getMainView()
ox, oy := mainView.Origin()

return mainView.SetOrigin(ox+gui.Config.UserConfig.Gui.ScrollHeight, oy)
content := mainView.BufferLines()
var largestNumberOfCharacters int
for _, txt := range content {
if len(txt) > largestNumberOfCharacters {
largestNumberOfCharacters = len(txt)
}
}

scrollCount := gui.Config.UserConfig.Gui.ScrollHeight
sizeX, _ := mainView.Size()
if ox+sizeX >= largestNumberOfCharacters {
if largestNumberOfCharacters > sizeX {
ox = largestNumberOfCharacters - sizeX
} else {
scrollCount = 0
}
}

return mainView.SetOrigin(ox+scrollCount, oy)
}

func (gui *Gui) autoScrollMain(g *gocui.Gui, v *gocui.View) error {
Expand Down

0 comments on commit 956ba40

Please sign in to comment.