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,15 +389,31 @@ AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( ...@@ -388,15 +389,31 @@ 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);
DCHECK(is_search_type != match.keyword.empty());
// True if input is in keyword mode and the match is a URL suggestion or the
// match has a different keyword.
bool would_cause_leaving_keyboard_mode =
input.prefer_keyword() &&
(!is_search_type ||
!base::StartsWith(base::UTF16ToUTF8(input.text()),
base::StrCat({base::UTF16ToUTF8(match.keyword), " "}),
base::CompareCase::INSENSITIVE_ASCII));
if (!would_cause_leaving_keyboard_mode) {
if (is_search_type) { if (is_search_type) {
if (match.fill_into_edit.size() >= input.text().size() && if (match.fill_into_edit.size() >= input.text().size() &&
std::equal(match.fill_into_edit.begin(), std::equal(match.fill_into_edit.begin(),
...@@ -421,6 +438,7 @@ AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( ...@@ -421,6 +438,7 @@ AutocompleteMatch ShortcutsProvider::ShortcutToACMatch(
match.inline_autocompletion.empty(); match.inline_autocompletion.empty();
} }
} }
}
// Try to mark pieces of the contents and description as matches if they // Try to mark pieces of the contents and description as matches if they
// appear in |input.text()|. // appear in |input.text()|.
......
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