Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composerShortcuts.ts

41 lines1.8 KB

1import type { ComposerHandleRef } from "../../composerHandleContext";
2import type { BranchToolbarHandle } from "../BranchToolbar";
3import { closeOpenPopups } from "../ui/open-popups";
4import type { ChatComposerHandle } from "./ChatComposer";
5import type { ChatShortcutCommands } from "./useChatShortcuts";
6​
7const openControl =
8 (composerRef: ComposerHandleRef, control: Parameters<ChatComposerHandle["openControl"]>[0]) =>
9 ({ event }: { readonly event: KeyboardEvent }) => {
10 if (!event.repeat) composerRef.current?.openControl(control);
11 };
12​
13/** Chords that open or step the composer's controls and its branch toolbar. Held keys do not repeat them. */
14export function composerShortcutCommands(
15 composerRef: ComposerHandleRef,
16 branchToolbarRef: { readonly current: BranchToolbarHandle | null },
17): ChatShortcutCommands {
18 return {
19 "modelPicker.toggle": ({ event }) => {
20 if (event.repeat || !composerRef.current) return;
21 if (!composerRef.current.isModelPickerOpen()) closeOpenPopups();
22 composerRef.current.toggleModelPicker();
23 },
24 "composer.increaseEffort": ({ event }) => {
25 if (!event.repeat) composerRef.current?.stepReasoningEffort(1);
26 },
27 "composer.decreaseEffort": ({ event }) => {
28 if (!event.repeat) composerRef.current?.stepReasoningEffort(-1);
29 },
30 "composer.host": openControl(composerRef, "composer.host"),
31 "composer.effort": openControl(composerRef, "composer.effort"),
32 "composer.mode": openControl(composerRef, "composer.mode"),
33 "composer.workspace": openControl(composerRef, "composer.workspace"),
34 "composer.branch": ({ event }) => {
35 if (!event.repeat) branchToolbarRef.current?.openBranchPicker();
36 },
37 "composer.previousWorktree": ({ event }) => {
38 if (!event.repeat) branchToolbarRef.current?.usePreviousWorktree();
39 },
40 } satisfies ChatShortcutCommands;