From 956ba40d639052a5f0604e2ae17bafe45a842813 Mon Sep 17 00:00:00 2001 From: winhung Date: Tue, 16 Jul 2019 22:37:44 +0800 Subject: [PATCH] scrolling does not go beyond the displayed text #31 --- pkg/gui/main_panel.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pkg/gui/main_panel.go b/pkg/gui/main_panel.go index 96ddde801..561a3615e 100644 --- a/pkg/gui/main_panel.go +++ b/pkg/gui/main_panel.go @@ -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 { @@ -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 {