[Bug] Pasting into a code block does not trigger auto-save (WYSIWYG mode)
Description
In WYSIWYG mode, pasting content into a code block never triggers auto-save, while typing in the same code block does. The file on disk is silently out of date, and the tab shows no unsaved indicator.
I traced this down to muya's pasteHandler (@marktext/muyajs, lib/contentState/pasteCtrl.js). The early-return branches for codeContent (and also languageInput and cellContent) end with just:
return this.partialRender()
while the normal paragraph paste path ends with:
this.checkInlineUpdate(cursorBlock) this.partialRender() this.muya.dispatchSelectionChange() this.muya.dispatchSelectionFormats() return this.muya.dispatchChange()
Because pasteHandler calls event.preventDefault() at the start, no native input event fires either, so the change event never reaches the app layer (LISTEN_FOR_CONTENT_CHANGE). As a result tab.isSaved stays true and the auto-save timer is never started.
Typing works because inputBinding in muya's keyboard handler calls this.muya.dispatchChange() on every DOM input event, regardless of block type.
Note that the undo history IS updated correctly on paste (cursor is set with isEdit: true), so as soon as the user types anything, clicks anywhere, or switches tabs, the change event fires and the pasted content gets saved together with the next edit — which makes the bug easy to miss.
Source-code mode is unaffected (CodeMirror cursorActivity → saveContent → LISTEN_FOR_CONTENT_CHANGE works fine on paste).
Suggested fix: in the three early-return branches of pasteHandler (codeContent, languageInput, cellContent), mirror the normal path and call this.muya.dispatchSelectionChange() / this.muya.dispatchSelectionFormats() / this.muya.dispatchChange() after rendering. Happy to submit a PR if the analysis is welcome.
Steps to Reproduce
- Enable auto-save in preferences (default 5 s delay).
- Open/save a markdown file in WYSIWYG mode.
- Create a code block and place the cursor inside it.
- Paste any text into the code block.
- Wait longer than the auto-save delay without any further input.
- Check the file on disk (or the tab's unsaved indicator): the pasted content is not saved. Also reproducible when pasting into a table cell, and when pasting into a code block's language input.
Expected Behavior
Pasting into a code block marks the document as modified and triggers auto-save after the configured delay, exactly like pasting into a normal paragraph.
Actual Behavior
No change event is dispatched. The tab remains marked as saved, and the file is not updated — the pasted content is only written to disk after some other edit occurs afterwards (typing a character, clicking, or switching tabs).
Screenshots / Logs
No response
Operating System
Windows
MarkText Version
0.19.1
OS Version
Windows 11 x64 (10.0.26200)
Reproducibility
- I can reliably reproduce this issue
Source: marktext/marktext