From 734f11d61b14a60e088cb6707637ca3413f36903 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sun, 9 Apr 2023 21:23:43 +1000 Subject: [PATCH] Simplify edge calculation when scrolling down (#1194) * Simplify edge calculation when scrolling down * Alternate implementation * Alternate implementation #2 --- nav.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nav.go b/nav.go index d8254914..54ac2e38 100644 --- a/nav.go +++ b/nav.go @@ -925,11 +925,13 @@ func (nav *nav) down(dist int) bool { dir.ind = min(maxind, dir.ind) dir.pos += dist - edge := min(min(nav.height/2, gOpts.scrolloff), maxind-dir.ind) - - // use a smaller value when the height is even and scrolloff is maxed - // in order to stay at the same row as much as possible while up/down - edge = min(edge, nav.height/2+nav.height%2-1) + // use a smaller value for half when the height is even and scrolloff is + // maxed in order to stay at the same row while scrolling up and down + half := nav.height / 2 + if nav.height%2 == 0 { + half-- + } + edge := min(min(half, gOpts.scrolloff), maxind-dir.ind) dir.pos = min(dir.pos, nav.height-edge-1) dir.pos = min(dir.pos, maxind)