-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Breaking Change][lexical][lexical-utils]: Bug Fix: Handle canBeEmpty in $splitNodes #7342
Merged
+475
−64
Conversation
This file contains 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
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
etrepum
commented
Mar 17, 2025
|
||
export class TestDecoratorNode extends DecoratorNode<JSX.Element> { | ||
__block: boolean = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DecoratorNode are inline by default but some of these tests were inserting it directly into the root. I added this to make that reasonable.
/cc @ivailop7 |
ivailop7
approved these changes
Mar 17, 2025
Merged
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
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.
Breaking Change
Previously
$insertNodeToNearestRoot
could create empty ElementNode when splitting the current node, now it respectscanBeEmpty()
and will not split in those cases.Description
This change makes
$insertNodeToNearestRoot
to respect thecanBeEmpty()
method of the nodes it is splitting and provides infrastructure to better control splitting (SplitAtPointCaretNextOptions
,$insertNodeToNearestRootAtCaret
,$splitAtPointCaretNext
).New lexical APIs:
$splitAtPointCaretNext
- a lower-level API to split at the given caret exactly once (not recursive) with full control over how that happens$getCollapsedCaretRange(pointCaret)
- convenience for$getCaretRange(pointCaret, pointCaret)
to reduce redundant codeNew @lexical/utils API:
$insertNodeToNearestRootAtCaret
- lower-level API that does$insertNodeToNearestRoot
recursive split and then insert without the quirks and selection changes (those happen in the$insertNodeToNearestRoot
function).I'm not very fond of the manner in which nodes are split (the empty splits are a bit awkward especially when not a ParagraphNode), but this doesn't break backwards compatibility in any case that we test and this function is only used in the playground and the implementation of commands that can be easily overridden (e.g.
INSERT_HORIZONTAL_RULE_COMMAND
). Now that the lower-level functions are exposed, people can control how this works for better UX.Closes #6849
Test plan
All existing e2e tests pass, new ListNode split test
Before
Splitting an empty ListItemNode creates a broken list:
After
Splitting an empty ListItemNode creates a complete second list: