Commit 81ac5803 authored by Daniel Zhang's avatar Daniel Zhang Committed by Commit Bot

cros: Fix autocomplete interaction with arrow keys

Currently, AppList autocomplete feature handles arrow
key events regardless of whether or not there is
autocomplete text present, causing unwanted
interactions.

Change autocomplete so that it only handles arrow keys
when autocomplete text is present.

Bug: 881039
Change-Id: I7041646e87e5cd4e95d6299017fa2259899f8994
Reviewed-on: https://chromium-review.googlesource.com/1208718Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Daniel Zhang <oxyflush@google.com>
Cr-Commit-Position: refs/heads/master@{#589582}
parent 7c48628d
......@@ -429,7 +429,7 @@ void SearchBoxView::AcceptAutocompleteText() {
if (!is_app_list_search_autocomplete_enabled_)
return;
if (highlight_range_.start() != search_box()->text().length())
if (HasAutocompleteText())
ContentsChanged(search_box(), search_box()->text());
}
......@@ -447,6 +447,15 @@ void SearchBoxView::AcceptOneCharInAutocompleteText() {
search_box()->SetSelectionRange(highlight_range_);
}
bool SearchBoxView::HasAutocompleteText() {
// If the selected range is non-empty, it will either be suggested by
// autocomplete or selected by the user. If the recorded autocomplete
// |highlight_range_| matches the selection range, this text is suggested by
// autocomplete.
return search_box()->GetSelectedRange() == highlight_range_ &&
highlight_range_.length() > 0;
}
void SearchBoxView::ClearAutocompleteText() {
if (!is_app_list_search_autocomplete_enabled_)
return;
......@@ -499,11 +508,13 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
key_event.key_code() != ui::VKEY_BACK) {
if (key_event.key_code() == ui::VKEY_TAB) {
AcceptAutocompleteText();
} else if (key_event.key_code() == ui::VKEY_UP ||
key_event.key_code() == ui::VKEY_DOWN ||
key_event.key_code() == ui::VKEY_LEFT ||
key_event.key_code() == ui::VKEY_RIGHT) {
} else if ((key_event.key_code() == ui::VKEY_UP ||
key_event.key_code() == ui::VKEY_DOWN ||
key_event.key_code() == ui::VKEY_LEFT ||
key_event.key_code() == ui::VKEY_RIGHT) &&
HasAutocompleteText()) {
ClearAutocompleteText();
return true;
} else {
const base::string16 pending_text = search_box()->GetSelectedText();
// Hitting the next key in the autocompete suggestion continues
......
......@@ -108,6 +108,10 @@ class APP_LIST_EXPORT SearchBoxView : public search_box::SearchBoxViewBase,
// Accepts one character in the autocomplete text and fires query.
void AcceptOneCharInAutocompleteText();
// Returns true if there is currently an autocomplete suggestion in
// search_box().
bool HasAutocompleteText();
// Removes all autocomplete text.
void ClearAutocompleteText();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment