commit 0e1ef82c6a78224e66b9eadc343c35b4809db4e3
parent 112722bb97e564d07e3d0c306535fb016027b017
Author: James Teh <jteh@mozilla.com>
Date: Mon, 8 Dec 2025 06:42:29 +0000
Bug 2000013: about:keyboard: Fix assignment of the arrow keys. r=mossop
Previously, pressing the left arrow key would result in an invalid keycode of VK_ARROW_LEFT.
This is because the DOM key name is ArrowLeft, but for XUL, the key code is named VK_LEFT (no ARROW).
The same was true for the other three arrow keys.
For these cases, we first check a new map of DOM key names to key codes before resorting to ShortcutUtils.getKeycodeAttribute.
Differential Revision: https://phabricator.services.mozilla.com/D273952
Diffstat:
3 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/browser/components/customkeys/CustomKeysParent.sys.mjs b/browser/components/customkeys/CustomKeysParent.sys.mjs
@@ -6,6 +6,13 @@ import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { CustomKeys } from "resource:///modules/CustomKeys.sys.mjs";
import { ShortcutUtils } from "resource://gre/modules/ShortcutUtils.sys.mjs";
+const KEY_NAMES_TO_CODES = {
+ ArrowDown: "VK_DOWN",
+ ArrowLeft: "VK_LEFT",
+ ArrowRight: "VK_RIGHT",
+ ArrowUp: "VK_UP",
+};
+
/**
* Actor implementation for about:keyboard.
*/
@@ -191,7 +198,9 @@ export class CustomKeysParent extends JSWindowActorParent {
data.isValid = false;
}
} else {
- data.keycode = ShortcutUtils.getKeycodeAttribute(event.key);
+ data.keycode =
+ KEY_NAMES_TO_CODES[event.key] ??
+ ShortcutUtils.getKeycodeAttribute(event.key);
}
data.shortcut = this.prettifyShortcut(data);
this.sendAsyncMessage("CustomKeys:CapturedKey", data);
diff --git a/browser/components/customkeys/tests/browser/browser_aboutKeyboard.js b/browser/components/customkeys/tests/browser/browser_aboutKeyboard.js
@@ -749,3 +749,45 @@ addAboutKbTask(async function testFunctionKey(tab) {
});
CustomKeys.resetAll();
});
+
+// Test that changing to an arrow key works correctly.
+addAboutKbTask(async function testFunctionKey(tab) {
+ await SpecialPowers.spawn(tab, [consts], async _consts => {
+ content.backRow = content.document.querySelector(
+ '.key[data-id="goBackKb"]'
+ );
+ ok(
+ !content.backRow.classList.contains("customized"),
+ "goBackKb is not customized"
+ );
+ info("Clicking Change for goBackKb");
+ content.input = content.backRow.querySelector(".new");
+ let focused = ContentTaskUtils.waitForEvent(content.input, "focus");
+ content.change = content.backRow.querySelector(".change");
+ content.change.click();
+ await focused;
+ ok(true, "New key input got focus");
+ content.focused = ContentTaskUtils.waitForEvent(content.change, "focus");
+ });
+ await Services.fog.testFlushAllChildren();
+ is(
+ Glean.browserCustomkeys.actions.change.testGetValue(),
+ 6,
+ "Correct telemetry for change action"
+ );
+ info(`Pressing ${consts.backDisplay}`);
+ EventUtils.synthesizeKey(...consts.backArgs, window);
+ await SpecialPowers.spawn(tab, [consts], async _consts => {
+ await content.focused;
+ ok(true, "Change button got focus");
+ ok(
+ !content.backRow.classList.contains("customized"),
+ "goBackKb is not customized"
+ );
+ is(
+ content.backRow.children[1].textContent,
+ _consts.backDisplay,
+ "Key is the default key"
+ );
+ });
+});
diff --git a/browser/components/customkeys/tests/browser/head.js b/browser/components/customkeys/tests/browser/head.js
@@ -17,6 +17,9 @@ const consts = {
downloadsDisplay: (isMac && "⌘J") || (isLinux && "Ctrl+Shift+Y") || "Ctrl+J",
// key_newNavigator
newWindowDisplay: isMac ? "⌘N" : "Ctrl+N",
+ // goBackKb
+ backDisplay: isMac ? "⌘←" : "Alt+Left Arrow",
+ backArgs: ["KEY_ArrowLeft", { accelKey: isMac, altKey: !isMac }],
// The following unused* constants specify a key combination which is unused by
// default. This will need to be updated if this key combination is assigned to