Skip to content

[lexical-playground] Bug Fix: Use isExactShortcutMatch for Dvorak keyboard compatibility#8260

Merged
etrepum merged 3 commits intofacebook:mainfrom
Sathvik-Chowdary-Veerapaneni:playground-dvorak-shortcuts-8255
Mar 28, 2026
Merged

[lexical-playground] Bug Fix: Use isExactShortcutMatch for Dvorak keyboard compatibility#8260
etrepum merged 3 commits intofacebook:mainfrom
Sathvik-Chowdary-Veerapaneni:playground-dvorak-shortcuts-8255

Conversation

@Sathvik-Chowdary-Veerapaneni
Copy link
Copy Markdown
Contributor

Summary

  • Refactors the playground ShortcutsPlugin to use isExactShortcutMatch (from the core lexical package) instead of manual KeyboardEvent.code checks
  • This fixes keyboard shortcuts being broken on non-QWERTY layouts (e.g., Dvorak), where physical key positions differ from the logical characters they produce
  • The core library already fixed this in [lexical] Bug Fix: REDO_COMMAND not triggered with non-English keyboard layouts (Ctrl+Y / Ctrl+Shift+Z) #8155 by introducing isExactShortcutMatch, which uses event.key (logical character) instead of event.code (physical position), but the playground code was still using the old approach

The Problem

On Dvorak layout, pressing Ctrl+V (paste) would trigger the Superscript shortcut because the physical V key is at the position where . (Period) is on QWERTY. The ShortcutsPlugin was checking event.code === 'Period' which matches the physical key position regardless of layout.

The Fix

All shortcut matcher functions in shortcuts.ts now use isExactShortcutMatch(event, key, modifierMask) which:

  1. Compares event.key (logical character) case-insensitively for standard keys
  2. Falls back to event.code only for non-ASCII keyboard layouts (e.g., Russian) where event.key is non-ASCII
  3. Correctly handles Dvorak and other remapped layouts by respecting the logical key

The heading shortcut handler in index.tsx was also updated to use event.key (which directly gives '1', '2', '3') instead of extracting the digit from event.code (e.g., 'Digit1').

Test plan

  • All 103 unit test files pass (2706 tests)
  • ESLint and Prettier checks pass
  • Manual testing: On Dvorak layout, Ctrl+V should paste (not trigger Superscript)
  • Manual testing: All playground shortcuts should work correctly on QWERTY layout
  • Manual testing: Shortcuts should work on non-English keyboard layouts (e.g., Russian)

Fixes #8255

…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
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

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

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

Request Review

@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 Mar 26, 2026
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.

e2e tests are failing

When Shift is held, event.key becomes '>' and '<' instead of '.' and ','
@Sathvik-Chowdary-Veerapaneni Sathvik-Chowdary-Veerapaneni changed the title Use isExactShortcutMatch in playground ShortcutsPlugin for Dvorak compatibility [lexical-playground] Bug Fix: Use isExactShortcutMatch for Dvorak keyboard compatibility Mar 26, 2026
@Sathvik-Chowdary-Veerapaneni
Copy link
Copy Markdown
Contributor Author

font size shortcuts were matching on ." and ,but with Shift held the key becomes>and<`, fixed that. the autocomplete failures look unrelated to this PR

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.

It might be worth having a windows user verify if the symbol based shortcuts still work as expected (such as ctrl+shift+, to decrease font size) when using a keyboard layout like one of the japanese ones where the ',' and '.' keys are remapped to something like 'ね' and 'る'

@etrepum etrepum added this pull request to the merge queue Mar 28, 2026
Merged via the queue into facebook:main with commit c798008 Mar 28, 2026
37 checks passed
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: Paste (and other hotkeys) broken with dvorak layout

2 participants