Skip to content

[lexical][lexical-selection] Bug Fix: Treat all TabNode as if they are in token mode#7602

Merged
etrepum merged 4 commits intofacebook:mainfrom
etrepum:tabnode-as-token
Jun 3, 2025
Merged

[lexical][lexical-selection] Bug Fix: Treat all TabNode as if they are in token mode#7602
etrepum merged 4 commits intofacebook:mainfrom
etrepum:tabnode-as-token

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Jun 3, 2025

Description

For legacy reasons TabNode is a 'normal' mode TextNode with the IS_UNMERGEABLE detail flag (used only in the reconciler's normalization), but the conditions in the rest of the core used node.isToken() to determine if the node should be modified or replaced without checking the IS_UNMERGEABLE flag.

To keep legacy serialization as-is, this PR changes the core to use $isTokenOrTab (new) and $isTokenOrSegmented functions instead of calling the TextNode.isToken method directly, and these functions both now check $isTabNode as part of their condition.

This also changes all property setters of __text to go through the setTextContent method (except for @lexical/selection's $sliceSelectedTextNodeContent which is used in an unusual "read-only" way), and adds an additional invariant to TabNode.spliceText to ensure that it is not modified by that either.

Closes #7601

Test plan

Unit tests to confirm that TabNode is not modified in the scenarios from #7601

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jun 3, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Jun 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 3, 2025 6:35pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 3, 2025 6:35pm

@facebook-github-bot facebook-github-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 Jun 3, 2025
@etrepum etrepum added this pull request to the merge queue Jun 3, 2025
Merged via the queue into facebook:main with commit d923795 Jun 3, 2025
39 checks passed
@etrepum etrepum mentioned this pull request Jun 4, 2025
fantactuka pushed a commit that referenced this pull request Aug 11, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Typing to a selection including TabNode and TextNode adds text to TabNode

3 participants