From 47f29b945441cc4ab8367b1cde5ef8a1d5291c27 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 5 Apr 2017 17:48:24 +0100 Subject: [PATCH] Simplify simulated unfill --- src/components/structures/ScrollPanel.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index cff6a86b2c..3575d69b3f 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -344,17 +344,17 @@ module.exports = React.createClass({ // pagination. // // If backwards is true, we unpaginate (remove) tiles from the back (top). - let i = backwards ? 0 : tiles.length - 1; - while ( - (backwards ? i < tiles.length : i > 0) && excessHeight > tiles[i].clientHeight - ) { + for (let i = 0; i < tiles.length; i++) { + const tile = tiles[backwards ? tiles.length - 1 - i : i]; // Subtract height of tile as if it were unpaginated - excessHeight -= tiles[i].clientHeight; + excessHeight -= tile.clientHeight; // The tile may not have a scroll token, so guard it - if (tiles[i].dataset.scrollToken) { - markerScrollToken = tiles[i].dataset.scrollToken; + if (tile.dataset.scrollToken) { + markerScrollToken = tile.dataset.scrollToken; + } + if (tile.clientHeight > excessHeight) { + break; } - i += backwards ? 1 : -1; } if (markerScrollToken) {