Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommandPalette: Fixed to not execute commands in IME composition. #52844

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/commands/src/components/command-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ export function CommandMenu() {
if ( ! isOpen ) {
return false;
}

const onKeyDown = ( event ) => {
if (
// Ignore keydowns from IMEs
event.nativeEvent.isComposing ||
// Workaround for Mac Safari where the final Enter/Backspace of an IME composition
// is `isComposing=false`, even though it's technically still part of the composition.
// These can only be detected by keyCode.
event.keyCode === 229
) {
event.preventDefault();
}
};

const isLoading = Object.values( loaders ).some( Boolean );

return (
Expand All @@ -211,7 +225,10 @@ export function CommandMenu() {
__experimentalHideHeader
>
<div className="commands-command-menu__container">
<Command label={ __( 'Command palette' ) }>
<Command
label={ __( 'Command palette' ) }
onKeyDown={ onKeyDown }
>
<div className="commands-command-menu__header">
<Command.Input
ref={ commandMenuInput }
Expand Down