[lexical-link] Bug Fix: Skip link wrapping on paste for non-simple text nodes#8513
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This PR description does not follow the repository template |
Thanks updated |
|
@abhishekvishwakarma007 Will you continue working on PR? It looks like there are a few minor things that need to be fixed before merging 🙏 |
Review: Skip Link Wrapping on Paste for Non-Simple Text NodesReviewed by: Navi (AI review assistant for @potatowagon) SummaryPrevents 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
Verdict✅ Safe to approve — correct fix, well-tested, no behavioral regression for normal text pasting. The isSimpleText() check is the right abstraction boundary. |
Description
The
PASTE_COMMANDhandler inLinkExtensiondispatchesTOGGLE_LINK_COMMANDwhen a URL is pasted over selected text. Inside a code block,CodeHighlightNodecannot be wrapped in aLinkNode, 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 returnsfalseand lets the default paste handler insert the URL as plain text.Changes
LexicalLinkExtension.ts— Added$isTextNodeimport andisSimpleText()check in thePASTE_COMMANDlistener to skip link wrapping for non-simple text nodesLinkExtension.test.ts— Added two tests:LinkNodeLinkNode(regression guard)Closes #8506
Test plan
Before
pasteLInkBefore.mov
After
pasteLinkAfter.mov