Skip to content

Commit

Permalink
Try again
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Oct 1, 2024
1 parent 3e684df commit 6458b58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
useBlockRefProvider( clientId ),
useFocusHandler( clientId ),
useEventHandlers( { clientId, isSelected } ),
useZoomOutModeExit(),
useZoomOutModeExit( { clientId } ),
useIsHovered( { clientId } ),
useIntersectionObserver(),
useMovingAnimation( { triggerAnimationOnChange: index, clientId } ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,50 @@ import { unlock } from '../../../lock-unlock';

/**
* Allows Zoom Out mode to be exited by double clicking in the selected block.
*
* @param {Object} props - The props.
* @param {string} props.clientId - The client ID of the block.
*/
export function useZoomOutModeExit() {
const { getSettings, isZoomOut, __unstableGetEditorMode } = unlock(
useSelect( blockEditorStore )
);
export function useZoomOutModeExit( { clientId } ) {
const {
getSettings,
isZoomOut,
getSectionRootClientId,
getBlockOrder,
__unstableGetEditorMode,
} = unlock( useSelect( blockEditorStore ) );

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

return useRefEffect(
( node ) => {
// In "compose" mode.
const composeMode =
__unstableGetEditorMode() === 'zoom-out' && isZoomOut();

if ( ! composeMode ) {
return;
}

const sectionsClientIds = getBlockOrder( getSectionRootClientId() );

const isSectionBlock = sectionsClientIds.includes( clientId );

// If this is not a section then don't attach the listener because
// the event will bubble up to the sections.
// This ensures that `node` is the section block.
if ( ! isSectionBlock ) {
return;
}

function onDoubleClick( event ) {
// In "compose" mode.
const composeMode =
__unstableGetEditorMode() === 'zoom-out' && isZoomOut();
event.stopPropagation();

if ( ! composeMode ) {
// Ignore double click unless it occured directly on the section block itself.
// See https://github.com/WordPress/gutenberg/issues/65750.
if ( event.target !== node ) {
return;
}

Expand Down

0 comments on commit 6458b58

Please sign in to comment.