[gnome-shell] When setting a search, do a redisplay immediately



commit 07a8d5ed2dcaa104db992f49b701009b776d35b4
Author: Colin Walters <walters verbum org>
Date:   Thu Nov 5 17:19:36 2009 -0500

    When setting a search, do a redisplay immediately
    
    Commit 94bd6f17180f0a8cbdbf2a66a47469fce601a9e1 introduced a trick
    where we only do the heavy lifting for "redisplay" when we're mapped.
    
    However, the search system wants to get the count of matched items,
    and control the visibility of the display based on that.  This introduces
    a circularity; avoid it by forcing the search to do a redisplay.
    
    In the future we should avoid this by separating out the "get matched
    things for search" from "display list of things".
    
    https://bugzilla.gnome.org/show_bug.cgi?id=600890

 js/ui/genericDisplay.js |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/genericDisplay.js b/js/ui/genericDisplay.js
index 4744669..e58c2c6 100644
--- a/js/ui/genericDisplay.js
+++ b/js/ui/genericDisplay.js
@@ -20,7 +20,8 @@ const Main = imports.ui.main;
 const RedisplayFlags = { NONE: 0,
                          RESET_CONTROLS: 1 << 0,
                          FULL: 1 << 1,
-                         SUBSEARCH: 1 << 2 };
+                         SUBSEARCH: 1 << 2,
+                         IMMEDIATE: 1 << 3 };
 
 const ITEM_DISPLAY_NAME_COLOR = new Clutter.Color();
 ITEM_DISPLAY_NAME_COLOR.from_pixel(0xffffffff);
@@ -369,16 +370,18 @@ GenericDisplay.prototype = {
     // Sets the search string and displays the matching items.
     setSearch: function(text) {
         let lowertext = text.toLowerCase();
-        if (lowertext == this._search)
+        if (lowertext == this._search) {
             return;
-        let flags = RedisplayFlags.RESET_CONTROLS;
+        }
+        let flags = RedisplayFlags.RESET_CONTROLS | RedisplayFlags.IMMEDIATE;
         if (this._search != '') {
             // Because we combine search terms with OR, we have to be sure that no new term
             // was introduced before deciding that the new search results will be a subset of
             // the existing search results.
             if (lowertext.indexOf(this._search) == 0 &&
-                lowertext.split(/\s+/).length == this._search.split(/\s+/).length)
+                lowertext.split(/\s+/).length == this._search.split(/\s+/).length) {
                 flags |= RedisplayFlags.SUBSEARCH;
+            }
         }
         this._search = lowertext;
         this._redisplay(flags);
@@ -643,9 +646,13 @@ GenericDisplay.prototype = {
      *  SUBSEARCH - Indicates that the current _search is a superstring of the previous
      *  one, which implies we only need to re-search through previous results.
      *  FULL - Indicates that we need recreate all displayed items; implies RESET_CONTROLS as well
+     *  IMMEDIATE - Do the full redisplay even if we're not mapped.  This is useful
+     *  if you want to get the number of matched items and show/hide a section based on
+     *  that number.
      */
     _redisplay: function(flags) {
-        if (!this._list.mapped) {
+        let immediate = (flags & RedisplayFlags.IMMEDIATE) > 0;
+        if (!immediate && !this._list.mapped) {
             this._pendingRedisplay |= flags;
             return;
         }



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