fix(tui): parse legacy alt-prefixed symbols (#6523)
This commit is contained in:
@@ -1159,8 +1159,8 @@ export function matchesKey(data: string, keyId: KeyId): boolean {
|
||||
if (data === `\x1b${rawCtrl}`) return true;
|
||||
}
|
||||
|
||||
if (modifier === MODIFIERS.alt && !_kittyProtocolActive && (isLetter || isDigit)) {
|
||||
// Legacy: alt+letter/digit is ESC followed by the key
|
||||
if (modifier === MODIFIERS.alt && !_kittyProtocolActive && (isLetter || isDigit || SYMBOL_KEYS.has(key))) {
|
||||
// Legacy: alt+printable key is ESC followed by the key
|
||||
if (data === `\x1b${key}`) return true;
|
||||
}
|
||||
|
||||
@@ -1296,9 +1296,10 @@ export function parseKey(data: string): string | undefined {
|
||||
if (code >= 1 && code <= 26) {
|
||||
return `ctrl+alt+${String.fromCharCode(code + 96)}`;
|
||||
}
|
||||
// Legacy alt+letter/digit (ESC followed by the key)
|
||||
if ((code >= 97 && code <= 122) || (code >= 48 && code <= 57)) {
|
||||
return `alt+${String.fromCharCode(code)}`;
|
||||
// Legacy alt+letter/digit/symbol (ESC followed by the key)
|
||||
const key = String.fromCharCode(code);
|
||||
if ((code >= 97 && code <= 122) || (code >= 48 && code <= 57) || SYMBOL_KEYS.has(key)) {
|
||||
return `alt+${key}`;
|
||||
}
|
||||
}
|
||||
if (data === "\x1b[A") return "up";
|
||||
|
||||
@@ -431,6 +431,10 @@ describe("matchesKey", () => {
|
||||
assert.strictEqual(parseKey("\x1ba"), "alt+a");
|
||||
assert.strictEqual(matchesKey("\x1b1", "alt+1"), true);
|
||||
assert.strictEqual(parseKey("\x1b1"), "alt+1");
|
||||
assert.strictEqual(matchesKey("\x1b,", "alt+,"), true);
|
||||
assert.strictEqual(parseKey("\x1b,"), "alt+,");
|
||||
assert.strictEqual(matchesKey("\x1b.", "alt+."), true);
|
||||
assert.strictEqual(parseKey("\x1b."), "alt+.");
|
||||
assert.strictEqual(matchesKey("\x1by", "alt+y"), true);
|
||||
assert.strictEqual(parseKey("\x1by"), "alt+y");
|
||||
assert.strictEqual(matchesKey("\x1bz", "alt+z"), true);
|
||||
@@ -451,6 +455,10 @@ describe("matchesKey", () => {
|
||||
assert.strictEqual(parseKey("\x1ba"), undefined);
|
||||
assert.strictEqual(matchesKey("\x1b1", "alt+1"), false);
|
||||
assert.strictEqual(parseKey("\x1b1"), undefined);
|
||||
assert.strictEqual(matchesKey("\x1b,", "alt+,"), false);
|
||||
assert.strictEqual(parseKey("\x1b,"), undefined);
|
||||
assert.strictEqual(matchesKey("\x1b.", "alt+."), false);
|
||||
assert.strictEqual(parseKey("\x1b."), undefined);
|
||||
assert.strictEqual(matchesKey("\x1by", "alt+y"), false);
|
||||
assert.strictEqual(parseKey("\x1by"), undefined);
|
||||
setKittyProtocolActive(false);
|
||||
|
||||
Reference in New Issue
Block a user