Skip to content

[lexical] Bug Fix: REDO_COMMAND not triggered with non-English keyboard layouts (Ctrl+Y / Ctrl+Shift+Z)#8155

Merged
etrepum merged 5 commits intofacebook:mainfrom
kenclaron:fix/non-english-keyboard-layout-support-shortcuts
Feb 25, 2026
Merged

[lexical] Bug Fix: REDO_COMMAND not triggered with non-English keyboard layouts (Ctrl+Y / Ctrl+Shift+Z)#8155
etrepum merged 5 commits intofacebook:mainfrom
kenclaron:fix/non-english-keyboard-layout-support-shortcuts

Conversation

@kenclaron
Copy link
Copy Markdown
Contributor

Description

  • REDO_COMMAND and other shortcuts are triggered correctly on all keyboard layouts.
  • added fallback with event.code for single-letter expectedKey for non-English keyboard layout.
  • added few unit tests for isExactShortcutMatch()

Closes #8147

Test plan

Before

After

  • added few unit tests for isExactShortcutMatch() in /packages/lexical/__tests__/unit/LexicalUtils.test.ts

…ditional checks by event.code, tests for isExactShortcutMatch
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Feb 24, 2026 10:34pm
lexical-playground Ready Ready Preview, Comment Feb 24, 2026 10:34pm

Request Review

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Feb 19, 2026

Hi @kenclaron!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Feb 19, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 19, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Feb 19, 2026
Copy link
Copy Markdown
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Feb 20, 2026

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.

@levensta
Copy link
Copy Markdown
Contributor

By the way, Google Docs can workaround the default behavior of Cmd + Y in browsers on MacOS

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Feb 20, 2026

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.

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Feb 22, 2026

FWIW at least on macOS the shortcut behavior when using ASCII remapping (e.g. dvorak) is that the shortcuts map to the logical key and not the physical key code. If you press Cmd+KeyB (physical key code) with a dvorak mapping it executes the logical key Cmd+X action (in native apps also, not just chrome). No idea how Windows users expect this to behave, but perhaps the right workaround is to make sure that the key is non-ascii before trying the code fallback.

Screenshot 2026-02-22 at 11 08 19

@levensta
Copy link
Copy Markdown
Contributor

@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

@kenclaron
Copy link
Copy Markdown
Contributor Author

kenclaron commented Feb 24, 2026

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 event.key as previously (not both event.key and event.code), by your comments. And added 1 jest-test for that user case.

About "we should incorporate the CMD + Y behavior as a standardized behavior". so I revert it part of code from the PR for now.

Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good assuming tests still pass!

@etrepum etrepum added this pull request to the merge queue Feb 25, 2026
Merged via the queue into facebook:main with commit 454ba98 Feb 25, 2026
39 checks passed
@etrepum etrepum mentioned this pull request Feb 25, 2026
Sathvik-Chowdary-Veerapaneni added a commit to Sathvik-Chowdary-Veerapaneni/lexical that referenced this pull request Mar 26, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: REDO_COMMAND not triggered with non-English keyboard layouts (Ctrl+Y / Ctrl+Shift+Z)

4 participants