Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Use windows-specific keybindings on linux #2331

Merged
merged 9 commits into from
Dec 13, 2012
33 changes: 11 additions & 22 deletions src/base-config/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
],
"edit.selectLine": [
{
"key": "Ctrl-L",
"platform": "win"
"key": "Ctrl-L"
},
{
"key": "Ctrl-L",
Expand All @@ -47,8 +46,7 @@
],
"edit.findNext": [
{
"key": "F3",
"platform": "win"
"key": "F3"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this file, in cases where the key bindings on mac are different from win/linux, the order is always generic first, followed by platform:mac. These can be specified in either order (and this file just happens to be organized that way), correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

{
"key": "Cmd-G",
Expand All @@ -57,8 +55,7 @@
],
"edit.findPrevious": [
{
"key": "Shift-F3",
"platform": "win"
"key": "Shift-F3"
},
{
"key": "Cmd-Shift-G",
Expand All @@ -67,8 +64,7 @@
],
"edit.replace": [
{
"key": "Ctrl-H",
"platform": "win"
"key": "Ctrl-H"
},
{
"key": "Cmd-Alt-F",
Expand Down Expand Up @@ -96,8 +92,7 @@
"edit.lineUp": [
{
"key": "Ctrl-Shift-Up",
"displayKey": "Ctrl-Shift-↑",
"platform": "win"
"displayKey": "Ctrl-Shift-↑"
},
{
"key": "Cmd-Ctrl-Up",
Expand All @@ -108,8 +103,7 @@
"edit.lineDown": [
{
"key": "Ctrl-Shift-Down",
"displayKey": "Ctrl-Shift-↓",
"platform": "win"
"displayKey": "Ctrl-Shift-↓"
},
{
"key": "Cmd-Ctrl-Down",
Expand Down Expand Up @@ -150,8 +144,7 @@
],
"navigate.gotoLine": [
{
"key": "Ctrl-G",
"platform": "win"
"key": "Ctrl-G"
},
{
"key": "Cmd-L",
Expand All @@ -163,8 +156,7 @@
],
"navigate.nextDoc": [
{
"key": "Ctrl-Tab",
"platform": "win"
"key": "Ctrl-Tab"
},
{
"key": "Ctrl-Tab",
Expand All @@ -173,8 +165,7 @@
],
"navigate.prevDoc": [
{
"key": "Ctrl-Shift-Tab",
"platform": "win"
"key": "Ctrl-Shift-Tab"
},
{
"key": "Ctrl-Shift-Tab",
Expand All @@ -198,8 +189,7 @@
],
"debug.showDeveloperTools": [
{
"key": "F12",
"platform": "win"
"key": "F12"
},
{
"key": "Cmd-Opt-I",
Expand All @@ -208,8 +198,7 @@
],
"debug.refreshWindow": [
{
"key": "F5",
"platform": "win"
"key": "F5"
},
{
"key": "Cmd-R",
Expand Down
18 changes: 13 additions & 5 deletions src/command/KeyBindingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ define(function (require, exports, module) {
* Takes a keyboard event and translates it into a key in a key map
*/
function _translateKeyboardEvent(event) {
var hasMacCtrl = (brackets.platform === "win") ? false : (event.ctrlKey),
hasCtrl = (brackets.platform === "win") ? (event.ctrlKey) : (event.metaKey),
var hasMacCtrl = (brackets.platform === "mac") ? (event.ctrlKey) : false,
hasCtrl = (brackets.platform !== "mac") ? (event.ctrlKey) : (event.metaKey),
hasAlt = (event.altKey),
hasShift = (event.shiftKey),
key = String.fromCharCode(event.keyCode);
Expand Down Expand Up @@ -304,7 +304,9 @@ define(function (require, exports, module) {
* @param {string} commandID
* @param {string|{{key: string, displayKey: string}}} keyBinding - a single shortcut.
* @param {?string} platform - undefined indicates all platforms
* @return {?{key: string, displayKey:String}} Returns a record for valid key bindings
* @return {?{key: string, displayKey:String}} Returns a record for valid key bindings.
* Returns null when key binding platform does not match, binding does not normalize,
* or is already assigned.
*/
function _addBinding(commandID, keyBinding, platform) {
var key,
Expand Down Expand Up @@ -407,7 +409,7 @@ define(function (require, exports, module) {
* @param {?({key: string, displayKey: string} | Array.<{key: string, displayKey: string, platform: string}>)} keyBindings - a single key binding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap these lines at 80 (or so) chars.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* or an array of keybindings. 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=").
* @param {?string} platform - the target OS of the keyBindings either "mac" or "win". If undefined, all platforms will use
* @param {?string} platform - the target OS of the keyBindings either "mac", "win" or "linux". If undefined, all platforms will use
* the key binding. Ignored if keyBindings is passed an Array.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording of "If undefined, all platforms will use the key binding." can be improved:

What about "If undefined, all platforms not explicitly defined will use the key binding." ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* @return {{key: string, displayKey:String}|Array.<{key: string, displayKey:String}>} Returns record(s) for valid key binding(s)
*/
Expand All @@ -424,7 +426,8 @@ define(function (require, exports, module) {
var keyBinding;
results = [];

keyBindings.forEach(function (keyBindingRequest) {
keyBindings.forEach(function addSingleBinding(keyBindingRequest) {
// attempt to add keybinding
keyBinding = _addBinding(commandID, keyBindingRequest, keyBindingRequest.platform);

if (keyBinding) {
Expand Down Expand Up @@ -485,6 +488,11 @@ define(function (require, exports, module) {
return bindings || [];
}

/**
* Adds default key bindings when commands are registered to CommandManager
* @param {$.Event} event jQuery event
* @param {Command} command Newly registered command
*/
function _handleCommandRegistered(event, command) {
var commandId = command.getID(),
defaults = KeyboardPrefs[commandId];
Expand Down