fix(webview): doesn't activate note context on click in desktop

This commit is contained in:
Elian Doran 2026-02-17 23:01:35 +02:00
parent 555b138a90
commit ec4fd371b5
No known key found for this signature in database
2 changed files with 31 additions and 7 deletions

View File

@ -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;
}
}
}

View File

@ -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 }) {