[Markdown Plugin] Support auto-conversion on native paste and add undoConversion option#3381
Open
juliaroldi wants to merge 5 commits into
Open
[Markdown Plugin] Support auto-conversion on native paste and add undoConversion option#3381juliaroldi wants to merge 5 commits into
juliaroldi wants to merge 5 commits into
Conversation
|
JiuqingSong
reviewed
Jun 24, 2026
| this.options.autoConversion | ||
| ) { | ||
| const clipboardData = event.data as ClipboardData; | ||
| const shouldConvert = this.options.autoConversion && clipboardData.pasteNativeEvent; |
Collaborator
There was a problem hiding this comment.
Need null check for clipboardData
Collaborator
There was a problem hiding this comment.
clipboardData itself needs null check. It comes from event.data. But event.data is not guaranteed to have valid value.
| isPastedContentMarkdown(this.editor, clipboardData) && | ||
| clipboardData.modelBeforePaste | ||
| ) { | ||
| mergeModel( |
Collaborator
There was a problem hiding this comment.
Suggest clone a model from clipboardData.modelBeforePaste, but do not modify the original one.
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.
Summary
Improves the Markdown paste plugin so that auto-conversion works for native (Ctrl+V) paste, not just the explicit "Paste as Markdown" path.
MarkdownPastePluginnow reacts to thecontentChangedevent with sourcePaste: whenautoConversionis enabled and the pasted content is detected as Markdown, it merges the converted Content Model intomodelBeforePasteand re-applies it viaformatContentModel. A newundoConversionoption (defaultfalse) takes an extra undo snapshot before the conversion so the user can undo the Markdown conversion separately from the paste.To distinguish genuine native paste events from programmatic clipboard reads,
extractClipboardItemsnow accepts anisPasteNativeflag that drivesClipboardData.pasteNativeEvent(previously hard-coded totrue).CopyPastePluginpassestruefor real paste events, whiledemo/scripts/utils/readClipboardData.tsleaves itundefined. The demo's editor options gain an "Undo auto-converted markdown" checkbox wired to the new option.How to test
yarn test:fast --testPathPattern=MarkdownPastePluginyarn builddemo), enable the Markdown plugin with "Auto convert on paste" on. Copy Markdown text (e.g.# Titleor**bold**) and paste with Ctrl+V.