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

fix LexicalNode.isBefore(), clean up and optimize getCommonAncestor, isBefore, getNodesBetween #6310

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix is before when there is offset in element
  • Loading branch information
Piechota committed Jun 15, 2024
commit 09aae521eedc66b4a49118682b49efadc6c39c50
6 changes: 4 additions & 2 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,18 @@ export class Point {
isBefore(b: PointType): boolean {
let aNode = this.getNode();
let bNode = b.getNode();
const aOffset = this.offset;
const bOffset = b.offset;
let aOffset = this.offset;
let bOffset = b.offset;

if ($isElementNode(aNode)) {
const aNodeDescendant = aNode.getDescendantByIndex<ElementNode>(aOffset);
aNode = aNodeDescendant != null ? aNodeDescendant : aNode;
aOffset = 0;
}
if ($isElementNode(bNode)) {
const bNodeDescendant = bNode.getDescendantByIndex<ElementNode>(bOffset);
bNode = bNodeDescendant != null ? bNodeDescendant : bNode;
bOffset = 0;
}
if (aNode === bNode) {
return aOffset < bOffset;
Expand Down
Loading