From f415a5d6eb10abbcb88a264abe3a7316b36be096 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Fri, 25 Aug 2023 19:59:40 +0900 Subject: [PATCH] Command Palette: Fix crash on block-related commands (#53923) * Command Palette: Fix crash on block-related commands * Update string --- .../components/use-block-commands/index.js | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/packages/block-editor/src/components/use-block-commands/index.js b/packages/block-editor/src/components/use-block-commands/index.js index bb7b7d97c3190..cb325438deca7 100644 --- a/packages/block-editor/src/components/use-block-commands/index.js +++ b/packages/block-editor/src/components/use-block-commands/index.js @@ -229,39 +229,54 @@ const useActionsCommands = () => { return { isLoading: false, commands: [] }; } - const icons = { - ungroup, - group, - move, - add, - remove, - duplicate: copy, - }; - const commands = [ - onUngroup, - onGroup, - onMoveTo, - onAddAfter, - onAddBefore, - onRemove, - onDuplicate, - ].map( ( callback ) => { - const action = callback.name - .replace( 'on', '' ) - .replace( /([a-z])([A-Z])/g, '$1 $2' ); - + { + name: 'ungroup', + label: __( 'Ungroup' ), + callback: onUngroup, + icon: ungroup, + }, + { + name: 'Group', + label: __( 'Group' ), + callback: onGroup, + icon: group, + }, + { + name: 'move-to', + label: __( 'Move to' ), + callback: onMoveTo, + icon: move, + }, + { + name: 'add-after', + label: __( 'Add after' ), + callback: onAddAfter, + icon: add, + }, + { + name: 'add-before', + label: __( 'Add before' ), + callback: onAddBefore, + icon: add, + }, + { + name: 'remove', + label: __( 'Remove' ), + callback: onRemove, + icon: remove, + }, + { + name: 'duplicate', + label: __( 'Duplicate' ), + callback: onDuplicate, + icon: copy, + }, + ].map( ( { name, label, callback, icon } ) => { return { - name: 'core/block-editor/action-' + callback.name, - // translators: %s: type of the command. - label: action, - icon: icons[ - callback.name - .replace( 'on', '' ) - .match( /[A-Z]{1}[a-z]*/ ) - .toString() - .toLowerCase() - ], + name: 'core/block-editor/action-' + name, + label, + icon, callback: ( { close } ) => { callback(); close();