[lexical] Bug Fix: insert at the caret inside an inline ElementNode that cannot be split - #8971
Closed
LeSingh1 wants to merge 1 commit into
Closed
Conversation
…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
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 8, 2026 01:40
|
@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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RangeSelection.insertNodessplits the ancestor chain from the anchor up to the nearest block before splicing inline content in. AnElementNodeis split by moving the children after the caret into the node returned by itsinsertNewAfter(), which returnsnullfor anyElementNodethat does not implement it — the base class default.$splitNodeAtPointignored thatnulland still reported the position after the whole node, so content pasted with the caret inside a custom inlineElementNodelanded 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.$removeTextAndSplitBlocknow returns the container alongside the index, but only the one affected call site opts into the new walk;insertParagraphand 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 oftext("ab") text("XYZ") text("cd"). The third is a control.Fixes #6477