| 1 | /** |
| 2 | * Returns true when the user's keyboard focus is somewhere inside the |
| 3 | * preview panel (URL bar, chrome buttons, or — once detected via Electron |
| 4 | * `<webview>` focus events — the embedded page). |
| 5 | * |
| 6 | * Used by the global keybinding handler to gate `preview.refresh` and |
| 7 | * `preview.focusUrl` to only fire while the preview owns focus. |
| 8 | */ |
| 9 | export function isPreviewFocused(): boolean { |
| 10 | const activeElement = document.activeElement; |
| 11 | if (!(activeElement instanceof HTMLElement)) return false; |
| 12 | if (!activeElement.isConnected) return false; |
| 13 | if (activeElement.tagName.toLowerCase() === "webview") return true; |
| 14 | return activeElement.closest("[data-preview-panel-mode]") !== null; |
| 15 | } |