Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block editor setting to allowZoomLevel #67245

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/block-editor/src/store/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function Header( {
showIconLabels,
hasFixedToolbar,
hasBlockSelection,
canBeZoomedOut,
} = useSelect( ( select ) => {
const { get: getPreference } = select( preferencesStore );
const {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
const isLargeViewport = useViewportMatch( 'medium' );
const {
allowRightClickOverrides,
allowZoomLevel,
blockTypes,
focusMode,
hasFixedToolbar,
Expand Down Expand Up @@ -186,6 +187,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
userPatternCategories: getUserPatternCategories(),
restBlockPatternCategories: getBlockPatternCategories(),
sectionRootClientId: getSectionRootBlock(),
allowZoomLevel: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the criterion is to allow/disable here. Something about the presence of a <main> tag?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not have an allowZoomLevel, instead if there is no sectionRootClientId means zoom out should not auto engage.

};
},
[ postType, postId, isLargeViewport, renderingMode ]
Expand Down Expand Up @@ -285,6 +287,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
[ globalStylesLinksDataKey ]: globalStylesLinksData,
allowedBlockTypes,
allowRightClickOverrides,
allowZoomLevel,
focusMode: focusMode && ! forceDisableFocusMode,
hasFixedToolbar,
isDistractionFree,
Expand Down Expand Up @@ -336,6 +339,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {

return blockEditorSettings;
}, [
allowZoomLevel,
allowedBlockTypes,
allowRightClickOverrides,
focusMode,
Expand Down
Loading