[polari/wip/fmuellner/window-experiments: 4/30] chatView: Factor out _setIndicatorMark() method



commit 5d1c406aaf6e08f3673740afb26cdf677fa7b40c
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jul 15 22:01:43 2016 +0200

    chatView: Factor out _setIndicatorMark() method
    
    It's self-contained functionality, and having it separate improves
    the readability of the calling code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768907

 src/chatView.js |   41 +++++++++++++++++++++++------------------
 1 files changed, 23 insertions(+), 18 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 96264a2..c68dd64 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -776,6 +776,27 @@ const ChatView = new Lang.Class({
         buffer.delete(buffer.get_start_iter(), iter);
     },
 
+    _setIndicatorMark: function(iter) {
+        let lineStart = iter.copy();
+        lineStart.set_line_offset(0);
+
+        let buffer = this._view.buffer;
+        let mark = buffer.get_mark('indicator-line');
+        if (mark) {
+            let [start, end] = this._getLineIters(buffer.get_iter_at_mark(mark));
+            buffer.remove_tag(this._lookupTag('indicator-line'), start, end);
+
+            buffer.move_mark(mark, lineStart);
+        } else {
+            buffer.create_mark('indicator-line', lineStart, true);
+        }
+
+        let [start, end] = this._getLineIters(iter);
+        buffer.apply_tag(this._lookupTag('indicator-line'), start, end);
+
+        this._needsIndicator = false;
+    },
+
     _checkMessages: function() {
         if (!this._active || !this._toplevelFocus || !this._channel)
             return;
@@ -1196,24 +1217,8 @@ const ChatView = new Lang.Class({
                 this._pending.set(id, mark);
             }
 
-            if (this._needsIndicator) {
-                iter.set_line_offset(0);
-
-                let mark = buffer.get_mark('indicator-line');
-                if (mark) {
-                    let [start, end] = this._getLineIters(buffer.get_iter_at_mark(mark));
-                    buffer.remove_tag(this._lookupTag('indicator-line'), start, end);
-
-                    buffer.move_mark(mark, iter);
-                } else {
-                    buffer.create_mark('indicator-line', iter, true);
-                }
-
-                let [start, end] = this._getLineIters(iter);
-                buffer.apply_tag(this._lookupTag('indicator-line'), start, end);
-
-                this._needsIndicator = false;
-            }
+            if (this._needsIndicator)
+                this._setIndicatorMark(buffer.get_end_iter());
         }
     },
 


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