[polari/gnome-3-20] chatView: Make auto-scrolling more robust



commit 555c4939a83168c6af9641b4305a1511c4c8c073
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Apr 19 14:26:20 2016 +0200

    chatView: Make auto-scrolling more robust
    
    We currently implement auto-scrolling by keeping track of the
    scroll position that corresponds to the bottom, and checking
    whether it matches the current scroll position. This used to
    work (mostly), until we started to animate auto-scrolling in
    commit 65f9c8a07 - now if more text is added to the log while
    the animation is still ongoing (another message, or even just
    a timestamp), the check will fail and stop auto-scrolling
    until the user manually scrolls to the bottom again.
    To fix this, simplify the code to keep track of whether we
    should auto-scroll instead of a particular scroll position:
    We simply disable auto-scrolling when the user scrolls up,
    and re-enable it when reaching the bottom edge. This should
    be much more robust, and probably fixes tons of other edge
    cases in addition to the issue outlined above.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765129

 src/chatView.js |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index eb2196a..38e4339 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -257,6 +257,10 @@ const ChatView = new Lang.Class({
         this.connect('state-flags-changed',
                      Lang.bind(this, this._updateToplevel));
         this.connect('scroll-event', Lang.bind(this, this._onScroll));
+        this.connect('edge-reached', (w, pos) => {
+            if (pos == Gtk.PositionType.BOTTOM)
+                this._autoscroll = true;
+        });
 
         this.vadjustment.connect('value-changed',
                                  Lang.bind(this, this._onValueChanged));
@@ -307,8 +311,7 @@ const ChatView = new Lang.Class({
         this._logWalker.get_events_async(NUM_INITIAL_LOG_EVENTS,
                                          Lang.bind(this, this._onLogEventsReady));
 
-        let adj = this.vadjustment;
-        this._scrollBottom = adj.upper - adj.page_size;
+        this._autoscroll = true;
 
         this._app = Gio.Application.get_default();
         PasteManager.DropTargetIface.addTargets(this, this._view);
@@ -566,19 +569,19 @@ const ChatView = new Lang.Class({
     },
 
     _updateScroll: function() {
-        let adj = this.vadjustment;
-        if (adj.value == this._scrollBottom) {
-            if (this._nPending == 0) {
-                this._view.emit('move-cursor',
-                                Gtk.MovementStep.BUFFER_ENDS, 1, false);
-            } else {
-                let id = Object.keys(this._pending).sort(function(a, b) {
-                    return a - b;
-                })[0];
-                this._view.scroll_mark_onscreen(this._pending[id]);
-            }
+        if (!this._autoscroll)
+            return;
+
+        if (this._nPending == 0) {
+            this._view.emit('move-cursor',
+                            Gtk.MovementStep.BUFFER_ENDS, 1, false);
+        } else {
+            let id = Object.keys(this._pending).sort(function(a, b) {
+                return a - b;
+            })[0];
+            this._autoscroll = false;
+            this._view.scroll_mark_onscreen(this._pending[id]);
         }
-        this._scrollBottom = adj.upper - adj.page_size;
     },
 
     _onScroll: function(w, event) {
@@ -590,6 +593,8 @@ const ChatView = new Lang.Class({
         if (hasDeltas && dy >= 0)
             return Gdk.EVENT_PROPAGATE;
 
+        this._autoscroll = false;
+
         return this._fetchBacklog();
     },
 
@@ -601,6 +606,8 @@ const ChatView = new Lang.Class({
             keyval != Gdk.KEY_KP_Page_Up)
             return Gdk.EVENT_PROPAGATE;
 
+        this._autoscroll = false;
+
         return this._fetchBacklog();
     },
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]