diff --git a/src/renderer/src/components/editor/pdf-scale-preference.test.ts b/src/renderer/src/components/editor/pdf-scale-preference.test.ts index a88764b5fa2..75ff14ba4c1 100644 --- a/src/renderer/src/components/editor/pdf-scale-preference.test.ts +++ b/src/renderer/src/components/editor/pdf-scale-preference.test.ts @@ -22,11 +22,11 @@ const bounds = { min: 0.25, max: 5 } describe('zoomPdfViewerWithWheel', () => { it('stops on the fit-width scale when a step would pass it, then leaves it', () => { - const viewer = fakeViewer(1) + const below = fakeViewer(1) + expect(zoomPdfViewerWithWheel(below, zoomInEvent, bounds, () => 1.5)).toBe('page-width') + expect(below.currentScaleValue).toBe('page-width') - expect(zoomPdfViewerWithWheel(viewer, zoomInEvent, bounds, () => 1.5)).toBe('page-width') - expect(viewer.currentScale).toBe(1.5) - - expect(zoomPdfViewerWithWheel(viewer, zoomInEvent, bounds, () => 1.5)).toBeGreaterThan(1.5) + const atFit = fakeViewer(1.5) + expect(zoomPdfViewerWithWheel(atFit, zoomInEvent, bounds, () => 1.5)).toBeGreaterThan(1.5) }) }) diff --git a/src/renderer/src/components/editor/pdf-scale-preference.ts b/src/renderer/src/components/editor/pdf-scale-preference.ts index bb38bbe3137..546b55b6e2f 100644 --- a/src/renderer/src/components/editor/pdf-scale-preference.ts +++ b/src/renderer/src/components/editor/pdf-scale-preference.ts @@ -87,12 +87,13 @@ export function zoomPdfViewerWithWheel( } const { container } = viewer const rect = container.getBoundingClientRect() - // Why: an absolute scale avoids updateScale's 0.01 rounding, which swallows slow pinches. - viewer.currentScale = next const fitted = next === fitScale if (fitted) { - // Why: same scale, so pdf.js only records the preset resizes refit to; update() below may change the page it fits. + // Why: the preset is what resizes refit to; a numeric set first could move pdf.js to a page of another width. viewer.currentScaleValue = 'page-width' + } else { + // Why: an absolute scale avoids updateScale's 0.01 rounding, which swallows slow pinches. + viewer.currentScale = next } // Why: pdf.js keeps the viewport's top-left fixed, so shift by the pointer's grown offset. const growth = next / previous - 1