The best way to control Claude Code, Codex and more from any computer or phone

main
ts 39 lines 1.34 KB
Raw
1 import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2 import { THREAD_JUMP_KEYBINDING_COMMANDS } from "@t3tools/contracts";
3
4 import type { ThreadListV2ListItem } from "../threads/threadListV2";
5 import {
6 useHardwareKeyboardCommand,
7 type HardwareKeyboardCommand,
8 } from "./hardwareKeyboardCommands";
9
10 type ThreadShortcutListItem = ThreadListV2ListItem | { readonly type: "v2-show-more" };
11
12 export function threadJumpIndex(command: HardwareKeyboardCommand) {
13 return THREAD_JUMP_KEYBINDING_COMMANDS.findIndex((candidate) => candidate === command);
14 }
15
16 export function threadJumpTarget(
17 items: ReadonlyArray<ThreadShortcutListItem>,
18 command: HardwareKeyboardCommand,
19 ) {
20 let index = threadJumpIndex(command);
21 if (index < 0) return null;
22 for (const item of items) {
23 const thread = item.type === "v2-thread" ? item.item.thread : null;
24 if (thread !== null && index-- === 0) return thread;
25 }
26 return null;
27 }
28
29 export function useThreadJumpShortcuts(
30 items: ReadonlyArray<ThreadShortcutListItem>,
31 onSelectThread: (thread: EnvironmentThreadShell) => void,
32 ) {
33 const jumpToThread = (command: HardwareKeyboardCommand) => {
34 const thread = threadJumpTarget(items, command);
35 if (thread !== null) onSelectThread(thread);
36 return true;
37 };
38 useHardwareKeyboardCommand(THREAD_JUMP_KEYBINDING_COMMANDS, jumpToThread);
39 }