Skip to content

Commit

Permalink
Follow-up to facebook#5948 regression, simplify decorator selection c…
Browse files Browse the repository at this point in the history
…heck with proper short-circuiting
  • Loading branch information
etrepum committed Aug 10, 2024
1 parent 9cb10ea commit 3122ac2
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions packages/lexical/src/LexicalNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,27 +295,16 @@ export class LexicalNode {

const parentNode = this.getParent();
if ($isDecoratorNode(this) && this.isInline() && parentNode) {
const {anchor, focus} = targetSelection;

if (anchor.isBefore(focus)) {
const anchorNode = anchor.getNode() as ElementNode;
const isAnchorPointToLast =
anchor.offset === anchorNode.getChildrenSize();
const isAnchorNodeIsParent = anchorNode.is(parentNode);
const isLastChild = anchorNode.getLastChildOrThrow().is(this);

if (isAnchorPointToLast && isAnchorNodeIsParent && isLastChild) {
return false;
}
} else {
const focusNode = focus.getNode() as ElementNode;
const isFocusPointToLast =
focus.offset === focusNode.getChildrenSize();
const isFocusNodeIsParent = focusNode.is(parentNode);
const isLastChild = focusNode.getLastChildOrThrow().is(this);
if (isFocusPointToLast && isFocusNodeIsParent && isLastChild) {
return false;
}
const firstPoint = targetSelection.isBackward()
? targetSelection.focus
: targetSelection.anchor;
const firstElement = firstPoint.getNode() as ElementNode;
if (
firstPoint.offset === firstElement.getChildrenSize() &&
firstElement.is(parentNode) &&
firstElement.getLastChildOrThrow().is(this)
) {
return false;
}
}
}
Expand Down

0 comments on commit 3122ac2

Please sign in to comment.