Skip to content

fix(desktop): route undo/redo to CodeMirror in source code mode - #4752

Merged
Jocs merged 1 commit into
developfrom
fix/781-source-mode-undo-redo
Jun 26, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/781-source-mode-undo-redo

Conversation

@Jocs

@Jocs Jocs commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

Undo/redo did nothing while in Source Code mode.

The Edit › Undo/Redo menu items and Cmd/Ctrl+Z dispatch through mt::editor-edit-action → bus undo/redo. Only editor.vue subscribed, and it called the muya (WYSIWYG) engine's undo()/redo() — invisible while source code mode is active and the muya editor is hidden — so undo appeared to do nothing.

sourceCode.vue now subscribes to the same bus events and runs CodeMirror's undo/redo command, mirroring the existing selectAll routing. editor.vue's handlers bail out while sourceCode is active, so the hidden engine's history is left untouched.

Verification

Added an e2e test (test/e2e/issue-781-source-undo.spec.ts) that, in source mode, types into the live CodeMirror instance, triggers undo through the same IPC the menu uses, and asserts the edit reverts (and redo re-applies it). Confirmed RED→GREEN against the built app:

  • without the fix: undo never reverts the CodeMirror value → test fails
  • with the fix: undo reverts, redo re-applies → test passes

Lint + typecheck clean.

Fixes #781

The Edit > Undo/Redo menu items and Cmd/Ctrl+Z dispatch through
mt::editor-edit-action -> bus undo/redo. Only editor.vue subscribed and
called the muya (WYSIWYG) engine's undo/redo, which is invisible while
source code mode is active, so undo did nothing in source mode.

sourceCode.vue now subscribes to the same bus events and runs
CodeMirror's undo/redo command, mirroring the existing selectAll
routing; editor.vue's handlers bail out while sourceCode is active so the
hidden engine history is left untouched.

Verified RED->GREEN with an e2e test against the built app.

Fixes #781

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4752:

Run: https://github.com/marktext/marktext/actions/runs/28255624034

Artifact Size Link
marktext-windows-arm64 275.6 MB Download
marktext-linux 627.4 MB Download
marktext-windows-x64 283.8 MB Download
marktext-macos-x64 293.0 MB Download
marktext-macos-arm64 282.7 MB Download

@Jocs
Jocs merged commit 1c32441 into develop Jun 26, 2026
10 checks passed
@Jocs
Jocs deleted the fix/781-source-mode-undo-redo branch June 26, 2026 18:51
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.

Cannot undo in source code mode

1 participant