Repository navigation
useHotkeys: ignore keys that belong to an IME composition - #676
Merged
Merged
Conversation
The Enter that confirms an IME conversion reached registered hotkeys, so Autocomplete selected the highlighted option and called onEnter with unfinished text. Return early in handleWindowKeyDown when isComposing is set or keyCode is 229 (Safari fires the confirming keydown after compositionend). Fixes reshaped-ui#671
Contributor
|
Looks good, thanks for the contribution 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
handleWindowKeyDowninuseSingletonHotkeysnow returns early whene.isComposingis true ore.keyCode === 229, so keys an IME is handling never reach registered hotkeys. With a Japanese, Chinese or Korean IME, the Enter that confirms a conversion no longer makesAutocompleteselect the highlighted option or callonEnter. Escape and arrow keys pressed during a composition are skipped the same way.The
keyCodecheck is for Safari, which firescompositionendbefore the keydown of the confirming Enter, soisComposingis already false on that event.Related Issue
Fixes #671
Screenshots / Recordings
None, there is no visual change.
Notes for Reviewers
e.key === "Process". I left it out because the check MDN recommends (isComposing || keyCode === 229) already catches the first and last keydown of a composition, whereisComposingis false. Happy to add it if you prefer.useHotkeysconsumer, not onlyAutocomplete. Skipped keys are also not added to the pressed-key map.useHotkeys > ignores IME compositiondispatches a composing Enter and a Safari-style Enter (keyCode: 229,isComposing: false) onwindow, then a normal Enter. Onmainit fails (the hotkey is called twice for the IME keydowns); with the change it passes.vitest --project=storybook594 tests passed,--project=unit181 passed, oxlint, oxfmt and tsc clean. I have not tried it with a real IME in a browser.