Skip to content

fix(editor): preserve source scroll position while editing - #710

Open
murongg wants to merge 2 commits into
v2from
fix/source-scroll-jump
Open

fix(editor): preserve source scroll position while editing#710
murongg wants to merge 2 commits into
v2from
fix/source-scroll-jump

Conversation

@murongg

@murongg murongg commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Editing a visible line in a long source document could move that line to the top of the viewport. Preserve the chosen viewport across typing, deletion, and native text replacement, revealing the caret only when it actually leaves the viewport.

The previous input-only capture missed text updates that arrive after the browser has already scrolled. Remember the last observed scroll position for that path. Observe input events even when higher-priority handlers consume them, cancel pending restores on user navigation/scrolling/blur or external document updates, and account for interface zoom when revealing an off-screen caret. Typewriter mode keeps its intentional centering.

Validation

  • pnpm --filter @markra/editor test: 40 files, 537 tests passed.
  • pnpm --filter @markra/app exec vitest run src/components/MarkdownSourceEditor.test.tsx: 18 tests passed.
  • pnpm --filter @markra/editor typecheck:test: passed.
  • pnpm --filter @markra/editor build: passed.
  • pnpm --filter @markra/app build: passed.
  • Browser QA with 1,000 synthetic lines reproduced the missed path before this follow-up: the visible line moved approximately 304 pixels after text replacement without preceding keyboard events. With the follow-up, English/Chinese text updates on lines 305, 306, and 307 preserved both the scroll offset and the line's viewport position (respectively 7293.5, 7318, and 7343 scroll offset before and after).

Regression tests also cover IME transactions, deletion, user scrolling and selection navigation superseding a queued restore, background updates, typewriter changes, and zoomed viewport coordinates. Full native IME testing with the user's exact document remains unverified.

@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
markra-web Ready Ready Preview Sep 5, 2026 7:09am UTC

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.

1 participant