@@ -497,7 +497,7 @@ define(function (require, exports, module) {
497497
498498 // TODO (issue #414): Replace this temporary fix with a more robust solution to handle focus and modality
499499 /**
500- * Enable or disable key bindings. Clients such as dialogs may wish to disable
500+ * Enable or disable key bindings. Clients such as dialogs may wish to disable
501501 * global key bindings temporarily.
502502 *
503503 * @param {string } A key-description string.
@@ -509,8 +509,8 @@ define(function (require, exports, module) {
509509
510510 /**
511511 * Add one or more key bindings to a particular Command.
512- *
513- * @param {!string } commandID
512+ *
513+ * @param {!string | Command } command - A command ID or command object
514514 * @param {?({key: string, displayKey: string} | Array.<{key: string, displayKey: string, platform: string}>) } keyBindings
515515 * a single key binding or an array of keybindings. Example:
516516 * "Shift-Cmd-F". Mac and Win key equivalents are automatically
@@ -522,14 +522,24 @@ define(function (require, exports, module) {
522522 * @return {{key: string, displayKey:String}|Array.<{key: string, displayKey:String}> }
523523 * Returns record(s) for valid key binding(s)
524524 */
525- function addBinding ( commandID , keyBindings , platform ) {
526- if ( ( commandID === null ) || ( commandID === undefined ) || ! keyBindings ) {
525+ function addBinding ( command , keyBindings , platform ) {
526+ var commandID = "" ,
527+ normalizedBindings = [ ] ,
528+ results ;
529+
530+ if ( ! command ) {
531+ console . error ( "addBinding(): missing required parameter: command" ) ;
527532 return ;
528533 }
529534
530- var normalizedBindings = [ ] ,
531- results ;
532-
535+ if ( ! keyBindings ) { return ; }
536+
537+ if ( typeof ( command ) === "string" ) {
538+ commandID = command ;
539+ } else {
540+ commandID = command . getID ( ) ;
541+ }
542+
533543 if ( Array . isArray ( keyBindings ) ) {
534544 var keyBinding ;
535545 results = [ ] ;
@@ -548,15 +558,29 @@ define(function (require, exports, module) {
548558
549559 return results ;
550560 }
551-
561+
552562 /**
553563 * Retrieve key bindings currently associated with a command
554564 *
555- * @param {!string } command - A command ID
565+ * @param {!string | Command } command - A command ID or command object
556566 * @return {!Array.<{{key: string, displayKey: string}}> } An array of associated key bindings.
557567 */
558- function getKeyBindings ( commandID ) {
559- var bindings = _commandMap [ commandID ] ;
568+ function getKeyBindings ( command ) {
569+ var bindings = [ ] ,
570+ commandID = "" ;
571+
572+ if ( ! command ) {
573+ console . error ( "getKeyBindings(): missing required parameter: command" ) ;
574+ return [ ] ;
575+ }
576+
577+ if ( typeof ( command ) === "string" ) {
578+ commandID = command ;
579+ } else {
580+ commandID = command . getID ( ) ;
581+ }
582+
583+ bindings = _commandMap [ commandID ] ;
560584 return bindings || [ ] ;
561585 }
562586
@@ -606,9 +630,9 @@ define(function (require, exports, module) {
606630 exports . getKeyBindings = getKeyBindings ;
607631
608632 /**
609- * Use windows-specific bindings if no other are found (e.g. Linux).
633+ * Use windows-specific bindings if no other are found (e.g. Linux).
610634 * Core Brackets modules that use key bindings should always define at
611- * least a generic keybinding that is applied for all platforms. This
635+ * least a generic keybinding that is applied for all platforms. This
612636 * setting effectively creates a compatibility mode for third party
613637 * extensions that define explicit key bindings for Windows and Mac, but
614638 * not Linux.
0 commit comments