diff --git a/apps/client/src/types-lib.d.ts b/apps/client/src/types-lib.d.ts index aa125f389d..4f942b8cb6 100644 --- a/apps/client/src/types-lib.d.ts +++ b/apps/client/src/types-lib.d.ts @@ -63,11 +63,13 @@ declare global { declare module "preact" { namespace JSX { + interface ElectronWebViewElement extends JSX.HTMLAttributes { + src: string; + class: string; + } + interface IntrinsicElements { - webview: { - src: string; - class: string; - } + webview: ElectronWebViewElement; } } } diff --git a/apps/client/src/widgets/type_widgets/WebView.tsx b/apps/client/src/widgets/type_widgets/WebView.tsx index b624a62800..bbf170933d 100644 --- a/apps/client/src/widgets/type_widgets/WebView.tsx +++ b/apps/client/src/widgets/type_widgets/WebView.tsx @@ -31,12 +31,34 @@ export default function WebView({ note, ntxId }: TypeWidgetProps) { } return isElectron - ? + ? : ; } -function DesktopWebView({ src }: { src: string }) { - return ; +function DesktopWebView({ src, ntxId }: { src: string, ntxId: string | null | undefined }) { + const webviewRef = useRef(null); + + useEffect(() => { + const webview = webviewRef.current; + if (!webview) return; + + function onBlur() { + if (document.activeElement === webview && ntxId) { + appContext.tabManager.activateNoteContext(ntxId); + } + } + + webview.addEventListener("focus", onBlur); + return () => { + webview.removeEventListener("focus", onBlur); + }; + }, [ ntxId ]); + + return ; } function BrowserWebView({ src, ntxId }: { src: string, ntxId: string | null | undefined }) {