From 48696a8d06539b6ddc742e94af75e5525ce43674 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 30 Nov 2016 17:19:11 +0100 Subject: [PATCH] Make the keyboard shortcuts `Ctrl + Up/Down` behave as `Home/End` (issue 7852) It seems that for normal web pages, at least in Firefox, the keyboard shortcuts Ctrl + Up/Down are functionally equivalent to Home/End. This is obviously an edge-case, but can be easily implemented by using the same logic as we do for Home/End. Fixes 7852. *Please note:* I'm finding it slightly difficult to interpret issue 7852, and bug 1285719, since among other things: the title includes the word "reverse" with no other mention of it, and the STR makes reference to print preview which doesn't seem applicable to the PDF viewer. However, compared to regular web pages in Firefox, I think the behavior of this patch makes sense here. --- web/app.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/web/app.js b/web/app.js index 7a192bbe3..156367f5f 100644 --- a/web/app.js +++ b/web/app.js @@ -1956,7 +1956,7 @@ window.addEventListener('keydown', function keydown(evt) { return; } - var handled = false; + var handled = false, ensureViewerFocused = false; var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | @@ -2019,6 +2019,22 @@ window.addEventListener('keydown', function keydown(evt) { handled = false; } break; + + case 38: // up arrow + if (isViewerInPresentationMode || PDFViewerApplication.page > 1) { + PDFViewerApplication.page = 1; + handled = true; + ensureViewerFocused = true; + } + break; + case 40: // down arrow + if (isViewerInPresentationMode || + PDFViewerApplication.page < PDFViewerApplication.pagesCount) { + PDFViewerApplication.page = PDFViewerApplication.pagesCount; + handled = true; + ensureViewerFocused = true; + } + break; } } @@ -2051,6 +2067,9 @@ window.addEventListener('keydown', function keydown(evt) { } if (handled) { + if (ensureViewerFocused && !isViewerInPresentationMode) { + pdfViewer.focus(); + } evt.preventDefault(); return; } @@ -2067,7 +2086,6 @@ window.addEventListener('keydown', function keydown(evt) { return; } } - var ensureViewerFocused = false; if (cmd === 0) { // no control key pressed at all. switch (evt.keyCode) {