Skip to content

fix(desktop): scroll the view up when the caret moves above the viewport (#3329) - #4742

Merged
Jocs merged 1 commit into
developfrom
fix/3329-scroll-up-arrow
Jun 26, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/3329-scroll-up-arrow

Conversation

@Jocs

@Jocs Jocs commented Jun 26, 2026

Copy link
Copy Markdown
Member

Fixes #3329

Problem

Moving the caret down scrolls the document so the caret stays visible, but moving it up (Arrow-Up) did not — the caret slid above the viewport while the text stayed put.

Root cause

The selection-change handler in editorWithTabs/editor.vue only handled the bottom edge (the #628 fix): when the caret is within 100px of the bottom (container.clientHeight - y < 100) it scrolls down. There was no symmetric branch for the top edge, so arrow keys (handled by the engine, which sets the caret programmatically and does not trigger the browser's native scroll-into-view) never scrolled the container upward.

Reproduced in the real built app (e2e): with a tall document, moving the caret to the bottom scrolls the view down, but moving it back up leaves scrollTop unchanged — the caret leaves the viewport.

Fix

Add the symmetric upward scroll: when the caret rises within 100px of the top edge (y < 100), scroll the container up so it stays visible — mirroring the existing down-scroll. It's an else if, so the two edges never fight, and it clamps to scrollTop: 0 at the document top.

Tests

Added test/e2e/scroll-up-arrow.spec.ts (real Electron app): in a 120-paragraph doc, pressing Arrow-Down scrolls the view down (already worked), and pressing Arrow-Up brings it back up. Confirmed RED on the pre-fix build (the up case leaves the view at the bottom) → GREEN after the fix, deterministic across 3 repeats. ESLint + vue-tsc typecheck pass.

…ort (#3329)

The `selection-change` scroll handler only auto-scrolled when the caret neared
the bottom edge (#628), so moving the caret up (Arrow-Up) let it slide above the
viewport without the document following. Add the symmetric upward scroll when
the caret rises within 100px of the top edge.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4742:

Run: https://github.com/marktext/marktext/actions/runs/28241609813

Artifact Size Link
marktext-windows-arm64 275.6 MB Download
marktext-macos-x64 293.0 MB Download
marktext-linux 627.3 MB Download
marktext-windows-x64 283.8 MB Download
marktext-macos-arm64 282.7 MB Download

@Jocs
Jocs merged commit c6eecd7 into develop Jun 26, 2026
10 checks passed
@Jocs
Jocs deleted the fix/3329-scroll-up-arrow branch June 26, 2026 16:40
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.

scrolling up with arrow key doesn't scroll text in document

1 participant