Chromium Code Reviews| Index: chrome/browser/autocomplete/search_provider.cc |
| diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc |
| index 143e4661205fe63682dea1a77529a34811f1e0dd..6300cd3adf4c8b19c3ddcdd431f7cba04a2d8079 100644 |
| --- a/chrome/browser/autocomplete/search_provider.cc |
| +++ b/chrome/browser/autocomplete/search_provider.cc |
| @@ -109,13 +109,21 @@ void SetAndClassifyMatchContents(const base::string16& query_string, |
| const base::string16& match_contents, |
| AutocompleteMatch* match) { |
| match->contents = match_contents.empty() ? query_string : match_contents; |
| - |
| + base::string16 lookup_text = input_text; |
| + if (match->type == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { |
| + size_t content_index = query_string.rfind(match_contents); |
|
Scott Hess - ex-Googler
2013/12/14 00:40:57
I'm like 27% confident in this code (probably less
Mark P
2013/12/14 00:49:53
FYI, I'm confident it can appear multiple times.
Anuj
2013/12/16 02:53:19
Yes, match_contents can appear multiple times, but
Anuj
2013/12/16 02:53:19
Done.
Scott Hess - ex-Googler
2013/12/16 20:26:13
I'll defer to Mark. I was mostly concerned that y
|
| + if (content_index != base::string16::npos) { |
| + const base::string16 prefix = query_string.substr(0, content_index); |
| + lookup_text = input_text.find(prefix) == 0 ? |
| + input_text.substr(prefix.length()) : input_text; |
|
Scott Hess - ex-Googler
2013/12/14 00:40:57
std::string::find() will keep looking for |prefix|
Anuj
2013/12/16 02:53:19
Done.
|
| + } |
| + } |
| // We do intra-string highlighting for suggestions - the suggested segment |
| // will be highlighted, e.g. for input_text = "you" the suggestion may be |
| // "youtube", so we'll bold the "tube" section: you*tube*. |
| - if (input_text != match_contents) { |
| - size_t input_position = match->contents.find(input_text); |
| - if (input_position == base::string16::npos) { |
| + if (lookup_text != match_contents) { |
| + size_t lookup_position = match->contents.find(lookup_text); |
| + if (lookup_position == base::string16::npos) { |
| // The input text is not a substring of the query string, e.g. input |
| // text is "slasdot" and the query string is "slashdot", so we bold the |
| // whole thing. |
| @@ -129,13 +137,13 @@ void SetAndClassifyMatchContents(const base::string16& query_string, |
| // short as a single character highlighted in a query suggestion result, |
| // e.g. for input text "s" and query string "southwest airlines", it |
| // looks odd if both the first and last s are highlighted. |
| - if (input_position != 0) { |
| + if (lookup_position != 0) { |
| match->contents_class.push_back(ACMatchClassification( |
| 0, ACMatchClassification::MATCH)); |
| } |
| match->contents_class.push_back( |
| - ACMatchClassification(input_position, ACMatchClassification::NONE)); |
| - size_t next_fragment_position = input_position + input_text.length(); |
| + ACMatchClassification(lookup_position, ACMatchClassification::NONE)); |
| + size_t next_fragment_position = lookup_position + lookup_text.length(); |
| if (next_fragment_position < query_string.length()) { |
| match->contents_class.push_back(ACMatchClassification( |
| next_fragment_position, ACMatchClassification::MATCH)); |