Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
isPlainCtrlCInterruptChord,
|
|
isPlainMetaCCopyChord,
|
|
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("plain Cmd+C copy with no selection passes through for Kitty Super+C", () => {
|
|
const event = keyboardEvent("c", "KeyC", { metaKey: true });
|
|
|
|
assert.equal(isPlainMetaCCopyChord(event), true);
|
|
assert.equal(isPlainCtrlCInterruptChord(event), false);
|
|
assert.equal(shouldPassThroughCopyShortcut("copy", false, event), true);
|
|
});
|
|
|
|
test("copy shortcut does not pass through when text is selected", () => {
|
|
const ctrlC = keyboardEvent("c", "KeyC", { ctrlKey: true });
|
|
const cmdC = keyboardEvent("c", "KeyC", { metaKey: true });
|
|
|
|
assert.equal(shouldPassThroughCopyShortcut("copy", true, ctrlC), false);
|
|
assert.equal(shouldPassThroughCopyShortcut("copy", true, cmdC), 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("C", "KeyC", { metaKey: true, shiftKey: true })),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldPassThroughCopyShortcut("copy", false, keyboardEvent("l", "KeyL", { ctrlKey: true })),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldPassThroughCopyShortcut("copy", false, keyboardEvent("c", "KeyC", { metaKey: true, ctrlKey: true })),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldPassThroughCopyShortcut("paste", false, keyboardEvent("c", "KeyC", { ctrlKey: true })),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldPassThroughCopyShortcut("paste", false, keyboardEvent("c", "KeyC", { metaKey: 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);
|
|
});
|
|
|
|
test("plain Cmd+C copy passthrough follows the physical C key on non-Latin layouts", () => {
|
|
const event = keyboardEvent("\u0441", "KeyC", { metaKey: true });
|
|
|
|
assert.equal(isPlainMetaCCopyChord(event), true);
|
|
assert.equal(shouldPassThroughCopyShortcut("copy", false, event), true);
|
|
});
|