Skip to content

Fix splitText when detached - #6501

Merged
zurfyx merged 1 commit into
mainfrom
splittextdetached
Aug 8, 2024
Merged

zurfyx merged 1 commit into
mainfrom
splittextdetached

Conversation

@zurfyx

@zurfyx zurfyx commented Aug 7, 2024

Copy link
Copy Markdown
Member

When splitText is run on a Node with no parent it crashes. I don't see any obvious reason why this function should only work on attached nodes and there are some valid cases when you'd want to attach the resulting nodes later and leverage splitText to preserve the styling and format.

@vercel

vercel Bot commented Aug 7, 2024

Copy link
Copy Markdown

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 Aug 7, 2024 9:23pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 7, 2024 9:23pm

@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 Aug 7, 2024
@github-actions

github-actions Bot commented Aug 7, 2024

Copy link
Copy Markdown

size-limit report 📦

Path Size
lexical - cjs 29.27 KB (0%)
lexical - esm 29.09 KB (0%)
@lexical/rich-text - cjs 37.68 KB (0%)
@lexical/rich-text - esm 30.92 KB (0%)
@lexical/plain-text - cjs 36.27 KB (0%)
@lexical/plain-text - esm 28.32 KB (0%)
@lexical/react - cjs 39.52 KB (0%)
@lexical/react - esm 32.39 KB (0%)

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks like a net improvement, but I think there may be other edge cases left in this method

Comment on lines +1012 to +1015
if (hasReplacedSelf) {
writableParent.splice(insertionIndex, 0, splitNodes);
this.remove();
} else {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I know this isn't the code that's changing in this PR but it seems like there might be a hasReplacedSelf selection bug, the above code to fixup selections only handles parts>0 and the splice selection fixup code won't do anything either because the node removal is happening separately. It also seems a bit odd that the special case only happens with IS_SEGMENTED and not IS_TOKEN

@zurfyx
zurfyx added this pull request to the merge queue Aug 8, 2024
Merged via the queue into main with commit 9cb10ea Aug 8, 2024
jkjk822 pushed a commit to jkjk822/lexical that referenced this pull request Aug 26, 2024
@zurfyx
zurfyx deleted the splittextdetached branch February 28, 2025 18:17

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — fa03a408 Deployed Aug 7, 2024 by vercel[bot]
Preview – lexical — fa03a408 Deployed Aug 7, 2024 by vercel[bot]
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.

3 participants