mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 14:28:12 +08:00
Fix logic bug in key internationalization for A-Z keys in alternate layouts
This commit is contained in:
@@ -71,8 +71,7 @@ export async function getLocalizedScanCode(e: KeyboardEvent): Promise<string> {
|
|||||||
// Use good-enough-for-now heuristics on the writing system keys, which are commonly subject to change by locale
|
// Use good-enough-for-now heuristics on the writing system keys, which are commonly subject to change by locale
|
||||||
|
|
||||||
// Number scan codes
|
// Number scan codes
|
||||||
const scanCodeDigit = /^Digit[0-9]$/.test(scanCode);
|
if (/^Digit[0-9]$/.test(scanCode)) {
|
||||||
if (scanCodeDigit) {
|
|
||||||
// For now it's good enough to treat every digit key, regardless of locale, as just its digit from the standard US layout.
|
// For now it's good enough to treat every digit key, regardless of locale, as just its digit from the standard US layout.
|
||||||
// Even on a keyboard like the French AZERTY layout, where numbers are shifted, users still refer to those keys by their numbers.
|
// Even on a keyboard like the French AZERTY layout, where numbers are shifted, users still refer to those keys by their numbers.
|
||||||
// This unfortunately means that any special symbols under these keys are overridden by their number, making it impossible to access some shortcuts that rely on those special symbols.
|
// This unfortunately means that any special symbols under these keys are overridden by their number, making it impossible to access some shortcuts that rely on those special symbols.
|
||||||
@@ -81,20 +80,15 @@ export async function getLocalizedScanCode(e: KeyboardEvent): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Letter scan codes
|
// Letter scan codes
|
||||||
const scanCodeLetter = scanCode.match(/^Key([A-Z])$/);
|
if (/^Key([A-Z])$/.test(scanCode)) {
|
||||||
if (scanCodeLetter) {
|
// Get the uppercase letter, with any accents or discritics removed if possible
|
||||||
const scanCodeLetterValue = String(scanCodeLetter[1]);
|
const rawLetter = keyText
|
||||||
|
.normalize("NFD")
|
||||||
|
.replace(/\p{Diacritic}/gu, "")
|
||||||
|
.toUpperCase();
|
||||||
|
|
||||||
// If the scan code matches the key letter (ignoring diacritics and case), use that letter directly
|
// If the key letter is in the A-Z range, use the key code for that letter
|
||||||
const letterOfScanCodeMatchesKey =
|
if (/^[A-Z]$/.test(rawLetter)) return `Key${rawLetter}`;
|
||||||
scanCodeLetterValue ===
|
|
||||||
keyText
|
|
||||||
.normalize("NFD")
|
|
||||||
.replace(/\p{Diacritic}/gu, "")
|
|
||||||
.toUpperCase();
|
|
||||||
if (letterOfScanCodeMatchesKey) {
|
|
||||||
return scanCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the key text isn't one of the named attribute values, that means it must be the literal unicode value which we use directly
|
// If the key text isn't one of the named attribute values, that means it must be the literal unicode value which we use directly
|
||||||
// It is likely a weird symbol that isn't in the A-Z range even with accents removed.
|
// It is likely a weird symbol that isn't in the A-Z range even with accents removed.
|
||||||
|
|||||||
Reference in New Issue
Block a user