Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(webview): doesn't activate note context on click in desktop
Elian Doranec4fd371b531
diff --git a/apps/client/src/types-lib.d.ts b/apps/client/src/types-lib.d.tsindex 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<HTMLElement> {+ 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.tsxindex 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- ? <DesktopWebView src={webViewSrc} />+ ? <DesktopWebView src={webViewSrc} ntxId={ntxId} />: <BrowserWebView src={webViewSrc} ntxId={ntxId} />;}-function DesktopWebView({ src }: { src: string }) {- return <webview src={src} class="note-detail-web-view-content" />;+function DesktopWebView({ src, ntxId }: { src: string, ntxId: string | null | undefined }) {+ const webviewRef = useRef<HTMLWebViewElement>(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 <webview+ ref={webviewRef}+ src={src}+ class="note-detail-web-view-content"+ />;}function BrowserWebView({ src, ntxId }: { src: string, ntxId: string | null | undefined }) {