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

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

Issue 11414303: Make Google Search autocomplete provider cursor aware. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years 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
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 507cf65f7607a73e37b5aaf18539d81a6ec9ac27..15b7f25c8ebe8fb43b056e1204840188df0e3866 100644
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
@@ -456,15 +456,34 @@ void OmniboxEditModel::StartAutocomplete(
bool keyword_is_selected = KeywordIsSelected();
popup_->SetHoveredLine(OmniboxPopupModel::kNoMatch);
+
+ size_t cursor_position;
+ if (inline_autocomplete_text_.empty()) {
+ // Cursor position is equivalent to the current selection's end.
+ size_t start;
+ view_->GetSelectionBounds(&start, &cursor_position);
+ } else {
+ // There are some cases where StartAutocomplete() may be called
+ // with non-empty |inline_autocomplete_text_|. In such cases, we cannot
+ // use the current selection, because it could result with the cursor
+ // position past the last character from the user text. Instead,
Peter Kasting 2012/12/18 03:01:01 In theory, inline autocompletions are supposed to
Bart N. 2012/12/18 23:47:39 Yes. See http://crbug.com/165961. I've updated the
+ // we assume that the cursor is simply at the end of input.
+ // One example is when user presses Ctrl key while having a highlighted
+ // inline autocomplete text.
+ // TODO: Rethink how we are going to handle this case to avoid
+ // inconsistent behavior when user presses Ctrl key.
+ cursor_position = user_text_.length();
+ }
+
// We don't explicitly clear OmniboxPopupModel::manually_selected_match, as
// Start ends up invoking OmniboxPopupModel::OnResultChanged which clears it.
- autocomplete_controller_->Start(
- user_text_, GetDesiredTLD(),
+ autocomplete_controller_->Start(AutocompleteInput(
+ user_text_, cursor_position, GetDesiredTLD(),
prevent_inline_autocomplete || just_deleted_text_ ||
(has_selected_text && inline_autocomplete_text_.empty()) ||
(paste_state_ != NONE), keyword_is_selected,
keyword_is_selected || allow_exact_keyword_match_,
- AutocompleteInput::ALL_MATCHES);
+ AutocompleteInput::ALL_MATCHES));
}
void OmniboxEditModel::StopAutocomplete() {

Powered by Google App Engine
This is Rietveld 408576698