Skip to content

fix(editor): PageDown advances on consecutive long wrapped lines#7555

Open
JohnMcLear wants to merge 1 commit intoether:developfrom
JohnMcLear:fix/pagedown-wrapped-lines-4562
Open

fix(editor): PageDown advances on consecutive long wrapped lines#7555
JohnMcLear wants to merge 1 commit intoether:developfrom
JohnMcLear:fix/pagedown-wrapped-lines-4562

Conversation

@JohnMcLear
Copy link
Copy Markdown
Member

Summary

Fix for #4562 — PageDown (and PageUp) became no-ops when the cursor sat on a very long wrapped line and the following lines were also very long.

Root cause

The page up/down handler in ace2_inner.ts advances the caret by numberOfLinesInViewport, computed from scroll.getVisibleLineRange(rep). That helper returns indices into rep.lineslogical lines, not visual/wrapped rows. When a single wrapped logical line fills the viewport (e.g., three ~2000-char lines), the range collapses to [n, n] and the advance count becomes 0:

// before
const numberOfLinesInViewport = newVisibleLineRange[1] - newVisibleLineRange[0];
// then: rep.selStart[0] += 0  →  caret doesn't move
//        scroll.setScrollY(caretOffsetTop)  →  scroll doesn't move

Fix: clamp to at least one logical line so the caret and viewport always advance.

Test plan

  • Playwright regression test reproducing the reporter's scenario (three ~2000-char lines, Ctrl+Home, PageDown → viewport scrolls or caret advances)
  • Existing page_up_down.spec.ts still passes (no behavior change for the common case where the viewport spans multiple logical lines)
  • pnpm run ts-check clean locally

Closes #4562

🤖 Generated with Claude Code

…lines

The page up/down handler advances the caret by numberOfLinesInViewport
computed from scroll.getVisibleLineRange(). That helper returns indices
into rep.lines (logical lines, not visual/wrapped rows), so when one
wrapped logical line fills the viewport — e.g., three consecutive lines
of ~2000 chars each — the range collapses to [n, n] and the advance
count becomes 0. The caret stays on line n, scroll stays at 0, and the
user sees "PageDown does nothing".

Clamp the advance to at least one logical line so the caret and viewport
always move.

Includes a Playwright regression test covering the reporter's repro
(three very long lines, Ctrl+Home, PageDown).

Closes ether#4562

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Fix PageDown/PageUp advance on consecutive long wrapped lines

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix PageDown/PageUp becoming no-ops on consecutive long wrapped lines
• Clamp viewport line count to minimum of 1 logical line
• Add regression test for issue #4562 with very long wrapped lines
Diagram
flowchart LR
  A["getVisibleLineRange returns logical line indices"] -->|"collapses to [n,n] for wrapped lines"| B["numberOfLinesInViewport = 0"]
  B -->|"causes no-op"| C["PageDown/PageUp fails"]
  D["Math.max clamp to 1"] -->|"guarantees minimum advance"| E["PageDown/PageUp always moves"]
Loading

Grey Divider

File Changes

1. src/static/js/ace2_inner.ts 🐞 Bug fix +7/-2

Clamp viewport line count to minimum of 1

• Changed numberOfLinesInViewport calculation to use Math.max(1, ...) to guarantee at least one
 line of movement
• Enhanced comment explaining that getVisibleLineRange returns logical line indices, not visual
 rows
• Prevents PageDown/PageUp from becoming no-ops when a single wrapped line fills the viewport

src/static/js/ace2_inner.ts


2. src/tests/frontend-new/specs/pagedown_wrapped_lines.spec.ts 🧪 Tests +77/-0

Add regression test for wrapped lines PageDown

• New Playwright regression test for issue #4562
• Tests PageDown behavior with three consecutive ~2000-character lines that wrap extensively
• Verifies that either viewport scrolls or caret advances to a later logical line
• Validates fix prevents the pre-fix behavior where both scroll and caret stayed put

src/tests/frontend-new/specs/pagedown_wrapped_lines.spec.ts


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects bot commented Apr 19, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

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.

Page down does not work on consecutive very long lines

1 participant