Add an argument to transformPasted indicating if paste is plain text #183
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ocavue/transformPasted-plain"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR introduces a new argument
plain: booleanto thetransformPasted callback, indicating whether the pasted content should be treated as plain text.The existing
transformPastedTextandclipboardTextParseralso include thisplainflag. However, these two functions have the argumenttext: string, whiletransformPasteddoes not. Therefore, I'm not entirely sure if the new API added in this PR aligns with the convention.In my case, I'd want to perform different transformations depending on whether the
Shiftkey is held down while pasting. While I can add a custom keydown handler myself, it would be much more convenient if ProseMirror could simply export theplaininformation.@ -101,7 +101,7 @@ export function parseFromClipboard(view: EditorView, text: string, html: string}I think it would be more correct to pass
asTexthere, since that reflects whether the content is actually treated as plain text, not just whether shift is held. Does that make sense?@ -101,7 +101,7 @@ export function parseFromClipboard(view: EditorView, text: string, html: string}I've switched to using
asTextin commit https://github.com/ProseMirror/prosemirror-view/pull/183/commits/85255cde184f2695c6fcf5d34a3530e8cdd12ba7.There are very subtle differences between
asTextandplainText, so I believe it's fine to make the switch. The only situation where these two variables differ, IMHO, is when pasting something into a code block without holding theShiftkey. In this case,plainTextis false, andasTextis true. However, the functionparseFromClipboardwould easily return at line 50 (code link), meaning thattransformPastedon line 104 (code link) won't be called at all, so it doesn't matter which variable we pass in this case.@ -101,7 +101,7 @@ export function parseFromClipboard(view: EditorView, text: string, html: string}I'm not sure if the behavior of
transformPastednot being called when pasting into a code block is a bug or intentional design.There's also the situation where there's text on the clipboard but no HTML.
Not calling
transformPastedin the code block case does sound like a bug. See patchad55444.Thanks for the review and merge!