A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: prevent scale vs page loop in pngx PDF viewer (#13406)
shamoon668fa77428b3
diff --git a/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.spec.ts b/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.spec.tsindex 0e16ac2b2..ffb1fe8b5 100644--- a/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.spec.ts+++ b/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.spec.ts@@ -129,13 +129,25 @@ describe('PngxPdfViewerComponent', () => {;(component as any).applyScale()expect(viewer.currentScaleValue).toBe(PdfZoomScale.PageFit)expect(viewer.currentScale).toBe(2)+ })++ it('does not reapply scale for page-only changes', async () => {+ await initComponent()+ const pdf = (component as any).pdf as { numPages: number }+ pdf.numPages = 3+ const viewer = (component as any).pdfViewer as PDFViewer+ viewer.setDocument(pdf)const applyScaleSpy = jest.spyOn(component as any, 'applyScale')component.page = 2- ;(component as any).lastViewerPage = 2- ;(component as any).applyViewerState()++ component.ngOnChanges({+ page: new SimpleChange(1, 2, false),+ })++ expect(viewer.currentPageNumber).toBe(2)expect((component as any).lastViewerPage).toBeUndefined()- expect(applyScaleSpy).toHaveBeenCalled()+ expect(applyScaleSpy).not.toHaveBeenCalled()})it('does not reset the viewer when it is already on the requested page', async () => {diff --git a/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.ts b/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.tsindex 4a0478316..153c67d91 100644--- a/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.ts+++ b/src-ui/src/app/components/common/pdf-viewer/pdf-viewer.component.ts@@ -116,7 +116,10 @@ export class PngxPdfViewerComponentchanges['zoomScale'] ||changes['rotation']) {- this.applyViewerState()+ // Prevent loop with page / scale application see https://github.com/paperless-ngx/paperless-ngx/issues/13404+ this.applyViewerState(+ !!(changes['zoom'] || changes['zoomScale'] || changes['rotation'])+ )}if (changes['searchQuery']) {@@ -240,7 +243,7 @@ export class PngxPdfViewerComponent}}- private applyViewerState(): void {+ private applyViewerState(applyScale = true): void {if (!this.pdfViewer) {return}@@ -264,7 +267,7 @@ export class PngxPdfViewerComponentif (this.page === this.lastViewerPage) {this.lastViewerPage = undefined}- if (hasPages) {+ if (hasPages && applyScale) {this.applyScale()}this.dispatchFindIfReady()