[gnome-maps] MainWindow: Bold string matches in search popup



commit 8102fe2d01fe079322f11a6edcdbe3588b403997
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sat Aug 24 23:57:52 2013 +0200

    MainWindow: Bold string matches in search popup
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706724

 src/mainWindow.js |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 89a1ea4..169ab04 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -242,15 +242,27 @@ const MainWindow = new Lang.Class({
         }
     },
 
+    // We want to match case insensitive but present in the correct case.
+    _boldMatch: function(description, searchStringLower) {
+        let index = description.toLowerCase().indexOf(searchStringLower);
+
+        if (index !== -1) {
+            let substring = description.substring(index,
+                                                  index + searchStringLower.length);
+
+            description = description.replace(substring, substring.bold());
+        }
+
+        return description;
+    },
+
     _showSearchResults: function(places) {
         let model = this._searchPopup.getModel();
 
-        if (places === null) {
-            this._searchPopup.hide();
-            return;
-        }
+        // Lower case to match case insensitive
+        let searchStringLower = this._searchEntry.text.toLowerCase();
 
-        places.forEach(function(place) {
+        places.forEach((function(place) {
             let iter = model.append();
             let location = place.get_location();
             let icon = place.icon;
@@ -258,15 +270,13 @@ const MainWindow = new Lang.Class({
             if (location == null)
                 return;
 
-            let description_markup =
-                '<b>' +
-                GLib.markup_escape_text(location.description, -1) +
-                '</b>';
+            let description = GLib.markup_escape_text(location.description, -1);
+            description = this._boldMatch(description, searchStringLower);
 
             model.set(iter,
                       [SearchResults.COL_DESCRIPTION,
                        SearchResults.COL_LOCATION],
-                      [description_markup,
+                      [description,
                        location]);
 
             if (icon !== null) {
@@ -274,7 +284,7 @@ const MainWindow = new Lang.Class({
                     model.set(iter, [SearchResults.COL_ICON], [pixbuf]);
                 });
             }
-        });
+        }).bind(this));
         this._searchPopup.showResult();
     },
 


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