Skip to content

Commit

Permalink
Offset insertion point in iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 committed Feb 1, 2021
1 parent d63f9a1 commit cbe933e
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions packages/block-editor/src/components/block-list/insertion-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ import { isRTL } from '@wordpress/i18n';
import Inserter from '../inserter';
import { getBlockDOMNode } from '../../utils/dom';

function offsetIframe( rect, ownerDocument ) {
const { defaultView } = ownerDocument;
const { frameElement } = defaultView;

if ( ! frameElement ) {
return rect;
}

const iframeRect = frameElement.getBoundingClientRect();

return new defaultView.DOMRect(
rect.left + iframeRect.left,
rect.top + iframeRect.top,
rect.width,
rect.height
);
}

function InsertionPointInserter( {
clientId,
rootClientId,
Expand Down Expand Up @@ -146,9 +164,15 @@ function InsertionPointPopover( {
}, [ previousElement, nextElement ] );

const getAnchorRect = useCallback( () => {
const previousRect = previousElement.getBoundingClientRect();
const previousRect = offsetIframe(
previousElement.getBoundingClientRect(),
previousElement.ownerDocument
);
const nextRect = nextElement
? nextElement.getBoundingClientRect()
? offsetIframe(
nextElement.getBoundingClientRect(),
nextElement.ownerDocument
)
: null;
if ( orientation === 'vertical' ) {
return {
Expand Down

0 comments on commit cbe933e

Please sign in to comment.