From de2a82625b639ee461e19d33f105ba6356665f2a Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sat, 18 Nov 2023 23:35:16 +1100 Subject: [PATCH] Fix `low`/`high` crash for big `scrolloff` values --- nav.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nav.go b/nav.go index f748619c..162a5bd0 100644 --- a/nav.go +++ b/nav.go @@ -1144,7 +1144,7 @@ func (nav *nav) high() bool { old := dir.ind beg := max(dir.ind-dir.pos, 0) - offs := gOpts.scrolloff + offs := min(nav.height/2, gOpts.scrolloff) if beg == 0 { offs = 0 } @@ -1175,7 +1175,14 @@ func (nav *nav) low() bool { old := dir.ind beg := max(dir.ind-dir.pos, 0) end := min(beg+nav.height, len(dir.files)) - offs := gOpts.scrolloff + + offs := min(nav.height/2, gOpts.scrolloff) + // use a smaller value for half when the height is even and scrolloff is + // maxed in order to stay at the same row when using both high and low + if nav.height%2 == 0 { + offs = min(nav.height/2-1, gOpts.scrolloff) + } + if end == len(dir.files) { offs = 0 }