diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-02 15:25:27 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-06 19:34:32 +1000 |
commit | e8f99c3326f543b713cafb6420a5b9c3c9b4d50c (patch) | |
tree | b2f57ecaa7becd9cc936c592dcd84466c4a78e8a /pkg/gui/global_handlers.go | |
parent | 1a5f380c00d218712dce1225d7948e3d81cda248 (diff) |
better scroll support
Diffstat (limited to 'pkg/gui/global_handlers.go')
-rw-r--r-- | pkg/gui/global_handlers.go | 16 |
1 files 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 } |