From 404a328a58e6d266aaeca70db46f6895478cefd4 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Sat, 7 Nov 2026 02:49:17 -0500 Subject: [PATCH] fix: PDF and Office preview zoom drifts, stalls, and loses track of its label (#33836) Fixes several zoom problems in the Files pane preview (pdf, docx, and pptx, which the backend converts to PDF): - Switching tabs and back reset the page to 100% while the label kept the old percentage. Hidden tabs measure 0 px wide, so PdfPagesPreview collapsed its thumbnails; their return resized the viewer, which re-rendered every page. PdfPagesPreview now keeps its layout while hidden, so the chosen zoom stays. - Changing slides in a pptx reset the zoom to 100% while the label kept the old value. A slide change now carries the zoom and position over to the new slide. - A pane resize rebuilt the zoom at 100% but left the label at the old value. renderAllPages now resets the label with it. - On pptx slides, zooming drifted off-center and stopped at about 244%. The element panzoom transforms was flex-centered inside its container, while panzoom measures bounds and zoom anchors from the container's top-left corner. That element now fills the container and centers the slide inside it, so the coordinates match the screen. - Resetting from a low zoom left the page off to the side, and from a stalled high zoom it could leave the page enlarged under a 100% label. The reset moved and zoomed through panzoom's bounds check, which skips the scale change when it adjusts the position. The reset now rebuilds the panzoom instance, as every render already does. --- src/lib/components/common/PDFViewer.svelte | 20 +++++++++++++------ .../components/common/PdfPagesPreview.svelte | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/lib/components/common/PDFViewer.svelte b/src/lib/components/common/PDFViewer.svelte index 33955255aa..722cb2ec8d 100644 --- a/src/lib/components/common/PDFViewer.svelte +++ b/src/lib/components/common/PDFViewer.svelte @@ -319,8 +319,7 @@ export const resetView = () => { if (pzInstance) { - pzInstance.moveTo(0, 0); - pzInstance.zoomAbs(0, 0, 1); + initPanzoom(); zoomLevel = 1; rerenderPages(1); } @@ -529,11 +528,19 @@ wrappers.push(wrapper); } + const { x, y, scale } = pzInstance?.getTransform() ?? { x: 0, y: 0, scale: 1 }; + const keepView = + singlePage && renderedPage && renderedPage !== selectedPage && Math.abs(scale - 1) >= 0.01; sceneElement.replaceChildren(...wrappers); void renderCommentMarkers(); lastRenderedZoom = 1; + zoomLevel = 1; renderedPage = singlePage ? selectedPage : 0; initPanzoom(); + if (keepView) { + pzInstance?.zoomAbs(0, 0, scale); + pzInstance?.moveTo(x, y); + } await scrollToTargetPage(); syncVisiblePage(); }; @@ -714,9 +721,7 @@ {/if}