diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts index 0ecccf43f8..75e24dc358 100644 --- a/apps/web/src/keybindings.test.ts +++ b/apps/web/src/keybindings.test.ts @@ -439,11 +439,11 @@ describe("terminalNavigationShortcutData", () => { it("maps Ctrl+Arrow on non-macOS to word movement", () => { assert.strictEqual( terminalNavigationShortcutData(event({ key: "ArrowLeft", ctrlKey: true }), "Win32"), - "\u001bb", + "\u001b[1;5D", ); assert.strictEqual( terminalNavigationShortcutData(event({ key: "ArrowRight", ctrlKey: true }), "Linux"), - "\u001bf", + "\u001b[1;5C", ); }); diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.ts index 09d9308aad..d56b6f612f 100644 --- a/apps/web/src/keybindings.ts +++ b/apps/web/src/keybindings.ts @@ -28,6 +28,8 @@ interface ShortcutMatchOptions { const TERMINAL_WORD_BACKWARD = "\u001bb"; const TERMINAL_WORD_FORWARD = "\u001bf"; +const TERMINAL_WORD_BACKWARD_CTRL = "\u001b[1;5D"; +const TERMINAL_WORD_FORWARD_CTRL = "\u001b[1;5C"; const TERMINAL_LINE_START = "\u0001"; const TERMINAL_LINE_END = "\u0005"; @@ -269,8 +271,11 @@ export function terminalNavigationShortcutData( return null; } - const moveWord = key === "arrowleft" ? TERMINAL_WORD_BACKWARD : TERMINAL_WORD_FORWARD; - const moveLine = key === "arrowleft" ? TERMINAL_LINE_START : TERMINAL_LINE_END; + const moveWord = + key === "arrowleft" ? TERMINAL_WORD_BACKWARD : TERMINAL_WORD_FORWARD; + const moveLine = + key === "arrowleft" ? TERMINAL_LINE_START : TERMINAL_LINE_END; + const moveWordCtrl = key === "arrowleft" ? TERMINAL_WORD_BACKWARD_CTRL : TERMINAL_WORD_FORWARD_CTRL; if (isMacPlatform(platform)) { if (event.altKey && !event.metaKey && !event.ctrlKey) { @@ -280,15 +285,12 @@ export function terminalNavigationShortcutData( return moveLine; } return null; + } else { + + if (event.ctrlKey && !event.metaKey && !event.altKey) { + return moveWordCtrl; + } + return null; } - - if (event.ctrlKey && !event.metaKey && !event.altKey) { - return moveWord; - } - - if (event.altKey && !event.metaKey && !event.ctrlKey) { - return moveWord; - } - - return null; + }