diff --git a/frontend/src/lib/components/PdfViewer.svelte b/frontend/src/lib/components/PdfViewer.svelte index f47dd422..a061b939 100644 --- a/frontend/src/lib/components/PdfViewer.svelte +++ b/frontend/src/lib/components/PdfViewer.svelte @@ -217,6 +217,26 @@ $effect(() => { if (transcribeMode) showAnnotations = true; }); +// Scroll-sync: when activeAnnotationId changes, navigate to its page +$effect(() => { + if (!activeAnnotationId || !pdfDoc) return; + const ann = annotations.find((a) => a.id === activeAnnotationId); + if (!ann) return; + + if (ann.pageNumber !== currentPage) { + currentPage = ann.pageNumber; + } + + // After page renders, scroll the annotation into view (double-rAF for async render) + const targetId = activeAnnotationId; + requestAnimationFrame(() => { + requestAnimationFrame(() => { + const el = document.querySelector(`[data-testid="annotation-${targetId}"]`); + el?.scrollIntoView({ behavior: 'smooth', block: 'center' }); + }); + }); +}); + function prevPage() { if (currentPage > 1) currentPage -= 1; } diff --git a/frontend/src/routes/documents/[id]/+page.svelte b/frontend/src/routes/documents/[id]/+page.svelte index 7864ce00..f3d00e33 100644 --- a/frontend/src/routes/documents/[id]/+page.svelte +++ b/frontend/src/routes/documents/[id]/+page.svelte @@ -197,8 +197,10 @@ onMount(() => { bind:transcribeMode={transcribeMode} /> -