Skip to content

Bug: Pasting text with consecutive blank lines into a code block results in text outside of the code block #8351

@jimrandomh

Description

@jimrandomh

In the Lexical playground (or another Lexical install that includes CodeBlockPlugin), create a new empty code block by typing three backticks. Then copy some plain text from elsewhere, which contains three or more newlines in a row (ie two blank lines), and paste it inside the code block. Text after the newlines will wind up as top-level paragraphs rather than inside the code block.

In CodeNode.insertNewAfter, there is code that checks whether the last two children of the code block are blank lines, and if so, breaks out of the code block and starts a paragraph block. This makes sense if the user is typing (it makes it possible to leave the code block by typing enter a few times at the end), but doesn't make sense while pasting. Adding !$hasUpdateTag(PASTE_TAG) to the condition appears to fix it, without changing the intended UI interaction that this bit of code enables.

Lexical version: v0.43.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions