Unify Keyboard Shortcuts and Commands under a unique API (commands) #59004
Labels
[Package] Keyboard Shortcuts
/packages/keyboard-shortcuts
[Type] Enhancement
A suggestion for improvement.
What are keyboard shortcuts? They are actions that are performed when you hit a certain key combination.
What are commands? They are actions that are performed when select them from a command palette menu.
As you may noticed in our code base, often times, we duplicate code to define one or the other. Both
@wordpress/keyboard-shortcuts
and@wordpress/commands
have very similar APIs: You register commands or shortcuts and they become available in the APP.I think it makes sense in the long run to unify these two APIs under a unique API. We have several options to go about this (or I would say, several steps):
Step 1
triggerCommand
action in the@wordpress/commands
palette and use it when defining shortcuts.Step 2
So a command config becomes something like:
There's a difficulty here, because current keyboard shortcuts separate
registerShortcut
calls from thecallback
definition which happens in theuseShortcut
calls. So we need to account for that somehow.cc @WordPress/gutenberg-core @artpi @mtias
The text was updated successfully, but these errors were encountered: