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

revealThreadTerminal.ts

21 lines894 Bytes

1import type { ScopedThreadRef } from "@t3tools/contracts";
2​
3import { selectThreadRightPanelState, useRightPanelStore } from "../rightPanelStore";
4import { useTerminalUiStateStore } from "../terminalUiStateStore";
5​
6/** Reveal an existing terminal in the panel that owns it, without opening another PTY. */
7export function revealThreadTerminal(threadRef: ScopedThreadRef, terminalId: string) {
8 const panels = useRightPanelStore.getState();
9 const surface = selectThreadRightPanelState(panels.byThreadKey, threadRef).surfaces.find(
10 (surface) => surface.kind === "terminal" && surface.terminalIds.includes(terminalId),
11 );
12 if (surface) {
13 panels.activateTerminal(threadRef, surface.id, terminalId);
14 panels.activateSurface(threadRef, surface.id);
15 return;
16 }
17 useTerminalUiStateStore.getState().ensureTerminal(threadRef, terminalId, {
18 open: true,
19 active: true,
20 });