Index: chrome/browser/ui/omnibox/omnibox_edit_model.cc |
diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
index 07bf79223be4616fa43130cd3150f59ebe2b5a3b..6bc5f55516575055c84c2d338df019116994df3d 100644 |
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc |
@@ -902,16 +902,38 @@ bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { |
else |
StartAutocomplete(false, true, true); |
- // 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; |
- const AutocompleteMatch& match = CurrentMatch(NULL); |
- original_url_ = match.destination_url; |
- view_->OnTemporaryTextMaybeChanged( |
- DisplayTextFromUserText(match.fill_into_edit), |
- save_original_selection, true); |
+ // When entering keyword mode via tab, the new text to show is whatever the |
+ // newly-selected match in the dropdown is. When entering via space, however, |
+ // we should make sure to use the actual |user_text_| as the basis for the new |
+ // text. This ensures that if the user types "<keyword><space>" and the |
+ // default match would have inline autocompleted a further string (e.g. |
+ // because there's a past multi-word search beginning with this keyword), the |
+ // inline autocompletion doesn't get filled in as the keyword search query |
+ // text. |
+ // |
+ // We also treat tabbing into keyword mode like tabbing through the popup in |
+ // that we set |has_temporary_text_|, whereas pressing space is treated like |
+ // a new keystroke that changes the current match instead of overlaying it |
+ // with a temporary one. This is important because rerunning autocomplete |
+ // after the user pressed space, which will have happened just before reaching |
+ // here, may have generated a new match, which the user won't actually see and |
+ // which we don't want to switch back to when existing keyword mode; see |
+ // comments in ClearKeyword(). |
+ if (entered_method == ENTERED_KEYWORD_MODE_VIA_TAB) { |
+ // 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; |
+ const AutocompleteMatch& match = CurrentMatch(NULL); |
+ original_url_ = match.destination_url; |
+ view_->OnTemporaryTextMaybeChanged( |
+ DisplayTextFromUserText(match.fill_into_edit), |
+ save_original_selection, true); |
+ } else { |
+ view_->OnTemporaryTextMaybeChanged(DisplayTextFromUserText(user_text_), |
+ false, true); |
+ } |
view_->UpdatePlaceholderText(); |
@@ -936,10 +958,25 @@ void OmniboxEditModel::ClearKeyword() { |
const base::string16 window_text(keyword_ + view_->GetText()); |
- // Only reset the result if the edit text has changed since the |
- // keyword was accepted, or if the popup is closed. |
- if (!just_deleted_text_ && view_->GetText().empty() && popup_model() && |
- popup_model()->IsOpen()) { |
+ // If we've tabbed into keyword mode and haven't done anything else, |
+ // |has_temporary_text_| will be true, and we should just revert into keyword |
+ // hint mode; otherwise we do a more complete state update/revert via |
+ // OnBefore/AfterPossibleChange(). |
+ // |
+ // If we were to do the "complete state revert" all the time, then in cases |
+ // where our associated keyword match is in the middle of the popup instead of |
+ // on the first line, tabbing into it and then hitting shift-tab would reset |
+ // the entire popup contents, and we'd wind up with the first line selected. |
+ // |
+ // If we were instead to "just switch back to keyword hint mode" all the time, |
+ // we could wind up with strange state in some cases. For example, if a user |
+ // has a keyword named "x", an inline-autocompletable history site "xyz.com", |
+ // and a lower-ranked inline-autocompletable search "x y", then typing "x" |
+ // will inline autocomplete to "xyz.com", hitting space will toggle into |
+ // keyword mode, but then hitting backspace might wind up with the default |
+ // match as the "x y" search, due to the particulars of how we re-run |
+ // autocomplete for "x " before toggling into keyword mode to begin with. |
+ if (has_temporary_text_) { |
is_keyword_hint_ = true; |
view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
false, true); |
@@ -1412,7 +1449,6 @@ bool OmniboxEditModel::MaybeAcceptKeywordBySpace( |
const base::string16& new_text) { |
size_t keyword_length = new_text.length() - 1; |
return (paste_state_ == NONE) && is_keyword_hint_ && |
- inline_autocomplete_text_.empty() && |
(keyword_.length() == keyword_length) && |
IsSpaceCharForAcceptingKeyword(new_text[keyword_length]) && |
!new_text.compare(0, keyword_length, keyword_, 0, keyword_length) && |