Closed minkapi closed 1 year ago
Thanks for the report.
I have not been able to reproduce this problem, but it might be because it is a Windows OS. The Enter key to confirm the input character did not execute the command.
As a supplement, the command palette uses cmdk, an external library. However, since it appears that it is possible to intervene in the keydown event, the following code might be able to fix the problem. This approach is also taken by #45607, #45626, and others.
diff --git a/packages/commands/src/components/command-menu.js b/packages/commands/src/components/command-menu.js
index b4a828f343..c02ddd4208 100644
--- a/packages/commands/src/components/command-menu.js
+++ b/packages/commands/src/components/command-menu.js
@@ -201,6 +201,21 @@ 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
+ ) {
+ console.log( 'prevented!' );
+ event.preventDefault();
+ }
+ };
+
const isLoading = Object.values( loaders ).some( Boolean );
return (
@@ -211,7 +226,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 }
I hope more people will test this issue.
https://github.com/WordPress/gutenberg/assets/54422211/880608f6-40db-4528-9653-922fadff7a4b
The following environments were tested.
Browser | result |
---|---|
Chrome ( 115 / 114 ) on Mac | reproduced |
Chrome ( 115 / 114 ) on Windows | not reproduced |
Safari 16.5.2 on Mac | reproduced |
firefox 115 on Mac | not reproduced |
firefox 115 on Windows | not reproduced |
Edge 114 on Windows | not reproduced |
Description
In WordPress 6.3 RC-1, entering Japanese (hiragana) into the command palette, converting it to kanji or other characters, and pressing enter will execute the command rather than completing the conversion.
When entering characters in Japanese language ( including Kanji), after entering "Hiragana", select which character to convert to and press Enter to confirm. I would expect the same problem in other languages that perform the same operation.
Step-by-step reproduction instructions
I expect users to use a Japanese keyboard.
Screenshots, screen recording, code snippet
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes