Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical] Bug Fix: TextNode in token mode should not be split by removeText #6690

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented Oct 1, 2024

Description

The #6456 removeText rewrite introduced a regression in token mode behavior where it behaved too similarly to segmented nodes, it would be split and replaced with a plain TextNode instead of being deleted in full. This takes the simple approach of just expanding the selection outwards if the focus or anchor node contains any content from a token node.

Closes #6687

Test plan

Before

There were no tests to show that token TextNode should be deleted in full by removeText

After

Now there are tests that cover removeText behavior for token TextNode

Copy link

vercel bot commented Oct 1, 2024

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 Oct 1, 2024 8:03pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 1, 2024 8:03pm

@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 Oct 1, 2024
Copy link

github-actions bot commented Oct 1, 2024

size-limit report 📦

Path Size
lexical - cjs 29.82 KB (0%)
lexical - esm 29.67 KB (0%)
@lexical/rich-text - cjs 38.42 KB (0%)
@lexical/rich-text - esm 31.51 KB (0%)
@lexical/plain-text - cjs 37.01 KB (0%)
@lexical/plain-text - esm 28.9 KB (0%)
@lexical/react - cjs 40.17 KB (0%)
@lexical/react - esm 32.97 KB (0%)

@etrepum etrepum force-pushed the token-removeText-regression branch from ea1aab1 to cd50c99 Compare October 1, 2024 18:15
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Oct 1, 2024
@etrepum etrepum marked this pull request as ready for review October 1, 2024 18:43
@etrepum etrepum changed the title [WIP] [lexical] Bug Fix: TextNode in token mode should not be split by removeText [lexical] Bug Fix: TextNode in token mode should not be split by removeText Oct 1, 2024
@adrianmxb
Copy link
Contributor

adrianmxb commented Oct 1, 2024

Appreciate the proposed changes and prefer this approach. Since I didn’t have the chance to follow up with tests earlier and you seem to have everything covered, I’ve gone ahead and closed my PR in favour of this one. That said, I do have a suggestion: it might be worth updating the fixText function to only create a new Text Node when in segmented mode. This would help prevent potential confusion later on.

@etrepum
Copy link
Collaborator Author

etrepum commented Oct 2, 2024

I don't think it's really worth the code churn to change fixText, the code now handles the token cases correctly because they all fall under node.getTextContent() === '' or del === 0. If I wrote this originally I might do it a bit differently but the logic down there doesn't seem wrong.

I do wonder if this makes sense at all since it seems that the logic to handle segmented deletion is elsewhere but if this better matches the previous behavior then it probably is the right thing to do.

@adrianmxb
Copy link
Contributor

Just to be clear, I only talk about replacing $isTokenOrSegmented(...) through a node.isSegmented() call. I would argue that relying on implicit behaviours (like node.getTextContent() === '' or del === 0) to exclude token nodes isn't clear to readers.

Making the exclusion explicit avoids potential confusion.

@@ -344,6 +344,295 @@ describe('LexicalSelection tests', () => {
});
});
describe('removeText', () => {
describe('with a leading TextNode and a trailing token TextNode', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding a test case

@potatowagon potatowagon added this pull request to the merge queue Oct 2, 2024
Merged via the queue into facebook:main with commit ecb70ac Oct 2, 2024
44 checks passed
@etrepum etrepum deleted the token-removeText-regression branch October 2, 2024 22:56
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: removeText misbehaves for text nodes in token mode
4 participants