mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 23:58:07 +02:00
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:
parent
3d83c646c6
commit
eaf14e5d47
2 changed files with 47 additions and 22 deletions
64
web/app.js
64
web/app.js
|
@ -2229,28 +2229,31 @@ function webViewerKeyDown(evt) {
|
|||
}
|
||||
|
||||
if (cmd === 0) { // no control key pressed at all.
|
||||
let turnPage = 0, turnOnlyIfPageFit = false;
|
||||
switch (evt.keyCode) {
|
||||
case 38: // up arrow
|
||||
case 33: // pg up
|
||||
case 8: // backspace
|
||||
if (!isViewerInPresentationMode &&
|
||||
pdfViewer.currentScaleValue !== 'page-fit') {
|
||||
break;
|
||||
// vertical scrolling using arrow/pg keys
|
||||
if (pdfViewer.isVerticalScrollbarEnabled) {
|
||||
turnOnlyIfPageFit = true;
|
||||
}
|
||||
/* in presentation mode */
|
||||
/* falls through */
|
||||
turnPage = -1;
|
||||
break;
|
||||
case 8: // backspace
|
||||
if (!isViewerInPresentationMode) {
|
||||
turnOnlyIfPageFit = true;
|
||||
}
|
||||
turnPage = -1;
|
||||
break;
|
||||
case 37: // left arrow
|
||||
// horizontal scrolling using arrow keys
|
||||
if (pdfViewer.isHorizontalScrollbarEnabled) {
|
||||
break;
|
||||
turnOnlyIfPageFit = true;
|
||||
}
|
||||
/* falls through */
|
||||
case 75: // 'k'
|
||||
case 80: // 'p'
|
||||
if (PDFViewerApplication.page > 1) {
|
||||
PDFViewerApplication.page--;
|
||||
}
|
||||
handled = true;
|
||||
turnPage = -1;
|
||||
break;
|
||||
case 27: // esc key
|
||||
if (PDFViewerApplication.secondaryToolbar.isOpen) {
|
||||
|
@ -2263,27 +2266,30 @@ function webViewerKeyDown(evt) {
|
|||
handled = true;
|
||||
}
|
||||
break;
|
||||
case 13: // enter key
|
||||
case 40: // down arrow
|
||||
case 34: // pg down
|
||||
case 32: // spacebar
|
||||
if (!isViewerInPresentationMode &&
|
||||
pdfViewer.currentScaleValue !== 'page-fit') {
|
||||
break;
|
||||
// vertical scrolling using arrow/pg keys
|
||||
if (pdfViewer.isVerticalScrollbarEnabled) {
|
||||
turnOnlyIfPageFit = true;
|
||||
}
|
||||
/* falls through */
|
||||
turnPage = 1;
|
||||
break;
|
||||
case 13: // enter key
|
||||
case 32: // spacebar
|
||||
if (!isViewerInPresentationMode) {
|
||||
turnOnlyIfPageFit = true;
|
||||
}
|
||||
turnPage = 1;
|
||||
break;
|
||||
case 39: // right arrow
|
||||
// horizontal scrolling using arrow keys
|
||||
if (pdfViewer.isHorizontalScrollbarEnabled) {
|
||||
break;
|
||||
turnOnlyIfPageFit = true;
|
||||
}
|
||||
/* falls through */
|
||||
case 74: // 'j'
|
||||
case 78: // 'n'
|
||||
if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
||||
PDFViewerApplication.page++;
|
||||
}
|
||||
handled = true;
|
||||
turnPage = 1;
|
||||
break;
|
||||
|
||||
case 36: // home
|
||||
|
@ -2313,6 +2319,20 @@ function webViewerKeyDown(evt) {
|
|||
PDFViewerApplication.rotatePages(90);
|
||||
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
|
||||
|
|
|
@ -845,6 +845,11 @@ class BaseViewer {
|
|||
false : (this.container.scrollWidth > this.container.clientWidth));
|
||||
}
|
||||
|
||||
get isVerticalScrollbarEnabled() {
|
||||
return (this.isInPresentationMode ?
|
||||
false : (this.container.scrollHeight > this.container.clientHeight));
|
||||
}
|
||||
|
||||
_getVisiblePages() {
|
||||
throw new Error('Not implemented: _getVisiblePages');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue