diff --git a/src/command/KeyBindingManager.js b/src/command/KeyBindingManager.js index 272fe3ea89..aa47fcea7e 100644 --- a/src/command/KeyBindingManager.js +++ b/src/command/KeyBindingManager.js @@ -719,11 +719,19 @@ define(function (require, exports, module) { normalized, normalizedDisplay, explicitPlatform = keyBinding.platform || platform, + explicitBrowserOnly = keyBinding.browserOnly, + explicitNativeOnly = keyBinding.nativeOnly, targetPlatform, command, bindingsToDelete = [], existing; + if(Phoenix.isNativeApp && explicitBrowserOnly) { + return null; + } + if(!Phoenix.isNativeApp && explicitNativeOnly) { + return null; + } // For platform: "all", use explicit current platform if (explicitPlatform && explicitPlatform !== "all") { targetPlatform = explicitPlatform; @@ -983,12 +991,13 @@ define(function (require, exports, module) { * Returns record(s) for valid key binding(s). * * @param {!string | Command} command - A command ID or command object - * @param {{key: string, displayKey:string, platform: string}} keyBindings + * @param {{key: string, displayKey:string, platform: string, browserOnly: boolean, nativeOnly:boolean}} keyBindings * A single key binding or an array of keybindings. * In an array of keybinding `platform` property is also available. Example: * "Shift-Cmd-F". Mac and Win key equivalents are automatically * mapped to each other. Use displayKey property to display a different - * string (e.g. "CMD+" instead of "CMD="). + * string (e.g. "CMD+" instead of "CMD="). if browserOnly is true, then the shortcut will only apply in browser + * if nativeOnly is set, the shortcut will only apply in native apps * @param {?string} platform The target OS of the keyBindings either * "mac", "win" or "linux". If undefined, all platforms not explicitly * defined will use the key binding. @@ -1022,7 +1031,7 @@ define(function (require, exports, module) { // process platform-specific bindings first keyBindings.sort(_sortByPlatform); - keyBindings.forEach(function addSingleBinding(keyBindingRequest) { + keyBindings.forEach(function (keyBindingRequest) { // attempt to add keybinding keyBinding = _addBinding(commandID, keyBindingRequest, { platform: keyBindingRequest.platform, diff --git a/src/extensions/default/CodeFolding/main.js b/src/extensions/default/CodeFolding/main.js index c791352b1d..77e1349d3e 100644 --- a/src/extensions/default/CodeFolding/main.js +++ b/src/extensions/default/CodeFolding/main.js @@ -49,12 +49,8 @@ define(function (require, exports, module) { GUTTER_NAME = "CodeMirror-foldgutter", CODE_FOLDING_GUTTER_PRIORITY = Editor.CODE_FOLDING_GUTTER_PRIORITY, codeFoldingMenuDivider = "codefolding.divider", - collapseKey = "Alt-Shift-Left", - collapseKeyDisplay = "Alt-Shift-←", - expandKey = "Alt-Shift-Right", - expandKeyDisplay = "Alt-Shift-→", - collapseAllKey = "Ctrl-Alt-[", - expandAllKey = "Ctrl-Alt-]"; + collapseKey = "Ctrl-Shift-[", + expandKey = "Ctrl-Shift-]"; ExtensionUtils.loadStyleSheet(module, "main.less"); @@ -360,8 +356,6 @@ define(function (require, exports, module) { KeyBindingManager.removeBinding(collapseKey); KeyBindingManager.removeBinding(expandKey); - KeyBindingManager.removeBinding(collapseAllKey); - KeyBindingManager.removeBinding(expandAllKey); //remove menus Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuDivider(codeFoldingMenuDivider.id); @@ -419,10 +413,8 @@ define(function (require, exports, module) { Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND); //register keybindings - KeyBindingManager.addBinding(COLLAPSE_ALL, [ {key: collapseAllKey}]); - KeyBindingManager.addBinding(EXPAND_ALL, [ {key: expandAllKey}]); - KeyBindingManager.addBinding(COLLAPSE, [{key: collapseKey, displayKey: collapseKeyDisplay}]); - KeyBindingManager.addBinding(EXPAND, [{key:expandKey, displayKey: expandKeyDisplay}]); + KeyBindingManager.addBinding(COLLAPSE, [{key: collapseKey}]); + KeyBindingManager.addBinding(EXPAND, [{key:expandKey}]); // Add gutters & restore saved expand/collapse state in all currently open editors diff --git a/src/extensionsIntegrated/NavigationAndHistory/keyboard.json b/src/extensionsIntegrated/NavigationAndHistory/keyboard.json index 0c696514cc..c7d452bd80 100644 --- a/src/extensionsIntegrated/NavigationAndHistory/keyboard.json +++ b/src/extensionsIntegrated/NavigationAndHistory/keyboard.json @@ -6,10 +6,6 @@ { "key": "Ctrl-Tab", "platform": "mac" - }, - { - "key": "Cmd-Shift-]", - "platform": "mac" } ], "recent-files.prev": [ @@ -19,22 +15,44 @@ { "key": "Ctrl-Shift-Tab", "platform": "mac" - }, - { - "key": "Cmd-Shift-[", - "platform": "mac" } ], "navigation.jump.back": [ { "key": "Alt-Left", - "displayKey": "Alt-←" + "displayKey": "Alt-←", + "platform": "win" + }, + { + "key": "Cmd-Alt-Left", + "displayKey": "Cmd-Alt-←", + "platform": "mac", + "nativeOnly": true + }, + { + "key": "Ctrl-Alt-Left", + "displayKey": "Ctrl-Alt-←", + "platform": "mac", + "browserOnly": true } ], "navigation.jump.fwd": [ { "key": "Alt-Right", - "displayKey": "Alt-→" + "displayKey": "Alt-→", + "platform": "win" + }, + { + "key": "Cmd-Alt-Right", + "displayKey": "Cmd-Alt-→", + "platform": "mac", + "nativeOnly": true + }, + { + "key": "Ctrl-Alt-Right", + "displayKey": "Ctrl-Alt-→", + "platform": "mac", + "browserOnly": true } ] } diff --git a/test/spec/KeyBindingManager-test.js b/test/spec/KeyBindingManager-test.js index 3719a56b9c..a5bec81a19 100644 --- a/test/spec/KeyBindingManager-test.js +++ b/test/spec/KeyBindingManager-test.js @@ -368,6 +368,58 @@ define(function (require, exports, module) { expect(KeyBindingManager.getKeymap()).toEqual(expected); }); + + it("should handle browserOnly and nativeOnly bindings correctly", function () { + // Test browser-only bindings + let result = KeyBindingManager.addBinding("test.browser", { + key: "F6", + browserOnly: true + }); + let keymap = KeyBindingManager.getKeymap(); + if(Phoenix.isNativeApp) { + expect(result).toBeNull(); + expect(keymap["F6"]).not.toBeDefined(); + } else { + expect(result.key).toBe("F6"); + expect(keymap["F6"].key).toBe("F6"); + } + // Test native-only bindings + result = KeyBindingManager.addBinding("test.native", { + key: "F7", + nativeOnly: true + }); + keymap = KeyBindingManager.getKeymap(); + if(!Phoenix.isNativeApp) { + expect(result).toBeNull(); + expect(keymap["F7"]).not.toBeDefined(); + } else { + expect(result.key).toBe("F7"); + expect(keymap["F7"].key).toBe("F7"); + } + }); + + it("should handle browserOnly and nativeOnly in multiple bindings", function () { + // Test browser-only bindings + let result = KeyBindingManager.addBinding("test.allPlats", [ + {key: "F6", browserOnly: true}, + {key: "F7", nativeOnly: true} + ]); + let keymap = KeyBindingManager.getKeymap(); + expect(result.length).toBe(1); + if (Phoenix.isNativeApp) { + // Native app environment + expect(result[0].key).toBe("F7"); // Only native binding should be added + expect(keymap["F7"]).toBeDefined(); + expect(keymap["F7"].key).toBe("F7"); + expect(keymap["F6"]).not.toBeDefined(); // Browser-only should not be defined + } else { + // Browser environment + expect(result[0].key).toBe("F6"); // Only browser binding should be added + expect(keymap["F6"]).toBeDefined(); + expect(keymap["F6"].key).toBe("F6"); + expect(keymap["F7"]).not.toBeDefined(); // Native-only should not be defined + } + }); }); describe("removeBinding", function () {