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

previewFocus.ts

16 lines838 Bytes

1export function isPreviewFocused(): boolean {
2 const activeElement = document.activeElement;
3 if (!(activeElement instanceof HTMLElement)) return false;
4 if (!activeElement.isConnected) return false;
5 if (activeElement.tagName.toLowerCase() === "webview") return true;
6 return activeElement.closest("[data-preview-panel-mode]") !== null;
7}
8​
9/** Narrower than isPreviewFocused, whose panel also hosts PR, diff, files and other surfaces. */
10export function isBrowserSurfaceFocused(): boolean {
11 const activeElement = document.activeElement;
12 if (!(activeElement instanceof HTMLElement) || !activeElement.isConnected) return false;
13 if (activeElement.tagName.toLowerCase() === "webview") return true;
14 const panel = activeElement.closest("[data-preview-panel-mode]");
15 return panel?.querySelector("[data-preview-view]") != null;