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

Zoom Out: When double clicking a template while zoomed out , reset zoom level instead of showing dialog #65963

Merged
Merged
Changes from 1 commit
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,8 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';
import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
Expand All @@ -11,6 +12,7 @@ import { __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/compone
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

/**
* Component that:
Expand All @@ -27,16 +29,24 @@ import { store as editorStore } from '../../store';
* editor iframe canvas.
*/
export default function EditTemplateBlocksNotification( { contentRef } ) {
const { onNavigateToEntityRecord, templateId } = useSelect( ( select ) => {
const { getEditorSettings, getCurrentTemplateId } =
select( editorStore );
const { isZoomOut, onNavigateToEntityRecord, templateId } = useSelect(
( select ) => {
const { getEditorSettings, getCurrentTemplateId } =
select( editorStore );

return {
onNavigateToEntityRecord:
getEditorSettings().onNavigateToEntityRecord,
templateId: getCurrentTemplateId(),
};
}, [] );
return {
isZoomOut: unlock( select( blockEditorStore ) ).isZoomOut(),
onNavigateToEntityRecord:
getEditorSettings().onNavigateToEntityRecord,
templateId: getCurrentTemplateId(),
};
},
[]
);

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

const canEditTemplate = useSelect(
( select ) =>
Expand All @@ -51,6 +61,14 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {

useEffect( () => {
const handleDblClick = ( event ) => {
// If the editor is zoomed out, reset the zoom level and switch to
// edit mode. The dialog will not be shown in this case.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth adding a link to the related Issue? Or perhaps describing that we already have a "double click" handler for exiting Zoom Out so we want to ensure the same behaviour on template parts?

if ( isZoomOut ) {
resetZoomLevel();
__unstableSetEditorMode( 'edit' );
return;
}

if ( ! canEditTemplate ) {
return;
}
Expand All @@ -69,7 +87,13 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {
return () => {
canvas?.removeEventListener( 'dblclick', handleDblClick );
};
}, [ contentRef, canEditTemplate ] );
}, [
contentRef,
canEditTemplate,
isZoomOut,
resetZoomLevel,
__unstableSetEditorMode,
] );

if ( ! canEditTemplate ) {
return null;
Expand Down
Loading