Skip to content

fix(app): match fixed shortcuts by physical key on non-Latin layouts - #797

Merged
murongg merged 2 commits into
markrahq:v2from
leemour:fix/non-latin-layout-shortcuts
Nov 24, 2026
Merged

murongg merged 2 commits into
markrahq:v2from
leemour:fix/non-latin-layout-shortcuts

Conversation

@leemour

@leemour leemour commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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.

useApplicationShortcuts read the letter from event.key, which on a Russian layout is щ for Ctrl+O. Now, when event.key is a single non-Latin letter, the handler takes the letter from the physical key (event.code, eg KeyO). Every other event keeps character matching as before.

Changes

  • packages/app/src/hooks/useNativeBindings.ts: fall back to the physical letter only when event.key is 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

Layout Before After
English and other Latin layouts (incl. AZERTY, Dvorak) Character based Unchanged, still character based
Layouts where the key gives a non-Latin letter (Russian, Ukrainian, Greek and so on) Fixed shortcuts don't fire Fall back to the physical letter
Keys that give punctuation on a non-Latin layout, eg Hebrew ' on the W key Character based Unchanged, still character based

The last row is a known limit. Hebrew Ctrl+W reports key: "'" and code: "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 test passed, 64 tests
  • pnpm --filter @markra/app typecheck:test passed
  • pnpm --filter @markra/app test passed, 141 files and 1668 tests
  • The Russian test fails on v2 without the fix. The Dvorak test fails on the first commit of this PR and passes now

Risks

  • The HTML table widget in packages/editor/src/codemirror/html-table-widget.ts has the same event.key pattern 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

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>
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

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

@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
markra-web Ready Ready Preview Nov 24, 2026 1:29am UTC

@murongg murongg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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() ?? "";

@murongg murongg Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Suggested change
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: Ctrl with key: "щ", code: "KeyO" calls openDocument once. Ctrl with key: "ы", code: "KeyS" calls saveDocument once.
  • Dvorak Save and Save As: Ctrl with key: "s", code: "Semicolon" calls saveDocument once. Ctrl+Shift with key: "S", code: "Semicolon" calls saveDocumentAs once.
  • Dvorak punctuation: Ctrl+Shift with key: ">", code: "KeyE" leaves exportHtml uncalled when that handler is available.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 murongg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@murongg
murongg merged commit 9030eb1 into markrahq:v2 Nov 24, 2026
24 checks passed

This branch was successfully deployed

1 active deployment
Preview — 557bb19e Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: App shortcuts like Ctrl+O don't work on non-Latin keyboard layouts

2 participants