[polari/wip/completion-filtering] tabCompletion: Allow to refine filter while the popup is showing



commit 6070a0a18f8d34a42fc865d9b7b41ef02a6d2e97
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Oct 10 14:55:52 2013 +0100

    tabCompletion: Allow to refine filter while the popup is showing

 src/tabCompletion.js |   38 ++++++++++++++++++++++++++++----------
 1 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/src/tabCompletion.js b/src/tabCompletion.js
index f568f77..7413033 100644
--- a/src/tabCompletion.js
+++ b/src/tabCompletion.js
@@ -100,15 +100,24 @@ const TabCompletion = new Lang.Class({
                 return true;
         }
 
-        if (Gdk.keyval_to_unicode(keyval) != 0) {
-            let popupShown = this._popup.visible;
-            this._stop();
-            // eat keys that would active the entry
-            // when showing the popup
-            return popupShown &&
-                   (keyval == Gdk.KEY_Return ||
-                    keyval == Gdk.KEY_KP_Enter ||
-                    keyval == Gdk.KEY_ISO_Enter);
+        let c = Gdk.keyval_to_unicode(keyval);
+        if (c != 0) {
+            let str = String.fromCharCode(c);
+            if (/[\w|-]/.test(str)) {
+                this._key += str;
+                this._refilter();
+
+                return true;
+            } else {
+                let popupShown = this._popup.visible;
+                this._stop();
+                // eat keys that would active the entry
+                // when showing the popup
+                return popupShown &&
+                       (keyval == Gdk.KEY_Return ||
+                        keyval == Gdk.KEY_KP_Enter ||
+                        keyval == Gdk.KEY_ISO_Enter);
+            }
         }
         return false;
     },
@@ -157,6 +166,10 @@ const TabCompletion = new Lang.Class({
             this._endPos = -1;
         this._previousCompletion = (this._endPos == this._startPos);
 
+        this._refilter();
+    },
+
+    _refilter: function() {
         this._list.invalidate_filter();
 
         let visibleRows = this._list.get_children().filter(function(c) {
@@ -164,8 +177,11 @@ const TabCompletion = new Lang.Class({
         });
         let nVisibleRows = visibleRows.length;
 
-        if (nVisibleRows == 0)
+        if (nVisibleRows == 0) {
+            this._insertCompletion(this._key);
+            this._stop();
             return;
+        }
 
         if (this._previousCompletion)
             this._setPreviousCompletionChained(true);
@@ -173,6 +189,8 @@ const TabCompletion = new Lang.Class({
         if (visibleRows.length > 1) {
             this._list.select_row(visibleRows[0]);
             this._showPopup()
+        } else {
+            this._popup.hide();
         }
     },
 


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