Skip to content
Prev Previous commit
Next Next commit
fix(hotkeys): fall back to event.code for international keyboard layo…
…ut compatibility
  • Loading branch information
waleedlatif1 committed Mar 28, 2026
commit 3fad92b6b0045526953dd45f93b8d31cf6447025
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,26 @@ function parseShortcut(shortcut: string): ParsedShortcut {
}
}

/**
* Maps a KeyboardEvent.code value to the logical key name used in shortcut definitions.
* Needed for international keyboard layouts where e.key may produce unexpected characters
* (e.g. macOS Option+letter yields 'å' instead of 'a', dead keys yield 'Dead').
*/
function codeToKey(code: string): string | undefined {
if (code.startsWith('Key')) return code.slice(3).toLowerCase()
if (code.startsWith('Digit')) return code.slice(5)
return undefined
}

function matchesShortcut(e: KeyboardEvent, parsed: ParsedShortcut): boolean {
const isMac = isMacPlatform()
const expectedCtrl = parsed.ctrl || (parsed.mod ? !isMac : false)
const expectedMeta = parsed.meta || (parsed.mod ? isMac : false)
const eventKey = e.key.length === 1 ? e.key.toLowerCase() : e.key
const keyMatches = eventKey === parsed.key || codeToKey(e.code) === parsed.key

return (
eventKey === parsed.key &&
keyMatches &&
!!e.ctrlKey === !!expectedCtrl &&
!!e.metaKey === !!expectedMeta &&
!!e.shiftKey === !!parsed.shift &&
Expand Down
Loading