| 1 | import type { ResolvedKeybindingsConfig } from "@t3tools/contracts"; |
| 2 | |
| 3 | import { isTerminalCloseShortcut, type ShortcutEventLike } from "../keybindings"; |
| 4 | |
| 5 | export interface TerminalCloseShortcutEvent extends ShortcutEventLike { |
| 6 | readonly repeat?: boolean; |
| 7 | readonly preventDefault: () => void; |
| 8 | } |
| 9 | |
| 10 | function terminalCloseShortcutOptions(platform?: string) { |
| 11 | return { |
| 12 | ...(platform === undefined ? {} : { platform }), |
| 13 | context: { terminalFocus: true, terminalOpen: true }, |
| 14 | }; |
| 15 | } |
| 16 | |
| 17 | export function preventTerminalCloseShortcut( |
| 18 | event: TerminalCloseShortcutEvent, |
| 19 | keybindings: ResolvedKeybindingsConfig, |
| 20 | platform?: string, |
| 21 | ): boolean { |
| 22 | if (!isTerminalCloseShortcut(event, keybindings, terminalCloseShortcutOptions(platform))) { |
| 23 | return false; |
| 24 | } |
| 25 | event.preventDefault(); |
| 26 | return true; |
| 27 | } |
| 28 | |
| 29 | export function preventRepeatedTerminalCloseShortcut( |
| 30 | event: TerminalCloseShortcutEvent, |
| 31 | keybindings: ResolvedKeybindingsConfig, |
| 32 | platform?: string, |
| 33 | ): boolean { |
| 34 | if (!event.repeat) return false; |
| 35 | return preventTerminalCloseShortcut(event, keybindings, platform); |
| 36 | } |