Skip to content

Commit 6068ab1

Browse files
authored
Merge pull request matrix-org#4171 from matrix-org/jryans/relative-scrolling-release
Adjust scroll offset with relative scrolling (for release)
2 parents aedd44a + 070b430 commit 6068ab1

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/components/structures/ScrollPanel.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ export default createReactClass({
523523
scrollRelative: function(mult) {
524524
const scrollNode = this._getScrollNode();
525525
const delta = mult * scrollNode.clientHeight * 0.5;
526-
scrollNode.scrollTop = scrollNode.scrollTop + delta;
526+
scrollNode.scrollBy(0, delta);
527527
this._saveScrollState();
528528
},
529529

@@ -705,17 +705,15 @@ export default createReactClass({
705705
// the currently filled piece of the timeline
706706
if (trackedNode) {
707707
const oldTop = trackedNode.offsetTop;
708-
// changing the height might change the scrollTop
709-
// if the new height is smaller than the scrollTop.
710-
// We calculate the diff that needs to be applied
711-
// ourselves, so be sure to measure the
712-
// scrollTop before changing the height.
713-
const preexistingScrollTop = sn.scrollTop;
714708
itemlist.style.height = `${newHeight}px`;
715709
const newTop = trackedNode.offsetTop;
716710
const topDiff = newTop - oldTop;
717-
sn.scrollTop = preexistingScrollTop + topDiff;
718-
debuglog("updateHeight to", {newHeight, topDiff, preexistingScrollTop});
711+
// important to scroll by a relative amount as
712+
// reading scrollTop and then setting it might
713+
// yield out of date values and cause a jump
714+
// when setting it
715+
sn.scrollBy(0, topDiff);
716+
debuglog("updateHeight to", {newHeight, topDiff});
719717
}
720718
}
721719
},
@@ -767,6 +765,7 @@ export default createReactClass({
767765
},
768766

769767
_topFromBottom(node) {
768+
// current capped height - distance from top = distance from bottom of container to top of tracked element
770769
return this._itemlist.current.clientHeight - node.offsetTop;
771770
},
772771

0 commit comments

Comments
 (0)