fix(keymap): match letter shortcuts by typed character on AZERTY (#291)

Letter shortcuts were matched by physical key (KeyboardEvent.code), so on AZERTY the key typing z (physical KeyW) dispatched Ctrl+W and closed the tab instead of undoing. Letters are now named by the character typed when Alt is not held; Alt combos keep the physical key since they may type a symbol (macOS Option, AltGr). The terminal's Ctrl+letter control codes use the typed letter too.

Co-authored-by: florentvdry <[email protected]>
Цей коміт міститься в:
Florent Vтаflorentvdry authored and GitHub committed 2026-10-29 22:49:08 +08:00
1 джерело b9cfd54742
коміт 14d7fd0061
4 files changed
+22 -4

No files matched your search

+3 -3
Переглянути файл
@@ -60,9 +60,9 @@ export function terminalKeyAction(e: KeyLike, hasSelection: boolean): TerminalKe
if (e.code === "KeyT") return { kind: "pass" };
}
if (ctrl && !meta && !alt) {
// Use the physical key so layouts and Shift don't change the control code.
const m = /^Key([A-Z])$/.exec(e.code);
if (m) return { kind: "send", data: String.fromCharCode(m[1]!.charCodeAt(0) - 64) };
// The letter the key types, so Shift doesn't change the control code and AZERTY's Ctrl+Z is ^Z, not ^W.
const letter = /^[a-zA-Z]$/.test(e.key) ? e.key : /^Key([A-Z])$/.exec(e.code)?.[1];
if (letter) return { kind: "send", data: String.fromCharCode(letter.toUpperCase().charCodeAt(0) - 64) };
if (e.code === "BracketLeft") return { kind: "send", data: "\x1b" };
if (e.code === "Backslash") return { kind: "send", data: "\x1c" };
if (e.code === "BracketRight") return { kind: "send", data: "\x1d" };
+5
Переглянути файл
@@ -128,6 +128,11 @@ describe("terminal keys", () => {
kind: "send",
data: "\x14",
});
// AZERTY: the key typing "z" is physically KeyW; Ctrl+Z must send ^Z (SIGTSTP), not ^W.
expect(terminalKeyAction(key({ key: "z", code: "KeyW", ctrlKey: true }), false)).toEqual({
kind: "send",
data: "\x1a",
});
});
it("implements macOS conveniences", () => {