Skip to content

Commit

Permalink
Exit zoom out mode on enter keypress of selected block
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Oct 1, 2024
1 parent 249f701 commit b6cb3ac
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useRefEffect } from '@wordpress/compose';
* Internal dependencies
*/
import { store as blockEditorStore } from '../../../store';
import { unlock } from '../../../lock-unlock';

/**
* Adds block behaviour:
Expand All @@ -20,9 +21,18 @@ import { store as blockEditorStore } from '../../../store';
* @param {string} clientId Block client ID.
*/
export function useEventHandlers( { clientId, isSelected } ) {
const { getBlockRootClientId, getBlockIndex } =
useSelect( blockEditorStore );
const { insertAfterBlock, removeBlock } = useDispatch( blockEditorStore );
const {
getBlockRootClientId,
getBlockIndex,
isZoomOut,
__unstableGetEditorMode,
} = unlock( useSelect( blockEditorStore ) );
const {
insertAfterBlock,
removeBlock,
__unstableSetEditorMode,
resetZoomLevel,
} = unlock( useDispatch( blockEditorStore ) );

return useRefEffect(
( node ) => {
Expand Down Expand Up @@ -56,7 +66,14 @@ export function useEventHandlers( { clientId, isSelected } ) {

event.preventDefault();

if ( keyCode === ENTER ) {
if (
keyCode === ENTER &&
__unstableGetEditorMode() === 'zoom-out' &&
isZoomOut()
) {
__unstableSetEditorMode( 'edit' );
resetZoomLevel();
} else if ( keyCode === ENTER ) {
insertAfterBlock( clientId );
} else {
removeBlock( clientId );
Expand Down Expand Up @@ -88,6 +105,10 @@ export function useEventHandlers( { clientId, isSelected } ) {
getBlockIndex,
insertAfterBlock,
removeBlock,
__unstableGetEditorMode,
__unstableSetEditorMode,
isZoomOut,
resetZoomLevel,
]
);
}

0 comments on commit b6cb3ac

Please sign in to comment.