Skip to content

[lexical] Bug Fix: insert at the caret inside an inline ElementNode that cannot be split - #8971

Closed
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix-6477-insert-inside-unsplittable-inline
Closed

[lexical] Bug Fix: insert at the caret inside an inline ElementNode that cannot be split#8971
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix-6477-insert-inside-unsplittable-inline

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

RangeSelection.insertNodes splits the ancestor chain from the anchor up to the nearest block before splicing inline content in. An ElementNode is split by moving the children after the caret into the node returned by its insertNewAfter(), which returns null for any ElementNode that does not implement it — the base class default. $splitNodeAtPoint ignored that null and still reported the position after the whole node, so content pasted with the caret inside a custom inline ElementNode landed after the node while typing the same text inserted it in place.

Stop the split walk on an unsplittable inline element and splice into it at the caret.

Nodes that implement insertNewAfterLinkNode, MarkNode, ListItemNode, CodeNode — are unaffected and still split. $removeTextAndSplitBlock now returns the container alongside the index, but only the one affected call site opts into the new walk; insertParagraph and the code-block and slot paste paths take the index alone and are unchanged.

Reverting the product file fails 2 of the 3 new tests with the reported symptom — text("abcd")) text("XYZ") instead of text("ab") text("XYZ") text("cd"). The third is a control.

Fixes #6477

…hat cannot be split

RangeSelection.insertNodes splits the ancestor chain from the anchor up to the
nearest block before splicing inline content in. An ElementNode is split by
moving the children after the caret into the node returned by its
insertNewAfter(), which returns null for any ElementNode that does not
implement it -- the base class default. $splitNodeAtPoint ignored that null and
still reported the position after the whole node, so content pasted with the
caret inside a custom inline ElementNode landed after the node while typing the
same text inserted it in place.

Stop the split walk on an unsplittable inline element and splice into it at the
caret. Nodes that implement insertNewAfter (LinkNode, MarkNode, ListItemNode,
CodeNode) are unaffected and still split; insertParagraph and the code
block/slot paste paths keep the previous walk.

Fixes facebook#6477
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 8, 2026
@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9058 with the other PRs that share this defect, per @etrepum's note on #9027 and @mayrang's on #9035. Same fix and same tests, one review.

@LeSingh1 LeSingh1 closed this Aug 10, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Pasting text from the clipboard into a CustomElementNode does not work properly

1 participant