Repository navigation
Description
Description
An edit made in the WYSIWYG editor immediately before entering source code mode is silently lost: it is missing from the source view, and after switching back to WYSIWYG it is permanently reverted — no undo entry, no dirty indicator for the lost change.
This is the inverse direction of #3590 (which covered edits made in source mode being lost on exit, fixed by the engine rewrite). Here the edit is made in WYSIWYG mode, in the same frame as the mode switch.
Steps to reproduce
- Open a document containing a task list, e.g.:
- [ ] parent - [ ] child1 - [ ] child2 - Click the
parentcheckbox and, immediately after (same frame — easiest with the keyboard shortcut already under your fingers), toggle View → Source Code Mode. - The source view still shows
- [ ] parent— the toggle is missing. - Toggle source code mode off again.
Expected: the checkbox toggle survives the round-trip.
Actual: the toggle is gone permanently — the document reverts to the pre-click state.
A task-checkbox click is the easiest deterministic repro (the click's model update is always deferred), but any same-frame pending edit is exposed to the same window.
Root cause
@muyajs/core batches edits into a deferred rAF-scheduled op flush (JSONState). Entering source code mode mounts sourceCode.vue, which snapshots currentFile.markdown before the pending batch has flushed, so CodeMirror opens on stale content. Exiting source mode then applies the stale snapshot back through setContent, which — by design, since #4658 — cancels the still-pending op batch to prevent cross-document corruption. The queued edit is dropped, making the loss permanent.
This is the same unflushed-batch class as #3803 (edit dropped from save, fixed by #4859 via flushActiveEditor()) and the tab-switch guard (#2938). The source-mode entry path is the remaining reader of currentFile.markdown that doesn't flush first.
Notably, the existing e2e spec test/e2e/task-list-autocheck.spec.ts ("with autoCheck OFF, clicking the parent changes only the parent") fails deterministically on develop on macOS because of this — it clicks a checkbox and immediately reads the markdown through a source-mode round-trip.
Fix
One-line fix: call muya.flush() in the watch(sourceCode, …, { flush: 'sync' }) handler in editorWithTabs/editor.vue — the same sync watcher that already computes the JIT cursor for the handoff — so the pending batch lands in the tab before sourceCode.vue mounts. PR incoming with a regression e2e spec.
Environment
- MarkText: develop @ e52106f (0.20.0-dev)
- OS: macOS (Darwin 25.5.0), Apple Silicon
- Verified by Playwright e2e against the built app: without the fix the checkbox edit is reverted even 500 ms after the round-trip; with the fix it survives an immediate round-trip.
Activity
fix(desktop): flush pending edits before entering source code mode (m…