@@ -66,14 +66,17 @@ define(function (require, exports, module) {
66
66
* @param {string } key The key that's pressed
67
67
* @return {string } The normalized key descriptor
68
68
*/
69
- function _buildKeyDescriptor ( hasCtrl , hasAlt , hasShift , key ) {
69
+ function _buildKeyDescriptor ( hasMacCtrl , hasCtrl , hasAlt , hasShift , key ) {
70
70
if ( ! key ) {
71
71
console . log ( "KeyBindingManager _buildKeyDescriptor() - No key provided!" ) ;
72
72
return "" ;
73
73
}
74
74
75
75
var keyDescriptor = [ ] ;
76
76
77
+ if ( hasMacCtrl ) {
78
+ keyDescriptor . push ( "Ctrl" ) ;
79
+ }
77
80
if ( hasAlt ) {
78
81
keyDescriptor . push ( "Alt" ) ;
79
82
}
@@ -86,7 +89,7 @@ define(function (require, exports, module) {
86
89
if ( brackets . platform === "win" ) {
87
90
keyDescriptor . unshift ( "Ctrl" ) ;
88
91
} else {
89
- keyDescriptor . push ( "Ctrl " ) ;
92
+ keyDescriptor . push ( "Cmd " ) ;
90
93
}
91
94
}
92
95
@@ -114,17 +117,21 @@ define(function (require, exports, module) {
114
117
* @return {string } The normalized key descriptor or null if the descriptor invalid
115
118
*/
116
119
function normalizeKeyDescriptorString ( origDescriptor ) {
117
- var hasCtrl = false ,
120
+ var hasMacCtrl = false ,
121
+ hasCtrl = false ,
118
122
hasAlt = false ,
119
123
hasShift = false ,
120
124
key = "" ,
121
125
error = false ;
122
126
123
127
origDescriptor . split ( "-" ) . forEach ( function parseDescriptor ( ele , i , arr ) {
124
128
if ( _isModifier ( "ctrl" , ele , hasCtrl ) ) {
125
- hasCtrl = true ;
129
+ if ( brackets . platform === "mac" ) {
130
+ hasMacCtrl = true ;
131
+ } else {
132
+ hasCtrl = true ;
133
+ }
126
134
} else if ( _isModifier ( "cmd" , ele , hasCtrl , origDescriptor ) ) {
127
- console . log ( "KeyBindingManager normalizeKeyDescriptorString() - Cmd getting mapped to Ctrl from: " + origDescriptor ) ;
128
135
hasCtrl = true ;
129
136
} else if ( _isModifier ( "alt" , ele , hasAlt , origDescriptor ) ) {
130
137
hasAlt = true ;
@@ -157,7 +164,7 @@ define(function (require, exports, module) {
157
164
return null ;
158
165
}
159
166
160
- return _buildKeyDescriptor ( hasCtrl , hasAlt , hasShift , key ) ;
167
+ return _buildKeyDescriptor ( hasMacCtrl , hasCtrl , hasAlt , hasShift , key ) ;
161
168
}
162
169
163
170
/**
@@ -200,7 +207,8 @@ define(function (require, exports, module) {
200
207
* Takes a keyboard event and translates it into a key in a key map
201
208
*/
202
209
function _translateKeyboardEvent ( event ) {
203
- var hasCtrl = ( event . metaKey || event . ctrlKey ) ,
210
+ var hasMacCtrl = ( brackets . platform === "win" ) ? false : ( event . ctrlKey ) ,
211
+ hasCtrl = ( brackets . platform === "win" ) ? ( event . ctrlKey ) : ( event . metaKey ) ,
204
212
hasAlt = ( event . altKey ) ,
205
213
hasShift = ( event . shiftKey ) ,
206
214
key = String . fromCharCode ( event . keyCode ) ;
@@ -224,7 +232,7 @@ define(function (require, exports, module) {
224
232
if ( key === "\t" ) { key = "Tab" ; }
225
233
key = _mapKeycodeToKey ( event . keyCode , key ) ;
226
234
227
- return _buildKeyDescriptor ( hasCtrl , hasAlt , hasShift , key ) ;
235
+ return _buildKeyDescriptor ( hasMacCtrl , hasCtrl , hasAlt , hasShift , key ) ;
228
236
}
229
237
230
238
/**
@@ -236,8 +244,9 @@ define(function (require, exports, module) {
236
244
var displayStr ;
237
245
238
246
if ( brackets . platform === "mac" ) {
239
- displayStr = descriptor . replace ( / - / g, "" ) ; // remove dashes
240
- displayStr = displayStr . replace ( "Ctrl" , "\u2318" ) ; // Ctrl > command symbol
247
+ displayStr = descriptor . replace ( / - / g, "" ) ; // remove dashes
248
+ displayStr = displayStr . replace ( "Ctrl" , "\u2303" ) ; // Ctrl > control symbol
249
+ displayStr = displayStr . replace ( "Cmd" , "\u2318" ) ; // Cmd > command symbol
241
250
displayStr = displayStr . replace ( "Shift" , "\u21E7" ) ; // Shift > shift symbol
242
251
displayStr = displayStr . replace ( "Alt" , "\u2325" ) ; // Alt > option symbol
243
252
} else {
@@ -269,7 +278,8 @@ define(function (require, exports, module) {
269
278
result = null ,
270
279
normalized ,
271
280
normalizedDisplay ,
272
- targetPlatform = keyBinding . platform || platform || brackets . platform ,
281
+ explicitPlatform = keyBinding . platform || platform ,
282
+ targetPlatform = explicitPlatform || brackets . platform ,
273
283
command ;
274
284
275
285
// skip if this binding doesn't match the current platform
@@ -278,6 +288,12 @@ define(function (require, exports, module) {
278
288
}
279
289
280
290
key = ( keyBinding . key ) || keyBinding ;
291
+ if ( brackets . platform === "mac" && explicitPlatform === undefined ) {
292
+ key = key . replace ( "Ctrl" , "Cmd" ) ;
293
+ if ( keyBinding . displayKey !== undefined ) {
294
+ keyBinding . displayKey = keyBinding . displayKey . replace ( "Ctrl" , "Cmd" ) ;
295
+ }
296
+ }
281
297
normalized = normalizeKeyDescriptorString ( key ) ;
282
298
283
299
// skip if the key binding is invalid
@@ -376,16 +392,14 @@ define(function (require, exports, module) {
376
392
results = [ ] ;
377
393
378
394
keyBindings . forEach ( function ( keyBindingRequest ) {
379
- targetPlatform = keyBindingRequest . platform || brackets . platform ;
380
- keyBinding = _addBinding ( commandID , keyBindingRequest , targetPlatform ) ;
395
+ keyBinding = _addBinding ( commandID , keyBindingRequest , keyBindingRequest . platform ) ;
381
396
382
397
if ( keyBinding ) {
383
398
results . push ( keyBinding ) ;
384
399
}
385
400
} ) ;
386
401
} else {
387
- targetPlatform = platform || brackets . platform ;
388
- results = _addBinding ( commandID , keyBindings , targetPlatform ) ;
402
+ results = _addBinding ( commandID , keyBindings , platform ) ;
389
403
}
390
404
391
405
return results ;
0 commit comments