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

Implement a navigation command that takes the user to the first JSLint error #2525

Merged
merged 4 commits into from
Jan 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/base-config/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@
"navigate.gotoDefinition": [
"Ctrl-T"
],
"navigate.gotoJSLintError": [
{
"key": "F8"
},
{
"key": "Cmd-'",
"platform": "mac"
}
],
"navigate.nextDoc": [
{
"key": "Ctrl-Tab"
Expand Down
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 39 additions & 2 deletions src/language/JSLintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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");
}
Expand All @@ -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;
}
}
});

Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down