fix: preserve multi-line paste in code blocks (#203)#212
Conversation
Co-authored-by: Ona <no-reply@ona.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
✅ UI verification passed — design spec compliance confirmed. Summary: The changed file ( |
|
✅ Post-merge verification passed. E2E suite: 47/52 passed, 2 failed, 3 skipped (dependent on failures). The 2 failures are pre-existing and unrelated to this PR's code-block paste changes:
This PR's new tests ( Ad-hoc smoke tests (production):
|
Closes #203
What
Pasting multi-line text into a code block only preserved the first line. Lexical's default rich-text paste handler (
$insertDataTransferForRichText) splits pasted text on newlines and callsselection.insertParagraph()for each\n. Inside aCodeNode, this breaks out of the code block and creates new paragraph nodes, discarding all lines after the first from the code block.How
Added a
PASTE_COMMANDhandler atCOMMAND_PRIORITY_HIGHinCodeHighlightPluginthat intercepts paste events when the selection is inside aCodeNode. Instead of delegating to the default handler, it splits the pasted plain text on newlines and insertsCodeHighlightNode+LineBreakNodepairs — keeping all lines inside the code block. The existing syntax-highlighting transform fromregisterCodeHighlightingre-tokenizes the pasted code automatically.Testing
e2e/editor-code-paste.spec.tswith two cases: