From 5f74d54123ce5973a032cb616787fcad90484b1e Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Wed, 8 Jan 2025 21:49:48 +0530 Subject: [PATCH] Block Action: Implement cut functionality in block actions and settings menu --- .../src/components/block-actions/index.js | 7 ++++++ .../block-settings-dropdown.js | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/block-editor/src/components/block-actions/index.js b/packages/block-editor/src/components/block-actions/index.js index f06c8addedad50..4c64de6b1c4cba 100644 --- a/packages/block-editor/src/components/block-actions/index.js +++ b/packages/block-editor/src/components/block-actions/index.js @@ -132,6 +132,13 @@ export default function BlockActions( { } notifyCopy( 'copy', clientIds ); }, + onCut() { + if ( clientIds.length === 1 ) { + flashBlock( clientIds[ 0 ] ); + } + notifyCopy( 'cut', clientIds ); + removeBlocks( clientIds, updateSelection ); + }, async onPasteStyles() { await pasteStyles( getBlocksByClientId( clientIds ) ); }, diff --git a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js index ade9ddd5ec1657..d373a316d2618e 100644 --- a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js +++ b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js @@ -46,6 +46,20 @@ function CopyMenuItem( { clientIds, onCopy, label, shortcut } ) { ); } +function CutMenuItem( { clientIds, onCut, label, shortcut } ) { + const { getBlocksByClientId } = useSelect( blockEditorStore ); + const ref = useCopyToClipboard( + () => serialize( getBlocksByClientId( clientIds ) ), + onCut + ); + const cutMenuItemLabel = label ? label : __( 'Cut' ); + return ( + + { cutMenuItemLabel } + + ); +} + export function BlockSettingsDropdown( { block, clientIds, @@ -117,6 +131,7 @@ export function BlockSettingsDropdown( { duplicate: getShortcutRepresentation( 'core/block-editor/duplicate' ), + cut: getShortcutRepresentation( 'core/block-editor/cut' ), remove: getShortcutRepresentation( 'core/block-editor/remove' ), insertAfter: getShortcutRepresentation( 'core/block-editor/insert-after' @@ -204,6 +219,7 @@ export function BlockSettingsDropdown( { onInsertBefore, onRemove, onCopy, + onCut, onPasteStyles, } ) => { // It is possible that some plugins register fills for this menu @@ -257,6 +273,13 @@ export function BlockSettingsDropdown( { 'c' ) } /> + { canDuplicate && (