Skip to content

fix: restore event.code fallback for macOS Option+letter shortcuts#58

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-single-letter-check
Closed

fix: restore event.code fallback for macOS Option+letter shortcuts#58
Copilot wants to merge 3 commits intomainfrom
copilot/fix-single-letter-check

Conversation

Copy link

Copilot AI commented Mar 9, 2026

PR #53 introduced isSingleLetterKey using /^\p{Letter}$/u, which matches all Unicode letters. This blocked the event.code fallback for macOS Option+letter combos — Option+A fires event.key='å', which is a Unicode letter, so the early return fired and Alt+A hotkeys stopped working. Same for π, ø, ƒ, ç, ß, µ, æ, œ, and their shift variants.

🎯 Changes

src/match.ts — narrow the early-return guard:

  • ASCII letters (A-Z): always trust the layout (Dvorak/Colemak/AZERTY preservation, unchanged)
  • Non-ASCII letters without Alt: trust the layout (Cyrillic, etc., unchanged)
  • Non-ASCII letters with Alt: fall through to event.code fallback ← the fix
// Before — blocks fallback for ANY Unicode letter
if (isSingleLetterKey(eventKey)) {
  return false
}

// After — only blocks when it's safe to trust the layout
if (isSingleLetterKey(eventKey) && (/^[A-Za-z]$/.test(eventKey) || !event.altKey)) {
  return false
}

src/constants.ts — fix normalizeKeyName for letters whose .toUpperCase() expands to multiple chars:

  • 'ß'.toUpperCase()'SS' (2 chars), which broke the eventKey.length === 1 guard downstream
  • Now returns the original key unchanged when uppercasing changes the length

tests/match.test.ts — regression tests for the affected Option+letter and Option+Shift+letter combinations.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

The isSingleLetterKey check used /^\p{Letter}$/u which matched all Unicode
letters, blocking the event.code fallback for macOS Option+letter combinations
like Option+A (å), Option+P (π), Option+S (ß), etc.

Changes:
- match.ts: only skip the code fallback for ASCII letters OR non-ASCII letters
  without Alt key. Non-ASCII letters produced while Alt is held (macOS Option
  combos) now fall through to the event.code fallback as expected.
- constants.ts: fix normalizeKeyName to not uppercase letters whose toUpperCase()
  returns multiple chars (e.g. ß → SS), which would otherwise break the length
  checks in the matching logic.
- match.test.ts: add regression tests for macOS Option+letter shortcuts.

Co-authored-by: KevinVandy <28243511+KevinVandy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix regression with isSingleLetter check for Mac options fix: restore event.code fallback for macOS Option+letter shortcuts Mar 9, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 9, 2026

Open in StackBlitz

@tanstack/angular-hotkeys

npm i https://pkg.pr.new/@tanstack/angular-hotkeys@58

@tanstack/hotkeys

npm i https://pkg.pr.new/@tanstack/hotkeys@58

@tanstack/hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/hotkeys-devtools@58

@tanstack/preact-hotkeys

npm i https://pkg.pr.new/@tanstack/preact-hotkeys@58

@tanstack/preact-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/preact-hotkeys-devtools@58

@tanstack/react-hotkeys

npm i https://pkg.pr.new/@tanstack/react-hotkeys@58

@tanstack/react-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/react-hotkeys-devtools@58

@tanstack/solid-hotkeys

npm i https://pkg.pr.new/@tanstack/solid-hotkeys@58

@tanstack/solid-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/solid-hotkeys-devtools@58

@tanstack/vue-hotkeys

npm i https://pkg.pr.new/@tanstack/vue-hotkeys@58

@tanstack/vue-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/vue-hotkeys-devtools@58

commit: 05b3d8f

@KevinVandy KevinVandy closed this Mar 10, 2026
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.

2 participants