Skip to content

fix(editor): stabilize math preview scrolling - #657

Merged
murongg merged 3 commits into
v2from
fix/654-math-scroll-performance
Aug 13, 2026
Merged

fix(editor): stabilize math preview scrolling#657
murongg merged 3 commits into
v2from
fix/654-math-scroll-performance

Conversation

@murongg

@murongg murongg commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • stop rebuilding all math decorations during viewport-only scroll updates
  • replace multiline formulas with a single state-backed CodeMirror block replacement
  • remove the .cm-line display: none layout workaround
  • cache rendered KaTeX across selection, focus, and Vim reveal-only updates
  • estimate offscreen formula height from the original source footprint
  • keep math focus synchronization out of active IME composition

Why

The issue attachment has roughly 929 math ranges. Viewport updates previously rescanned and rerendered all of them, while multiline formulas hid individual editor lines outside CodeMirror’s block height model. Together these could make large scroll jumps expensive and leave WebKit with stale document geometry.

Moving block decorations into editor state fixed the height model, but the first CI run also exposed a focus-sync transaction racing controlled Chinese IME input. Focus changes are now applied synchronously before composition, deferred while composition owns the editable DOM, and reconciled after composition ends.

Validation

  • pnpm --filter @markra/app test — 1,494 tests passed, including the controlled IME/image regression
  • pnpm --filter @markra/editor test — 450 tests passed
  • pnpm --filter @markra/app build and typecheck:test — passed
  • pnpm --filter @markra/editor build and typecheck:test — passed
  • pnpm --filter @markra/desktop build — passed, including vendor chunk verification
  • clean Chromium session with the issue attachment — a 14,000px jump reached section 7.2 with 15 visible lines, 4 display formulas, 0 hidden math lines, stable 160079px height at 150ms/850ms, and no error toast

Risk

  • Tauri dev launched successfully, but the Mac was locked so the WebKit window could not be operated for the final smoke test. The PR remains draft until that target-specific check is completed.
  • Parallel local stress runs exposed existing deferred-parser timing flakes in unrelated preview tests. The affected files passed in isolation, and the sequential editor suite passed 450/450.

Refs #654

Keep full-document math decorations stable during viewport-only updates while still refreshing for parser progress and editor state changes.

Refs #654
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
markra-web Ready Ready Preview Aug 8, 2026 5:16am

Replace multiline source with state-backed block decorations so CodeMirror owns the complete visual height. Cache rendered formulas across reveal-only updates and estimate offscreen block height from the source footprint.

Refs #654
@murongg
murongg marked this pull request as ready for review August 13, 2026 10:18
@murongg
murongg merged commit 6fdf3d4 into v2 Aug 13, 2026
21 checks passed
@murongg
murongg deleted the fix/654-math-scroll-performance branch August 13, 2026 10:18
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