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

Unified Diff: chrome/browser/autocomplete/autocomplete_edit.cc

Issue 3152029: Ctrl-based actions should take precedence over ctrl-enter (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Cleaning things up Created 10 years, 4 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
Index: chrome/browser/autocomplete/autocomplete_edit.cc
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index dc4fde383ce7f16495df23c161bc934d11bf6061..43062766a401672ae70057c69c092cd9ccaccbb4 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -170,7 +170,21 @@ void AutocompleteEditModel::GetDataForURLExport(GURL* url,
}
std::wstring AutocompleteEditModel::GetDesiredTLD() const {
- return (control_key_state_ == DOWN_WITHOUT_CHANGE) ?
+ // Tricky corner case: The user has typed "foo" and currently sees an inline
+ // autocomplete suggestion of "foo.net". He now presses ctrl-a (e.g. to
+ // select all, on Windows). If we treat the ctrl press as potentially for the
+ // sake of ctrl-enter, then we risk "www.foo.com" being promoted as the best
+ // match. This would make the autocompleted text disappear, leaving our user
+ // feeling very confused when the wrong text gets highlighted.
+ //
+ // Thus, we only treat the user as pressing ctrl-enter when the user presses
+ // ctrl without any fragile state built up in the omnibox:
+ // * the contents of the omnibox have not changed since the keypress,
+ // * there is no autocompleted text visible, and
+ // * the user is not typing a keyword query.
+ return (control_key_state_ == DOWN_WITHOUT_CHANGE &&
+ inline_autocomplete_text_.empty() &&
+ !KeywordIsSelected())?
Peter Kasting 2010/08/25 01:35:07 Nit: Put as many conditions on one line as possibl
std::wstring(L"com") : std::wstring();
}
@@ -705,18 +719,21 @@ void AutocompleteEditModel::InternalSetUserText(const std::wstring& text) {
inline_autocomplete_text_.clear();
}
+bool AutocompleteEditModel::KeywordIsSelected() const {
+ return ((keyword_ui_state_ != NO_KEYWORD) && !is_keyword_hint_ &&
+ !keyword_.empty());
+}
+
std::wstring AutocompleteEditModel::DisplayTextFromUserText(
const std::wstring& text) const {
- return ((keyword_ui_state_ == NO_KEYWORD) || is_keyword_hint_ ||
- keyword_.empty()) ?
- text : KeywordProvider::SplitReplacementStringFromInput(text);
+ return KeywordIsSelected() ?
+ KeywordProvider::SplitReplacementStringFromInput(text) : text;
}
std::wstring AutocompleteEditModel::UserTextFromDisplayText(
const std::wstring& text) const {
- return ((keyword_ui_state_ == NO_KEYWORD) || is_keyword_hint_ ||
- keyword_.empty()) ?
- text : (keyword_ + L" " + text);
+ return KeywordIsSelected() ?
Peter Kasting 2010/08/25 01:35:07 Nit: This will all fit on one line.
+ (keyword_ + L" " + text) : text;
}
void AutocompleteEditModel::GetInfoForCurrentText(
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit.h ('k') | chrome/browser/autocomplete/history_url_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698