Skip to content

Plain text paste into code block breaks out after first few lines #3

@jondkinney

Description

@jondkinney

Bug

When pasting multiline plain text into an existing (empty) code block, only the first couple of lines stay inside the code block. The remaining lines spill out below as regular paragraphs.

Steps to reproduce

  1. Create an empty code block in the editor (via toolbar or ``` shortcut)
  2. Place cursor inside the code block
  3. Copy multiline code as plain text (e.g., from GitHub's file viewer, a terminal, or a text editor)
  4. Paste into the code block

Expected

All pasted lines should be inserted inside the code block.

Actual

Only the first 1-2 lines remain in the code block. The rest appear as plain paragraphs below it.

Root cause

In src/editor/clipboard.js:19, #isPastingIntoCodeBlock() returns true and the custom paste handler bails out (return false), deferring to Lexical's default $insertDataTransferForRichText. The default handler doesn't properly constrain multiline plain text insertion within a CodeNode — it splits on newlines and creates separate nodes that escape the code block boundary.

Related

  • GitHub's file viewer copies as plain text only (invisible textarea), so the CommonMark <code class="language-*"> detection in detectLanguage() never fires for that source. This is a separate issue but compounds the UX problem.

Screenshots

Code block paste breakout

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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