TypeScript
fix(web): preserve Ctrl+Arrow terminal key sequences (#23480)
Utkarsh Patil0f6de8c22c0b
diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.tsindex a0ba7fa7ee0..1f0a096fcca 100644--- a/apps/web/src/keybindings.test.ts+++ b/apps/web/src/keybindings.test.ts@@ -21,6 +21,7 @@ import {resolveShortcutCommand,shouldShowThreadJumpHintsForModifiers,shortcutLabelForCommand,+ terminalNavigationShortcutData,type ShortcutEventLike,} from "./keybindings";@@ -35,6 +36,31 @@ function event(overrides: Partial<ShortcutEventLike> = {}): ShortcutEventLike {};}+describe("terminal word navigation", () => {+ it.each(["Win32", "Linux x86_64"])(+ "leaves Ctrl+Arrow to the terminal encoder on %s",+ (platform) => {+ for (const key of ["ArrowLeft", "ArrowRight"]) {+ assert.equal(terminalNavigationShortcutData(event({ key, ctrlKey: true }), platform), null);+ }+ },+ );++ it.each(["Win32", "Linux x86_64", "MacIntel"])(+ "preserves Alt+Arrow word navigation on %s",+ (platform) => {+ assert.equal(+ terminalNavigationShortcutData(event({ key: "ArrowLeft", altKey: true }), platform),+ "\u001bb",+ );+ assert.equal(+ terminalNavigationShortcutData(event({ key: "ArrowRight", altKey: true }), platform),+ "\u001bf",+ );+ },+ );+});+function modShortcut(key: string,overrides: Partial<Omit<KeybindingShortcut, "key">> = {},diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.tsindex d3d3de58d36..18c1b4c53c5 100644--- a/apps/web/src/keybindings.ts+++ b/apps/web/src/keybindings.ts@@ -464,10 +464,6 @@ export function terminalNavigationShortcutData(return null;}- if (event.ctrlKey && !event.metaKey && !event.altKey) {- return moveWord;- }-if (event.altKey && !event.metaKey && !event.ctrlKey) {return moveWord;}diff --git a/apps/web/src/terminal/ghostty/core.test.ts b/apps/web/src/terminal/ghostty/core.test.tsindex 69bf963ae34..7fc9661555e 100644--- a/apps/web/src/terminal/ghostty/core.test.ts+++ b/apps/web/src/terminal/ghostty/core.test.ts@@ -12,6 +12,7 @@ import {import { writeTerminalOutputUpdate } from "../../components/ThreadTerminalDrawer";import { GHOSTTY_CELL_WIDE, GhosttyTerminalCore, ghosttyCellText } from "./core";import { loadGhosttyRuntime } from "./runtime";+import { terminalNavigationShortcutData } from "../../keybindings";vi.mock("./vendor/ghostty-vt.wasm?url", async () => ({default: (await import("./vendor/ghostty-vt.wasm?inline")).default,@@ -101,6 +102,26 @@ describe("GhosttyTerminalCore snapshots", () => {vi.restoreAllMocks();});+ it.each([+ { key: "ArrowLeft", expected: "\x1b[1;5D" },+ { key: "ArrowRight", expected: "\x1b[1;5C" },+ ])("sends Ctrl+$key as a modified arrow instead of Alt+B/F", async ({ key, expected }) => {+ const core = await createCore();+ const event = {+ code: key,+ key,+ repeat: false,+ shiftKey: false,+ ctrlKey: true,+ altKey: false,+ metaKey: false,+ isComposing: false,+ getModifierState: () => false,+ } as unknown as KeyboardEvent;++ expect(terminalNavigationShortcutData(event, "Win32") ?? core.encodeKey(event)).toBe(expected);+ });+it.each([{ code: "", key: "Backspace", expected: "\x7f" },{ code: "Unidentified", key: "Backspace", expected: "\x7f" },