mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 08:52:12 +00:00
On Windows and Linux, Ctrl+C in the Run/Debug consoles and other DOM output views did nothing because no handler copied the selection. Each output view (Run and Debug consoles, Build output and message detail, Git console, database output, Docker logs) now copies its own selection on Ctrl+C / Ctrl+Insert (Cmd+C on macOS) through a shared helper, leaving views with their own copy handling (database grid, Problems) untouched. In terminals, Ctrl+C copies a selection on Windows and Linux and otherwise interrupts; on macOS it always interrupts. The console menu shows the host's copy shortcut. Not verified on a real Windows machine. Fixes #372
67 lines
2.6 KiB
TypeScript
67 lines
2.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { installTerminalKeys } from "./keys";
|
|
import { installKeyboardDispatcher, useKeymap } from "@/platform/keymap";
|
|
import { registerAction } from "@/platform/actions";
|
|
import { usePlatform } from "@/platform/platformInfo";
|
|
|
|
const mock = vi.hoisted(() => ({
|
|
session: { hasSelection: true, send: vi.fn(), copySelection: vi.fn() },
|
|
settings: { terminal: { overrideIdeShortcuts: true } },
|
|
}));
|
|
vi.mock("./loader", () => ({ terminalRuntime: () => ({ sessionFromElement: () => mock.session }) }));
|
|
vi.mock("@/platform/workflowSettings", () => ({ workflowSettings: () => mock.settings }));
|
|
|
|
beforeEach(() => usePlatform.setState({ os: "windows" }));
|
|
afterEach(() => usePlatform.setState({ os: "macos" }));
|
|
afterEach(() => vi.clearAllMocks());
|
|
|
|
describe("terminal copy capture", () => {
|
|
it.each([true, false])("copies before xterm and IDE dispatch with override shortcuts %s", (override) => {
|
|
mock.settings.terminal.overrideIdeShortcuts = override;
|
|
mock.session.hasSelection = true;
|
|
useKeymap.setState({ preset: "intellij-windows", overrides: {} });
|
|
const globalCopy = vi.fn();
|
|
const removeAction = registerAction({ id: "edit.copy", title: "Copy", run: globalCopy });
|
|
const removeKeys = installTerminalKeys();
|
|
const removeDispatcher = installKeyboardDispatcher();
|
|
const downstream = vi.fn();
|
|
window.addEventListener("keydown", downstream);
|
|
try {
|
|
for (const shiftKey of [false, true]) {
|
|
const event = new KeyboardEvent("keydown", {
|
|
key: "c",
|
|
code: "KeyC",
|
|
ctrlKey: true,
|
|
shiftKey,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
});
|
|
window.dispatchEvent(event);
|
|
expect(event.defaultPrevented).toBe(true);
|
|
}
|
|
expect(mock.session.copySelection).toHaveBeenCalledTimes(2);
|
|
expect(mock.session.send).not.toHaveBeenCalled();
|
|
expect(globalCopy).not.toHaveBeenCalled();
|
|
expect(downstream).not.toHaveBeenCalled();
|
|
} finally {
|
|
window.removeEventListener("keydown", downstream);
|
|
removeDispatcher();
|
|
removeKeys();
|
|
removeAction();
|
|
}
|
|
});
|
|
|
|
it("sends SIGINT when there is no selection", () => {
|
|
mock.settings.terminal.overrideIdeShortcuts = true;
|
|
mock.session.hasSelection = false;
|
|
const dispose = installTerminalKeys();
|
|
try {
|
|
window.dispatchEvent(new KeyboardEvent("keydown", { key: "c", code: "KeyC", ctrlKey: true }));
|
|
expect(mock.session.send).toHaveBeenCalledWith("\x03");
|
|
expect(mock.session.copySelection).not.toHaveBeenCalled();
|
|
} finally {
|
|
dispose();
|
|
}
|
|
});
|
|
});
|