mirror of
https://github.com/zadam/trilium.git
synced 2026-02-23 06:04:25 +01:00
fix(webview): doesn't activate note context on click in desktop
This commit is contained in:
parent
555b138a90
commit
ec4fd371b5
10
apps/client/src/types-lib.d.ts
vendored
10
apps/client/src/types-lib.d.ts
vendored
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 }) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user