From 71a26381c056246cfb2ab43cd7fb2cbc1767b779 Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Tue, 3 Dec 2024 21:07:30 +0100 Subject: [PATCH] Fix unwanted view adjustment after page down (#3555) Fix regression introduced while implementing nano-like page up/down in commit b2dbcb3e: if the view is already at the end of the buffer and the last line is even above the bottom, i.e. there are some empty lines displayed below the last line (e.g. if we have scrolled past the last line via the mouse wheel), pressing PageDown not just moves the cursor to the last line but also unexpectedly adjusts the view so that the last line is exactly at the bottom. --- internal/action/actions.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 4599606c..2d7c474d 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -46,6 +46,14 @@ func (h *BufPane) ScrollAdjust() { h.SetView(v) } +// ScrollReachedEnd returns true if the view is at the end of the buffer, +// i.e. the last line of the buffer is in the view. +func (h *BufPane) ScrollReachedEnd() bool { + v := h.GetView() + end := h.SLocFromLoc(h.Buf.End()) + return h.Diff(v.StartLine, end) < h.BufView().Height +} + // MousePress is the event that should happen when a normal click happens // This is almost always bound to left click func (h *BufPane) MousePress(e *tcell.EventMouse) bool { @@ -1707,7 +1715,7 @@ func (h *BufPane) SelectPageDown() bool { } h.MoveCursorDown(scrollAmount) h.Cursor.SelectTo(h.Cursor.Loc) - if h.Cursor.Num == 0 { + if h.Cursor.Num == 0 && !h.ScrollReachedEnd() { h.ScrollDown(scrollAmount) h.ScrollAdjust() } @@ -1736,7 +1744,7 @@ func (h *BufPane) CursorPageDown() bool { pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64)) scrollAmount := h.BufView().Height - pageOverlap h.MoveCursorDown(scrollAmount) - if h.Cursor.Num == 0 { + if h.Cursor.Num == 0 && !h.ScrollReachedEnd() { h.ScrollDown(scrollAmount) h.ScrollAdjust() }