Modify key events for horizontal scrolling

Specifically, when there is no vertical scrollbar, let up, down, page
up, and page down all trigger moving to the next or previous page.
This commit is contained in:
Ryan Hendrickson 2018-05-14 23:10:32 -04:00
parent 3d83c646c6
commit eaf14e5d47
2 changed files with 47 additions and 22 deletions

View File

@ -2229,28 +2229,31 @@ function webViewerKeyDown(evt) {
} }
if (cmd === 0) { // no control key pressed at all. if (cmd === 0) { // no control key pressed at all.
let turnPage = 0, turnOnlyIfPageFit = false;
switch (evt.keyCode) { switch (evt.keyCode) {
case 38: // up arrow case 38: // up arrow
case 33: // pg up case 33: // pg up
case 8: // backspace // vertical scrolling using arrow/pg keys
if (!isViewerInPresentationMode && if (pdfViewer.isVerticalScrollbarEnabled) {
pdfViewer.currentScaleValue !== 'page-fit') { turnOnlyIfPageFit = true;
break;
} }
/* in presentation mode */ turnPage = -1;
/* falls through */ break;
case 8: // backspace
if (!isViewerInPresentationMode) {
turnOnlyIfPageFit = true;
}
turnPage = -1;
break;
case 37: // left arrow case 37: // left arrow
// horizontal scrolling using arrow keys // horizontal scrolling using arrow keys
if (pdfViewer.isHorizontalScrollbarEnabled) { if (pdfViewer.isHorizontalScrollbarEnabled) {
break; turnOnlyIfPageFit = true;
} }
/* falls through */ /* falls through */
case 75: // 'k' case 75: // 'k'
case 80: // 'p' case 80: // 'p'
if (PDFViewerApplication.page > 1) { turnPage = -1;
PDFViewerApplication.page--;
}
handled = true;
break; break;
case 27: // esc key case 27: // esc key
if (PDFViewerApplication.secondaryToolbar.isOpen) { if (PDFViewerApplication.secondaryToolbar.isOpen) {
@ -2263,27 +2266,30 @@ function webViewerKeyDown(evt) {
handled = true; handled = true;
} }
break; break;
case 13: // enter key
case 40: // down arrow case 40: // down arrow
case 34: // pg down case 34: // pg down
case 32: // spacebar // vertical scrolling using arrow/pg keys
if (!isViewerInPresentationMode && if (pdfViewer.isVerticalScrollbarEnabled) {
pdfViewer.currentScaleValue !== 'page-fit') { turnOnlyIfPageFit = true;
break;
} }
/* falls through */ turnPage = 1;
break;
case 13: // enter key
case 32: // spacebar
if (!isViewerInPresentationMode) {
turnOnlyIfPageFit = true;
}
turnPage = 1;
break;
case 39: // right arrow case 39: // right arrow
// horizontal scrolling using arrow keys // horizontal scrolling using arrow keys
if (pdfViewer.isHorizontalScrollbarEnabled) { if (pdfViewer.isHorizontalScrollbarEnabled) {
break; turnOnlyIfPageFit = true;
} }
/* falls through */ /* falls through */
case 74: // 'j' case 74: // 'j'
case 78: // 'n' case 78: // 'n'
if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) { turnPage = 1;
PDFViewerApplication.page++;
}
handled = true;
break; break;
case 36: // home case 36: // home
@ -2313,6 +2319,20 @@ function webViewerKeyDown(evt) {
PDFViewerApplication.rotatePages(90); PDFViewerApplication.rotatePages(90);
break; break;
} }
if (turnPage !== 0 &&
(!turnOnlyIfPageFit || pdfViewer.currentScaleValue === 'page-fit')) {
if (turnPage > 0) {
if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
PDFViewerApplication.page++;
}
} else {
if (PDFViewerApplication.page > 1) {
PDFViewerApplication.page--;
}
}
handled = true;
}
} }
if (cmd === 4) { // shift-key if (cmd === 4) { // shift-key

View File

@ -845,6 +845,11 @@ class BaseViewer {
false : (this.container.scrollWidth > this.container.clientWidth)); false : (this.container.scrollWidth > this.container.clientWidth));
} }
get isVerticalScrollbarEnabled() {
return (this.isInPresentationMode ?
false : (this.container.scrollHeight > this.container.clientHeight));
}
_getVisiblePages() { _getVisiblePages() {
throw new Error('Not implemented: _getVisiblePages'); throw new Error('Not implemented: _getVisiblePages');
} }