Skip to content

Commit ff875b0

Browse files
committed
feat: go to next and previous problem
1 parent a388eaf commit ff875b0

6 files changed

Lines changed: 102 additions & 1 deletion

File tree

src/base-config/keyboard.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@
304304
"key": "Alt-PageDown"
305305
}
306306
],
307+
"navigate.gotoNextProblem": [
308+
"F8"
309+
],
310+
"navigate.gotoPrevProblem": [
311+
"Shift-F8"
312+
],
307313
"navigate.prevDocListOrder": [
308314
{
309315
"key": "Alt-PageUp"

src/command/Commands.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ define(function (require, exports, module) {
149149
exports.NAVIGATE_GOTO_DEFINITION_PROJECT = "navigate.gotoDefinitionInProject"; // QuickOpen.js doDefinitionSearchInProject()
150150
exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine"; // QuickOpen.js doGotoLine()
151151
exports.NAVIGATE_GOTO_FIRST_PROBLEM = "navigate.gotoFirstProblem"; // CodeInspection.js handleGotoFirstProblem()
152+
exports.NAVIGATE_GOTO_NEXT_PROBLEM = "navigate.gotoNextProblem"; // CodeInspection.js handleGotoNextProblem()
153+
exports.NAVIGATE_GOTO_PREV_PROBLEM = "navigate.gotoPrevProblem"; // CodeInspection.js handleGotoPrevProblem()
152154
exports.TOGGLE_QUICK_EDIT = "navigate.toggleQuickEdit"; // EditorManager.js _toggleInlineWidget()
153155
exports.TOGGLE_QUICK_DOCS = "navigate.toggleQuickDocs"; // EditorManager.js _toggleInlineWidget()
154156
exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch"; // MultiRangeInlineEditor.js _nextRange()

src/command/DefaultMenus.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ define(function (require, exports, module) {
235235
menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION);
236236
menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION_PROJECT);
237237
menu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION);
238-
menu.addMenuItem(Commands.NAVIGATE_GOTO_FIRST_PROBLEM);
238+
menu.addMenuItem(Commands.NAVIGATE_GOTO_NEXT_PROBLEM);
239+
menu.addMenuItem(Commands.NAVIGATE_GOTO_PREV_PROBLEM);
239240
menu.addMenuDivider();
240241
menu.addMenuItem(Commands.NAVIGATE_NEXT_DOC);
241242
menu.addMenuItem(Commands.NAVIGATE_PREV_DOC);

src/editor/Editor.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,26 @@ define(function (require, exports, module) {
13331333
});
13341334
};
13351335

1336+
/**
1337+
* Returns the first mark of a specific type found after the given position.
1338+
* @param {{line: number, ch: number}} position - The starting position to search from.
1339+
* @param {string} markType - The type of mark to look for.
1340+
* @returns {Array[TextMarker]} The array of text markers found, or an empty array if none are found.
1341+
*/
1342+
Editor.prototype.getMarksAfter = function (position, markType) {
1343+
return this.findMarks(position, { line: this.lineCount(), ch: 0 }, markType) || [];
1344+
};
1345+
1346+
/**
1347+
* Returns the first mark of a specific type found before the given position.
1348+
* @param {{line: number, ch: number}} position - The ending position to search up to.
1349+
* @param {string} markType - The type of mark to look for.
1350+
* @returns {Array[TextMarker]} The array of text markers found, or an empty array if none are found.
1351+
*/
1352+
Editor.prototype.getMarksBefore = function (position, markType) {
1353+
return this.findMarks({ line: 0, ch: 0 }, position, markType) || [];
1354+
};
1355+
13361356
/**
13371357
* Returns an array containing all marked ranges in the document.
13381358
* @param {string} [markType] - Optional, if given will only return marks of that type. Else returns everything.

src/language/CodeInspection.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ define(function (require, exports, module) {
181181
*/
182182
function setGotoEnabled(gotoEnabled) {
183183
CommandManager.get(Commands.NAVIGATE_GOTO_FIRST_PROBLEM).setEnabled(gotoEnabled);
184+
CommandManager.get(Commands.NAVIGATE_GOTO_NEXT_PROBLEM).setEnabled(gotoEnabled);
185+
CommandManager.get(Commands.NAVIGATE_GOTO_PREV_PROBLEM).setEnabled(gotoEnabled);
184186
_gotoEnabled = gotoEnabled;
185187
}
186188

@@ -1076,10 +1078,78 @@ define(function (require, exports, module) {
10761078
}
10771079
}
10781080

1081+
function handleGotoNextProblem() {
1082+
if (_gotoEnabled) {
1083+
const editor = EditorManager.getCurrentFullEditor();
1084+
if(!editor){
1085+
return;
1086+
}
1087+
const currentCursor = editor.getCursorPos();
1088+
const nextMarks = editor.getMarksAfter(currentCursor, CODE_MARK_TYPE_INSPECTOR);
1089+
if(!nextMarks.length || !nextMarks[0].find()){
1090+
return;
1091+
}
1092+
1093+
let nextMark = null;
1094+
for (let i = 0; i < nextMarks.length; i++) {
1095+
const markRange = nextMarks[i].find();
1096+
if (markRange && (markRange.from.line > currentCursor.line ||
1097+
(markRange.from.line === currentCursor.line && markRange.from.ch > currentCursor.ch))) {
1098+
nextMark = nextMarks[i];
1099+
break;
1100+
}
1101+
}
1102+
1103+
if (!nextMark) {
1104+
return;
1105+
}
1106+
const nextMarkRange = nextMark.find();
1107+
if (nextMarkRange) {
1108+
editor.setCursorPos(nextMarkRange.from.line, nextMarkRange.from.ch);
1109+
}
1110+
}
1111+
}
1112+
1113+
function handleGotoPrevProblem() {
1114+
if (_gotoEnabled) {
1115+
const editor = EditorManager.getCurrentFullEditor();
1116+
if (!editor) {
1117+
return;
1118+
}
1119+
const currentCursor = editor.getCursorPos();
1120+
const prevMarks = editor.getMarksBefore(currentCursor, CODE_MARK_TYPE_INSPECTOR);
1121+
1122+
if (!prevMarks.length) {
1123+
return;
1124+
}
1125+
1126+
let prevMark = null;
1127+
for (let i = prevMarks.length - 1; i >= 0; i--) {
1128+
const markRange = prevMarks[i].find();
1129+
if (markRange && (markRange.to.line < currentCursor.line ||
1130+
(markRange.to.line === currentCursor.line && markRange.to.ch < currentCursor.ch))) {
1131+
prevMark = prevMarks[i];
1132+
break;
1133+
}
1134+
}
1135+
1136+
if (!prevMark) {
1137+
return;
1138+
}
1139+
1140+
const prevMarkRange = prevMark.find();
1141+
if (prevMarkRange) {
1142+
editor.setCursorPos(prevMarkRange.from.line, prevMarkRange.from.ch);
1143+
}
1144+
}
1145+
}
1146+
10791147
// Register command handlers
10801148
CommandManager.register(Strings.CMD_VIEW_TOGGLE_INSPECTION, Commands.VIEW_TOGGLE_INSPECTION, toggleEnabled);
10811149
CommandManager.register(Strings.CMD_VIEW_TOGGLE_PROBLEMS, Commands.VIEW_TOGGLE_PROBLEMS, toggleProblems);
10821150
CommandManager.register(Strings.CMD_GOTO_FIRST_PROBLEM, Commands.NAVIGATE_GOTO_FIRST_PROBLEM, handleGotoFirstProblem);
1151+
CommandManager.register(Strings.CMD_GOTO_NEXT_PROBLEM, Commands.NAVIGATE_GOTO_NEXT_PROBLEM, handleGotoNextProblem);
1152+
CommandManager.register(Strings.CMD_GOTO_PREV_PROBLEM, Commands.NAVIGATE_GOTO_PREV_PROBLEM, handleGotoPrevProblem);
10831153

10841154
// Register preferences
10851155
prefs.definePreference(PREF_ENABLED, "boolean", brackets.config["linting.enabled_by_default"], {

src/nls/root/strings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ define({
567567
"CMD_GOTO_DEFINITION": "Quick Find Definition",
568568
"CMD_GOTO_DEFINITION_PROJECT": "Quick Find Definition in Project",
569569
"CMD_GOTO_FIRST_PROBLEM": "Go to First Problem",
570+
"CMD_GOTO_NEXT_PROBLEM": "Go to Next Problem",
571+
"CMD_GOTO_PREV_PROBLEM": "Go to Previous Problem",
570572
"CMD_TOGGLE_QUICK_EDIT": "Quick Edit",
571573
"CMD_TOGGLE_QUICK_DOCS": "Quick Docs",
572574
"CMD_QUICK_EDIT_PREV_MATCH": "Previous Quick Edit Item",

0 commit comments

Comments
 (0)