Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5373)

Unified Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 11034019: Cursor jumps to end of omnibox when activating keyword mode via inserted space (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Patch Rebased Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « AUTHORS ('k') | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 66c483b4a171037f263e5361ee3b735c677b4b68..1a1b2ac16c48596b2df2c5beba4ccfe70fc06d60 100644
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
@@ -886,10 +886,30 @@ void OmniboxEditModel::OnPopupDataChanged(
bool call_controller_onchanged = true;
inline_autocomplete_text_ = text;
- if (view_->OnInlineAutocompleteTextMaybeChanged(
- DisplayTextFromUserText(user_text_ + inline_autocomplete_text_),
- DisplayTextFromUserText(user_text_).length()))
+
+ if (keyword_state_changed && KeywordIsSelected()) {
+ // If we reach here, the user most likely entered keyword mode by inserting
+ // a space between a keyword name and a search string (as pressing space or
+ // tab after the keyword name alone would have been be handled in
+ // MaybeAcceptKeywordBySpace() by calling AcceptKeyword(), which won't reach
+ // here). In this case, we don't want to call
+ // OnInlineAutocompleteTextMaybeChanged() as normal, because that will
+ // correctly change the text (to the search string alone) but move the caret
+ // to the end of the string; instead we want the caret at the start of the
+ // search string since that's where it was in the original input. So we set
+ // the text and caret position directly.
+ //
+ // It may also be possible to reach here if we're reverting from having
+ // temporary text back to a default match that's a keyword search, but in
+ // that case the RevertTemporaryText() call below will reset the caret or
+ // selection correctly so the caret positioning we do here won't matter.
+ view_->SetWindowTextAndCaretPos(DisplayTextFromUserText(user_text_), 0,
+ false, false);
+ } else if (view_->OnInlineAutocompleteTextMaybeChanged(
+ DisplayTextFromUserText(user_text_ + inline_autocomplete_text_),
+ DisplayTextFromUserText(user_text_).length())) {
call_controller_onchanged = false;
+ }
// If |has_temporary_text_| is true, then we previously had a manual selection
// but now don't (or |destination_for_temporary_text_change| would have been
« no previous file with comments | « AUTHORS ('k') | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698