Further modernize PDFThumbnailViewer.scrollThumbnailIntoView
The way that we're currently handling the last-`id` is very old, and there's no longer any good reason to special-case things when only one thumbnail is visible. Furthermore, we can also modernize the loop slightly by using `for...of` instead of `Array.prototype.some()` when checking for fully visible thumbnails.
This commit is contained in:
parent
6323f8532a
commit
e78e4e72bf
@ -99,26 +99,21 @@ class PDFThumbnailViewer {
|
|||||||
// ... and add the highlight to the new thumbnail.
|
// ... and add the highlight to the new thumbnail.
|
||||||
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
||||||
}
|
}
|
||||||
const visibleThumbs = this._getVisibleThumbs();
|
const { first, last, views } = this._getVisibleThumbs();
|
||||||
const numVisibleThumbs = visibleThumbs.views.length;
|
|
||||||
|
|
||||||
// If the thumbnail isn't currently visible, scroll it into view.
|
// If the thumbnail isn't currently visible, scroll it into view.
|
||||||
if (numVisibleThumbs > 0) {
|
if (views.length > 0) {
|
||||||
const first = visibleThumbs.first.id;
|
|
||||||
// Account for only one thumbnail being visible.
|
|
||||||
const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
|
|
||||||
|
|
||||||
let shouldScroll = false;
|
let shouldScroll = false;
|
||||||
if (pageNumber <= first || pageNumber >= last) {
|
if (pageNumber <= first.id || pageNumber >= last.id) {
|
||||||
shouldScroll = true;
|
shouldScroll = true;
|
||||||
} else {
|
} else {
|
||||||
visibleThumbs.views.some(function (view) {
|
for (const { id, percent } of views) {
|
||||||
if (view.id !== pageNumber) {
|
if (id !== pageNumber) {
|
||||||
return false;
|
continue;
|
||||||
}
|
}
|
||||||
shouldScroll = view.percent < 100;
|
shouldScroll = percent < 100;
|
||||||
return true;
|
break;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if (shouldScroll) {
|
if (shouldScroll) {
|
||||||
scrollIntoView(thumbnailView.div, { top: THUMBNAIL_SCROLL_MARGIN });
|
scrollIntoView(thumbnailView.div, { top: THUMBNAIL_SCROLL_MARGIN });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user