Skip to content

Commit

Permalink
Simplify logic, use DOMRect
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Aug 31, 2022
1 parent a265060 commit 4351685
Showing 1 changed file with 22 additions and 50 deletions.
72 changes: 22 additions & 50 deletions packages/block-editor/src/components/block-popover/inbetween.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,68 +101,40 @@ function BlockPopoverInbetween( {
return {
ownerDocument,
getBoundingClientRect() {
const previousRect = previousElement
const prevRect = previousElement
? previousElement.getBoundingClientRect()
: null;
const nextRect = nextElement
? nextElement.getBoundingClientRect()
: null;

let left = 0;
let top = 0;

if ( isVertical ) {
// vertical
top = prevRect ? prevRect.bottom : nextRect.top;

if ( isRTL() ) {
return {
top: previousRect
? previousRect.bottom
: nextRect.top,
left: previousRect
? previousRect.right
: nextRect.right,
right: previousRect
? previousRect.left
: nextRect.left,
bottom: nextRect
? nextRect.top
: previousRect.bottom,
height: 0,
width: 0,
};
// vertical, rtl
left = prevRect ? prevRect.right : nextRect.right;
} else {
// vertical, ltr
left = prevRect ? prevRect.left : nextRect.left;
}
} else {
top = prevRect ? prevRect.top : nextRect.top;

return {
top: previousRect ? previousRect.bottom : nextRect.top,
left: previousRect ? previousRect.left : nextRect.left,
right: previousRect
? previousRect.right
: nextRect.right,
bottom: nextRect ? nextRect.top : previousRect.bottom,
height: 0,
width: 0,
};
}

if ( isRTL() ) {
return {
top: previousRect ? previousRect.top : nextRect.top,
left: previousRect ? previousRect.left : nextRect.right,
right: nextRect ? nextRect.right : previousRect.left,
bottom: previousRect
? previousRect.bottom
: nextRect.bottom,
height: 0,
width: 0,
};
if ( isRTL() ) {
// non vertical, rtl
left = prevRect ? prevRect.left : nextRect.right;
} else {
// non vertical, ltr
left = prevRect ? prevRect.right : nextRect.left;
}
}

return {
top: previousRect ? previousRect.top : nextRect.top,
left: previousRect ? previousRect.right : nextRect.left,
right: nextRect ? nextRect.left : previousRect.right,
bottom: previousRect
? previousRect.bottom
: nextRect.bottom,
height: 0,
width: 0,
};
return new window.DOMRect( left, top, 0, 0 );
},
};
}, [ previousElement, nextElement, isVisible ] );
Expand Down

0 comments on commit 4351685

Please sign in to comment.