Commit 5ee6563c authored by Demetrios Papadopoulos's avatar Demetrios Papadopoulos Committed by Commit Bot

History WebUI: Fix cmd/ctrl+a to select text when search box is focused.

Also adding a test to cover this case.

Fixed: 1031551
Change-Id: If4ea5b40e33fe9b21dbed78c665fcb60a43aadd4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1959467Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723631}
parent 3ebad3dd
......@@ -304,8 +304,7 @@ Polymer({
// <if expr="is_macosx">
hasTriggerModifier = !e.ctrlKey && e.metaKey;
// </if>
if (hasTriggerModifier) {
this.onSelectAllCommand_();
if (hasTriggerModifier && this.onSelectAllCommand_()) {
e.preventDefault();
}
}
......@@ -319,13 +318,17 @@ Polymer({
this.deleteSelected();
},
/** @private */
/**
* @return {boolean} Whether the command was actually triggered.
* @private
*/
onSelectAllCommand_: function() {
if (this.$.toolbar.searchField.isSearchFocused() ||
this.syncedTabsSelected_(this.selectedPage_)) {
return;
return false;
}
this.selectOrUnselectAll();
return true;
},
/**
......
......@@ -81,4 +81,41 @@ suite('<history-list>', function() {
assertFalse(items[2].row_.isActive());
assertTrue(items[3].row_.isActive());
});
test('selection of all items using ctrl + a', async function() {
app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS);
await test_util.flushTasks();
const toolbar = app.$.toolbar;
const field = toolbar.$['main-toolbar'].getSearchField();
field.blur();
assertFalse(field.showingSearch);
const modifier = cr.isMac ? 'meta' : 'ctrl';
let promise = test_util.eventToPromise('keydown', document);
MockInteractions.pressAndReleaseKeyOn(document.body, 65, modifier, 'a');
let keydownEvent = await promise;
assertTrue(keydownEvent.defaultPrevented);
assertDeepEquals(
[true, true, true, true], element.historyData_.map(i => i.selected));
// If everything is already selected, the same shortcut will trigger
// cancelling selection.
MockInteractions.pressAndReleaseKeyOn(document.body, 65, modifier, 'a');
assertDeepEquals(
[false, false, false, false],
element.historyData_.map(i => i.selected));
// If the search field is focused, the keyboard event should be handled by
// the browser (which triggers selection of the text within the search
// input).
field.getSearchInput().focus();
promise = test_util.eventToPromise('keydown', document);
MockInteractions.pressAndReleaseKeyOn(document.body, 65, modifier, 'a');
keydownEvent = await promise;
assertFalse(keydownEvent.defaultPrevented);
assertDeepEquals(
[false, false, false, false],
element.historyData_.map(i => i.selected));
});
});
......@@ -163,28 +163,6 @@ suite('<history-list>', function() {
});
});
test('selection of all items using ctrl + a', function() {
app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS);
return test_util.flushTasks().then(function() {
const field = toolbar.$['main-toolbar'].getSearchField();
field.blur();
assertFalse(field.showingSearch);
const modifier = cr.isMac ? 'meta' : 'ctrl';
MockInteractions.pressAndReleaseKeyOn(document.body, 65, modifier, 'a');
assertDeepEquals(
[true, true, true, true], element.historyData_.map(i => i.selected));
// If everything is already selected, the same shortcut will trigger
// cancelling selection.
MockInteractions.pressAndReleaseKeyOn(document.body, 65, modifier, 'a');
assertDeepEquals(
[false, false, false, false],
element.historyData_.map(i => i.selected));
});
});
// See http://crbug.com/845802.
test('disabling ctrl + a command on syncedTabs page', function() {
app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS);
......
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