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

Try: Show copy shortcut in block options. #60339

Merged
merged 2 commits into from
Apr 2, 2024
Merged
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 @@ -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
Loading