Skip to content

Commit

Permalink
rebase and refactor to trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Oct 9, 2024
1 parent 7340783 commit bf676b2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
useMergeRefs,
useRefEffect,
useDisabled,
usePrevious,
} from '@wordpress/compose';
import { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -371,6 +372,29 @@ function Iframe( {
// mode. They're only needed to capture focus in edit mode.
const shouldRenderFocusCaptureElements = tabIndex >= 0 && ! isPreviewMode;

const previousScale = usePrevious( scale );

// Scroll based on the new scale
useEffect( () => {
if ( ! iframeDocument || isZoomedOut ) {
return;
}

const maxWidth = 750;
const previousScaleNumber =
previousScale === 'default'
? Math.min( containerWidth, maxWidth ) /
prevContainerWidthRef.current
: previousScale;

const { documentElement } = iframeDocument;
const { scrollTop, scrollLeft } = documentElement;
const delta = 1 + scale - previousScaleNumber;

documentElement.scrollTop = delta * scrollTop;
documentElement.scrollLeft = delta * scrollLeft;
}, [ scale, previousScale, iframeDocument, isZoomedOut, containerWidth ] );

const iframe = (
<>
{ shouldRenderFocusCaptureElements && before }
Expand Down

0 comments on commit bf676b2

Please sign in to comment.