From 13fda7caeb4904f3e3162529073a2896db1dd0cc Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 26 May 2022 11:58:36 +0200 Subject: [PATCH] Remove the `view`-specific getters in the `PDFSidebar` class With the exception of `isThumbnailViewVisible`, these getters are completely unused. Generally speaking, using the `visibleView`-getter directly works just as well and seems (at least to me) to be overall preferable considering how our classes are usually implemented. --- web/app.js | 16 +++++++--------- web/pdf_sidebar.js | 18 +----------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/web/app.js b/web/app.js index 90c492dfd..13f8dfa97 100644 --- a/web/app.js +++ b/web/app.js @@ -1765,7 +1765,7 @@ const PDFViewerApplication = { forceRendering() { this.pdfRenderingQueue.printing = !!this.printService; this.pdfRenderingQueue.isThumbnailViewEnabled = - this.pdfSidebar.isThumbnailViewVisible; + this.pdfSidebar.visibleView === SidebarView.THUMBS; this.pdfRenderingQueue.renderHighestPriority(); }, @@ -2261,7 +2261,7 @@ function webViewerPageRendered({ pageNumber, error }) { } // Use the rendered page to set the corresponding thumbnail image. - if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) { + if (PDFViewerApplication.pdfSidebar.visibleView === SidebarView.THUMBS) { const pageView = PDFViewerApplication.pdfViewer.getPageView( /* index = */ pageNumber - 1 ); @@ -2338,21 +2338,19 @@ function webViewerPresentationModeChanged(evt) { PDFViewerApplication.pdfViewer.presentationModeState = evt.state; } -function webViewerSidebarViewChanged(evt) { +function webViewerSidebarViewChanged({ view }) { PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = - PDFViewerApplication.pdfSidebar.isThumbnailViewVisible; + view === SidebarView.THUMBS; if (PDFViewerApplication.isInitialViewSet) { // Only update the storage when the document has been loaded *and* rendered. - PDFViewerApplication.store?.set("sidebarView", evt.view).catch(() => { + PDFViewerApplication.store?.set("sidebarView", view).catch(() => { // Unable to write to storage. }); } } -function webViewerUpdateViewarea(evt) { - const location = evt.location; - +function webViewerUpdateViewarea({ location }) { if (PDFViewerApplication.isInitialViewSet) { // Only update the storage when the document has been loaded *and* rendered. PDFViewerApplication.store @@ -2587,7 +2585,7 @@ function webViewerPageChanging({ pageNumber, pageLabel }) { PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel); PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber); - if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) { + if (PDFViewerApplication.pdfSidebar.visibleView === SidebarView.THUMBS) { PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber); } } diff --git a/web/pdf_sidebar.js b/web/pdf_sidebar.js index e2c0b201f..534b38e39 100644 --- a/web/pdf_sidebar.js +++ b/web/pdf_sidebar.js @@ -120,22 +120,6 @@ class PDFSidebar { return this.isOpen ? this.active : SidebarView.NONE; } - get isThumbnailViewVisible() { - return this.isOpen && this.active === SidebarView.THUMBS; - } - - get isOutlineViewVisible() { - return this.isOpen && this.active === SidebarView.OUTLINE; - } - - get isAttachmentsViewVisible() { - return this.isOpen && this.active === SidebarView.ATTACHMENTS; - } - - get isLayersViewVisible() { - return this.isOpen && this.active === SidebarView.LAYERS; - } - /** * @param {number} view - The sidebar view that should become visible, * must be one of the values in {SidebarView}. @@ -447,7 +431,7 @@ class PDFSidebar { this.eventBus._on("presentationmodechanged", evt => { if ( evt.state === PresentationModeState.NORMAL && - this.isThumbnailViewVisible + this.visibleView === SidebarView.THUMBS ) { this._updateThumbnailViewer(); }