[lexical] Bug Fix: REDO_COMMAND not triggered with non-English keyboard layouts (Ctrl+Y / Ctrl+Shift+Z)#8155
Conversation
…ditional checks by event.code, tests for isExactShortcutMatch
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @kenclaron! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
zurfyx
left a comment
There was a problem hiding this comment.
I wonder whether we should incorporate the CMD + Y behavior as a standardized behavior within the library given that it's part of major providers such as Office and GDocs. Now it does correctly trigger CMD + Shift + Z for me but not the other, even though I also recognize it's not a standard per say @etrepum
|
I don't have strong opinions about handling CMD+Y specifically, all of the Mac browsers have it bound to "Show all History" by default. I think the only people who would try that keyboard shortcut are people who are not used to macOS that happen to be using a mac. I think probably a higher priority should be abstracting all of the built-in keyboard shortcuts so that they are provided by an extension that makes it easier to reconfigure them, right now it's pretty awkward to override any key handling. That way an app can decide if it should behave this way (e.g. for a full page document editor) or if it would be better to follow native conventions. For the context of this PR specifically my primary concern is that I don't know how it behaves with a keyboard map that maps ascii to ascii, e.g. dvorak or azerty. Possibly it should have a check to make sure that the key is non-ascii before trying the code, or maybe some of these shortcuts should only check the code? I don't have a windows machine to test and playwright doesn't support any keyboard remapping. |
|
By the way, Google Docs can workaround the default behavior of Cmd + Y in browsers on MacOS |
|
Yes, google docs can override cmd+y, but if you're using lexical for a form field or a chat input or something like that you might not want it to do that by default. |
|
@kenclaron will you continue working on this PR? As a user of the Cyrillic keyboard layout, I am very interested in seeing this fix included in the lexical core Looks like there's a small fix left to make it work and get compatible |
…. English/Dvorak)
…ttps://github.com/kenclaron/lexical into fix/non-english-keyboard-layout-support-shortcuts
|
Thanks for comments! I added an additional check for non-standard keyboard layouts with ASCII characters (e.g. English/Dvorak) so that it works only on About "we should incorporate the CMD + Y behavior as a standardized behavior". so I revert it part of code from the PR for now. |
etrepum
left a comment
There was a problem hiding this comment.
This looks good assuming tests still pass!
…patibility The playground's ShortcutsPlugin was using KeyboardEvent.code (physical key position) to match shortcuts, which breaks on non-QWERTY layouts like Dvorak. For example, Ctrl+V (paste) would trigger the Superscript shortcut because the physical V key maps to '.' on Dvorak. Refactor all shortcut matchers to use isExactShortcutMatch from the core library, which was introduced in facebook#8155 to handle this correctly. It uses event.key (logical character) for matching, with a fallback to event.code only for non-ASCII keyboard layouts. Fixes facebook#8255

Description
REDO_COMMANDand other shortcuts are triggered correctly on all keyboard layouts.event.codefor single-letterexpectedKeyfor non-English keyboard layout.isExactShortcutMatch()Closes #8147
Test plan
Before
isExactShortcutMatch()After
isExactShortcutMatch()in/packages/lexical/__tests__/unit/LexicalUtils.test.ts