From a66f9e90665b4f3f1b1c8ab15eb6629a9e75b868 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 May 2025 12:55:07 +0000 Subject: [PATCH] Remove alt-to-ctrl arrow key hacks and update tests Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com> --- src/common/input/Keyboard.test.ts | 43 +++++++++++++++---------------- src/common/input/Keyboard.ts | 24 ----------------- 2 files changed, 21 insertions(+), 46 deletions(-) diff --git a/src/common/input/Keyboard.test.ts b/src/common/input/Keyboard.test.ts index c598fc58c..310d90f6b 100644 --- a/src/common/input/Keyboard.test.ts +++ b/src/common/input/Keyboard.test.ts @@ -123,19 +123,18 @@ describe('Keyboard', () => { }); describe('On non-macOS platforms', () => { - // Evalueate alt + arrow key movement, which is a feature of terminal emulators but not VT100 - // http://unix.stackexchange.com/a/108106 - it('should return \\x1b[5D for alt+left', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 37 }, { isMac: false }).key, '\x1b[1;5D'); // CSI 5 D + // Alt + arrow keys should now emit the standard Alt escape sequences instead of Ctrl sequences + it('should return \\x1b[1;3D for alt+left', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 37 }, { isMac: false }).key, '\x1b[1;3D'); // Standard Alt+Left }); - it('should return \\x1b[5C for alt+right', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 39 }, { isMac: false }).key, '\x1b[1;5C'); // CSI 5 C + it('should return \\x1b[1;3C for alt+right', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 39 }, { isMac: false }).key, '\x1b[1;3C'); // Standard Alt+Right }); - it('should return \\x1b[5D for alt+up', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 38 }, { isMac: false }).key, '\x1b[1;5A'); // CSI 5 D + it('should return \\x1b[1;3A for alt+up', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 38 }, { isMac: false }).key, '\x1b[1;3A'); // Standard Alt+Up }); - it('should return \\x1b[5C for alt+down', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 40 }, { isMac: false }).key, '\x1b[1;5B'); // CSI 5 C + it('should return \\x1b[1;3B for alt+down', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 40 }, { isMac: false }).key, '\x1b[1;3B'); // Standard Alt+Down }); it('should return \\x1ba for alt+a', () => { assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 65 }, { isMac: false }).key, '\x1ba'); @@ -149,17 +148,17 @@ describe('Keyboard', () => { }); describe('On macOS platforms', () => { - it('should return \\x1bb for alt+left', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 37 }, { isMac: true }).key, '\x1bb'); // CSI 5 D + it('should return \\x1b[1;3D for alt+left', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 37 }, { isMac: true }).key, '\x1b[1;3D'); // Standard Alt+Left }); - it('should return \\x1bf for alt+right', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 39 }, { isMac: true }).key, '\x1bf'); // CSI 5 C + it('should return \\x1b[1;3C for alt+right', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 39 }, { isMac: true }).key, '\x1b[1;3C'); // Standard Alt+Right }); - it('should return \\x1bb for alt+up', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 38 }, { isMac: true }).key, '\x1b[1;3A'); // CSI 5 D + it('should return \\x1b[1;3A for alt+up', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 38 }, { isMac: true }).key, '\x1b[1;3A'); // Standard Alt+Up }); - it('should return \\x1bf for alt+down', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 40 }, { isMac: true }).key, '\x1b[1;3B'); // CSI 5 C + it('should return \\x1b[1;3B for alt+down', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 40 }, { isMac: true }).key, '\x1b[1;3B'); // Standard Alt+Down }); it('should return undefined for alt+a', () => { assert.strictEqual(testEvaluateKeyboardEvent({ altKey: true, keyCode: 65 }, { isMac: true }).key, undefined); @@ -176,11 +175,11 @@ describe('Keyboard', () => { }); }); - it('should return \\x1b[5A for alt+up', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 38 }).key, '\x1b[1;5A'); // CSI 5 A + it('should return \\x1b[1;3A for alt+up', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 38 }).key, '\x1b[1;3A'); // Standard Alt+Up }); - it('should return \\x1b[5B for alt+down', () => { - assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 40 }).key, '\x1b[1;5B'); // CSI 5 B + it('should return \\x1b[1;3B for alt+down', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 40 }).key, '\x1b[1;3B'); // Standard Alt+Down }); it('should return the correct escape sequence for modified F1-F12 keys', () => { assert.equal(testEvaluateKeyboardEvent({ shiftKey: true, keyCode: 112 }).key, '\x1b[1;2P'); diff --git a/src/common/input/Keyboard.ts b/src/common/input/Keyboard.ts index b86eeac46..c825b4120 100644 --- a/src/common/input/Keyboard.ts +++ b/src/common/input/Keyboard.ts @@ -117,12 +117,6 @@ export function evaluateKeyboardEvent( } if (modifiers) { result.key = C0.ESC + '[1;' + (modifiers + 1) + 'D'; - // HACK: Make Alt + left-arrow behave like Ctrl + left-arrow: move one word backwards - // http://unix.stackexchange.com/a/108106 - // macOS uses different escape sequences than linux - if (result.key === C0.ESC + '[1;3D') { - result.key = C0.ESC + (isMac ? 'b' : '[1;5D'); - } } else if (applicationCursorMode) { result.key = C0.ESC + 'OD'; } else { @@ -136,12 +130,6 @@ export function evaluateKeyboardEvent( } if (modifiers) { result.key = C0.ESC + '[1;' + (modifiers + 1) + 'C'; - // HACK: Make Alt + right-arrow behave like Ctrl + right-arrow: move one word forward - // http://unix.stackexchange.com/a/108106 - // macOS uses different escape sequences than linux - if (result.key === C0.ESC + '[1;3C') { - result.key = C0.ESC + (isMac ? 'f' : '[1;5C'); - } } else if (applicationCursorMode) { result.key = C0.ESC + 'OC'; } else { @@ -155,12 +143,6 @@ export function evaluateKeyboardEvent( } if (modifiers) { result.key = C0.ESC + '[1;' + (modifiers + 1) + 'A'; - // HACK: Make Alt + up-arrow behave like Ctrl + up-arrow - // http://unix.stackexchange.com/a/108106 - // macOS uses different escape sequences than linux - if (!isMac && result.key === C0.ESC + '[1;3A') { - result.key = C0.ESC + '[1;5A'; - } } else if (applicationCursorMode) { result.key = C0.ESC + 'OA'; } else { @@ -174,12 +156,6 @@ export function evaluateKeyboardEvent( } if (modifiers) { result.key = C0.ESC + '[1;' + (modifiers + 1) + 'B'; - // HACK: Make Alt + down-arrow behave like Ctrl + down-arrow - // http://unix.stackexchange.com/a/108106 - // macOS uses different escape sequences than linux - if (!isMac && result.key === C0.ESC + '[1;3B') { - result.key = C0.ESC + '[1;5B'; - } } else if (applicationCursorMode) { result.key = C0.ESC + 'OB'; } else {