Skip to content

Fix pasting into blockquote splitting on line breaks#911

Open
samuelpecher wants to merge 2 commits intomainfrom
fix-paste-quote-linebreak
Open

Fix pasting into blockquote splitting on line breaks#911
samuelpecher wants to merge 2 commits intomainfrom
fix-paste-quote-linebreak

Conversation

@samuelpecher
Copy link
Collaborator

Summary

  • Fixed pasting text with line breaks into a blockquote — content now stays within the quote instead of breaking out at each newline
  • When pasting inside a QuoteNode, paragraph wrappers are flattened into inline children separated by line breaks

Fixes Fizzy card #4979: Pasting as quoted text doesn't always work as expected

When pasting text containing newlines into a blockquote, the pasted
content would break out of the quote at each line break. This happened
because $generateNodesFromDOM produced multiple ParagraphNode objects
that selection.insertNodes() placed as top-level siblings outside the
blockquote.

The fix detects when pasting inside a QuoteNode and flattens paragraph
wrappers into inline children (text nodes separated by line breaks)
before inserting, keeping all content within the quote.
Copilot AI review requested due to automatic review settings March 23, 2026 14:45
@samuelpecher samuelpecher self-assigned this Mar 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes an issue where pasting text with line breaks into a blockquote would cause the content to break out of the quote at each newline. The fix adds special handling for paste operations inside quote nodes by flattening paragraph wrappers and separating them with line breaks instead.

Changes:

  • Added a check in the insertDOM method to detect when pasting into a quote node and invoke special handling
  • Added a new private method #$insertNodesIntoQuote that flattens paragraph wrappers from pasted content into inline children separated by line breaks within the quote

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


#$insertNodesIntoQuote(selection, nodes) {
const anchorNode = selection.anchor.getNode()
const quoteNode = anchorNode.getParents().find($isQuoteNode)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method getParents() does not exist in Lexical. Based on the codebase patterns (e.g., selection.js:510-516), you should traverse parent nodes using a loop with getParent(). The code should collect parents in an array or use a while loop to find the quote node ancestor.

Suggested change
const quoteNode = anchorNode.getParents().find($isQuoteNode)
let quoteNode = null
let parent = anchorNode.getParent()
while (parent !== null) {
if ($isQuoteNode(parent)) {
quoteNode = parent
break
}
parent = parent.getParent()
}

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the readers, LexicalNode does expose getParents(), but $getNearestNodeOfType(node, CodeNode) is the best approach here.

…de blocks when pasting into blockquotes

Replace getParents().find($isQuoteNode) with $getNearestNodeOfType(anchorNode, QuoteNode)
for consistency with the rest of the codebase. Extend the paste-into-blockquote flattening
logic to also handle heading and code block elements, preventing them from escaping the
blockquote on paste.
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.

2 participants