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.
|
||||
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
||||
}
|
||||
const visibleThumbs = this._getVisibleThumbs();
|
||||
const numVisibleThumbs = visibleThumbs.views.length;
|
||||
const { first, last, views } = this._getVisibleThumbs();
|
||||
|
||||
// If the thumbnail isn't currently visible, scroll it into view.
|
||||
if (numVisibleThumbs > 0) {
|
||||
const first = visibleThumbs.first.id;
|
||||
// Account for only one thumbnail being visible.
|
||||
const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
|
||||
|
||||
if (views.length > 0) {
|
||||
let shouldScroll = false;
|
||||
if (pageNumber <= first || pageNumber >= last) {
|
||||
if (pageNumber <= first.id || pageNumber >= last.id) {
|
||||
shouldScroll = true;
|
||||
} else {
|
||||
visibleThumbs.views.some(function (view) {
|
||||
if (view.id !== pageNumber) {
|
||||
return false;
|
||||
for (const { id, percent } of views) {
|
||||
if (id !== pageNumber) {
|
||||
continue;
|
||||
}
|
||||
shouldScroll = percent < 100;
|
||||
break;
|
||||
}
|
||||
shouldScroll = view.percent < 100;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
if (shouldScroll) {
|
||||
scrollIntoView(thumbnailView.div, { top: THUMBNAIL_SCROLL_MARGIN });
|
||||
|
Loading…
x
Reference in New Issue
Block a user