From 41546230dc6a731e8796804326d3e48aa2f49c5a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 29 May 2025 13:20:54 +0000 Subject: [PATCH] Remove alt -> ctrl+arrow hack and update tests Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com> --- src/common/input/Keyboard.test.ts | 40 +++++++++++++++---------------- src/common/input/Keyboard.ts | 24 ------------------- 2 files changed, 20 insertions(+), 44 deletions(-) diff --git a/src/common/input/Keyboard.test.ts b/src/common/input/Keyboard.test.ts index c598fc58..55a4884c 100644 --- a/src/common/input/Keyboard.test.ts +++ b/src/common/input/Keyboard.test.ts @@ -125,17 +125,17 @@ 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 + it('should return \\x1b[1;3D for alt+left', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 37 }, { isMac: false }).key, '\x1b[1;3D'); // CSI 1;3 D }); - 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'); // CSI 1;3 C }); - 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'); // CSI 1;3 A }); - 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'); // CSI 1;3 B }); it('should return \\x1ba for alt+a', () => { assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 65 }, { isMac: false }).key, '\x1ba'); @@ -149,17 +149,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'); // CSI 1;3 D }); - 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'); // CSI 1;3 C }); - 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'); // CSI 1;3 A }); - 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'); // CSI 1;3 B }); it('should return undefined for alt+a', () => { assert.strictEqual(testEvaluateKeyboardEvent({ altKey: true, keyCode: 65 }, { isMac: true }).key, undefined); @@ -176,11 +176,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'); // CSI 1;3 A }); - 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'); // CSI 1;3 B }); 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 b86eeac4..c825b412 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 {