Skip to content

Commit 83b865f

Browse files
fix(web): copy terminal selection with Ctrl+Insert (#8541)
1 parent d6dbe8d commit 83b865f

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎apps/web/src/terminal/ghostty/surface.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,20 @@ describe("isTerminalCopyShortcut", () => {
556556
expect(isTerminalCopyShortcut(event({ key: "C", metaKey: true }), "MacIntel")).toBe(true);
557557
expect(isTerminalCopyShortcut(event({ key: "j", metaKey: true }), "MacIntel")).toBe(false);
558558
});
559+
560+
it("supports the conventional Ctrl+Insert copy shortcut", () => {
561+
expect(isTerminalCopyShortcut(event({ key: "Insert", ctrlKey: true }), "Linux x86_64")).toBe(
562+
true,
563+
);
564+
expect(isTerminalCopyShortcut(event({ key: "Insert" }), "Linux x86_64")).toBe(false);
565+
expect(
566+
isTerminalCopyShortcut(
567+
event({ key: "Insert", ctrlKey: true, shiftKey: true }),
568+
"Linux x86_64",
569+
),
570+
).toBe(false);
571+
expect(isTerminalCopyShortcut(event({ key: "Insert", ctrlKey: true }), "MacIntel")).toBe(false);
572+
});
559573
});
560574

561575
describe("applyTerminalCopyEvent", () => {

‎apps/web/src/terminal/ghostty/surface.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ export function isTerminalCopyShortcut(
321321
event: Pick<KeyboardEvent, "ctrlKey" | "key" | "metaKey" | "shiftKey">,
322322
platform = navigator.platform,
323323
) {
324-
if (event.key.toLowerCase() !== "c") return false;
324+
const key = event.key.toLowerCase();
325+
if (key === "insert" && !isMacPlatform(platform)) {
326+
return event.ctrlKey && !event.shiftKey && !event.metaKey;
327+
}
328+
if (key !== "c") return false;
325329
return isMacPlatform(platform) ? event.metaKey : event.ctrlKey;
326330
}
327331

@@ -1027,12 +1031,12 @@ export class GhosttyTerminalSurface {
10271031
// A plain Ctrl+C/Cmd+C fires the browser's native copy event, caught in
10281032
// onCopyEvent; not preventing the default keeps that path alive. WebKit
10291033
// omits the keyboard copy event without a DOM selection, so race the
1030-
// clipboard write against it the same way paste races its read. The
1031-
// Shift variant has no native event (Chrome binds Ctrl+Shift+C to
1034+
// clipboard write against it the same way paste races its read. Ctrl+Shift+C
1035+
// and Ctrl+Insert have no native copy event (Chrome binds the former to
10321036
// inspect), so synthesize one with execCommand("copy").
10331037
const selection = this.getSelection();
10341038
this.primeCopy(selection);
1035-
if (event.shiftKey) {
1039+
if (event.shiftKey || event.key.toLowerCase() === "insert") {
10361040
event.preventDefault();
10371041
document.execCommand("copy");
10381042
} else {

0 commit comments

Comments
 (0)