Commit 0fdf0936 authored by sreeram@chromium.org's avatar sreeram@chromium.org

Fix handling of inline autocomplete text vis-a-vis Instant.

Consider the following scenario:
1. Type "g" in the omnibox.
--> The omnibox inline autocompletes "oogle.com".
2. Hit Tab.
--> You're now in keyword mode.

Here, inline_autocomplete_text_ is still "oogle.com", though the display text
is a blank string. The previous code caused a crash. Now, we check properly
that the inline text is a suffix of the display text.

Arguably, the inline text should always be a suffix of the display text, say by
clearing it in OmniboxEditModel::AcceptKeyword(): http://crbug.com/141890

R=pkasting@google.com
BUG=141878
TEST=Scenario in CL description above shouldn't crash.

Review URL: https://chromiumcodereview.appspot.com/10824261

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151146 0039d316-1c4b-4281-b951-d872f2087c98
parent 59e82f0e
......@@ -649,10 +649,11 @@ bool OmniboxEditModel::AcceptKeyword() {
// Ensure the current selection is saved before showing keyword mode
// so that moving to another line and then reverting the text will restore
// the current state properly.
bool save_original_selection = !has_temporary_text_;
has_temporary_text_ = true;
view_->OnTemporaryTextMaybeChanged(
DisplayTextFromUserText(CurrentMatch().fill_into_edit),
!has_temporary_text_);
has_temporary_text_ = true;
save_original_selection);
content::RecordAction(UserMetricsAction("AcceptedKeywordHint"));
return true;
......@@ -1120,19 +1121,25 @@ bool OmniboxEditModel::DoInstant(
return false;
if (user_input_in_progress_ && popup_->IsOpen()) {
string16 text = view_->GetText();
AutocompleteInput::RemoveForcedQueryStringIfNecessary(
autocomplete_controller_->input().type(), &text);
// If there's any inline autocompletion, split it out from |text|.
if (!inline_autocomplete_text_.empty()) {
DCHECK_GE(text.size(), inline_autocomplete_text_.size());
text.resize(text.size() - inline_autocomplete_text_.size());
*suggested_text = inline_autocomplete_text_;
// The two pieces of text we want to send Instant, viz., what the user has
// typed, and any inline autocomplete suggestion.
string16 user_text = user_text_;
*suggested_text = inline_autocomplete_text_;
// If there's temporary text, that overrides the user_text. In this case, we
// should ignore any inline_autocomplete_text_, because it won't be visible.
if (has_temporary_text_) {
user_text = CurrentMatch().fill_into_edit;
suggested_text->clear();
}
return instant->Update(match, text, UseVerbatimInstant(), suggested_text,
complete_behavior);
// Remove any keywords and "?" prefix.
user_text = DisplayTextFromUserText(user_text);
AutocompleteInput::RemoveForcedQueryStringIfNecessary(
autocomplete_controller_->input().type(), &user_text);
return instant->Update(match, user_text, UseVerbatimInstant(),
suggested_text, complete_behavior);
}
// It's possible DoInstant() was called due to an OnChanged() event from the
......
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