Skip to content

Commit

Permalink
Try: Show copy shortcut in block options. (#60339)
Browse files Browse the repository at this point in the history
* Try: Show copy shortcut in block options.

* Add shortcut to only the main copy item.
  • Loading branch information
jasmussen committed Apr 2, 2024
1 parent cee2fde commit 314a6b8
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -11,6 +11,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
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,
Expand All @@ -33,14 +34,18 @@ const POPOVER_PROPS = {
placement: 'bottom-start',
};

function CopyMenuItem( { clientIds, onCopy, label } ) {
function CopyMenuItem( { clientIds, onCopy, label, shortcut } ) {
const { getBlocksByClientId } = useSelect( blockEditorStore );
const ref = useCopyToClipboard(
() => serialize( getBlocksByClientId( clientIds ) ),
onCopy
);
const copyMenuItemLabel = label ? label : __( 'Copy' );
return <MenuItem ref={ ref }>{ copyMenuItemLabel }</MenuItem>;
return (
<MenuItem ref={ ref } shortcut={ shortcut }>
{ copyMenuItemLabel }
</MenuItem>
);
}

export function BlockSettingsDropdown( {
Expand Down Expand Up @@ -279,6 +284,7 @@ export function BlockSettingsDropdown( {
<CopyMenuItem
clientIds={ clientIds }
onCopy={ onCopy }
shortcut={ displayShortcut.primary( 'c' ) }
/>
{ canDuplicate && (
<MenuItem
Expand Down

0 comments on commit 314a6b8

Please sign in to comment.