diff --git a/src/features/terminal/embedded.test.ts b/src/features/terminal/embedded.test.ts index 919f4cc080..6b67046f93 100644 --- a/src/features/terminal/embedded.test.ts +++ b/src/features/terminal/embedded.test.ts @@ -141,6 +141,21 @@ it("copies embedded Run terminal selections before xterm can send Ctrl+C", () => } }); +it("leaves paste strokes in embedded Run terminals to the native paste", () => { + const host = document.createElement("div"); + document.body.append(host); + const term = createEmbeddedTerminal(host, { onData: vi.fn(), onResize: vi.fn() }); + try { + for (const init of [{ ctrlKey: true }, { ctrlKey: true, shiftKey: true }]) { + const paste = new KeyboardEvent("keydown", { key: "v", code: "KeyV", cancelable: true, ...init }); + expect(terminal.handler(paste)).toBe(false); + expect(paste.defaultPrevented).toBe(false); + } + } finally { + term.dispose(); + } +}); + it("delivers input-method commits to the owner on macOS as the terminal sessions do", () => { usePlatform.setState({ os: "macos" }); const host = document.createElement("div"); diff --git a/src/features/terminal/embedded.ts b/src/features/terminal/embedded.ts index a67f173b25..8de15f0b5a 100644 --- a/src/features/terminal/embedded.ts +++ b/src/features/terminal/embedded.ts @@ -74,6 +74,9 @@ export function createEmbeddedTerminal(host: HTMLElement, opts: EmbeddedTerminal noteCopySource(text, { kind: "terminal", title: "Terminal" }); void writeClipboardText(text).catch(() => undefined); } + } else if (action.kind === "paste") { + // Keep xterm from sending Ctrl+V as ^V; the native paste reaches its textarea. + return false; } else { return true; } diff --git a/src/features/terminal/keys.ts b/src/features/terminal/keys.ts index cd4ea7b770..0ced0637c8 100644 --- a/src/features/terminal/keys.ts +++ b/src/features/terminal/keys.ts @@ -20,6 +20,7 @@ import { effectiveBindings, isMacHost, letterOf, registerKeyClaim, strokeOf } fr import { workflowSettings } from "@/platform/workflowSettings"; import { terminalRuntime } from "./loader"; import { isImeKey } from "@/platform/ime"; +import { usePlatform } from "@/platform/platformInfo"; export type TerminalKeyResult = | { kind: "send"; data: string } @@ -56,6 +57,10 @@ export function terminalKeyAction(e: KeyLike, hasSelection: boolean): TerminalKe } const letter = letterOf(e); if (ctrl && !meta && !alt && letter === "C" && hasSelection && !isMacHost()) return { kind: "copy" }; + // Windows terminals paste on plain Ctrl+V; elsewhere it stays ^V (the shell's quoted-insert). + if (ctrl && !shift && !meta && !alt && letter === "V" && usePlatform.getState().os === "windows") { + return { kind: "paste" }; + } if (ctrl && shift && !meta && !alt) { if (letter === "C") return hasSelection ? { kind: "copy" } : { kind: "pass" }; if (letter === "V") return { kind: "paste" }; diff --git a/src/features/terminal/terminal.test.ts b/src/features/terminal/terminal.test.ts index 9de9cad659..7153870ee2 100644 --- a/src/features/terminal/terminal.test.ts +++ b/src/features/terminal/terminal.test.ts @@ -202,6 +202,19 @@ describe("terminal keys", () => { } }); + it("pastes on plain Ctrl+V only on Windows", () => { + const ctrlV = key({ key: "v", code: "KeyV", ctrlKey: true }); + try { + usePlatform.setState({ os: "windows" }); + expect(terminalKeyAction(ctrlV, false)).toEqual({ kind: "paste" }); + usePlatform.setState({ os: "linux" }); + expect(terminalKeyAction(ctrlV, false)).toEqual({ kind: "send", data: "\x16" }); + } finally { + usePlatform.setState({ os: "macos" }); + } + expect(terminalKeyAction(ctrlV, false)).toEqual({ kind: "send", data: "\x16" }); + }); + it("keeps Ctrl+C as interrupt on macOS even with a selection", () => { usePlatform.setState({ os: "macos" }); expect(terminalKeyAction(key({ key: "c", code: "KeyC", ctrlKey: true }), true)).not.toEqual({ kind: "copy" });