From 01f05ac6fd1f23d79a6aced588198e706d31e8c7 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 30 Dec 2025 09:47:02 +0200 Subject: [PATCH] fix(pdf): active context not changed when clicking preview --- apps/client/src/widgets/type_widgets/File.tsx | 4 ++-- .../src/widgets/type_widgets/file/Pdf.tsx | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/File.tsx b/apps/client/src/widgets/type_widgets/File.tsx index b720d6a0d..a26bb0987 100644 --- a/apps/client/src/widgets/type_widgets/File.tsx +++ b/apps/client/src/widgets/type_widgets/File.tsx @@ -10,13 +10,13 @@ import { TypeWidgetProps } from "./type_widget"; const TEXT_MAX_NUM_CHARS = 5000; -export default function FileTypeWidget({ note, parentComponent }: TypeWidgetProps) { +export default function FileTypeWidget({ note, parentComponent, noteContext }: TypeWidgetProps) { const blob = useNoteBlob(note, parentComponent?.componentId); if (blob?.content) { return ; } else if (note.mime === "application/pdf") { - return ; + return ; } else if (note.mime.startsWith("video/")) { return ; } else if (note.mime.startsWith("audio/")) { diff --git a/apps/client/src/widgets/type_widgets/file/Pdf.tsx b/apps/client/src/widgets/type_widgets/file/Pdf.tsx index f254e13c4..1c4e24573 100644 --- a/apps/client/src/widgets/type_widgets/file/Pdf.tsx +++ b/apps/client/src/widgets/type_widgets/file/Pdf.tsx @@ -1,6 +1,7 @@ import { RefObject } from "preact"; import { useCallback, useEffect, useRef } from "preact/hooks"; +import appContext from "../../../components/app_context"; import FBlob from "../../../entities/fblob"; import FNote from "../../../entities/fnote"; import server from "../../../services/server"; @@ -14,10 +15,11 @@ const VARIABLE_WHITELIST = new Set([ "main-text-color" ]); -export default function PdfPreview({ note, blob, componentId }: { +export default function PdfPreview({ note, blob, componentId, ntxId }: { note: FNote, blob: FBlob | null | undefined, componentId: string | undefined; + ntxId: string | null | undefined; }) { const iframeRef = useRef(null); const { onLoad } = useStyleInjection(iframeRef); @@ -49,8 +51,28 @@ export default function PdfPreview({ note, blob, componentId }: { } }, [ blob ]); + // Trigger focus when iframe content is clicked (iframe focus doesn't bubble) + useEffect(() => { + const iframe = iframeRef.current; + if (!iframe) return; + + const handleIframeClick = () => { + if (ntxId) { + appContext.tabManager.activateNoteContext(ntxId); + } + }; + + // Listen for clicks on the iframe's content window + const iframeDoc = iframe.contentWindow?.document; + if (iframeDoc) { + iframeDoc.addEventListener('click', handleIframeClick); + return () => iframeDoc.removeEventListener('click', handleIframeClick); + } + }, [ iframeRef.current?.contentWindow, ntxId ]); + return (historyConfig &&