about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorLes Orchard <me@lmorchard.com>2018-11-09 12:06:43 -0500
committerEugen Rochko <eugen@zeonfederated.com>2018-11-09 18:06:43 +0100
commit2f86fc5e0a45eb2002d4b481ae093197ad523479 (patch)
tree5c0498a39de84deb80ef207a2889450afe813bdc /app
parent08b3de4d5ee73f06966724108a3975a9110140e3 (diff)
Identify manual scrolling to cancel scroll to top reset on mouse idle (#9245)
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/components/scrollable_list.js23
1 files changed, 17 insertions, 6 deletions
diff --git a/app/javascript/mastodon/components/scrollable_list.js b/app/javascript/mastodon/components/scrollable_list.js
index 91a895bce..7551d0b1f 100644
--- a/app/javascript/mastodon/components/scrollable_list.js
+++ b/app/javascript/mastodon/components/scrollable_list.js
@@ -59,6 +59,13 @@ export default class ScrollableList extends PureComponent {
       } else if (this.props.onScroll) {
         this.props.onScroll();
       }
+
+      if (!this.lastScrollWasSynthetic) {
+        // If the last scroll wasn't caused by setScrollTop(), assume it was
+        // intentional and cancel any pending scroll reset on mouse idle
+        this.scrollToTopOnMouseIdle = false;
+      }
+      this.lastScrollWasSynthetic = false;
     }
   }, 150, {
     trailing: true,
@@ -66,8 +73,16 @@ export default class ScrollableList extends PureComponent {
 
   mouseIdleTimer = null;
   mouseMovedRecently = false;
+  lastScrollWasSynthetic = false;
   scrollToTopOnMouseIdle = false;
 
+  setScrollTop = newScrollTop => {
+    if (this.node.scrollTop !== newScrollTop) {
+      this.lastScrollWasSynthetic = true;
+      this.node.scrollTop = newScrollTop;
+    }
+  };
+
   clearMouseIdleTimer = () => {
     if (this.mouseIdleTimer === null) {
       return;
@@ -99,7 +114,7 @@ export default class ScrollableList extends PureComponent {
 
   handleMouseIdle = () => {
     if (this.scrollToTopOnMouseIdle) {
-      this.node.scrollTop = 0;
+      this.setScrollTop(0);
     }
 
     this.mouseMovedRecently = false;
@@ -132,11 +147,7 @@ export default class ScrollableList extends PureComponent {
     // Reset the scroll position when a new child comes in in order not to
     // jerk the scrollbar around if you're already scrolled down the page.
     if (snapshot !== null) {
-      const newScrollTop = this.node.scrollHeight - snapshot;
-
-      if (this.node.scrollTop !== newScrollTop) {
-        this.node.scrollTop = newScrollTop;
-      }
+      this.setScrollTop(this.node.scrollHeight - snapshot);
     }
   }