Repository navigation
fix(app): match fixed shortcuts by physical key on non-Latin layouts - #797
Conversation
useApplicationShortcuts read the shortcut letter from event.key, which is a Cyrillic letter on a Russian layout (Ctrl+O arrives as "щ"), so Open, Save, Close, Export and the other fixed shortcuts did nothing there. Reuse shortcutKeyFromKeyboardEvent, which the configurable shortcuts already use. It keeps character-based matching on Latin layouts and falls back to the physical key only when event.key is not usable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@leemour is attempting to deploy a commit to the murongg's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
murongg
left a comment
There was a problem hiding this comment.
Please fix the Dvorak regression before merging. The new Russian-layout test passes on this commit, and the two affected test files passed all 70 existing tests. I also ran focused Vitest cases with synthetic keyboard events. Both Dvorak cases pass with the v2 handler and fail with this change. The Hebrew Ctrl+W case fails with both handlers.
| if (handleSettingsWindowShortcut(event, openSettings)) return; | ||
|
|
||
| const key = event.key.toLowerCase(); | ||
| const key = shortcutKeyFromKeyboardEvent(event)?.toLowerCase() ?? ""; |
There was a problem hiding this comment.
[P2] Preserve fixed shortcuts on Dvorak. Dvorak's S key reports key: "s" and code: "Semicolon". The shared parser resolves the physical punctuation key first, so Ctrl+S and Ctrl+Shift+S stop reaching Save and Save As. The same change turns Dvorak Ctrl+Shift+period (key: ">", code: "KeyE") into Export HTML. Please keep character matching for fixed letter shortcuts, narrow when the physical fallback applies, and add regression tests for both cases. Dvorak keymap
For fixed letter shortcuts, use the physical letter only when event.key is a single non-Latin letter. This keeps Dvorak's letter mappings and preserves the meaning of punctuation key events.
| const key = shortcutKeyFromKeyboardEvent(event)?.toLowerCase() ?? ""; | |
| const isNonLatinLetter = | |
| /^\p{Letter}$/u.test(event.key) && | |
| !/^\p{Script=Latin}$/u.test(event.key); | |
| const physicalLetter = isNonLatinLetter | |
| ? /^Key([A-Z])$/.exec(event.code)?.[1] | |
| : undefined; | |
| const key = (physicalLetter ?? event.key).toLowerCase(); |
After applying this suggestion, remove the now-unused shortcutKeyFromKeyboardEvent import here and revert the export-only change in packages/shared/src/keyboard-shortcuts.ts.
Please keep the Russian-layout test and add the Dvorak cases to useNativeBindings.test.tsx:
- Russian Open and Save:
Ctrlwithkey: "щ", code: "KeyO"callsopenDocumentonce.Ctrlwithkey: "ы", code: "KeyS"callssaveDocumentonce. - Dvorak Save and Save As:
Ctrlwithkey: "s", code: "Semicolon"callssaveDocumentonce.Ctrl+Shiftwithkey: "S", code: "Semicolon"callssaveDocumentAsonce. - Dvorak punctuation:
Ctrl+Shiftwithkey: ">", code: "KeyE"leavesexportHtmluncalled when that handler is available.
There was a problem hiding this comment.
Thanks for catching this. Applied your suggestion in 557bb19, reverted the export in @markra/shared and added the Dvorak test next to the Russian one (Save, Save As, and Ctrl+Shift+period leaving Export HTML alone). The Dvorak test fails on the previous commit and passes now. App tests: 141 files, 1668 passed.
| } | ||
|
|
||
| function shortcutKeyFromKeyboardEvent( | ||
| export function shortcutKeyFromKeyboardEvent( |
There was a problem hiding this comment.
[P3] Hebrew Ctrl+W still misses Close. With the XKB Hebrew basic layout, this chord can report key: "'" and code: "KeyW". The parser accepts the apostrophe as a configured shortcut key and returns before it checks the physical letter. Please cover this case in the fixed-shortcut matcher or narrow the Hebrew-layout claim in the PR description. XKB Hebrew keymap
There was a problem hiding this comment.
I went with narrowing the description. Hebrew Ctrl+W gives key: "'", code: "KeyW", and Dvorak's apostrophe key gives the same key with code: "KeyQ". Mapping it to the physical key would turn Dvorak Ctrl+' into Ctrl+Q, so I left punctuation keys character based. The PR description now says only keys that produce a non-Latin letter fall back to the physical key, and lists Hebrew W as a known limit.
The previous change took the key for fixed shortcuts from shortcutKeyFromKeyboardEvent, which resolves punctuation codes first. On Dvorak the S key reports code Semicolon, so Ctrl+S and Ctrl+Shift+S stopped reaching Save and Save As, and Ctrl+Shift+period (key ">", code KeyE) turned into Export HTML. Fall back to the physical letter only when event.key is a single non-Latin letter. Latin layouts, Dvorak included, keep character matching. Revert the export from @markra/shared. Add a Dvorak regression test next to the Russian one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
murongg
left a comment
There was a problem hiding this comment.
Verified on 557bb19. Russian Open and Save still work. The Dvorak regression test fails on da0d413 and passes on 557bb19, covering Save, Save As, and Ctrl+Shift+period leaving Export HTML uncalled. All 71 tests in the two relevant files passed locally, along with the app test typecheck. The documented Hebrew Ctrl+W limitation matches the scope of this fix.
Summary
Makes the fixed app shortcuts (Ctrl+O, Ctrl+S, Ctrl+W, Ctrl+P and so on) work on non-Latin keyboard layouts. Closes #796.
useApplicationShortcutsread the letter fromevent.key, which on a Russian layout isщfor Ctrl+O. Now, whenevent.keyis a single non-Latin letter, the handler takes the letter from the physical key (event.code, egKeyO). Every other event keeps character matching as before.Changes
packages/app/src/hooks/useNativeBindings.ts: fall back to the physical letter only whenevent.keyis a single non-Latin letter.packages/app/src/hooks/useNativeBindings.test.tsx: Russian Ctrl+O and Ctrl+S, plus Dvorak Ctrl+S, Ctrl+Shift+S and Ctrl+Shift+period (must not trigger Export HTML).Behavior
'on the W keyThe last row is a known limit. Hebrew Ctrl+W reports
key: "'"andcode: "KeyW", which looks the same as Dvorak's'key (code: "KeyQ"). Using the physical key there would turn Dvorak Ctrl+' into Ctrl+Q, so those keys stay character based. Hebrew letters such as Ctrl+O (ם) work.Ctrl+F already had its own
event.code === "KeyF"check, so it behaves the same as before.Verification
pnpm --filter @markra/shared testpassed, 64 testspnpm --filter @markra/app typecheck:testpassedpnpm --filter @markra/app testpassed, 141 files and 1668 testsv2without the fix. The Dvorak test fails on the first commit of this PR and passes nowRisks
packages/editor/src/codemirror/html-table-widget.tshas the sameevent.keypattern for undo, redo and select all inside a table. I left it out to keep this PR small. Happy to send a follow-up if you'd like.I worked on this together with Claude Code.
🤖 Generated with Claude Code