Bug 1162140 - Allow user to select search suggestions in Awesome Bar. r=adw

This commit is contained in:
Marco Bonardo 2015-06-11 13:20:46 -07:00
parent ef17d64c59
commit 0591e76929
4 changed files with 37 additions and 19 deletions

View File

@ -966,7 +966,7 @@ Search.prototype = {
match.engineAlias = alias;
let query = this._searchTokens.slice(1).join(" ");
yield this._addSearchEngineMatch(match, query);
this._addSearchEngineMatch(match, query);
return true;
},
@ -976,16 +976,17 @@ Search.prototype = {
return;
let query = this._originalSearchString;
yield this._addSearchEngineMatch(match, query);
this._addSearchEngineMatch(match, query);
},
_addSearchEngineMatch: function* (match, query) {
_addSearchEngineMatch(match, query, suggestion) {
let actionURLParams = {
engineName: match.engineName,
input: this._originalSearchString,
searchQuery: query,
};
if (suggestion)
actionURLParams.searchSuggestion = suggestion;
if (match.engineAlias) {
actionURLParams.alias = match.engineAlias;
}

View File

@ -11,3 +11,7 @@
image-rendering: -moz-crisp-edges;
}
}
richlistitem > .ac-title-box > .ac-title > .ac-comment:not([selected]) > html|span.ac-selected-text {
display: none;
}

View File

@ -1539,11 +1539,10 @@ extends="chrome://global/content/bindings/popup.xml#popup">
let index = (match[1] || 1) - 1;
if (index >= 0 && index < aReplacements.length) {
let replacement = aReplacements[index];
pairs.push([...replacement]);
pairs.push([...aReplacements[index]]);
}
} else {
pairs.push([part, false]);
pairs.push([part]);
}
}
@ -1572,8 +1571,15 @@ extends="chrome://global/content/bindings/popup.xml#popup">
if (emphasise) {
let span = aDescriptionElement.appendChild(
document.createElementNS("http://www.w3.org/1999/xhtml", "span"));
span.className = "ac-emphasize-text";
span.textContent = text;
switch(emphasise) {
case "match":
span.className = "ac-emphasize-text";
break;
case "selected":
span.className = "ac-selected-text";
break;
}
} else {
aDescriptionElement.appendChild(document.createTextNode(text));
}
@ -1629,10 +1635,22 @@ extends="chrome://global/content/bindings/popup.xml#popup">
} else if (action.type == "searchengine") {
emphasiseUrl = false;
let sourceStr = this._stringBundle.GetStringFromName("searchWithEngineForQuery");
title = this._generateEmphasisPairs(sourceStr, [
[action.params.engineName, false],
[action.params.searchQuery, true]
// The order here is not localizable, we default to appending
// "- Search with Engine" to the search string, to be able to
// properly generate emphasis pairs. That said, no localization
// changed the order while it was possible, so doesn't look like
// there's a strong need for that.
let {engineName, searchSuggestion, searchQuery} = action.params;
let engineStr = "- " +
this._stringBundle.formatStringFromName("searchWithEngine",
[engineName], 1);
let suggestedPart = "";
if (searchSuggestion) {
suggestedPart = searchSuggestion.substr(searchQuery.length);
}
title = this._generateEmphasisPairs(`%1$S${suggestedPart} %2$S`, [
[searchQuery, "match"],
[engineStr, "selected"],
]);
// If this is a default search match, we remove the image so we
// can style it ourselves with a generic search icon.
@ -1649,7 +1667,7 @@ extends="chrome://global/content/bindings/popup.xml#popup">
let sourceStr = this._stringBundle.GetStringFromName("visitURL");
title = this._generateEmphasisPairs(sourceStr, [
[displayUrl, true],
[displayUrl, "match"],
]);
}
@ -1679,7 +1697,7 @@ extends="chrome://global/content/bindings/popup.xml#popup">
let sourceStr = this._stringBundle.GetStringFromName("visitURL");
title = this._generateEmphasisPairs(sourceStr, [
[displayUrl, true],
[displayUrl, "match"],
]);
types.delete("autofill");

View File

@ -6,11 +6,6 @@
# the search engine provider's name. This format was chosen because
# the provider can also end with "Search" (e.g.: MSN Search).
searchWithEngine = Search with %S
# LOCALIZATION NOTE (searchWithEngineForQuery):
# %1$S is the search engine's name, %2$S is the search query.
# This format was chosen because the provider can also end with "Search"
# (e.g.: MSN Search).
searchWithEngineForQuery = %2$S — Search with %1$S
switchToTab = Switch to tab
# LOCALIZATION NOTE (visitURL):
# %S is the URL to visit.