Skip to content

Commit

Permalink
Close inserter on double click to exit Zoom Out
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Sep 11, 2024
1 parent ae3f130 commit 42ba373
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useDispatch } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useRefEffect } from '@wordpress/compose';

/**
Expand All @@ -20,6 +20,16 @@ export function useZoomOutModeExit( { editorMode } ) {
useDispatch( blockEditorStore )
);

const { setIsInserterOpened } = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );

const { __experimentalSetIsInserterOpened } = getSettings();

return {
setIsInserterOpened: __experimentalSetIsInserterOpened,
};
}, [] );

return useRefEffect(
( node ) => {
if ( editorMode !== 'zoom-out' ) {
Expand All @@ -29,6 +39,10 @@ export function useZoomOutModeExit( { editorMode } ) {
function onDoubleClick( event ) {
if ( ! event.defaultPrevented ) {
event.preventDefault();
// Setting may be undefined.
if ( typeof setIsInserterOpened === 'function' ) {
setIsInserterOpened( false );
}
__unstableSetEditorMode( 'edit' );
}
}
Expand Down

0 comments on commit 42ba373

Please sign in to comment.