Skip to content

Commit

Permalink
adds handler for inserter tabs that engages zoom out view and mode
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Oct 2, 2024
1 parent 41804e1 commit cdab3fe
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDebouncedInput } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -32,6 +32,7 @@ import InserterSearchResults from './search-results';
import useInsertionPoint from './hooks/use-insertion-point';
import { store as blockEditorStore } from '../../store';
import TabbedSidebar from '../tabbed-sidebar';
import { unlock } from '../../lock-unlock';

const NOOP = () => {};
function InserterMenu(
Expand Down Expand Up @@ -283,7 +284,22 @@ function InserterMenu(
showMediaPanel,
] );

const { resetZoomLevel, setZoomLevel, __unstableSetEditorMode } = unlock(
useDispatch( blockEditorStore )
);

const handleZoomOut = ( newSelectedTab ) => {
if ( isZoomOutMode && newSelectedTab !== 'patterns' ) {
resetZoomLevel();
__unstableSetEditorMode( 'edit' );
} else if ( ! isZoomOutMode && newSelectedTab === 'patterns' ) {
setZoomLevel( 50 );
__unstableSetEditorMode( 'zoom-out' );
}
};

const handleSetSelectedTab = ( value ) => {
handleZoomOut( value );
// If no longer on patterns tab remove the category setting.
if ( value !== 'patterns' ) {
setSelectedPatternCategory( null );
Expand Down

0 comments on commit cdab3fe

Please sign in to comment.