Skip to content

Commit

Permalink
put block editor in zoom out mode when inserting patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Mar 18, 2024
1 parent 2bcd06b commit a2cecab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@wordpress/element';
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useDebouncedInput } from '@wordpress/compose';

/**
Expand Down Expand Up @@ -57,6 +57,8 @@ function InserterMenu(
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
const [ selectedTab, setSelectedTab ] = useState( null );
const { __unstableGetEditorMode } = useSelect( blockEditorStore );
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );

const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
Expand Down Expand Up @@ -213,6 +215,12 @@ function InserterMenu(
if ( value !== 'patterns' ) {
setSelectedPatternCategory( null );
}
// Enter the zoom-out mode when selecting the patterns tab and exit otherwise.
if ( value === 'patterns' ) {
__unstableSetEditorMode( 'zoom-out' );
} else if ( __unstableGetEditorMode() === 'zoom-out' ) {
__unstableSetEditorMode( 'edit' );
}
setSelectedTab( value );
};

Expand Down
9 changes: 8 additions & 1 deletion packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { Notice } from '@wordpress/components';
import { useInstanceId, useViewportMatch } from '@wordpress/compose';
import { store as preferencesStore } from '@wordpress/preferences';
Expand Down Expand Up @@ -83,6 +83,9 @@ export default function Editor( { isLoading } ) {

const isLargeViewport = useViewportMatch( 'medium' );

const { __unstableSetEditorMode: setBlockEditorMode } =
useDispatch( blockEditorStore );

const {
context,
contextPost,
Expand Down Expand Up @@ -180,6 +183,10 @@ export default function Editor( { isLoading } ) {
( ( postWithTemplate && !! contextPost && !! editedPost ) ||
( ! postWithTemplate && !! editedPost ) );

if ( ! shouldShowInserter && blockEditorMode === 'zoom-out' ) {
setBlockEditorMode( 'edit' );
}

return (
<>
{ ! isReady ? <CanvasLoader id={ loadingProgressId } /> : null }
Expand Down

0 comments on commit a2cecab

Please sign in to comment.