Skip to content

Commit

Permalink
Fix unwanted view adjustment after page down (#3555)
Browse files Browse the repository at this point in the history
Fix regression introduced while implementing nano-like page up/down in
commit b2dbcb3: 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.
  • Loading branch information
dmaluka authored Dec 3, 2024
1 parent 831e31d commit 71a2638
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/action/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 71a2638

Please sign in to comment.