Skip to content

[lexical-link] Bug Fix: Skip link wrapping on paste for non-simple text nodes#8513

Merged
etrepum merged 5 commits into
facebook:mainfrom
abhishekvishwakarma007:fix/code-block-paste-link
May 29, 2026
Merged

[lexical-link] Bug Fix: Skip link wrapping on paste for non-simple text nodes#8513
etrepum merged 5 commits into
facebook:mainfrom
abhishekvishwakarma007:fix/code-block-paste-link

Conversation

@abhishekvishwakarma007

@abhishekvishwakarma007 abhishekvishwakarma007 commented May 14, 2026

Copy link
Copy Markdown
Contributor

Description

The PASTE_COMMAND handler in LinkExtension dispatches TOGGLE_LINK_COMMAND when a URL is pasted over selected text. Inside a code block, CodeHighlightNode cannot be wrapped in a LinkNode, so the paste silently fails and nothing is inserted.

This fix adds an isSimpleText() guard — if any selected text node is not simple text (e.g. CodeHighlightNode), the handler returns false and lets the default paste handler insert the URL as plain text.

Changes

  • LexicalLinkExtension.ts — Added $isTextNode import and isSimpleText() check in the PASTE_COMMAND listener to skip link wrapping for non-simple text nodes
  • LinkExtension.test.ts — Added two tests:
    • Pasting a URL inside a code block does not create a LinkNode
    • Pasting a URL over plain text in a paragraph still wraps it in a LinkNode (regression guard)

Closes #8506

Test plan

Before

pasteLInkBefore.mov

Paste silently fails — nothing happens, the original text remains unchanged.

After

pasteLinkAfter.mov

Paste works correctly — the URL replaces the selected text as plain text inside the code block.

…xt nodes (facebook#8506)

Prevent PASTE_COMMAND handler from dispatching TOGGLE_LINK_COMMAND when
the selection contains non-simple text nodes (e.g. CodeHighlightNode
inside a code block). This fixes paste silently failing in code blocks
when the clipboard contains a URL.
@vercel

vercel Bot commented May 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment May 29, 2026 11:22pm
lexical-playground Ready Ready Preview, Comment May 29, 2026 11:22pm

Request Review

@etrepum

etrepum commented May 14, 2026

Copy link
Copy Markdown
Collaborator

This PR description does not follow the repository template

@abhishekvishwakarma007

Copy link
Copy Markdown
Contributor Author

This PR description does not follow the repository template

Thanks updated

Comment thread packages/lexical-link/src/__tests__/unit/LinkExtension.test.ts Outdated
Comment thread packages/lexical-link/src/LexicalLinkExtension.ts Outdated
Comment thread packages/lexical-link/src/__tests__/unit/LinkExtension.test.ts Outdated
Comment thread packages/lexical-link/src/__tests__/unit/LinkExtension.test.ts Outdated
Comment thread packages/lexical-link/src/__tests__/unit/LinkExtension.test.ts Outdated
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label May 14, 2026
@levensta

Copy link
Copy Markdown
Contributor

@abhishekvishwakarma007 Will you continue working on PR? It looks like there are a few minor things that need to be fixed before merging 🙏

@potatowagon

Copy link
Copy Markdown
Contributor

Review: Skip Link Wrapping on Paste for Non-Simple Text Nodes

Reviewed by: Navi (AI review assistant for @potatowagon)

Summary

Prevents URL auto-linking when pasting into code blocks (or other non-simple text nodes like code highlight nodes). Previously, pasting a URL while text was selected inside a code block would wrap it in a link — breaking code formatting.

What I Verified

  • Logic correctness: The condition nodes.every(node => !\(node) || node.isSimpleText()) correctly identifies that ALL selected text nodes must be simple (non-formatted) text for auto-linking to apply. Code highlight nodes have isSimpleText() === false, so they're excluded.
  • Regression safety: The existing check (!nodes.some(node => \(node))) is preserved as an AND condition, so existing behavior for element-level selections is unchanged.
  • Test coverage: Comprehensive tests added — mock ClipboardEvent for jsdom, test for code blocks, and test confirming normal text still auto-links. Well structured.
  • CI status: All e2e tests pass across Linux/Mac/Windows on Chromium, Firefox, and WebKit.

Verdict

Safe to approve — correct fix, well-tested, no behavioral regression for normal text pasting. The isSimpleText() check is the right abstraction boundary.

@etrepum etrepum added this pull request to the merge queue May 29, 2026
Merged via the queue into facebook:main with commit c117c73 May 29, 2026
42 checks passed
@etrepum etrepum mentioned this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

4 participants