From ea1ec7ffab891f3d79cd5aec3e544f51a4c84cb7 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 4 Feb 2023 22:17:53 +0100 Subject: [PATCH 1/4] Remove a couple of unnecessary `pdfDocument` checks in `web/app.js` These functions invoke the `PDFViewer.currentPageNumber` setter, which already checks that a `pdfDocument` is currently active. Also, given that they're event handlers for the First/Last-page buttons (in the SecondaryToolbar) they can't be invoked before the viewer has been fully initalized. --- web/app.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/web/app.js b/web/app.js index 58a3ea613..c4b04559d 100644 --- a/web/app.js +++ b/web/app.js @@ -2487,14 +2487,10 @@ function webViewerDownload() { PDFViewerApplication.downloadOrSave(); } function webViewerFirstPage() { - if (PDFViewerApplication.pdfDocument) { - PDFViewerApplication.page = 1; - } + PDFViewerApplication.page = 1; } function webViewerLastPage() { - if (PDFViewerApplication.pdfDocument) { - PDFViewerApplication.page = PDFViewerApplication.pagesCount; - } + PDFViewerApplication.page = PDFViewerApplication.pagesCount; } function webViewerNextPage() { PDFViewerApplication.pdfViewer.nextPage(); From d930f267f6b268466afb8b18415a26f048eb8a8b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 4 Feb 2023 22:44:46 +0100 Subject: [PATCH 2/4] Remove a couple of unnecessary PresentationMode-checks in `webViewerKeyDown` Given that the `PDFViewerApplication.{zoomIn, zoomOut}` methods already contain PresentationMode-checks, this is just unnecessary duplication. --- web/app.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/web/app.js b/web/app.js index c4b04559d..5af753a99 100644 --- a/web/app.js +++ b/web/app.js @@ -2968,17 +2968,13 @@ function webViewerKeyDown(evt) { case 107: // FF '+' and '=' case 187: // Chrome '+' case 171: // FF with German keyboard - if (!isViewerInPresentationMode) { - PDFViewerApplication.zoomIn(); - } + PDFViewerApplication.zoomIn(); handled = true; break; case 173: // FF/Mac '-' case 109: // FF '-' case 189: // Chrome '-' - if (!isViewerInPresentationMode) { - PDFViewerApplication.zoomOut(); - } + PDFViewerApplication.zoomOut(); handled = true; break; case 48: // '0' From d6178a13d7384290db2b0582a4e3c1c9c592d2db Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 4 Feb 2023 22:56:20 +0100 Subject: [PATCH 3/4] Reduce a tiny bit of duplication in the `webViewerInitialized` function --- web/app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index 5af753a99..a8e1513fe 100644 --- a/web/app.js +++ b/web/app.js @@ -2166,7 +2166,7 @@ function reportPageStatsPDFBug({ pageNumber }) { } function webViewerInitialized() { - const { appConfig, eventBus } = PDFViewerApplication; + const { appConfig, eventBus, l10n } = PDFViewerApplication; let file; if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { const queryString = document.location.search.substring(1); @@ -2217,7 +2217,7 @@ function webViewerInitialized() { if (!PDFViewerApplication.supportsDocumentFonts) { AppOptions.set("disableFontFace", true); - PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => { + l10n.get("web_fonts_disabled").then(msg => { console.warn(msg); }); } @@ -2259,7 +2259,7 @@ function webViewerInitialized() { throw new Error("Not implemented: webViewerInitialized"); } } catch (reason) { - PDFViewerApplication.l10n.get("loading_error").then(msg => { + l10n.get("loading_error").then(msg => { PDFViewerApplication._documentError(msg, reason); }); } From d9181236b27fbbb2f99473b24550f34e7585950e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 4 Feb 2023 23:10:41 +0100 Subject: [PATCH 4/4] [GENERIC viewer] Simplify the keyboard find-again state building By using modern JavaScript features, we can ever so slightly reduce the amount of code needed here. --- web/app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index a8e1513fe..989d6172a 100644 --- a/web/app.js +++ b/web/app.js @@ -2954,12 +2954,12 @@ function webViewerKeyDown(evt) { if (!PDFViewerApplication.supportsIntegratedFind) { const { state } = PDFViewerApplication.findController; if (state) { - const eventState = Object.assign(Object.create(null), state, { + const newState = { source: window, type: "again", findPrevious: cmd === 5 || cmd === 12, - }); - eventBus.dispatch("find", eventState); + }; + eventBus.dispatch("find", { ...state, ...newState }); } handled = true; }