Skip to content

Commit

Permalink
Command Palette: Fix crash on block-related commands (#53923)
Browse files Browse the repository at this point in the history
* Command Palette: Fix crash on block-related commands

* Update string
  • Loading branch information
t-hamano authored Aug 25, 2023
1 parent 44a8678 commit f415a5d
Showing 1 changed file with 46 additions and 31 deletions.
77 changes: 46 additions & 31 deletions packages/block-editor/src/components/use-block-commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

1 comment on commit f415a5d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in f415a5d.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5975083008
📝 Reported issues:

Please sign in to comment.