Skip to content

Commit

Permalink
List View: Unify shortcut handlers (#61130)
Browse files Browse the repository at this point in the history
* List View: Unify shortcut handlers
* Don't move the block selection handler
* Remove fragment
* Close the dropdown when inserting block before|after

Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
  • Loading branch information
3 people committed Apr 30, 2024
1 parent ce214f5 commit f99f65b
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 329 deletions.
Expand Up @@ -12,10 +12,7 @@ import { moreVertical } from '@wordpress/icons';
import { Children, cloneElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { displayShortcut } from '@wordpress/keycodes';
import {
store as keyboardShortcutsStore,
__unstableUseShortcutEventMatch,
} from '@wordpress/keyboard-shortcuts';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { pipe, useCopyToClipboard } from '@wordpress/compose';

/**
Expand Down Expand Up @@ -125,7 +122,6 @@ export function BlockSettingsDropdown( {
),
};
}, [] );
const isMatch = __unstableUseShortcutEventMatch();
const hasSelectedBlocks = selectedBlockClientIds.length > 0;

async function updateSelectionAfterDuplicate( clientIdsPromise ) {
Expand Down Expand Up @@ -213,52 +209,6 @@ export function BlockSettingsDropdown( {
open={ open }
onToggle={ onToggle }
noIcons
menuProps={ {
/**
* @param {KeyboardEvent} event
*/
onKeyDown( event ) {
if ( event.defaultPrevented ) return;

if (
isMatch( 'core/block-editor/remove', event ) &&
canRemove
) {
event.preventDefault();
onRemove();
updateSelectionAfterRemove();
} else if (
isMatch(
'core/block-editor/duplicate',
event
) &&
canDuplicate
) {
event.preventDefault();
updateSelectionAfterDuplicate( onDuplicate() );
} else if (
isMatch(
'core/block-editor/insert-after',
event
) &&
canInsertBlock
) {
event.preventDefault();
setOpenedBlockSettingsMenu( undefined );
onInsertAfter();
} else if (
isMatch(
'core/block-editor/insert-before',
event
) &&
canInsertBlock
) {
event.preventDefault();
setOpenedBlockSettingsMenu( undefined );
onInsertBefore();
}
},
} }
{ ...props }
>
{ ( { onClose } ) => (
Expand Down

0 comments on commit f99f65b

Please sign in to comment.