From ec4fd371b531964ba90c9849cc1ca915f66660b4 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 17 Feb 2026 23:01:35 +0200 Subject: [PATCH] fix(webview): doesn't activate note context on click in desktop --- apps/client/src/types-lib.d.ts | 10 ++++--- .../src/widgets/type_widgets/WebView.tsx | 28 +++++++++++++++++-- 2 files changed, 31 insertions(+), 7 deletions(-) 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 }) {