From 002afda50328362c780ff8cd6e0c0cefec2b1771 Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Wed, 29 May 2013 22:48:30 +0200 Subject: [PATCH] SearchDisplay: handle certain result IDs specially Allow the prefix 'special:' applied to result IDs to mark results that should be always shown, even when they would overflow the maximum results cap. This will be used by epiphany for the special "Search the Web" result. https://bugzilla.gnome.org/show_bug.cgi?id=707055 --- js/ui/appDisplay.js | 4 ++++ js/ui/remoteSearch.js | 10 ++++++++++ js/ui/searchDisplay.js | 2 +- js/ui/wanda.js | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 52d7b70ae..f9c585982 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -877,6 +877,10 @@ const AppSearchProvider = new Lang.Class({ callback(metas); }, + filterResults: function(results, maxNumber) { + return results.slice(0, maxNumber); + }, + getInitialResultSet: function(terms) { this.searchSystem.setResults(this, this._appSys.initial_search(terms)); }, diff --git a/js/ui/remoteSearch.js b/js/ui/remoteSearch.js index b1f485e13..f48a37fa5 100644 --- a/js/ui/remoteSearch.js +++ b/js/ui/remoteSearch.js @@ -207,6 +207,16 @@ const RemoteSearchProvider = new Lang.Class({ icon_size: size }); }, + filterResults: function(results, maxNumber) { + if (results.length <= maxNumber) + return results; + + let regularResults = results.filter(function(r) { return !r.startsWith('special:'); }); + let specialResults = results.filter(function(r) { return r.startsWith('special:'); }); + + return regularResults.slice(0, maxNumber).concat(specialResults.slice(0, maxNumber)); + }, + _getResultsFinished: function(results, error) { if (error) return; diff --git a/js/ui/searchDisplay.js b/js/ui/searchDisplay.js index 69c79a1af..8ae97abba 100644 --- a/js/ui/searchDisplay.js +++ b/js/ui/searchDisplay.js @@ -230,7 +230,7 @@ const SearchResultsBase = new Lang.Class({ callback(); } else { let maxResults = this._getMaxDisplayedResults(); - let results = providerResults.slice(0, maxResults); + let results = this.provider.filterResults(providerResults, maxResults); let hasMoreResults = results.length < providerResults.length; this.provider.getResultMetas(results, Lang.bind(this, function(metas) { diff --git a/js/ui/wanda.js b/js/ui/wanda.js index 731a63109..6ed238766 100644 --- a/js/ui/wanda.js +++ b/js/ui/wanda.js @@ -132,6 +132,10 @@ const WandaSearchProvider = new Lang.Class({ }]); }, + filterResults: function(results) { + return results; + }, + getInitialResultSet: function(terms) { if (terms.join(' ') == MAGIC_FISH_KEY) { this.searchSystem.setResults(this, [ FISH_NAME ]);