-
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
fix LexicalNode.isBefore(), clean up and optimize getCommonAncestor, isBefore, getNodesBetween #6310
base: main
Are you sure you want to change the base?
Conversation
isBefore treated parent as last element in hierarchy.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
This reverts commit 09aae52.
Ok, there is one bug with current implementation.
So it isn't inconsistent with when it goes down the tree and when parent is at the end. With changed version it's more consistent, but it doesn't fix |
Additionally cleaned few other methods, and fixed bug in getNodesBetween:
for TextNode2.getNodesBetween( TextNode4 ) it will return TextNode2, ElementNode0, ElementNode3, TextNode4. |
So it turned out getNodesBetween has to return every parent that is touched because selection expects that. This one still fixes inconsistency when switching caller with target |
Currently
LexicalNode.isBefore()
when tested withparent.isBefore(child)
will return false.It seems more logically correct (and similar to editor's node tree) for parent to be before child.
Right now everything that tests for
.isBefore()
uses onlyTextNode
.LexicalSelection.ts
beforeisBefore()
is called there is (inPointType.isBefore()
):that looks for first child that is not
ElementNode
LexicalNode.getNodesBetween()
inLexicalNode.getNodes()
is also behindgetDescendantByIndex()
in
CodeHighlighter.ts
functon$handleShiftLines()
that usesisBefore()
starts withThat will early out on parent and second
getNodesBetween()
is also behind this early out.From what I saw it works correctly if we assume that parent is at the end of children.
But I feel like it's less intuitive and not consistent with
getIndexWithinParent()
getDescendantByIndex()
that go from 0 to children count.Original
isBefore()
is quite old #590and doesn't explain what it fixes.