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

terminalFocus.ts

14 lines561 Bytes

1export type TerminalFocusOwner = "drawer" | "right-panel";
2​
3export function getTerminalFocusOwner(): TerminalFocusOwner | null {
4 const activeElement = document.activeElement;
5 if (!(activeElement instanceof HTMLElement)) return null;
6 if (!activeElement.isConnected) return null;
7 const owner = activeElement.closest<HTMLElement>("[data-terminal-owner]")?.dataset.terminalOwner;
8 if (owner === "drawer" || owner === "right-panel") return owner;
9 return null;
11​
12export function isTerminalFocused(): boolean {
13 return getTerminalFocusOwner() !== null;