Commit 6a600583 authored by manuk's avatar manuk Committed by Commit Bot

[Omnibox] When in keyword mode, don't allow shortcut matches of different...

[Omnibox] When in keyword mode, don't allow shortcut matches of different keywords to be the default match.

Prior to this cl, when the user has searched for `searchProvder searchTerm` (not in keyword mode) then typing in `searchProvider `, entering keyword mode, and typing `s` could result in the shortcut match for the earlier search becoming the default match and causing him to leave keyword mode.

Bug: 632215
Change-Id: I19ee38e3e5c9ee68f8f7703afccef1276027b521
Reviewed-on: https://chromium-review.googlesource.com/c/1182295
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597202}
parent f9bb833d
...@@ -41,7 +41,7 @@ struct TestShortcutData shortcut_test_db[] = { ...@@ -41,7 +41,7 @@ struct TestShortcutData shortcut_test_db[] = {
{"BD85DBA2-8C29-49F9-84AE-48E1E90880F1", "echo echo", "echo echo", {"BD85DBA2-8C29-49F9-84AE-48E1E90880F1", "echo echo", "echo echo",
"chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo", "chrome-extension://cedabbhfglmiikkmdgcpjdkocfcmbkee/?q=echo",
"Run Echo command: echo", "0,0", "Echo", "0,4", ui::PAGE_TRANSITION_TYPED, "Run Echo command: echo", "0,0", "Echo", "0,4", ui::PAGE_TRANSITION_TYPED,
AutocompleteMatchType::EXTENSION_APP_DEPRECATED, "echo", 1, 1}, AutocompleteMatchType::EXTENSION_APP_DEPRECATED, "", 1, 1},
}; };
} // namespace } // namespace
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -388,37 +389,54 @@ AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( ...@@ -388,37 +389,54 @@ AutocompleteMatch ShortcutsProvider::ShortcutToACMatch(
base::UTF16ToUTF8(shortcut.text)); base::UTF16ToUTF8(shortcut.text));
// Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible.
// If the match is a search query this is easy: simply check whether the // If the input is in keyword mode, navigation matches cannot be the default
// user text is a prefix of the query. If the match is a navigation, we // match, and search query matches can only be the default match if their
// assume the fill_into_edit looks something like a URL, so we use // keywords matches the input's keyword, as otherwise, default,
// URLPrefix::GetInlineAutocompleteOffset() to try and strip off any prefixes // different-keyword matches may result in leaving keyword mode. Additionally,
// that the user might not think would change the meaning, but would // if the match is a search query, check whether the user text is a prefix of
// otherwise prevent inline autocompletion. This allows, for example, the // the query. If the match is a navigation, we assume the fill_into_edit looks
// input of "foo.c" to autocomplete to "foo.com" for a fill_into_edit of // something like a URL, so we use URLPrefix::GetInlineAutocompleteOffset() to
// "http://foo.com". // try and strip off any prefixes that the user might not think would change
// the meaning, but would otherwise prevent inline autocompletion. This
// allows, for example, the input of "foo.c" to autocomplete to "foo.com" for
// a fill_into_edit of "http://foo.com".
const bool is_search_type = AutocompleteMatch::IsSearchType(match.type); const bool is_search_type = AutocompleteMatch::IsSearchType(match.type);
if (is_search_type) {
if (match.fill_into_edit.size() >= input.text().size() && DCHECK(is_search_type != match.keyword.empty());
std::equal(match.fill_into_edit.begin(),
match.fill_into_edit.begin() + input.text().size(), // True if input is in keyword mode and the match is a URL suggestion or the
input.text().begin(), // match has a different keyword.
SimpleCaseInsensitiveCompareUCS2())) { bool would_cause_leaving_keyboard_mode =
match.inline_autocompletion = input.prefer_keyword() &&
match.fill_into_edit.substr(input.text().length()); (!is_search_type ||
match.allowed_to_be_default_match = !base::StartsWith(base::UTF16ToUTF8(input.text()),
!input.prevent_inline_autocomplete() || base::StrCat({base::UTF16ToUTF8(match.keyword), " "}),
match.inline_autocompletion.empty(); base::CompareCase::INSENSITIVE_ASCII));
}
} else { if (!would_cause_leaving_keyboard_mode) {
const size_t inline_autocomplete_offset = if (is_search_type) {
URLPrefix::GetInlineAutocompleteOffset( if (match.fill_into_edit.size() >= input.text().size() &&
input.text(), fixed_up_input_text, true, match.fill_into_edit); std::equal(match.fill_into_edit.begin(),
if (inline_autocomplete_offset != base::string16::npos) { match.fill_into_edit.begin() + input.text().size(),
match.inline_autocompletion = input.text().begin(),
match.fill_into_edit.substr(inline_autocomplete_offset); SimpleCaseInsensitiveCompareUCS2())) {
match.allowed_to_be_default_match = match.inline_autocompletion =
!HistoryProvider::PreventInlineAutocomplete(input) || match.fill_into_edit.substr(input.text().length());
match.inline_autocompletion.empty(); match.allowed_to_be_default_match =
!input.prevent_inline_autocomplete() ||
match.inline_autocompletion.empty();
}
} else {
const size_t inline_autocomplete_offset =
URLPrefix::GetInlineAutocompleteOffset(
input.text(), fixed_up_input_text, true, match.fill_into_edit);
if (inline_autocomplete_offset != base::string16::npos) {
match.inline_autocompletion =
match.fill_into_edit.substr(inline_autocomplete_offset);
match.allowed_to_be_default_match =
!HistoryProvider::PreventInlineAutocomplete(input) ||
match.inline_autocompletion.empty();
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment