Bug 1537712 - Listen for key modifiers in json view hotkeys r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D160148
This commit is contained in:
Zachary Svoboda 2022-10-26 19:08:18 +00:00
parent 56139a3664
commit 15b7791200
2 changed files with 20 additions and 12 deletions

View file

@ -62,7 +62,7 @@ add_task(async function() {
".jsonPanelBox .panelContent" ".jsonPanelBox .panelContent"
); );
ok(scroller.scrollTop > 0, "Not scrolled to the top."); ok(scroller.scrollTop > 0, "Not scrolled to the top.");
// Synthetize up arrow key to select first row. // Synthesize up arrow key to select first row.
content.document.querySelector(".treeTable").focus(); content.document.querySelector(".treeTable").focus();
}); });
await BrowserTestUtils.synthesizeKey("VK_UP", {}, tab.linkedBrowser); await BrowserTestUtils.synthesizeKey("VK_UP", {}, tab.linkedBrowser);
@ -92,7 +92,7 @@ add_task(async function() {
await clickJsonNode(".treeRow:first-child"); await clickJsonNode(".treeRow:first-child");
await assertRowSelected(1); await assertRowSelected(1);
// Synthetize multiple down arrow keydowns to select following rows. // Synthesize multiple down arrow keydowns to select following rows.
await SpecialPowers.spawn(tab.linkedBrowser, [], function() { await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
content.document.querySelector(".treeTable").focus(); content.document.querySelector(".treeTable").focus();
}); });
@ -105,12 +105,22 @@ add_task(async function() {
await assertRowSelected(i); await assertRowSelected(i);
} }
// Now synthetize the keyup, this shouldn't change selected row. // Now synthesize the keyup, this shouldn't change selected row.
await BrowserTestUtils.synthesizeKey( await BrowserTestUtils.synthesizeKey(
"VK_DOWN", "VK_DOWN",
{ type: "keyup" }, { type: "keyup" },
tab.linkedBrowser tab.linkedBrowser
); );
await wait(500);
await assertRowSelected(numRows - 1);
// Finally, synthesize keydown with a modifier, this also shouldn't change selected row.
await BrowserTestUtils.synthesizeKey(
"VK_DOWN",
{ type: "keydown", shiftKey: true },
tab.linkedBrowser
);
await wait(500);
await assertRowSelected(numRows - 1); await assertRowSelected(numRows - 1);
}); });

View file

@ -345,14 +345,14 @@ define(function(require, exports, module) {
// eslint-disable-next-line complexity // eslint-disable-next-line complexity
onKeyDown(event) { onKeyDown(event) {
const keyEligibleForFirstLetterNavigation = const keyEligibleForFirstLetterNavigation = event.key.length === 1;
event.key.length === 1 &&
!event.ctrlKey &&
!event.metaKey &&
!event.altKey;
if ( if (
!SUPPORTED_KEYS.includes(event.key) && (!SUPPORTED_KEYS.includes(event.key) &&
!keyEligibleForFirstLetterNavigation !keyEligibleForFirstLetterNavigation) ||
event.shiftKey ||
event.ctrlKey ||
event.metaKey ||
event.altKey
) { ) {
return; return;
} }
@ -413,14 +413,12 @@ define(function(require, exports, module) {
this.selectRow(firstRow, { alignTo: "top" }); this.selectRow(firstRow, { alignTo: "top" });
} }
break; break;
case "End": case "End":
const lastRow = rows[rows.length - 1]; const lastRow = rows[rows.length - 1];
if (lastRow) { if (lastRow) {
this.selectRow(lastRow, { alignTo: "bottom" }); this.selectRow(lastRow, { alignTo: "bottom" });
} }
break; break;
case "Enter": case "Enter":
case " ": case " ":
// On space or enter make selected row active. This means keyboard // On space or enter make selected row active. This means keyboard