Skip to content

Commands: Add unified API for keyboard shortcuts and commands#69964

Open
Sukhendu2002 wants to merge 1 commit intoWordPress:trunkfrom
Sukhendu2002:add/59004-unify-shortcuts-commands
Open

Commands: Add unified API for keyboard shortcuts and commands#69964
Sukhendu2002 wants to merge 1 commit intoWordPress:trunkfrom
Sukhendu2002:add/59004-unify-shortcuts-commands

Conversation

@Sukhendu2002
Copy link
Contributor

@Sukhendu2002 Sukhendu2002 commented Apr 22, 2025

What?

Part of: #59004

This PR implements Step 1 of the proposal to unify keyboard shortcuts and commands under a single API.

This PR introduces:

  • triggerCommand action to programmatically execute a command
  • useShortcutCommand hook to bind a keyboard shortcut to a command

Example

// 1. Register the command
useCommand({
    name: 'core/toggle-fullscreen-mode',
    label: isFullscreen ? __( 'Exit fullscreen' ) : __( 'Enter fullscreen' ),
    icon: fullscreen,
    callback: ({ close }) => {
        toggle( 'core/edit-post', 'fullscreenMode' );
        close();
        createInfoNotice(...);
    },
});

// 2. Connect the shortcut to the command
useShortcutCommand( 
    'core/edit-post/toggle-fullscreen',  // Shortcut name
    'core/toggle-fullscreen-mode'        // Command name
);

@Sukhendu2002 Sukhendu2002 marked this pull request as ready for review April 22, 2025 19:09
@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Sukhendu2002 <sukhendu2002@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] New API New API to be used by plugin developers or package users. [Package] Commands /packages/commands labels Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Commands /packages/commands [Type] New API New API to be used by plugin developers or package users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants