Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Unified Diff: chrome/browser/autocomplete/autocomplete_controller.cc

Issue 440753003: Omnibox: Make Exact Match Tab-to-Search Work (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: peter's comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_provider_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/autocomplete_controller.cc
diff --git a/chrome/browser/autocomplete/autocomplete_controller.cc b/chrome/browser/autocomplete/autocomplete_controller.cc
index f7771443dc70cf78a6874adce3062993c76f767c..6ca1105f29cdb80edcd4e789a8047976efb5927f 100644
--- a/chrome/browser/autocomplete/autocomplete_controller.cc
+++ b/chrome/browser/autocomplete/autocomplete_controller.cc
@@ -504,6 +504,10 @@ void AutocompleteController::UpdateAssociatedKeywords(
if (!keyword_provider_)
return;
+ // Determine if the user's input is an exact keyword match.
+ base::string16 exact_keyword = keyword_provider_->GetKeywordForText(
+ TemplateURLService::CleanUserInputKeyword(input_.text()));
+
std::set<base::string16> keywords;
for (ACMatches::iterator match(result->begin()); match != result->end();
++match) {
@@ -514,18 +518,30 @@ void AutocompleteController::UpdateAssociatedKeywords(
continue;
}
+ // When the user has typed an exact keyword, we want tab-to-search on the
+ // default match to select that keyword, even if the match
+ // inline-autocompletes to a different keyword. (This prevents inline
+ // autocompletions from blocking a user's attempts to use an explicitly-set
+ // keyword of their own creation.) So use |exact_keyword| if it's
+ // available.
+ if (!exact_keyword.empty() && !keywords.count(exact_keyword)) {
+ keywords.insert(exact_keyword);
+ match->associated_keyword.reset(new AutocompleteMatch(
+ keyword_provider_->CreateVerbatimMatch(exact_keyword,
+ exact_keyword, input_)));
+ continue;
+ }
+
+ // Otherwise use the particular match's associated keyword.
Peter Kasting 2014/08/04 22:53:11 Nit: This comment is now somewhat misleading as yo
Mark P 2014/08/04 22:58:24 Done. I see why it's better. Thank you for rewri
+ keyword = keyword_provider_->GetKeywordForText(match->fill_into_edit);
+
// Only add the keyword if the match does not have a duplicate keyword with
// a more relevant match.
- keyword = match->associated_keyword.get() ?
- match->associated_keyword->keyword :
- keyword_provider_->GetKeywordForText(match->fill_into_edit);
if (!keyword.empty() && !keywords.count(keyword)) {
keywords.insert(keyword);
-
- if (!match->associated_keyword.get())
- match->associated_keyword.reset(new AutocompleteMatch(
- keyword_provider_->CreateVerbatimMatch(match->fill_into_edit,
- keyword, input_)));
+ match->associated_keyword.reset(new AutocompleteMatch(
+ keyword_provider_->CreateVerbatimMatch(match->fill_into_edit,
+ keyword, input_)));
} else {
match->associated_keyword.reset();
}
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698