From 17d917a4ffb1c28594ff984d785aac184bec0cfa Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Tue, 25 Jun 2013 11:37:58 -0700 Subject: [PATCH] fix #2957. fix unit tests by re-enabling multiple bindings. --- Gruntfile.js | 5 ++--- package.json | 4 ++-- src/command/KeyBindingManager.js | 33 +++++++++++++++++++++++--------- src/config.json | 2 +- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 81778357cf5..c2ec2dfe5b5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -157,9 +157,8 @@ module.exports = function (grunt) { grunt.registerTask('install', ['write-config']); // task: test - //grunt.registerTask('test', ['jshint', 'jasmine']); -// grunt.registerTask('test', ['jshint', 'jasmine-node']); - grunt.registerTask('test', ['jshint']); + grunt.registerTask('test', ['jshint:all', 'jasmine']); + //grunt.registerTask('test', ['jshint:all', 'jasmine', jasmine-node']); // task: set-sprint // Update sprint number in package.json and rewrite src/config.json diff --git a/package.json b/package.json index 074018833ae..d16fde6a11f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "grunt-cli": "0.1.6", "phantomjs": "1.9.0-1", "grunt-lib-phantomjs": "0.3.0", - "grunt-contrib-jshint": "0.2.0", + "grunt-contrib-jshint": "0.6.0", "grunt-contrib-watch": "0.3.1", "grunt-contrib-jasmine": "0.4.2", "grunt-template-jasmine-requirejs": "0.1.0", @@ -35,4 +35,4 @@ "url": "https://github.com/adobe/brackets/blob/master/LICENSE" } ] -} \ No newline at end of file +} diff --git a/src/command/KeyBindingManager.js b/src/command/KeyBindingManager.js index 27ae8c84e60..d9400eab258 100644 --- a/src/command/KeyBindingManager.js +++ b/src/command/KeyBindingManager.js @@ -22,7 +22,7 @@ */ -/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true, boss: true */ +/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true*/ /*global define, $, brackets, window */ /*unittests: KeyBindingManager */ @@ -40,6 +40,10 @@ define(function (require, exports, module) { Strings = require("strings"); var KeyboardPrefs = JSON.parse(require("text!base-config/keyboard.json")); + + var ADD_BINDING_ERROR = { + EXPLICIT_BINDING_EXISTS: 1 + }; /** * @private @@ -415,8 +419,7 @@ define(function (require, exports, module) { removeBinding(normalized); } else { // do not re-assign a key binding - console.error("Cannot assign " + normalized + " to " + commandID + ". It is already assigned to " + _keyMap[normalized].commandID); - return null; + return { errorType: ADD_BINDING_ERROR.EXPLICIT_BINDING_EXISTS, keyBinding: normalized }; } } @@ -551,7 +554,7 @@ define(function (require, exports, module) { } if (Array.isArray(keyBindings)) { - var keyBinding; + var keyBinding, errors = []; results = []; keyBindings.sort(function (a, b) { @@ -572,17 +575,29 @@ define(function (require, exports, module) { } }); - keyBindings.some(function addSingleBinding(keyBindingRequest) { + keyBindings.forEach(function addSingleBinding(keyBindingRequest) { // attempt to add keybinding keyBinding = _addBinding(commandID, keyBindingRequest, keyBindingRequest.platform); if (keyBinding) { - results.push(keyBinding); - return true; + if (keyBinding.errorType) { + errors.push(keyBinding); + } else { + results.push(keyBinding); + } } - - return false; }); + + if (errors.length) { + // only use console.error if no bindings were assigned + var logType = (results.length === 0) ? "error" : "log"; + + errors.forEach(function (error) { + if (error.errorType === ADD_BINDING_ERROR.EXPLICIT_BINDING_EXISTS) { + console[logType]("Cannot assign " + error.keyBinding + " to " + commandID + ". It is already assigned to " + _keyMap[error.keyBinding].commandID); + } + }); + } } else { results = _addBinding(commandID, keyBindings, platform); } diff --git a/src/config.json b/src/config.json index 938e173c5a4..4f61316c46a 100644 --- a/src/config.json +++ b/src/config.json @@ -34,7 +34,7 @@ "grunt-cli": "0.1.6", "phantomjs": "1.9.0-1", "grunt-lib-phantomjs": "0.3.0", - "grunt-contrib-jshint": "0.2.0", + "grunt-contrib-jshint": "0.6.0", "grunt-contrib-watch": "0.3.1", "grunt-contrib-jasmine": "0.4.2", "grunt-template-jasmine-requirejs": "0.1.0",