fix(terminal): paste on plain Ctrl+V on Windows (#5646)

Plain Ctrl+V sent ^V to the shell on every platform, so Windows users had to use Ctrl+Shift+V or the context menu to paste. On Windows it now pastes in terminal tabs and in the embedded Run/Debug consoles, where xterm would otherwise turn the stroke into ^V itself. Linux and macOS keep ^V for the shell.

Fixes #5290
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-24 22:32:54 +08:00
1 джерело 72b4d5c6de
коміт 18eb515c83
4 files changed
+36

No files matched your search

+15
Переглянути файл
@@ -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");
+3
Переглянути файл
@@ -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;
}
+5
Переглянути файл
@@ -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" };
+13
Переглянути файл
@@ -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" });