Open History to see the last commit
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 // A side chat shares the preview's right panel but is a chat, not the preview.
7 return (
8 activeElement.closest("[data-preview-panel-mode]") !== null &&
9 activeElement.closest("[data-side-chat-pane]") === null
10 );
11}
12
13/** Narrower than isPreviewFocused, whose panel also hosts PR, diff, files and other surfaces. */
14export function isBrowserSurfaceFocused(): boolean {
15 const activeElement = document.activeElement;
16 if (!(activeElement instanceof HTMLElement) || !activeElement.isConnected) return false;
17 if (activeElement.tagName.toLowerCase() === "webview") return true;
18 const panel = activeElement.closest("[data-preview-panel-mode]");
19 return panel?.querySelector("[data-preview-view]") != null;
20}