From da11e31fe52ccf209cf3026d38f79a43ae5eefae Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 11 Oct 2019 16:01:28 -0700 Subject: [PATCH 1/2] Don't use ctrl+up/down hack on macOS Fixes #2387 --- src/common/input/Keyboard.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/input/Keyboard.ts b/src/common/input/Keyboard.ts index e4ae3d23..1bf378c1 100644 --- a/src/common/input/Keyboard.ts +++ b/src/common/input/Keyboard.ts @@ -122,7 +122,7 @@ export function evaluateKeyboardEvent( // http://unix.stackexchange.com/a/108106 // macOS uses different escape sequences than linux if (result.key === C0.ESC + '[1;3D') { - result.key = isMac ? C0.ESC + 'b' : C0.ESC + '[1;5D'; + result.key = C0.ESC + (isMac ? 'b' : '[1;5D'); } } else if (applicationCursorMode) { result.key = C0.ESC + 'OD'; @@ -141,7 +141,7 @@ export function evaluateKeyboardEvent( // http://unix.stackexchange.com/a/108106 // macOS uses different escape sequences than linux if (result.key === C0.ESC + '[1;3C') { - result.key = isMac ? C0.ESC + 'f' : C0.ESC + '[1;5C'; + result.key = C0.ESC + (isMac ? 'f' : '[1;5C'); } } else if (applicationCursorMode) { result.key = C0.ESC + 'OC'; @@ -158,7 +158,8 @@ export function evaluateKeyboardEvent( result.key = C0.ESC + '[1;' + (modifiers + 1) + 'A'; // HACK: Make Alt + up-arrow behave like Ctrl + up-arrow // http://unix.stackexchange.com/a/108106 - if (result.key === C0.ESC + '[1;3A') { + // macOS uses different escape sequences than linux + if (!isMac && result.key === C0.ESC + '[1;3A') { result.key = C0.ESC + '[1;5A'; } } else if (applicationCursorMode) { @@ -176,7 +177,8 @@ export function evaluateKeyboardEvent( result.key = C0.ESC + '[1;' + (modifiers + 1) + 'B'; // HACK: Make Alt + down-arrow behave like Ctrl + down-arrow // http://unix.stackexchange.com/a/108106 - if (result.key === C0.ESC + '[1;3B') { + // macOS uses different escape sequences than linux + if (!isMac && result.key === C0.ESC + '[1;3B') { result.key = C0.ESC + '[1;5B'; } } else if (applicationCursorMode) { From 3d6815ca6f1e03471306f62255c0688ad7e5284c Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 11 Oct 2019 16:05:54 -0700 Subject: [PATCH 2/2] Add tests for alt+up/down --- src/common/input/Keyboard.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/common/input/Keyboard.test.ts b/src/common/input/Keyboard.test.ts index 409a3192..a304923e 100644 --- a/src/common/input/Keyboard.test.ts +++ b/src/common/input/Keyboard.test.ts @@ -108,6 +108,12 @@ describe('Keyboard', () => { 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[5D for alt+up', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 38 }, { isMac: false }).key, '\x1b[1;5A'); // CSI 5 D + }); + 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 \\x1ba for alt+a', () => { assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 65 }, { isMac: false }).key, '\x1ba'); }); @@ -120,6 +126,12 @@ describe('Keyboard', () => { it('should return \\x1bf for alt+right', () => { assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 39 }, { isMac: true }).key, '\x1bf'); // CSI 5 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 \\x1bf for alt+down', () => { + assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 40 }, { isMac: true }).key, '\x1b[1;3B'); // CSI 5 C + }); it('should return undefined for alt+a', () => { assert.strictEqual(testEvaluateKeyboardEvent({ altKey: true, keyCode: 65 }, { isMac: true }).key, undefined), { isMac: true }; });