fix(desktop): flush pending edits before entering source code mode - #5103
Open
richbodo wants to merge 1 commit into
Open
fix(desktop): flush pending edits before entering source code mode#5103richbodo wants to merge 1 commit into
richbodo wants to merge 1 commit into
Conversation
An edit made in the same frame as the WYSIWYG -> source switch (e.g. a task-checkbox click) was missing from the CodeMirror snapshot, and the swap back out of source mode cancels the engine's scheduled op flush (marktext#4658), silently reverting the edit. Flush the rAF batch in the sync sourceCode watcher so the tab holds fresh markdown before sourceCode.vue mounts — the same guard saving (marktext#3803/marktext#4859) and tab switching (marktext#2938) already use. Fixes marktext#5102 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5102
Problem
An edit made in the WYSIWYG editor in the same frame as switching to source code mode (deterministic repro: clicking a task-list checkbox, then immediately toggling View → Source Code Mode) is silently lost:
@muyajs/corequeues the edit in its deferred rAF op batch (JSONState).sourceCode.vuemounts and snapshotscurrentFile.markdownbefore that batch flushes, so CodeMirror opens on stale content.setContent, which cancels the still-pending batch by design (fix(muya): drop pending op batch on setContent to prevent cross-document corruption (#2938) #4658) — the edit is reverted permanently, with no undo entry.This is the same unflushed-batch class as #3803 (dropped edit on save, fixed in #4859) and the tab-switch guard (#2938); source-mode entry was the remaining reader of
currentFile.markdownwithout a flush.It also explains a deterministic e2e failure on develop on macOS:
test/e2e/task-list-autocheck.spec.ts› "with autoCheck OFF, clicking the parent changes only the parent" clicks a checkbox and immediately reads markdown through a source-mode round-trip, and fails 4/4 runs without this fix.Fix
Call
editor.value.flush()in the existingwatch(sourceCode, …, { flush: 'sync' })handler ineditorWithTabs/editor.vue— the sync watcher that already prepares the tab (JIT cursor) before thev-if-gatedsourceCode.vuemounts. The pending batch lands in the tab first, so the snapshot is always fresh.Tests
test/e2e/source-mode-flush.spec.ts: clicks a checkbox and immediately round-trips through source mode with no settle wait; asserts the toggle is present in the source view and survives the round-trip. Fails on develop, passes with the fix.task-list-autocheck.spec.ts(previously failing deterministically on macOS): now passes, including with--repeat-each=2.lintandtypecheckclean.🤖 Generated with Claude Code