diff --git a/src/base-config/keyboard.json b/src/base-config/keyboard.json index 5a9eafe5578..3d54d613f54 100644 --- a/src/base-config/keyboard.json +++ b/src/base-config/keyboard.json @@ -160,6 +160,15 @@ "navigate.gotoDefinition": [ "Ctrl-T" ], + "navigate.gotoJSLintError": [ + { + "key": "F8" + }, + { + "key": "Cmd-'", + "platform": "mac" + } + ], "navigate.nextDoc": [ { "key": "Ctrl-Tab" diff --git a/src/command/Commands.js b/src/command/Commands.js index 6278785278e..797d78c26b9 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -89,6 +89,7 @@ define(function (require, exports, module) { exports.NAVIGATE_SHOW_IN_FILE_TREE = "navigate.showInFileTree"; exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen"; exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition"; + exports.NAVIGATE_GOTO_JSLINT_ERROR = "navigate.gotoJSLintError"; exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine"; exports.TOGGLE_QUICK_EDIT = "navigate.toggleQuickEdit"; exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch"; diff --git a/src/command/Menus.js b/src/command/Menus.js index d78f14ba712..9ca9ce121ff 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -936,6 +936,7 @@ define(function (require, exports, module) { menu.addMenuItem(Commands.NAVIGATE_GOTO_LINE); menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION); + menu.addMenuItem(Commands.NAVIGATE_GOTO_JSLINT_ERROR); menu.addMenuDivider(); menu.addMenuItem(Commands.NAVIGATE_NEXT_DOC); menu.addMenuItem(Commands.NAVIGATE_PREV_DOC); diff --git a/src/language/JSLintUtils.js b/src/language/JSLintUtils.js index b2b988b3caa..b71afad6183 100644 --- a/src/language/JSLintUtils.js +++ b/src/language/JSLintUtils.js @@ -71,6 +71,27 @@ define(function (require, exports, module) { return _enabled; } + /** + * @private + * @type {function()} + * Holds a pointer to the function that selects the first error in the + * list. Stored when running JSLint and used by the "Go to First JSLint + * Error" command + */ + var _gotoFirstErrorFunction = null; + + /** + * @private + * Enable or disable the "Go to First JSLint Error" command + * @param {boolean} gotoEnabled Whether it is enabled. + */ + function _setGotoEnabled(gotoEnabled) { + CommandManager.get(Commands.NAVIGATE_GOTO_JSLINT_ERROR).setEnabled(gotoEnabled); + if (!gotoEnabled) { + _gotoFirstErrorFunction = null; + } + } + /** * Run JSLint on the current document. Reports results to the main UI. Displays * a gold star when no errors are found. @@ -123,7 +144,7 @@ define(function (require, exports, module) { .append(makeCell(item.evidence || "")) .appendTo($errorTable); - $row.click(function () { + var clickCallback = function () { if ($selectedRow) { $selectedRow.removeClass("selected"); } @@ -133,7 +154,11 @@ define(function (require, exports, module) { var editor = EditorManager.getCurrentFullEditor(); editor.setCursorPos(item.line - 1, item.character - 1); EditorManager.focusEditor(); - }); + }; + $row.click(clickCallback); + if (i === 0) { // first result, so store callback for goto command + _gotoFirstErrorFunction = clickCallback; + } } }); @@ -149,10 +174,12 @@ define(function (require, exports, module) { } else { StatusBar.updateIndicator(module.id, true, "jslint-errors", StringUtils.format(Strings.JSLINT_ERRORS_INFORMATION, JSLINT.errors.length)); } + _setGotoEnabled(true); } else { $lintResults.hide(); $goldStar.show(); StatusBar.updateIndicator(module.id, true, "jslint-valid", Strings.JSLINT_NO_ERRORS); + _setGotoEnabled(false); } PerfUtils.addMeasurement(perfTimerDOM); @@ -163,6 +190,7 @@ define(function (require, exports, module) { $lintResults.hide(); $goldStar.hide(); StatusBar.updateIndicator(module.id, true, "jslint-disabled", Strings.JSLINT_DISABLED); + _setGotoEnabled(false); } EditorManager.resizeEditor(); @@ -215,8 +243,17 @@ define(function (require, exports, module) { setEnabled(!getEnabled()); } + /** Command to go to the first JSLint Error */ + function _handleGotoJSLintError() { + run(); + if (_gotoFirstErrorFunction) { + _gotoFirstErrorFunction(); + } + } + // Register command handlers CommandManager.register(Strings.CMD_JSLINT, Commands.TOGGLE_JSLINT, _handleToggleJSLint); + CommandManager.register(Strings.CMD_JSLINT_FIRST_ERROR, Commands.NAVIGATE_GOTO_JSLINT_ERROR, _handleGotoJSLintError); // Init PreferenceStorage _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs); diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 691e8eb3f84..48d18aaad64 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -211,6 +211,7 @@ define({ "CMD_QUICK_OPEN" : "Quick Open", "CMD_GOTO_LINE" : "Go to Line", "CMD_GOTO_DEFINITION" : "Go to Definition", + "CMD_JSLINT_FIRST_ERROR" : "Go to First JSLint Error", "CMD_TOGGLE_QUICK_EDIT" : "Quick Edit", "CMD_QUICK_EDIT_PREV_MATCH" : "Previous Match", "CMD_QUICK_EDIT_NEXT_MATCH" : "Next Match",