Skip to content

Commit

Permalink
Keyboard Shortcuts: Registered cut and copy as block level shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Jan 9, 2025
1 parent be5b4c5 commit bf79be1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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 } from '@wordpress/keyboard-shortcuts';
import { pipe, useCopyToClipboard } from '@wordpress/compose';

Expand Down Expand Up @@ -137,6 +136,8 @@ export function BlockSettingsDropdown( {
const shortcuts = useSelect( ( select ) => {
const { getShortcutRepresentation } = select( keyboardShortcutsStore );
return {
copy: getShortcutRepresentation( 'core/block-editor/copy' ),
cut: getShortcutRepresentation( 'core/block-editor/cut' ),
duplicate: getShortcutRepresentation(
'core/block-editor/duplicate'
),
Expand Down Expand Up @@ -276,18 +277,14 @@ export function BlockSettingsDropdown( {
<CopyMenuItem
clientIds={ clientIds }
onEvent={ onCopy }
shortcut={ displayShortcut.primary(
'c'
) }
shortcut={ shortcuts.copy }
/>
<CopyMenuItem
clientIds={ clientIds }
onEvent={ onCopy }
label={ __( 'Cut' ) }
eventType="cut"
shortcut={ displayShortcut.primary(
'x'
) }
shortcut={ shortcuts.cut }
__experimentalUpdateSelection={
! __experimentalSelectBlock
}
Expand Down
20 changes: 20 additions & 0 deletions packages/block-editor/src/components/keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ function KeyboardShortcutsRegister() {
// Registering the shortcuts.
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
useEffect( () => {
registerShortcut( {
name: 'core/block-editor/copy',
category: 'block',
description: __( 'Copy the selected block(s).' ),
keyCombination: {
modifier: 'primary',
character: 'c',
},
} );

registerShortcut( {
name: 'core/block-editor/cut',
category: 'block',
description: __( 'Cut the selected block(s).' ),
keyCombination: {
modifier: 'primary',
character: 'x',
},
} );

registerShortcut( {
name: 'core/block-editor/duplicate',
category: 'block',
Expand Down

0 comments on commit bf79be1

Please sign in to comment.