From 4bfdbe3094832c5491edf15c1923a5d6c7616d25 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 22 Mar 2019 15:23:21 +0100 Subject: [PATCH] fix jumping when unfilling the top while scrolling down --- src/components/structures/ScrollPanel.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index a04e4ef171..7f992097bf 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -642,11 +642,17 @@ module.exports = React.createClass({ // the currently filled piece of the timeline if (trackedNode) { const oldTop = trackedNode.offsetTop; + // changing the height might change the scrollTop + // if the new height is smaller than the scrollTop. + // We calculate the diff that needs to be applied + // ourselves, so be sure to measure the + // scrollTop before changing the height. + const preexistingScrollTop = sn.scrollTop; itemlist.style.height = `${newHeight}px`; const newTop = trackedNode.offsetTop; const topDiff = newTop - oldTop; - sn.scrollTop = sn.scrollTop + topDiff; - debuglog("updateHeight to", newHeight, topDiff); + sn.scrollTop = preexistingScrollTop + topDiff; + debuglog("updateHeight to", {newHeight, topDiff, preexistingScrollTop}); } } },