Bug 1965273 - support up/down shortcut keys on macOS for tabswitches, r=tabbrowser-reviewers,sthompson

Differential Revision: https://phabricator.services.mozilla.com/D248464
This commit is contained in:
Gijs Kruitbosch
2025-05-08 19:56:38 +00:00
committed by gijskruitbosch@gmail.com
parent 526bc24c5a
commit 728ff6d544
2 changed files with 36 additions and 34 deletions

View File

@@ -121,6 +121,20 @@ add_task(async function test() {
tab1, tab1,
"Tab1 should be activated by pressing Ctrl+" + reverseKey + " on Tab2" "Tab1 should be activated by pressing Ctrl+" + reverseKey + " on Tab2"
); );
EventUtils.synthesizeKey("VK_DOWN", { altKey: true, metaKey: true });
is(
gBrowser.selectedTab,
tab2,
"Tab2 should be activated by pressing Ctrl+down on Tab1"
);
EventUtils.synthesizeKey("VK_UP", { altKey: true, metaKey: true });
is(
gBrowser.selectedTab,
tab1,
"Tab1 should be activated by pressing Ctrl+down on Tab2"
);
} }
gBrowser.selectedTab = tab2; gBrowser.selectedTab = tab2;

View File

@@ -327,13 +327,23 @@ export var ShortcutUtils = {
* @param {KeyboardEvent} event The event to check for a related system action. * @param {KeyboardEvent} event The event to check for a related system action.
* @returns {string} A string identifying the action, or null if no action is found. * @returns {string} A string identifying the action, or null if no action is found.
*/ */
// eslint-disable-next-line complexity
getSystemActionForEvent(event, { rtl } = {}) { getSystemActionForEvent(event, { rtl } = {}) {
// On Windows, Win key state is not strictly checked so that we can ignore // On Windows, Win key state is not strictly checked so that we can ignore
// Win key state to check the other modifier state. // Win key state to check the other modifier state.
const meaningfulMetaKey = event.metaKey && AppConstants.platform != "win"; const meaningfulMetaKey = event.metaKey && AppConstants.platform != "win";
// This is set to true only when the Meta key is accel key on the platform. const ctrlOnly =
const accelMetaKey = event.metaKey && this.metaKeyIsCommandKey(); event.ctrlKey && !event.shiftKey && !event.altKey && !meaningfulMetaKey;
const ctrlShift =
event.ctrlKey && event.shiftKey && !event.altKey && !meaningfulMetaKey;
// If Meta is accel on this platform, allow meta+alt combination:
const metaAltAccel =
event.metaKey &&
this.metaKeyIsCommandKey() &&
event.altKey &&
!event.shiftKey &&
!event.ctrlKey;
switch (event.keyCode) { switch (event.keyCode) {
case event.DOM_VK_TAB: case event.DOM_VK_TAB:
if (event.ctrlKey && !event.altKey && !meaningfulMetaKey) { if (event.ctrlKey && !event.altKey && !meaningfulMetaKey) {
@@ -347,48 +357,30 @@ export var ShortcutUtils = {
} }
break; break;
case event.DOM_VK_PAGE_UP: case event.DOM_VK_PAGE_UP:
if ( if (ctrlOnly) {
event.ctrlKey &&
!event.shiftKey &&
!event.altKey &&
!meaningfulMetaKey
) {
return ShortcutUtils.PREVIOUS_TAB; return ShortcutUtils.PREVIOUS_TAB;
} }
if ( if (ctrlShift) {
event.ctrlKey &&
event.shiftKey &&
!event.altKey &&
!meaningfulMetaKey
) {
return ShortcutUtils.MOVE_TAB_BACKWARD; return ShortcutUtils.MOVE_TAB_BACKWARD;
} }
break; break;
case event.DOM_VK_PAGE_DOWN: case event.DOM_VK_PAGE_DOWN:
if ( if (ctrlOnly) {
event.ctrlKey &&
!event.shiftKey &&
!event.altKey &&
!meaningfulMetaKey
) {
return ShortcutUtils.NEXT_TAB; return ShortcutUtils.NEXT_TAB;
} }
if ( if (ctrlShift) {
event.ctrlKey &&
event.shiftKey &&
!event.altKey &&
!meaningfulMetaKey
) {
return ShortcutUtils.MOVE_TAB_FORWARD; return ShortcutUtils.MOVE_TAB_FORWARD;
} }
break; break;
case event.DOM_VK_UP: // fall through
case event.DOM_VK_LEFT: case event.DOM_VK_LEFT:
if (accelMetaKey && event.altKey && !event.shiftKey && !event.ctrlKey) { if (metaAltAccel) {
return ShortcutUtils.PREVIOUS_TAB; return ShortcutUtils.PREVIOUS_TAB;
} }
break; break;
case event.DOM_VK_DOWN: // fall through
case event.DOM_VK_RIGHT: case event.DOM_VK_RIGHT:
if (accelMetaKey && event.altKey && !event.shiftKey && !event.ctrlKey) { if (metaAltAccel) {
return ShortcutUtils.NEXT_TAB; return ShortcutUtils.NEXT_TAB;
} }
break; break;
@@ -412,11 +404,7 @@ export var ShortcutUtils = {
} }
// Not on Mac from now on. // Not on Mac from now on.
if (AppConstants.platform != "macosx") { if (AppConstants.platform != "macosx") {
if ( if (ctrlOnly && event.keyCode == KeyEvent.DOM_VK_F4) {
event.ctrlKey &&
!event.shiftKey &&
event.keyCode == KeyEvent.DOM_VK_F4
) {
return ShortcutUtils.CLOSE_TAB; return ShortcutUtils.CLOSE_TAB;
} }
} }