mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-02 01:09:04 +02:00
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:
parent
83e63e79a2
commit
5f2313f94b
2 changed files with 36 additions and 34 deletions
|
|
@ -121,6 +121,20 @@ add_task(async function test() {
|
|||
tab1,
|
||||
"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;
|
||||
|
|
|
|||
|
|
@ -327,13 +327,23 @@ export var ShortcutUtils = {
|
|||
* @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.
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
getSystemActionForEvent(event, { rtl } = {}) {
|
||||
// On Windows, Win key state is not strictly checked so that we can ignore
|
||||
// Win key state to check the other modifier state.
|
||||
const meaningfulMetaKey = event.metaKey && AppConstants.platform != "win";
|
||||
// This is set to true only when the Meta key is accel key on the platform.
|
||||
const accelMetaKey = event.metaKey && this.metaKeyIsCommandKey();
|
||||
const ctrlOnly =
|
||||
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) {
|
||||
case event.DOM_VK_TAB:
|
||||
if (event.ctrlKey && !event.altKey && !meaningfulMetaKey) {
|
||||
|
|
@ -347,48 +357,30 @@ export var ShortcutUtils = {
|
|||
}
|
||||
break;
|
||||
case event.DOM_VK_PAGE_UP:
|
||||
if (
|
||||
event.ctrlKey &&
|
||||
!event.shiftKey &&
|
||||
!event.altKey &&
|
||||
!meaningfulMetaKey
|
||||
) {
|
||||
if (ctrlOnly) {
|
||||
return ShortcutUtils.PREVIOUS_TAB;
|
||||
}
|
||||
if (
|
||||
event.ctrlKey &&
|
||||
event.shiftKey &&
|
||||
!event.altKey &&
|
||||
!meaningfulMetaKey
|
||||
) {
|
||||
if (ctrlShift) {
|
||||
return ShortcutUtils.MOVE_TAB_BACKWARD;
|
||||
}
|
||||
break;
|
||||
case event.DOM_VK_PAGE_DOWN:
|
||||
if (
|
||||
event.ctrlKey &&
|
||||
!event.shiftKey &&
|
||||
!event.altKey &&
|
||||
!meaningfulMetaKey
|
||||
) {
|
||||
if (ctrlOnly) {
|
||||
return ShortcutUtils.NEXT_TAB;
|
||||
}
|
||||
if (
|
||||
event.ctrlKey &&
|
||||
event.shiftKey &&
|
||||
!event.altKey &&
|
||||
!meaningfulMetaKey
|
||||
) {
|
||||
if (ctrlShift) {
|
||||
return ShortcutUtils.MOVE_TAB_FORWARD;
|
||||
}
|
||||
break;
|
||||
case event.DOM_VK_UP: // fall through
|
||||
case event.DOM_VK_LEFT:
|
||||
if (accelMetaKey && event.altKey && !event.shiftKey && !event.ctrlKey) {
|
||||
if (metaAltAccel) {
|
||||
return ShortcutUtils.PREVIOUS_TAB;
|
||||
}
|
||||
break;
|
||||
case event.DOM_VK_DOWN: // fall through
|
||||
case event.DOM_VK_RIGHT:
|
||||
if (accelMetaKey && event.altKey && !event.shiftKey && !event.ctrlKey) {
|
||||
if (metaAltAccel) {
|
||||
return ShortcutUtils.NEXT_TAB;
|
||||
}
|
||||
break;
|
||||
|
|
@ -412,11 +404,7 @@ export var ShortcutUtils = {
|
|||
}
|
||||
// Not on Mac from now on.
|
||||
if (AppConstants.platform != "macosx") {
|
||||
if (
|
||||
event.ctrlKey &&
|
||||
!event.shiftKey &&
|
||||
event.keyCode == KeyEvent.DOM_VK_F4
|
||||
) {
|
||||
if (ctrlOnly && event.keyCode == KeyEvent.DOM_VK_F4) {
|
||||
return ShortcutUtils.CLOSE_TAB;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue