From e8f99c3326f543b713cafb6420a5b9c3c9b4d50c Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 2 Apr 2021 15:25:27 +1100 Subject: [PATCH] better scroll support --- pkg/gui/global_handlers.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index a4526d46e..a76087cda 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -77,12 +77,24 @@ func (gui *Gui) scrollDownView(viewName string) error { } ox, oy := mainView.Origin() y := oy - if !gui.Config.GetUserConfig().Gui.ScrollPastBottom { + canScrollPastBottom := gui.Config.GetUserConfig().Gui.ScrollPastBottom + if !canScrollPastBottom { _, sy := mainView.Size() y += sy } scrollHeight := gui.Config.GetUserConfig().Gui.ScrollHeight - if y < mainView.LinesHeight() { + scrollableLines := mainView.ViewLinesHeight() - y + if scrollableLines > 0 { + // margin is about how many lines must still appear if you scroll + // all the way down. In practice every file ends in a newline so it will really + // just show a single line + margin := 1 + if canScrollPastBottom { + margin = 2 + } + if scrollableLines-margin < scrollHeight { + scrollHeight = scrollableLines - margin + } if err := mainView.SetOrigin(ox, oy+scrollHeight); err != nil { return err }