Fix Alt+letter preview shortcuts on macOS#2055
Merged
Merged
Conversation
macOS Option rewrites the typed character (Option+K → '˚'), so matching Alt+letter shortcuts on event.key alone left them dead on a Mac. Resolve the letter by event.key when it is a plain letter — reliable on every Windows/Linux layout, AZERTY/BÉPO/Dvorak included — and fall back to event.code (the physical key) only when the OS rewrote it to a glyph, as on macOS. Guard with !mod (ctrl/meta) so Windows AltGr and macOS Cmd+Option chords don't fire them. Preferring event.key also avoids a physical-position clash on BÉPO under Windows/Linux, where the 'J' key sits on the QWERTY 'P' position and 'O' on 'R': a plain event.code match fired Alt+P / Alt+R there instead of the intended shortcut. The match is a shared isAltLetter helper, reused by SharedPlaylistPlayer's Alt+J/K. Known limitation — macOS + non-QWERTY: on macOS the Option modifier rewrites event.key on every layout, so the match always falls back to event.code (physical QWERTY position) there. On layouts that relocate these letters (BÉPO, Dvorak) the macOS shortcut therefore keys off physical position, not the printed cap, so Alt+letter can be dead or hit a neighbouring shortcut (e.g. BÉPO's 'J' cap is physical KeyP, so Option+J matches Alt+P). Recovering the cap letter would need navigator.keyboard.getLayoutMap(), which Safari/Firefox don't expose. A test pins this behaviour so the trade-off is explicit; Windows/Linux is unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
event.keywere all dead on a Mac.Solution
event.key) when it is a plain a-z character, and falls back toevent.codeonly when the OS rewrote it (macOS Option) or the layout is non-Latin.