From 65e4652142ce6c9b803a29d794337e4c2d9d00c2 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 8 Feb 2013 21:05:15 -0500 Subject: [PATCH] viewSelector: Make sure not to start searching when we only have whitespace As this is thrown out before we actually query providers, we end up with a confusing screen that says "Searching..." that won't ever get results. https://bugzilla.gnome.org/show_bug.cgi?id=693458 --- js/ui/search.js | 9 --------- js/ui/viewSelector.js | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/js/ui/search.js b/js/ui/search.js index 96f92fa7c..dced01c04 100644 --- a/js/ui/search.js +++ b/js/ui/search.js @@ -60,15 +60,6 @@ const SearchSystem = new Lang.Class({ this.emit('search-updated', this._previousResults[i]); }, - updateSearch: function(searchString) { - searchString = searchString.replace(/^\s+/g, '').replace(/\s+$/g, ''); - if (searchString == '') - return; - - let terms = searchString.split(/\s+/); - this.updateSearchResults(terms); - }, - updateSearchResults: function(terms) { if (!terms) return; diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js index f2da6d183..c925cfdae 100644 --- a/js/ui/viewSelector.js +++ b/js/ui/viewSelector.js @@ -35,6 +35,14 @@ const FocusTrap = new Lang.Class({ } }); +function getTermsForSearchString(searchString) { + searchString = searchString.replace(/^\s+/g, '').replace(/\s+$/g, ''); + if (searchString == '') + return []; + + let terms = searchString.split(/\s+/); + return terms; +} const ViewSelector = new Lang.Class({ Name: 'ViewSelector', @@ -328,8 +336,10 @@ const ViewSelector = new Lang.Class({ }, _onTextChanged: function (se, prop) { + let terms = getTermsForSearchString(this._entry.get_text()); + let searchPreviouslyActive = this._searchActive; - this._searchActive = this._entry.get_text() != ''; + this._searchActive = (terms.length > 0); let startSearch = this._searchActive && !searchPreviouslyActive; if (startSearch) @@ -423,8 +433,10 @@ const ViewSelector = new Lang.Class({ _doSearch: function () { this._searchTimeoutId = 0; - this._searchSystem.updateSearch(this._text.text); + let terms = getTermsForSearchString(this._entry.get_text()); + + this._searchSystem.updateSearchResults(terms); this._showPage(this._searchPage); },