Skip to content

fix(ui): bound page scroll so paging cannot skip unrendered rows - #312

Merged
umputun merged 3 commits into
masterfrom
fix/pagedown-overshoot
Aug 10, 2026
Merged

umputun merged 3 commits into
masterfrom
fix/pagedown-overshoot

Conversation

@umputun

@umputun umputun commented Aug 10, 2026

Copy link
Copy Markdown
Owner

page down could scroll the viewport further than one page and skip rows that were never rendered.

moveDiffCursorDownBy / moveDiffCursorUpBy walk the cursor until its visual delta reaches rows, then scroll the viewport by that actual delta. One cursor step can span many rows through hunkLineHeight (wrap continuations, annotation blocks), so a tall line sitting at the page boundary made the walk overshoot: with a 5-row annotation there, the viewport advanced up to 4 rows past a full page and the tail of that annotation was scrolled past without ever being displayed. Recoverable with pgup, but nothing bounded the shift and no test caught it.

both walks now undo the step that carries the delta past rows, restoring diffCursor and cursorOnAnnotation (the only two fields the move helpers mutate) and breaking immediately.

the rollback is gated on worthRollingBack - half a page of walked budget - rather than on having moved at all. That gate matters: a block taller than the page has no selectable cursor position inside it, so rolling back to the row or two walked before it scrolls the pane by almost nothing and the next press takes the same oversized step anyway. Gating on "has moved" produced exactly that one-row collapse.

known limit, recorded in .claude/rules/gotchas.md: a single step taller than the whole page still scrolls by its full height and still skips. There is no cursor position inside such a block, so "don't skip", "cursor stays visible" and "cursor sits on a selectable line" cannot all hold. Master behaves the same way; this does not make it worse. It is also why pgdown then pgup is only exactly reversible for uniform-height content.

three tests, each verified to fail when the branch it covers is removed: the down-direction bound, the up-direction bound (previously untested - the old pgup assertion was satisfied by construction), and the no-collapse case.

umputun added 2 commits August 9, 2026 19:32
moveDiffCursorDownBy/UpBy walked the cursor until its visual delta reached
rows, then scrolled the viewport by that actual delta. One cursor step can
span many rows through hunkLineHeight (wrap continuations, annotation
blocks), so a tall line at the page boundary advanced the viewport further
than a page and skipped rows that were never displayed.

both walks now undo the step that carries the delta past rows, restoring
diffCursor and cursorOnAnnotation and breaking immediately. The first step
stays exempt so a line taller than the whole viewport remains reachable,
which still scrolls by its full height.
…oved

the rollback fired whenever any step had been taken, so a block taller than the
page ahead of the cursor collapsed pgdown to a one-row scroll: the annotation
flip consumed one row, the next step overshot, and the walk rolled back to that
single row. The screen looked unchanged and the following press took the same
oversized step anyway.

worthRollingBack requires half a page of walked budget before undoing a step.
A block with no selectable position inside it is now stepped over in one press
as before, while an ordinary tall line at the page boundary still rolls back.

adds the up-direction case, which had no test - the previous pgup assertion was
satisfied by construction and held with the rollback deleted - and corrects the
down-walk comment, which named the line stepped onto when the height comes from
the line stepped off.
Copilot AI lite review requested due to automatic review settings August 10, 2026 01:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes diff-pane paging so PgDown/PgUp can’t advance the viewport by more than the requested page size when a single cursor step spans many rendered rows (wrap continuations / multi-line annotation blocks), preventing “skipped” rows that were never rendered.

Changes:

  • Bound the cursor-walk paging logic to roll back the overshooting step (when it’s worthwhile) and then scroll by the actual walked delta.
  • Added targeted regression tests for down/up overshoot and the “don’t collapse to near-zero scroll” case with blocks taller than a page.
  • Documented the paging walk/rollback behavior in the gotchas notes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
app/ui/diffnav.go Adds overshoot rollback + worthRollingBack gating to keep paging within a page when encountering tall rendered lines.
app/ui/diffnav_test.go Adds regression tests ensuring paging doesn’t skip unseen rows and still progresses past content taller than the viewport.
.claude/rules/gotchas.md Updates internal gotchas documentation to reflect the new paging/rollback behavior and its limits.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread app/ui/diffnav.go Outdated
Comment on lines +224 to +225
// anyway - worse than simply taking it now. half a page is the bar, matching ctrl+d/ctrl+u.
// a first step always passes (walked is 0), so the walk can never refuse to move.
worthRollingBack returns false for walked == 0, so 'a first step always
passes' read as 'returns true' directly above the return statement. State
the mechanism instead.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Deploying revdiff with  Cloudflare Pages  Cloudflare Pages

Latest commit: a4cda26
Status: ✅  Deploy successful!
Preview URL: https://c0b1960d.revdiff.pages.dev
Branch Preview URL: https://fix-pagedown-overshoot.revdiff.pages.dev

View logs

@umputun
umputun merged commit 306209c into master Aug 10, 2026
5 checks passed
@umputun
umputun deleted the fix/pagedown-overshoot branch August 10, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants