Bug 571203 - Handle spaces in overlay search
Previously we were stripping all whitespace. Instead, just strip leading+trailing whitespace, split the remaining search into individual terms which we search for independently. Items are grouped by the number of terms they match, then sorted alphabetically.
This commit is contained in:
parent
2d3988c5fc
commit
85dae56a31
@ -178,15 +178,13 @@ AppDisplay.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Sorts the list of item ids in-place based on the alphabetical order of the names of
|
// Compares items associated with the item ids based on the alphabetical order
|
||||||
// the items associated with the ids.
|
// of the item names.
|
||||||
_sortItems : function(itemIds) {
|
// Returns an integer value indicating the result of the comparison.
|
||||||
let me = this;
|
_compareItems : function(itemIdA, itemIdB) {
|
||||||
itemIds.sort(function (a,b) {
|
let appA = this._allItems[itemIdA];
|
||||||
let appA = me._allItems[a];
|
let appB = this._allItems[itemIdB];
|
||||||
let appB = me._allItems[b];
|
|
||||||
return appA.get_name().localeCompare(appB.get_name());
|
return appA.get_name().localeCompare(appB.get_name());
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Checks if the item info can be a match for the search string by checking
|
// Checks if the item info can be a match for the search string by checking
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
const Clutter = imports.gi.Clutter;
|
const Clutter = imports.gi.Clutter;
|
||||||
const Gio = imports.gi.Gio;
|
const Gio = imports.gi.Gio;
|
||||||
const Gtk = imports.gi.Gtk;
|
const Gtk = imports.gi.Gtk;
|
||||||
|
const Lang = imports.lang;
|
||||||
const Shell = imports.gi.Shell;
|
const Shell = imports.gi.Shell;
|
||||||
const Signals = imports.signals;
|
const Signals = imports.signals;
|
||||||
|
|
||||||
@ -153,7 +154,7 @@ DocDisplay.prototype = {
|
|||||||
for (docId in this._allItems) {
|
for (docId in this._allItems) {
|
||||||
docIds.push(docId);
|
docIds.push(docId);
|
||||||
}
|
}
|
||||||
this._sortItems(docIds);
|
docIds.sort(Lang.bind(this, function (a,b) { return this._compareItems(a,b); }));
|
||||||
|
|
||||||
let added = 0;
|
let added = 0;
|
||||||
for (let i = 0; i < docIds.length && added < this._maxItems; i++) {
|
for (let i = 0; i < docIds.length && added < this._maxItems; i++) {
|
||||||
@ -166,13 +167,12 @@ DocDisplay.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Sorts the list of item ids in-place based on how recently the items associated with
|
// Compares items associated with the item ids based on how recently the items
|
||||||
// the ids were last visited.
|
// were last visited.
|
||||||
_sortItems : function(itemIds) {
|
// Returns an integer value indicating the result of the comparison.
|
||||||
let me = this;
|
_compareItems : function(itemIdA, itemIdB) {
|
||||||
itemIds.sort(function (a,b) {
|
let docA = this._allItems[itemIdA];
|
||||||
let docA = me._allItems[a];
|
let docB = this._allItems[itemIdB];
|
||||||
let docB = me._allItems[b];
|
|
||||||
// We actually used get_modified() instead of get_visited() here, as GtkRecentInfo
|
// We actually used get_modified() instead of get_visited() here, as GtkRecentInfo
|
||||||
// doesn't updated get_visited() correctly.
|
// doesn't updated get_visited() correctly.
|
||||||
// See http://bugzilla.gnome.org/show_bug.cgi?id=567094
|
// See http://bugzilla.gnome.org/show_bug.cgi?id=567094
|
||||||
@ -182,7 +182,6 @@ DocDisplay.prototype = {
|
|||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Checks if the item info can be a match for the search string by checking
|
// Checks if the item info can be a match for the search string by checking
|
||||||
|
@ -6,8 +6,8 @@ const Gio = imports.gi.Gio;
|
|||||||
const Gtk = imports.gi.Gtk;
|
const Gtk = imports.gi.Gtk;
|
||||||
const Lang = imports.lang;
|
const Lang = imports.lang;
|
||||||
const Pango = imports.gi.Pango;
|
const Pango = imports.gi.Pango;
|
||||||
const Shell = imports.gi.Shell;
|
|
||||||
const Signals = imports.signals;
|
const Signals = imports.signals;
|
||||||
|
const Shell = imports.gi.Shell;
|
||||||
const Tidy = imports.gi.Tidy;
|
const Tidy = imports.gi.Tidy;
|
||||||
|
|
||||||
const DND = imports.ui.dnd;
|
const DND = imports.ui.dnd;
|
||||||
@ -391,9 +391,11 @@ GenericDisplay.prototype = {
|
|||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
},
|
},
|
||||||
|
|
||||||
// Sorts the list of item ids in-place based on the order in which the items
|
// Compares items associated with the item ids based on the order in which the
|
||||||
// associated with the ids should be displayed.
|
// items should be displayed.
|
||||||
_sortItems: function(itemIds) {
|
// Intended to be used as a compareFunction for array.sort().
|
||||||
|
// Returns an integer value indicating the result of the comparison.
|
||||||
|
_compareItems: function(itemIdA, itemIdB) {
|
||||||
throw new Error("Not implemented");
|
throw new Error("Not implemented");
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -424,15 +426,43 @@ GenericDisplay.prototype = {
|
|||||||
// and displays up to this._maxItems that matched.
|
// and displays up to this._maxItems that matched.
|
||||||
_doSearchFilter: function() {
|
_doSearchFilter: function() {
|
||||||
this._removeAllDisplayItems();
|
this._removeAllDisplayItems();
|
||||||
let matchedItems = [];
|
let matchedItems = {};
|
||||||
|
|
||||||
|
// Break the search up into terms, and search for each
|
||||||
|
// individual term. Keep track of the number of terms
|
||||||
|
// each item matched.
|
||||||
|
let terms = this._search.split(/\s+/);
|
||||||
|
for (let i = 0; i < terms.length; i++) {
|
||||||
|
let term = terms[i];
|
||||||
for (itemId in this._allItems) {
|
for (itemId in this._allItems) {
|
||||||
let item = this._allItems[itemId];
|
let item = this._allItems[itemId];
|
||||||
if (this._isInfoMatching(item, this._search))
|
if (this._isInfoMatching(item, term)) {
|
||||||
matchedItems.push(itemId);
|
let count = matchedItems[itemId];
|
||||||
|
if (!count)
|
||||||
|
count = 0;
|
||||||
|
count += 1;
|
||||||
|
matchedItems[itemId] = count;
|
||||||
}
|
}
|
||||||
this._sortItems(matchedItems);
|
}
|
||||||
for (let i = 0; i < matchedItems.length && i < this._maxItems; i++) {
|
}
|
||||||
this._addDisplayItem(matchedItems[i]);
|
|
||||||
|
let matchedList = [];
|
||||||
|
for (itemId in matchedItems) {
|
||||||
|
matchedList.push(itemId);
|
||||||
|
}
|
||||||
|
matchedList.sort(Lang.bind(this, function (a, b) {
|
||||||
|
let countA = matchedItems[a];
|
||||||
|
let countB = matchedItems[b];
|
||||||
|
if (countA > countB)
|
||||||
|
return -1;
|
||||||
|
else if (countA < countB)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return this._compareItems(a, b);
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (var i = 0; i < matchedList.length && i < this._maxItems; i++) {
|
||||||
|
this._addDisplayItem(matchedList[i]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -119,7 +119,8 @@ Sideshow.prototype = {
|
|||||||
if (me._searchQueued)
|
if (me._searchQueued)
|
||||||
return;
|
return;
|
||||||
Mainloop.timeout_add(250, function() {
|
Mainloop.timeout_add(250, function() {
|
||||||
let text = me._searchEntry.text.replace(/\s/g, "");
|
// Strip leading and trailing whitespace
|
||||||
|
let text = me._searchEntry.text.replace(/^\s+/g, "").replace(/\s+$/g, "");
|
||||||
me._searchQueued = false;
|
me._searchQueued = false;
|
||||||
me._searchActive = text != '';
|
me._searchActive = text != '';
|
||||||
me._appDisplay.setSearch(text);
|
me._appDisplay.setSearch(text);
|
||||||
|
Loading…
Reference in New Issue
Block a user