// The shortcuts of the Terminal feature. This file is in the main bundle, because the workbench routes the keys // and Help lists them while the feature code is not loaded yet. import { message } from "../i18n/index.ts"; /** The actions of a terminal shortcut. "toggle" shows or hides the terminal panel. */ export type TerminalAction = "toggle" | "new" | "window" | "split" | "previous" | "next" | "commands" | "directories"; export type TerminalKeyEvent = Pick; /** The terminal action of a key event, or null. Backquote and Digit5 match the physical key on each keyboard layout. */ export function terminalShortcut(event: TerminalKeyEvent): TerminalAction | null { if (!event.ctrlKey && !event.metaKey) return null; if (event.code === "Backquote" || event.key === "`") return event.shiftKey ? event.altKey ? "window" : "new" : "toggle"; if (event.shiftKey && event.code === "Digit5" && !event.altKey) return "split"; if (!event.shiftKey && !event.altKey && event.key.toLowerCase() === "j") return "toggle"; if (!event.shiftKey && !event.altKey && event.key === "ArrowUp") return "previous"; if (!event.shiftKey && !event.altKey && event.key === "ArrowDown") return "next"; if (!event.shiftKey && event.altKey && event.key.toLowerCase() === "r") return "commands"; if (!event.shiftKey && !event.altKey && event.key.toLowerCase() === "g") return "directories"; return null; } /** The written combination of each action, for menus and Help. `keys()` in `src/lib/ui/shortcuts.ts` gives the label. */ export const TERMINAL_KEYS = { toggle: "Mod+J", new: "Mod+Shift+`", window: "Mod+Shift+Alt+`", split: "Mod+Shift+5", previous: "Mod+ArrowUp", next: "Mod+ArrowDown", commands: "Mod+Alt+R", directories: "Mod+G", } as const satisfies Record; /** The Terminal rows of Help. They show only while Terminal is on. */ export const TERMINAL_SHORTCUTS: readonly { label: string; keys: string }[] = [ { label: message("Show or hide the terminal"), keys: TERMINAL_KEYS.toggle }, { label: message("New terminal"), keys: TERMINAL_KEYS.new }, { label: message("New terminal window"), keys: TERMINAL_KEYS.window }, { label: message("Split terminal"), keys: TERMINAL_KEYS.split }, { label: message("Scroll to the previous command"), keys: TERMINAL_KEYS.previous }, { label: message("Scroll to the next command"), keys: TERMINAL_KEYS.next }, { label: message("Run a recent command"), keys: TERMINAL_KEYS.commands }, { label: message("Go to a recent folder"), keys: TERMINAL_KEYS.directories }, { label: message("Copy the selected output"), keys: "Mod+Shift+C" }, ];