From b50a5126606afc8d8d24dc572c964a03a6fa579c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 27 Jan 2019 14:50:16 +0100 Subject: [PATCH] In `getVisibleElements`, check `firstVisibleElementInd` rather than `numViews` before backtracking (PR 10443 follow-up) When `firstVisibleElementInd === 0`, regardless of the number of views, there's no reason to attempt to backtrack at all since it's never possible to find an element before the *first* one anyway. --- web/ui_utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/ui_utils.js b/web/ui_utils.js index 7c1a6c110..f2d9bb058 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -446,7 +446,8 @@ function getVisibleElements(scrollEl, views, sortByVisibility = false, // Please note the return value of the `binarySearchFirstItem` function when // no valid element is found (hence the `firstVisibleElementInd` check below). - if (numViews > 0 && firstVisibleElementInd < numViews && !horizontal) { + if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && + !horizontal) { // In wrapped scrolling (or vertical scrolling with spreads), with some page // sizes, isElementBottomAfterViewTop doesn't satisfy the binary search // condition: there can be pages with bottoms above the view top between