Bug 1496811 - Show only top single result when search only engine alias is typed in the address bar r=mak
authorDrew Willcoxon <adw@mozilla.com>
Wed, 17 Oct 2018 15:26:46 +0000
changeset 441693 0f5b5590bf693f33a11789b21db874bcbd9a8389
parent 441692 0589e0ff75c7d7d1eced9c91230492d7cc39c2d6
child 441694 2fee8f9b283dac85340edf7815fd62b93352bd33
push id34873
push userdluca@mozilla.com
push dateWed, 17 Oct 2018 22:54:14 +0000
treeherdermozilla-central@bfd23ad81ef4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1496811
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1496811 - Show only top single result when search only engine alias is typed in the address bar r=mak Differential Revision: https://phabricator.services.mozilla.com/D8804
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/unifiedcomplete/test_search_engine_alias.js
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -826,16 +826,25 @@ Search.prototype = {
     // any other searches so we aren't kicking off potentially expensive
     // searches on every keystroke.
     // Though, if there's no heuristic result, we start searching immediately,
     // since autocomplete may be waiting for us.
     if (hasHeuristic) {
       await this._sleep(UrlbarPrefs.get("delay"));
       if (!this.pending)
         return;
+
+      // If the heuristic result is a search engine result with an alias and an
+      // empty query, then we're done.  We want to show only that single result
+      // as a clear hint that the user can continue typing to search.
+      if (this._searchEngineAliasHasEmptyQuery) {
+        this._cleanUpNonCurrentMatches(null, false);
+        this._autocompleteSearch.finishSearch(true);
+        return;
+      }
     }
 
     // Only add extension suggestions if the first token is a registered keyword
     // and the search string has characters after the first token.
     let extensionsCompletePromise = Promise.resolve();
     if (this._searchTokens.length > 0 &&
         ExtensionSearchHandler.isKeywordRegistered(this._searchTokens[0]) &&
         this._originalSearchString.length > this._searchTokens[0].length) {
@@ -1356,16 +1365,17 @@ Search.prototype = {
     let match = await PlacesSearchAutocompleteProvider.findMatchByAlias(alias);
     if (!match)
       return false;
 
     match.engineAlias = alias;
     let query = this._trimmedOriginalSearchString.substr(alias.length + 1);
 
     this._addSearchEngineMatch(match, query);
+    this._searchEngineAliasHasEmptyQuery = !query;
     if (!this._keywordSubstitute) {
       this._keywordSubstitute = match.resultDomain;
     }
     return true;
   },
 
   async _matchCurrentSearchEngine() {
     let match = await PlacesSearchAutocompleteProvider.getDefaultMatch();
@@ -1780,38 +1790,39 @@ Search.prototype = {
     this._usedURLs[index] = {key: urlMapKey, action, type: match.type};
     return { index, replace };
   },
 
   /**
    * Removes matches from a previous search, that are no more returned by the
    * current search
    * @param type
-   *        The UrlbarUtils.MATCH_GROUP to clean up.
+   *        The UrlbarUtils.MATCH_GROUP to clean up.  Pass null (or another
+   *        falsey value) to clean up all groups.
    * @param [optional] notify
    *        Whether to notify a result change.
    */
   _cleanUpNonCurrentMatches(type, notify = true) {
     if (this._previousSearchMatchTypes.length == 0 || !this.pending)
       return;
 
     let index = 0;
     let changed = false;
     if (!this._buckets) {
       // No match arrived yet, so any match of the given type should be removed
       // from the top.
       while (this._previousSearchMatchTypes.length &&
-             this._previousSearchMatchTypes[0] == type) {
+             (!type || this._previousSearchMatchTypes[0] == type)) {
         this._previousSearchMatchTypes.shift();
         this._result.removeMatchAt(0);
         changed = true;
       }
     } else {
       for (let bucket of this._buckets) {
-        if (bucket.type != type) {
+        if (type && bucket.type != type) {
           index += bucket.count;
           continue;
         }
         index += bucket.insertIndex;
 
         while (bucket.count > bucket.insertIndex) {
           this._result.removeMatchAt(index);
           changed = true;
--- a/toolkit/components/places/tests/unifiedcomplete/test_search_engine_alias.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_search_engine_alias.js
@@ -13,26 +13,24 @@ add_task(async function() {
   await PlacesTestUtils.addVisits([{ uri: histURI, title: "History entry" }]);
 
   for (let alias of ["get", "post"]) {
     await check_autocomplete({
       search: alias,
       searchParam: "enable-actions",
       matches: [ makeSearchMatch(alias, { engineName: `Aliased${alias.toUpperCase()}MozSearch`,
                                           searchQuery: "", alias, heuristic: true }),
-        { uri: histURI, title: "History entry" },
       ],
     });
 
     await check_autocomplete({
       search: `${alias} `,
       searchParam: "enable-actions",
       matches: [ makeSearchMatch(`${alias} `, { engineName: `Aliased${alias.toUpperCase()}MozSearch`,
                                                 searchQuery: "", alias, heuristic: true }),
-        { uri: histURI, title: "History entry" },
       ],
     });
 
     await check_autocomplete({
       search: `${alias} fire`,
       searchParam: "enable-actions",
       matches: [ makeSearchMatch(`${alias} fire`, { engineName: `Aliased${alias.toUpperCase()}MozSearch`,
                                                     searchQuery: "fire", alias, heuristic: true }),