Chromium Code Reviews| Index: components/omnibox/browser/omnibox_edit_model.cc |
| diff --git a/components/omnibox/browser/omnibox_edit_model.cc b/components/omnibox/browser/omnibox_edit_model.cc |
| index a20b4a8f0791917444cee9256fb95c18f77f2344..1970ce62e01dfaa6950d6d19687ce9329bd76a19 100644 |
| --- a/components/omnibox/browser/omnibox_edit_model.cc |
| +++ b/components/omnibox/browser/omnibox_edit_model.cc |
| @@ -410,41 +410,19 @@ void OmniboxEditModel::StartAutocomplete(bool has_selected_text, |
| bool prevent_inline_autocomplete) { |
| const base::string16 input_text = MaybePrependKeyword(user_text_); |
| - // Compute the cursor position. There are three cases: |
| - // 1. The user is in the midst of typing; there is no inline autocompletion. |
| - // 2. The user is in the midst of typing; there is inline autocompletion. |
| - // 3. The user is not in the midst of typing, but is triggering this some |
| - // other way, e.g. hitting ctrl-K while the view is showing the permanent |
| - // or temporary text. |
| - size_t cursor_position; |
| - if (!has_temporary_text_ && (user_text_ == view_->GetText())) { |
| - // Case 1 above. In this case there's a meaningful current cursor position, |
| - // so we read it from the view. (Note that if there is a selected range, |
| - // the "cursor position" is considered to be the selection's end.) |
| - size_t start; |
| - view_->GetSelectionBounds(&start, &cursor_position); |
| + size_t start, cursor_position; |
| + view_->GetSelectionBounds(&start, &cursor_position); |
| - // For keyword searches, the text that AutocompleteInput expects is of the |
| - // form "<keyword> <query>", where our query is |user_text_|. So we need to |
| - // adjust the cursor position forward by the length of any keyword added by |
| - // MaybePrependKeyword() above. |
| + // For keyword searches, the text that AutocompleteInput expects is |
| + // of the form "<keyword> <query>", where our query is |user_text_|. |
| + // So we need to adjust the cursor position forward by the length of |
| + // any keyword added by MaybePrependKeyword() above. |
| + if (is_keyword_selected()) |
| cursor_position += input_text.length() - user_text_.length(); |
| - } else { |
| - // Case 2 or 3 above. In case 2, the existing inline autocompletion will be |
| - // ignored for this next autocomplete run. The current cursor position is |
| - // always effectively "the end of the input text". (If the user changes |
| - // this cursor position by arrowing, it will accept the inline |
| - // autocompletion, which would put us in case 1.) In case 3, there is no |
| - // meaningful current cursor position; the correct default behavior is to |
| - // simply claim the cursor is at the end of the input. |
| - cursor_position = input_text.length(); |
| - } |
| - GURL current_url; |
| - if (client_->CurrentPageExists()) |
| - current_url = client_->GetURL(); |
| input_ = AutocompleteInput( |
| - input_text, cursor_position, std::string(), current_url, ClassifyPage(), |
| + input_text, cursor_position, std::string(), |
| + client_->CurrentPageExists() ? client_->GetURL() : GURL(), ClassifyPage(), |
|
Peter Kasting
2016/10/25 02:46:33
Seems like this isn't the only place that does thi
Tom (Use chromium acct)
2016/10/25 18:50:31
Done.
|
| prevent_inline_autocomplete || just_deleted_text_ || |
| (has_selected_text && inline_autocomplete_text_.empty()) || |
| (paste_state_ != NONE), |
| @@ -560,13 +538,29 @@ void OmniboxEditModel::EnterKeywordModeForDefaultSearchProvider( |
| KeywordModeEntryMethod entry_method) { |
| autocomplete_controller()->Stop(false); |
| - user_input_in_progress_ = true; |
| - keyword_ = client_->GetTemplateURLService()-> |
| - GetDefaultSearchProvider()->keyword(); |
| + switch (entry_method) { |
| + case KeywordModeEntryMethod::KEYBOARD_SHORTCUT: |
|
Tom (Use chromium acct)
2016/10/25 02:11:08
I don't know if it's better for EnterKeywordModeFo
|
| + view_->SetUserText( |
| + user_input_in_progress_ ? view_->GetText() : base::string16(), false); |
| + view_->SelectAll(false); |
|
Peter Kasting
2016/10/25 02:46:33
Nit: Personally I'd write this as a call to the Mo
Tom (Use chromium acct)
2016/10/25 18:50:31
The doc on SetUserText says only the view should c
|
| + break; |
| + case KeywordModeEntryMethod::QUESTION_MARK: |
| + DCHECK_EQ(base::ASCIIToUTF16("?"), view_->GetText().substr(0, 1)); |
| + view_->SetUserText(view_->GetText().substr(1), false); |
|
Peter Kasting
2016/10/25 02:46:33
No reason for "view_->" on this, that's just a wra
Tom (Use chromium acct)
2016/10/25 18:50:31
Ok, done. I've also made the changes above. I us
|
| + view_->SetWindowTextAndCaretPos(view_->GetText(), 0, false, false); |
|
Tom (Use chromium acct)
2016/10/25 02:11:08
It would be useful if OmniboxView had a SetUserTex
Peter Kasting
2016/10/25 02:46:33
I don't think so, but we can revisit after respond
|
| + break; |
| + default: |
| + NOTREACHED(); |
| + } |
| + |
| + keyword_ = |
| + client_->GetTemplateURLService()->GetDefaultSearchProvider()->keyword(); |
| is_keyword_hint_ = false; |
| keyword_mode_entry_method_ = entry_method; |
|
Peter Kasting
2016/10/25 02:46:33
Nit: I would move this block above the switch. Se
|
| - StartAutocomplete(false, false); |
| + size_t sel_start, sel_end; |
| + view_->GetSelectionBounds(&sel_start, &sel_end); |
| + StartAutocomplete(sel_start != sel_end, false); |
|
Peter Kasting
2016/10/25 02:46:33
The primary difference between this and just calli
Tom (Use chromium acct)
2016/10/25 18:50:31
I'd argue we want the UpdatePopup() behavior becau
|
| UMA_HISTOGRAM_ENUMERATION( |
| kEnteredKeywordModeHistogram, static_cast<int>(entry_method), |
| @@ -1216,11 +1210,8 @@ bool OmniboxEditModel::OnAfterPossibleChange( |
| // If the user input a "?" at the beginning of the text, put them into |
| // keyword mode for their default search provider. |
| if ((state_changes.new_sel_start == 1) && (user_text_[0] == '?')) { |
| - view_->SetUserText(user_text_.substr(1)); |
| EnterKeywordModeForDefaultSearchProvider( |
| KeywordModeEntryMethod::QUESTION_MARK); |
| - // Set the caret position to 0 without changing the user text. |
| - view_->SetWindowTextAndCaretPos(view_->GetText(), 0, false, false); |
| return false; |
| } |