Index: chrome/browser/autocomplete/autocomplete_edit.cc |
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc |
index ff2d5d3c6a18c62addbf1b20151cf5ecbf4c581b..2264f0b7f230f858797eaa3b3975d3e5390f5916 100644 |
--- a/chrome/browser/autocomplete/autocomplete_edit.cc |
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc |
@@ -629,9 +629,11 @@ bool AutocompleteEditModel::OnAfterPossibleChange( |
else if (text_differs) |
paste_state_ = NONE; |
+ const bool had_inline_autocomplete = !inline_autocomplete_text_.empty(); |
Peter Kasting
2011/01/25 02:12:22
Nit: You can roll this back into the statement bel
James Su
2011/01/25 02:52:48
Done.
|
+ |
// Modifying the selection counts as accepting the autocompleted text. |
const bool user_text_changed = |
- text_differs || (selection_differs && !inline_autocomplete_text_.empty()); |
+ text_differs || (selection_differs && had_inline_autocomplete); |
// If something has changed while the control key is down, prevent |
// "ctrl-enter" until the control key is released. When we do this, we need |
@@ -645,20 +647,12 @@ bool AutocompleteEditModel::OnAfterPossibleChange( |
return false; |
} |
+ const std::wstring old_user_text = user_text_; |
// If the user text has not changed, we do not want to change the model's |
// state associated with the text. Otherwise, we can get surprising behavior |
// where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 |
if (user_text_changed) { |
- const std::wstring new_user_text = UserTextFromDisplayText(new_text); |
- |
- // Try to accept the current keyword if the user only typed a space at the |
- // end of content. Model's state and popup will be updated when the keyword |
- // is accepted. So we just need to return false here. |
- if (allow_keyword_ui_change && !selection_differs && |
- MaybeAcceptKeywordBySpace(new_user_text)) |
- return false; |
- |
- InternalSetUserText(new_user_text); |
+ InternalSetUserText(UserTextFromDisplayText(new_text)); |
has_temporary_text_ = false; |
// Track when the user has deleted text so we won't allow inline |
@@ -667,6 +661,14 @@ bool AutocompleteEditModel::OnAfterPossibleChange( |
} |
view_->UpdatePopup(); |
+ |
+ // Try to accept the current keyword if the user only typed a space at the |
Peter Kasting
2011/01/25 02:12:22
Nit: This comment might now be more accurate as:
James Su
2011/01/25 02:52:48
Done.
|
+ // end of content. Model's state and popup will be updated when the keyword |
+ // is accepted. So we just need to return false here. |
+ if (text_differs && allow_keyword_ui_change && !just_deleted_text && |
Peter Kasting
2011/01/25 02:12:22
Nit: Even more condensed:
return !text_differs
James Su
2011/01/25 02:52:48
I'd prefer to keep the old one, which is more read
Peter Kasting
2011/01/25 04:25:48
Then how about this:
return !(text_differs && a
|
+ MaybeAcceptKeywordBySpace(old_user_text, user_text_)) |
+ return false; |
+ |
return true; |
} |
@@ -782,13 +784,16 @@ bool AutocompleteEditModel::GetURLForText(const std::wstring& text, |
} |
bool AutocompleteEditModel::MaybeAcceptKeywordBySpace( |
+ const std::wstring& old_user_text, |
const std::wstring& new_user_text) { |
return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && |
- inline_autocomplete_text_.empty() && !user_text_.empty() && |
- (new_user_text.length() == user_text_.length() + 1) && |
- !new_user_text.compare(0, user_text_.length(), user_text_) && |
- IsSpaceCharForAcceptingKeyword(new_user_text[user_text_.length()]) && |
- !IsWhitespace(user_text_[user_text_.length() - 1]) && |
+ inline_autocomplete_text_.empty() && |
+ !old_user_text.empty() && new_user_text.length() >= 2 && |
Peter Kasting
2011/01/25 02:12:22
Nit: "!old_user_text.empty()" is unnecessary given
James Su
2011/01/25 02:52:48
Done.
|
+ (old_user_text.length() + 1 >= new_user_text.length()) && |
+ !new_user_text.compare(0, new_user_text.length() - 1, old_user_text, |
+ 0, new_user_text.length() - 1) && |
+ IsSpaceCharForAcceptingKeyword(new_user_text[new_user_text.length() - 1]) && |
Peter Kasting
2011/01/25 02:12:22
Nit: 80 columns.
Also, I think it'll be a littler
James Su
2011/01/25 02:52:48
Done.
|
+ !IsWhitespace(new_user_text[new_user_text.length() - 2]) && |
AcceptKeyword(); |
} |