[polari] chatView: Make auto-scrolling more robust



commit 5df0c4f699aa7e214c7f547012e0031e6b78e9f2
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 e144658..50ecf98 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -265,6 +265,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));
@@ -315,8 +319,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);
@@ -578,19 +581,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) {
@@ -602,6 +605,8 @@ const ChatView = new Lang.Class({
         if (hasDeltas && dy >= 0)
             return Gdk.EVENT_PROPAGATE;
 
+        this._autoscroll = false;
+
         return this._fetchBacklog();
     },
 
@@ -628,6 +633,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]