-
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
[lexical][lexical-utils][lexical-selection][lexical-table] Feature: NodeCaret abstraction for traversals and ranges #7046
Merged
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 ↗︎
|
This comment was marked as outdated.
This comment was marked as outdated.
zurfyx
previously approved these changes
Feb 6, 2025
Will merge this after v0.24.0 so there's some nightly releases before it goes live |
Latest couple commits:
Should be good to merge once re-approved |
zurfyx
approved these changes
Feb 8, 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.
Description
A fair amount of bugs and complexity in our code results from ambiguity and awkwardness around traversing the node tree, as well as issues around coordinates becoming stale after mutations. This is a proposal for a new set of abstractions that can be used in place of the typical
PointType
andRangeSelection
to work through these sorts of traversal use cases with hopefully fewer bugs.There are three major deficiencies that the design of
NodeCaret
hopes to address:Docs:
I can write up some flow types when/if we move forward with the proposal to reduce the maintenance burden if anything changes before acceptance.
Cost
The current estimate looks like it's currently at
31.55 KB (+8.56% 🔺)
which is +~2.5kB for the production cjs build. There will be some follow-up PRs to reduce this further with additional refactoring to use this API more internally.Other changes
I didn't refactor everything with NodeCaret but chose a few places that would be straightforward and/or make it easier to fix a few bugs. More will come later which should reduce code size.
lexical
RangeSelection.removeText
with new algorithm based on CaretRangeTextNode.splitText
algorithm@lexical/selection
$forEachSelectedTextNode
to work with types other than RangeSelection$patchStyle
for updating the style of an individual TextNode or collapsed RangeSelection$ensureForwardRangeSelection
function to flip anchor/focus when backwards$setBlocksType
: Add new$afterCreateElement
argument to allow user to specify how properties propagate to the new block (e.g. format and indent by default - fixes an indent related bug)$copyBlockFormatIndent
used as new$setBlocksType
optional argument default@lexical/table
$createTableSelectionFrom
@lexical/utils
$dfs
and related functions with NodeCaret implementationsCloses #7076
Closes #7081