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

Close inserter on exiting Zoom Out to edit #65194

Merged
merged 3 commits into from
Sep 12, 2024
Merged
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
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 @@ -16,6 +16,10 @@ import { unlock } from '../../../lock-unlock';
* @param {string} clientId Block client ID.
*/
export function useZoomOutModeExit( { editorMode } ) {
const getSettings = useSelect(
( select ) => select( blockEditorStore ).getSettings
);

const { __unstableSetEditorMode } = unlock(
useDispatch( blockEditorStore )
);
Expand All @@ -29,6 +33,14 @@ export function useZoomOutModeExit( { editorMode } ) {
function onDoubleClick( event ) {
if ( ! event.defaultPrevented ) {
event.preventDefault();

const { __experimentalSetIsInserterOpened } = getSettings();

if (
typeof __experimentalSetIsInserterOpened === 'function'
) {
__experimentalSetIsInserterOpened( false );
}
Comment on lines +37 to +43
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This pattern follows the advice in #64573 (comment)

__unstableSetEditorMode( 'edit' );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
getPreviousBlockClientId,
canRemoveBlock,
canMoveBlock,
getSettings,
} = select( blockEditorStore );

const { __experimentalSetIsInserterOpened: setIsInserterOpened } =
getSettings();

const { getBlockType } = select( blocksStore );
const { name } = getBlock( clientId );
const blockType = getBlockType( name );
Expand Down Expand Up @@ -63,6 +68,7 @@ export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
isPrevBlockTemplatePart,
canRemove: canRemoveBlock( clientId ),
canMove: canMoveBlock( clientId ),
setIsInserterOpened,
};
},
[ clientId ]
Expand All @@ -75,6 +81,7 @@ export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
isPrevBlockTemplatePart,
canRemove,
canMove,
setIsInserterOpened,
} = selected;

const { removeBlock, __unstableSetEditorMode } =
Expand Down Expand Up @@ -132,6 +139,10 @@ export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
icon={ edit }
label={ __( 'Edit' ) }
onClick={ () => {
// Setting may be undefined.
if ( typeof setIsInserterOpened === 'function' ) {
setIsInserterOpened( false );
}
__unstableSetEditorMode( 'edit' );
__unstableContentRef.current?.focus();
} }
Expand Down
Loading