From ca3f6181d7ef20ff5b35c9778ac51efc6c764e45 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 9 Nov 2024 11:54:41 +0900 Subject: [PATCH] page-up/down: undo last up/down if items are skipped Fix #4069 --- src/terminal.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index dd3590c..2bd12f7 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -4468,13 +4468,16 @@ func (t *Terminal) Loop() error { } } - for ; linesToMove > 0; linesToMove-- { - cy := t.cy + for i := 0; i < linesToMove; i++ { + cy, offset := t.cy, t.offset t.vset(cy + direction) t.constrain() - if cy == t.cy || - direction > 0 && t.offset >= maxOffset || - direction < 0 && t.offset <= minOffset { + if cy == t.cy { + break + } + if i > 0 && (direction > 0 && t.offset > maxOffset || + direction < 0 && t.offset < minOffset) { + t.cy, t.offset = cy, offset break } }