Files
Netcatty/components/terminal/runtime/terminalInterruptShortcut.ts
T
0d21e37a19 fix(terminal): map macOS Command+. to interrupt running command like Ctrl+C (#3409)
* fix(#3408): automated AI fix

* fix: address Codex review on PR #3409

* fix: address Codex review on PR #3409

* fix: address Codex review on PR #3409

* fix: address Codex review on PR #3409

* fix: address Codex review on PR #3409

* fix: address Codex review on PR #3409

* fix: address Codex review on PR #3409

* fix: preserve physical releases for Command-period interrupts

* fix: allow Command-period with selected terminal text

* style: keep Command-period additions ASCII-only

* test: validate Command-period fixture without renderer errors

* fix: support logical period across macOS keyboard layouts

---------

Co-authored-by: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com>
Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
2026-09-18 14:11:05 +08:00

27 lines
1.1 KiB
TypeScript

type InterruptShortcutEvent = Pick<KeyboardEvent, "altKey" | "code" | "ctrlKey" | "key" | "metaKey" | "shiftKey">;
/**
* macOS Terminal convention: Command-Period interrupts the running
* command, equivalent to Ctrl+C. Netcatty does not bind Command-Period elsewhere, so on
* macOS it is forwarded as a SIGINT interrupt (#3408).
*/
export function isMacCommandPeriodInterruptChord(
event: InterruptShortcutEvent,
): boolean {
if (!event.metaKey || event.ctrlKey || event.altKey) return false;
// Shift can produce the logical period (for example on AZERTY).
// Only the physical-key fallback requires an unshifted event.
if (/^[\x20-\x7e]$/.test(event.key)) return event.key === ".";
return !event.shiftKey && event.code === "Period";
}
export function shouldUseUrgentTerminalInterrupt(
event: InterruptShortcutEvent,
options: { hasSelection: boolean },
): boolean {
if (options.hasSelection) return false;
if (!event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return false;
if (/^[\x20-\x7e]$/.test(event.key)) return event.key.toLowerCase() === "c";
return event.code === "KeyC" || event.key.toLowerCase() === "c";
}