Skip to content

fix(editor): preserve selection across view modes - #655

Merged
murongg merged 2 commits into
v2from
fix/649-editor-mode-switch
Aug 8, 2026
Merged

fix(editor): preserve selection across view modes#655
murongg merged 2 commits into
v2from
fix/649-editor-mode-switch

Conversation

@murongg

@murongg murongg commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • preserve CodeMirror selections and focus when switching between Preview, Source, and Split modes
  • remeasure the revealed editor surface so long documents do not appear blank after a mode switch
  • preload the source editor chunk during idle time after the visual editor is ready
  • reuse the same module promise for preloading and lazy rendering, with a source-shaped loading placeholder as fallback

Why

Switching modes recreated the source editor at offset 0 and could leave the visual editor unfocused or measured while hidden. This lost the active cursor position and could make the editing surface appear blank. The first switch also waited for the source editor chunk even when the app had already become idle.

Validation

  • pnpm --filter @markra/app exec vitest run — 130 test files and 1493 tests passed
  • pnpm --filter @markra/desktop build — production build and vendor chunk verification passed
  • manual browser QA with an 80-section document across Preview → Source → Split → Preview — cursor continuity, focus restoration, visible rendering, and zero console errors confirmed

Risk

  • preloading starts only after the active visual editor is ready and uses a cancellable idle callback or delayed timeout fallback
  • selection offsets are clamped to the current document length before restoration
  • no hidden source editor instance, persisted-data change, or configuration migration

Closes #649

@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 12:23am

@murongg
murongg merged commit 64727b1 into v2 Aug 8, 2026
21 checks passed
@murongg
murongg deleted the fix/649-editor-mode-switch branch August 8, 2026 00:42
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.

[Bug]: 切换至源码模式时出现短暂白屏且光标位置无法保留

1 participant