mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-09 15:58:34 +00:00
88142d2a92
* fix: let Ctrl+C send SIGINT when no text is selected in terminal When the copy shortcut is customized to Ctrl+C (default Ctrl+Shift+C), the terminal always consumed the event for copy even without a text selection, preventing the standard Ctrl+C → SIGINT interrupt signal. Added a guard in attachCustomKeyEventHandler: if the matched action is 'copy' and term.hasSelection() is false, return true to pass the event through to xterm.js, which encodes it as \x03 (ETX) for normal SIGINT delivery. When text IS selected, copy proceeds as before. This change is platform-agnostic (renderer-side only) and does not affect any other terminal actions or default key bindings. * fix: gate copy passthrough on Ctrl+C/⌃C interrupt chord specifically The previous fix passed ALL no-selection copy bindings through to xterm, which would send unintended escape/control sequences to the remote process if copy were bound to keys like F5 or Ctrl+L. Now gate the passthrough on the exact interrupt chord: Ctrl+C (PC) or ⌃C (Mac) — key 'c' with only Ctrl pressed, no Shift/Alt/Meta. Any other copy binding with no selection is consumed as a safe no-op. * fix: preserve Ctrl-C passthrough for copy shortcut --------- Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
isPlainCtrlCInterruptChord,
|
|
shouldPassThroughCopyShortcut,
|
|
} from "./terminalCopyShortcut.ts";
|
|
|
|
const keyboardEvent = (
|
|
key: string,
|
|
code: string,
|
|
modifiers: Partial<KeyboardEvent> = {},
|
|
): KeyboardEvent => ({
|
|
key,
|
|
code,
|
|
ctrlKey: false,
|
|
shiftKey: false,
|
|
altKey: false,
|
|
metaKey: false,
|
|
...modifiers,
|
|
}) as KeyboardEvent;
|
|
|
|
test("plain Ctrl+C copy with no selection passes through for SIGINT", () => {
|
|
const event = keyboardEvent("c", "KeyC", { ctrlKey: true });
|
|
|
|
assert.equal(isPlainCtrlCInterruptChord(event), true);
|
|
assert.equal(shouldPassThroughCopyShortcut("copy", false, event), true);
|
|
});
|
|
|
|
test("copy shortcut does not pass through when text is selected", () => {
|
|
const event = keyboardEvent("c", "KeyC", { ctrlKey: true });
|
|
|
|
assert.equal(shouldPassThroughCopyShortcut("copy", true, event), false);
|
|
});
|
|
|
|
test("copy shortcut does not pass through for shifted or alternate chords", () => {
|
|
assert.equal(
|
|
shouldPassThroughCopyShortcut("copy", false, keyboardEvent("C", "KeyC", { ctrlKey: true, shiftKey: true })),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldPassThroughCopyShortcut("copy", false, keyboardEvent("l", "KeyL", { ctrlKey: true })),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldPassThroughCopyShortcut("paste", false, keyboardEvent("c", "KeyC", { ctrlKey: true })),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("plain Ctrl+C copy passthrough follows the physical C key on non-Latin layouts", () => {
|
|
const event = keyboardEvent("\u0441", "KeyC", { ctrlKey: true });
|
|
|
|
assert.equal(isPlainCtrlCInterruptChord(event), true);
|
|
assert.equal(shouldPassThroughCopyShortcut("copy", false, event), true);
|
|
});
|