Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion apps/web/src/components/ThreadTerminalDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import {
resolveWrappedTerminalLinkRange,
wrappedTerminalLinkRangeIntersectsBufferLine,
} from "../terminal-links";
import { isTerminalClearShortcut, terminalNavigationShortcutData } from "../keybindings";
import {
isTerminalClearShortcut,
terminalDeleteShortcutData,
terminalNavigationShortcutData,
} from "../keybindings";
import {
DEFAULT_THREAD_TERMINAL_HEIGHT,
DEFAULT_THREAD_TERMINAL_ID,
Expand Down Expand Up @@ -407,6 +411,14 @@ export function TerminalViewport({
return false;
}

const deleteData = terminalDeleteShortcutData(event);
if (deleteData !== null) {
event.preventDefault();
event.stopPropagation();
void sendTerminalInput(deleteData, "Failed to delete terminal input");
return false;
}

if (!isTerminalClearShortcut(event)) return true;
event.preventDefault();
event.stopPropagation();
Expand Down
29 changes: 29 additions & 0 deletions apps/web/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
resolveShortcutCommand,
shouldShowThreadJumpHints,
shortcutLabelForCommand,
terminalDeleteShortcutData,
terminalNavigationShortcutData,
threadJumpCommandForIndex,
threadJumpIndexFromCommand,
Expand Down Expand Up @@ -560,6 +561,34 @@ describe("isTerminalClearShortcut", () => {
});
});

describe("terminalDeleteShortcutData", () => {
it("maps Cmd+Backspace on macOS to delete-to-line-start", () => {
assert.strictEqual(
terminalDeleteShortcutData(event({ key: "Backspace", metaKey: true }), "MacIntel"),
"\u0015",
);
});

it("ignores non-macOS platforms and modified variants", () => {
assert.isNull(terminalDeleteShortcutData(event({ key: "Backspace", metaKey: true }), "Linux"));
assert.isNull(
terminalDeleteShortcutData(
event({ key: "Backspace", metaKey: true, altKey: true }),
"MacIntel",
),
);
});

it("ignores non-keydown events", () => {
assert.isNull(
terminalDeleteShortcutData(
event({ type: "keyup", key: "Backspace", metaKey: true }),
"MacIntel",
),
);
});
});

describe("terminalNavigationShortcutData", () => {
it("maps Option+Arrow on macOS to word movement", () => {
assert.strictEqual(
Expand Down
23 changes: 23 additions & 0 deletions apps/web/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const TERMINAL_WORD_BACKWARD = "\u001bb";
const TERMINAL_WORD_FORWARD = "\u001bf";
const TERMINAL_LINE_START = "\u0001";
const TERMINAL_LINE_END = "\u0005";
const TERMINAL_DELETE_TO_LINE_START = "\u0015";
const EVENT_CODE_KEY_ALIASES: Readonly<Record<string, readonly string[]>> = {
BracketLeft: ["["],
BracketRight: ["]"],
Expand Down Expand Up @@ -370,6 +371,28 @@ export function isTerminalClearShortcut(
);
}

export function terminalDeleteShortcutData(
event: ShortcutEventLike,
platform = navigator.platform,
): string | null {
if (event.type !== undefined && event.type !== "keydown") {
return null;
}

if (!isMacPlatform(platform)) {
return null;
}

const key = normalizeEventKey(event.key);
if (key !== "backspace") {
return null;
}

return event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey
? TERMINAL_DELETE_TO_LINE_START
: null;
}

export function terminalNavigationShortcutData(
event: ShortcutEventLike,
platform = navigator.platform,
Expand Down
Loading