diff --git a/packages/block-editor/src/store/private-actions.js b/packages/block-editor/src/store/private-actions.js index e79833e0a73da7..b24eedda2b904f 100644 --- a/packages/block-editor/src/store/private-actions.js +++ b/packages/block-editor/src/store/private-actions.js @@ -428,8 +428,12 @@ export const modifyContentLockBlock = export const setZoomLevel = ( zoom = 100 ) => ( { select, dispatch } ) => { + // Disable zoom level if it's not allowed. + if ( ! select.getSettings()?.allowZoomLevel ) { + zoom = 100; + } // When switching to zoom-out mode, we need to select the parent section - if ( zoom !== 100 ) { + else if ( zoom !== 100 ) { const firstSelectedClientId = select.getBlockSelectionStart(); const sectionRootClientId = select.getSectionRootClientId(); diff --git a/packages/editor/src/components/header/index.js b/packages/editor/src/components/header/index.js index 2a5629b080caf8..502f08654e8ab7 100644 --- a/packages/editor/src/components/header/index.js +++ b/packages/editor/src/components/header/index.js @@ -64,6 +64,7 @@ function Header( { showIconLabels, hasFixedToolbar, hasBlockSelection, + canBeZoomedOut, } = useSelect( ( select ) => { const { get: getPreference } = select( preferencesStore ); const { @@ -80,13 +81,12 @@ function Header( { hasFixedToolbar: getPreference( 'core', 'fixedToolbar' ), hasBlockSelection: !! select( blockEditorStore ).getBlockSelectionStart(), + canBeZoomedOut: + select( blockEditorStore ).getSettings()?.allowZoomLevel && + [ 'post', 'page', 'wp_template' ].includes( postType ), }; }, [] ); - const canBeZoomedOut = [ 'post', 'page', 'wp_template' ].includes( - postType - ); - const disablePreviewOption = [ NAVIGATION_POST_TYPE, TEMPLATE_PART_POST_TYPE, diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index f5c45f431e2c85..9d728128737819 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -108,6 +108,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) { const isLargeViewport = useViewportMatch( 'medium' ); const { allowRightClickOverrides, + allowZoomLevel, blockTypes, focusMode, hasFixedToolbar, @@ -186,6 +187,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) { userPatternCategories: getUserPatternCategories(), restBlockPatternCategories: getBlockPatternCategories(), sectionRootClientId: getSectionRootBlock(), + allowZoomLevel: true, }; }, [ postType, postId, isLargeViewport, renderingMode ] @@ -285,6 +287,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) { [ globalStylesLinksDataKey ]: globalStylesLinksData, allowedBlockTypes, allowRightClickOverrides, + allowZoomLevel, focusMode: focusMode && ! forceDisableFocusMode, hasFixedToolbar, isDistractionFree, @@ -336,6 +339,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) { return blockEditorSettings; }, [ + allowZoomLevel, allowedBlockTypes, allowRightClickOverrides, focusMode,