[lexical] Bug Fix: keep the text mode on every part of a split TextNode - #8924
[lexical] Bug Fix: keep the text mode on every part of a split TextNode#8924LeSingh1 wants to merge 1 commit into
Conversation
splitText() copies format, style, detail and NodeState onto the parts it creates but not __mode. Splitting a token TextNode therefore left a token head followed by normal-mode tails, which are editable and can be merged into neighbouring text by normalization. Segmented nodes keep their existing behaviour of being downgraded to normal.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
AFAIK downgrade of mode here is intentional, special modes are lost when the text is manipulated. I don't think this should be merged without careful consideration of the consequences.
|
That's a fair reading for segmented — the segmented branch replaces the node with a fresh Token is different, and the reason I filed this is that the current behaviour isn't a downgrade, it's an inconsistency. The non-segmented branch does So the invariant "special modes are lost when the text is manipulated" isn't what the code does — it's lost on every part except the first. That leaves a token head glued to editable tails, and the tails are Either consistent answer seems defensible to me and I don't have a stake in which:
Happy to switch this to option 2 if that's the intent. It'd be worth deciding either way, since the callers most affected are internal ( |
|
IIRC “lost on every part but the first” is consistent with the expected behavior. I will only be convinced one way or the other if a full audit of every splitText call site when the subject is a TextNode not in normal mode to see if any expectations are violated. Even better evidence would be a demonstration of unexpected behavior in the playground due to the current semantics. |
Description
splitText()copies format, style, detail and NodeState onto the parts it creates, but not__mode. The first part reuses the node being split so it keeps its mode; every later part is created as a normal-modeTextNode. Splitting a token node therefore yields a token head followed by editable tails, which areisSimpleText()and can be merged into adjacent text by normalization.The siblings now inherit the mode of the first part. Segmented nodes are still downgraded to normal, because the first part is already replaced with a plain
TextNodein that branch.Related but distinct: #4167 asks that
RangeSelection.formatTextnot callsplitTexton token nodes. That's a guard at one caller; this issplitText's own contract losing the mode, which affects every caller ($splitTextPointCaret, drop handling,$insertNodeToNearestRootAtCaret, markdown and autolink transformers). You may want to consider them together.Test plan
Before
New unit test
splitText keeps the token mode on every partfails on main:After
Passes;
Tests 102 passed (102)in that file. The existingconvert segmented node into plain texttest is unaffected — the fix reads the mode off the already-created first part, so the segmented branch is unchanged.pnpm run test-unitgreen (227 files, 4939 passed).