Commit 8658da38 authored by Roman Arora's avatar Roman Arora Committed by Josip Sokcevic

Tab Search: Check for key modifiers before navigation

Check for key event modifires before triggering keyboard navigation.

Fixed: 1111003
Change-Id: Icccfc2938d4812974b628273edc7d68fc825a559
Reviewed-on: https://chrome-internal-review.googlesource.com/c/chrome/browser/resources/tab_search/+/3202978Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarTom Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819580}
parent 492cfe67
......@@ -145,35 +145,45 @@ export class TabSearchAppElement extends PolymerElement {
}
/**
* TODO(crbug.com/1111003): Check for the presence of modifiers before
* triggering a navigation.
* @param {!KeyboardEvent} e
* @private
*/
onKeyDown_(e) {
if (this.selectedIndex_ !== -1) {
switch (e.key) {
case 'ArrowUp':
this.selectItem_(-1);
break;
case 'ArrowDown':
this.selectItem_(1);
break;
case 'Home':
this.selectItem_(-this.selectedIndex_);
break;
case 'End':
this.selectItem_(
this.filteredOpenTabs_.length - 1 - this.selectedIndex_);
break;
case 'Enter':
const selectedItem = this.filteredOpenTabs_[this.selectedIndex_];
this.apiProxy_.switchToTab({tabId: selectedItem.tabId});
break;
}
// Do not interfere with the search field's management of text selection.
if (e.shiftKey) {
return;
}
e.stopPropagation();
if (this.selectedIndex_ === -1) {
// No tabs matching the search text criteria.
return;
}
switch (e.key) {
case 'ArrowUp':
this.selectItem_(-1);
e.preventDefault();
break;
case 'ArrowDown':
this.selectItem_(1);
e.preventDefault();
break;
case 'Home':
this.selectItem_(-this.selectedIndex_);
e.preventDefault();
break;
case 'End':
this.selectItem_(
this.filteredOpenTabs_.length - 1 - this.selectedIndex_);
e.preventDefault();
break;
case 'Enter':
const selectedItem = this.filteredOpenTabs_[this.selectedIndex_];
this.apiProxy_.switchToTab({tabId: selectedItem.tabId});
break;
}
}
/**
......
......@@ -177,6 +177,18 @@ suite('TabSearchAppTest', () => {
assertEquals(0, tabSearchApp.getSelectedIndex());
});
test('Key with modifiers should not affect selected item', async () => {
await setupTest(sampleData());
const searchField = /** @type {!TabSearchSearchField} */
(tabSearchApp.shadowRoot.querySelector('#searchField'));
for (const key of ['ArrowUp', 'ArrowDown', 'Home', 'End']) {
keyDownOn(searchField, 0, ['shift'], key);
assertEquals(0, tabSearchApp.getSelectedIndex());
}
});
test('refresh on tabs changed', async () => {
await setupTest(sampleData());
verifyTabIds(queryRows(), [1, 5, 6, 2, 3, 4]);
......
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