[lexical][lexical-extension][lexical-playground] Refactor: Compiled keyboard shortcut dispatch
Description
This PR continues etrepum's WIP PR https://github.com/etrepum/lexical/pull/18 — replacing the imperative if/else shortcut matching in $handleKeyDown with a compiled CompiledKeyboardShortcuts table that dispatches in O(1) via Map lookup keyed by "${modifierBits}:${key.toLowerCase()}", with a byCode fallback for non-Latin keyboard layouts.
What changed
packages/lexical/src/LexicalKeyboardShortcuts.ts (new) — extracted from LexicalUtils.ts. Contains CompiledKeyboardShortcuts<S>, compileKeyboardShortcuts, registerKeyboardShortcuts, KeyboardShortcut / KeyboardShortcutMatch interfaces, and CONTROL_OR_META / CONTROL_OR_ALT modifier masks.
packages/lexical/src/LexicalEvents.ts — the ~90-line if/else if chain in $handleKeyDown is replaced with a compiled shortcut table using factory helpers (dispatch, prevent, enter, copyOrCut). The 26 is* predicate functions in LexicalUtils.ts are removed (they were internal, never exported).
packages/lexical-extension/src/KeyboardShortcutsExtension.ts (new) — extension framework integration. Provides signal-based runtime remapping, $disabled / $dispatch callbacks on individual shortcuts, and mergeConfig for name-based shortcut overlay across the extension graph.
packages/lexical-playground/src/plugins/ShortcutsExtension/ (new, replaces ShortcutsPlugin/) — migrates the playground's 26 shortcut actions from a React component to an extension. All action callbacks use fromEditor (the editor that originated KEY_DOWN_COMMAND) instead of a closure-captured editor prop, which is more correct in nested editor setups.
Backwards compatibility
No BC concerns. All removed is* predicate functions were internal (never exported from lexical/src/index.ts). KeyboardEventModifierMask is newly exported (was internal). All new symbols are additive exports.
Test plan
- [x]
pnpm test-unit— 3996 pass - [x] e2e (chromium) — 771 pass
- [x] Parity test (
keyDownDispatchParity.ts): verifies the compiled table matches the old if/else chain for 25 keys × 16 modifier combinations on both Apple and non-Apple platforms, including non-Latin layout fallback ('и'/KeyB,'я'/KeyZ) - [x]
KeyboardShortcutsExtension.test.ts: shortcut dispatch,$disabledcallback,$dispatchoverride, signal-based runtime remapping - [x] Manual playground testing (Chrome, Safari, Firefox on macOS): 43 scenarios covering block format, lists, text format, alignment, font size, indent, link, comment, and core shortcuts (bold/italic/underline/undo/redo/tab/enter). All 43 scenarios behave identically to playground.lexical.dev (main).
- [x] tsc / flow / prettier / eslint clean
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
|---|---|---|---|
| Preview | Aug 13, 2026 7:24pm | ||
| Preview | Aug 13, 2026 7:24pm |
@etrepum is attempting to deploy a commit to the Meta Open Source Team on Vercel.
A member of the Team first needs to authorize it.