/** * @file keys.ts * @description Keyboard helpers shared by every single-line submit field. * `isSubmitEnter` ignores the Enter that confirms an IME candidate (Vietnamese * Telex, CJK): without it a rename or commit message is committed half-typed. * `copyOnCtrlShiftC` makes Ctrl+Shift+C a copy, as in a Linux terminal, instead * of the browser's inspect-element shortcut (App.tsx installs it, capture phase). * @author Nguyễn Ngọc Trí Vĩ */ import type { KeyboardEvent as ReactKeyboardEvent } from "react"; /** True for a plain Enter that should submit — not Shift+Enter, not mid-IME. */ export function isSubmitEnter(e: ReactKeyboardEvent | KeyboardEvent): boolean { const native = "nativeEvent" in e ? e.nativeEvent : e; return e.key === "Enter" && !e.shiftKey && !native.isComposing && native.keyCode !== 229; } /** * Ctrl+Shift+C copies the selection — a field's, the page's or a terminal's * (xterm answers the `copy` event) — instead of opening DevTools. F12 and * Ctrl+Shift+I still open them. With nothing selected it does nothing. */ export function copyOnCtrlShiftC(e: KeyboardEvent): void { if (e.code !== "KeyC" || !e.ctrlKey || !e.shiftKey || e.altKey || e.metaKey) return; e.preventDefault(); document.execCommand("copy"); }