Skip to content

Commit bc8f3ea

Browse files
committed
fix: in mac browsers, "Cmd-Alt-Right" and left is reserved for browser navigation and not assignable
So added framework option nativeOnly and browserOnly to selectiveley apply shortcut. in browser, mac, nav back and forward will be assigned to `Ctrl-Alt-Right` and left instead.
1 parent 43f686a commit bc8f3ea

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/command/KeyBindingManager.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,19 @@ define(function (require, exports, module) {
719719
normalized,
720720
normalizedDisplay,
721721
explicitPlatform = keyBinding.platform || platform,
722+
explicitBrowserOnly = keyBinding.browserOnly,
723+
explicitNativeOnly = keyBinding.nativeOnly,
722724
targetPlatform,
723725
command,
724726
bindingsToDelete = [],
725727
existing;
726728

729+
if(Phoenix.isNativeApp && explicitBrowserOnly) {
730+
return null;
731+
}
732+
if(!Phoenix.isNativeApp && explicitNativeOnly) {
733+
return null;
734+
}
727735
// For platform: "all", use explicit current platform
728736
if (explicitPlatform && explicitPlatform !== "all") {
729737
targetPlatform = explicitPlatform;
@@ -983,12 +991,13 @@ define(function (require, exports, module) {
983991
* Returns record(s) for valid key binding(s).
984992
*
985993
* @param {!string | Command} command - A command ID or command object
986-
* @param {{key: string, displayKey:string, platform: string}} keyBindings
994+
* @param {{key: string, displayKey:string, platform: string, browserOnly: boolean, nativeOnly:boolean}} keyBindings
987995
* A single key binding or an array of keybindings.
988996
* In an array of keybinding `platform` property is also available. Example:
989997
* "Shift-Cmd-F". Mac and Win key equivalents are automatically
990998
* mapped to each other. Use displayKey property to display a different
991-
* string (e.g. "CMD+" instead of "CMD=").
999+
* string (e.g. "CMD+" instead of "CMD="). if browserOnly is true, then the shortcut will only apply in browser
1000+
* if nativeOnly is set, the shortcut will only apply in native apps
9921001
* @param {?string} platform The target OS of the keyBindings either
9931002
* "mac", "win" or "linux". If undefined, all platforms not explicitly
9941003
* defined will use the key binding.
@@ -1022,7 +1031,7 @@ define(function (require, exports, module) {
10221031
// process platform-specific bindings first
10231032
keyBindings.sort(_sortByPlatform);
10241033

1025-
keyBindings.forEach(function addSingleBinding(keyBindingRequest) {
1034+
keyBindings.forEach(function (keyBindingRequest) {
10261035
// attempt to add keybinding
10271036
keyBinding = _addBinding(commandID, keyBindingRequest, {
10281037
platform: keyBindingRequest.platform,

src/extensionsIntegrated/NavigationAndHistory/keyboard.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@
2626
{
2727
"key": "Cmd-Alt-Left",
2828
"displayKey": "Cmd-Alt-←",
29-
"platform": "mac"
29+
"platform": "mac",
30+
"nativeOnly": true
31+
},
32+
{
33+
"key": "Ctrl-Alt-Left",
34+
"displayKey": "Ctrl-Alt-←",
35+
"platform": "mac",
36+
"browserOnly": true
3037
}
3138
],
3239
"navigation.jump.fwd": [
@@ -38,7 +45,14 @@
3845
{
3946
"key": "Cmd-Alt-Right",
4047
"displayKey": "Cmd-Alt-→",
41-
"platform": "mac"
48+
"platform": "mac",
49+
"nativeOnly": true
50+
},
51+
{
52+
"key": "Ctrl-Alt-Right",
53+
"displayKey": "Ctrl-Alt-→",
54+
"platform": "mac",
55+
"browserOnly": true
4256
}
4357
]
4458
}

0 commit comments

Comments
 (0)