From d6e8b8fbc161fd166ffd642d1b74bdaa0e7f9740 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 2 Nov 2021 11:48:18 +0100 Subject: [PATCH 1/2] Use `BaseViewer.previousPage` more in the default viewer (PR 12870 follow-up) I missed this one spot in PR 12870, when converting the other cases in the "keydown" event handler. However, given that it only matters in PresentationMode and/or when "page-fit" zooming is enabled, this oversight shouldn't have had any user-observable impact (but we should fix it nonetheless). --- web/app.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index c3743396e..bd95b1282 100644 --- a/web/app.js +++ b/web/app.js @@ -3057,9 +3057,8 @@ function webViewerKeyDown(evt) { ) { break; } - if (PDFViewerApplication.page > 1) { - PDFViewerApplication.page--; - } + pdfViewer.previousPage(); + handled = true; break; From 292a715c1c8e44d00edc082b6ad1c098fa510f55 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 2 Nov 2021 12:00:57 +0100 Subject: [PATCH 2/2] Use optional chaining to simplify `PDFViewerApplication.store` accesses in various event handlers This way we no longer need the intermediate variables. --- web/app.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/web/app.js b/web/app.js index bd95b1282..28a9d5969 100644 --- a/web/app.js +++ b/web/app.js @@ -2413,28 +2413,29 @@ function webViewerSidebarViewChanged(evt) { PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible; - const store = PDFViewerApplication.store; - if (store && PDFViewerApplication.isInitialViewSet) { + if (PDFViewerApplication.isInitialViewSet) { // Only update the storage when the document has been loaded *and* rendered. - store.set("sidebarView", evt.view).catch(function () {}); + PDFViewerApplication.store?.set("sidebarView", evt.view).catch(() => { + // Unable to write to storage. + }); } } function webViewerUpdateViewarea(evt) { - const location = evt.location, - store = PDFViewerApplication.store; + const location = evt.location; - if (store && PDFViewerApplication.isInitialViewSet) { - store - .setMultiple({ + if (PDFViewerApplication.isInitialViewSet) { + // Only update the storage when the document has been loaded *and* rendered. + PDFViewerApplication.store + ?.setMultiple({ page: location.pageNumber, zoom: location.scale, scrollLeft: location.left, scrollTop: location.top, rotation: location.rotation, }) - .catch(function () { - /* unable to write to storage */ + .catch(() => { + // Unable to write to storage. }); } const href = PDFViewerApplication.pdfLinkService.getAnchorUrl( @@ -2453,18 +2454,20 @@ function webViewerUpdateViewarea(evt) { } function webViewerScrollModeChanged(evt) { - const store = PDFViewerApplication.store; - if (store && PDFViewerApplication.isInitialViewSet) { + if (PDFViewerApplication.isInitialViewSet) { // Only update the storage when the document has been loaded *and* rendered. - store.set("scrollMode", evt.mode).catch(function () {}); + PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => { + // Unable to write to storage. + }); } } function webViewerSpreadModeChanged(evt) { - const store = PDFViewerApplication.store; - if (store && PDFViewerApplication.isInitialViewSet) { + if (PDFViewerApplication.isInitialViewSet) { // Only update the storage when the document has been loaded *and* rendered. - store.set("spreadMode", evt.mode).catch(function () {}); + PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => { + // Unable to write to storage. + }); } }