Skip to content

Commit

Permalink
Try: Show copy shortcut in block options. (WordPress#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 authored and cbravobernal committed Apr 9, 2024
1 parent 5172fb4 commit d4ebea9
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
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 d4ebea9

Please sign in to comment.