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

Update/replace edit button with enter on selection #65760

Merged
merged 2 commits into from
Oct 4, 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
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,
]
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { dragHandle, trash, edit } from '@wordpress/icons';
import { dragHandle, trash } from '@wordpress/icons';
import { Button, ToolbarButton } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';
Expand All @@ -15,7 +15,6 @@ import BlockDraggable from '../block-draggable';
import BlockMover from '../block-mover';
import Shuffle from '../block-toolbar/shuffle';
import NavigableToolbar from '../navigable-toolbar';
import { unlock } from '../../lock-unlock';

export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
const selected = useSelect(
Expand Down Expand Up @@ -74,12 +73,9 @@ export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
isPrevBlockTemplatePart,
canRemove,
canMove,
setIsInserterOpened,
} = selected;

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

const showBlockDraggable = canMove && ! isBlockTemplatePart;

Expand Down Expand Up @@ -123,23 +119,6 @@ export default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {
<Shuffle clientId={ clientId } as={ ToolbarButton } />
) }

{ ! isBlockTemplatePart && (
<ToolbarButton
className="zoom-out-toolbar-button"
icon={ edit }
label={ __( 'Edit' ) }
onClick={ () => {
// Setting may be undefined.
if ( typeof setIsInserterOpened === 'function' ) {
setIsInserterOpened( false );
}
__unstableSetEditorMode( 'edit' );
resetZoomLevel();
__unstableContentRef.current?.focus();
} }
/>
) }

{ canRemove && ! isBlockTemplatePart && (
<ToolbarButton
className="zoom-out-toolbar-button"
Expand Down
Loading