Permalink
Browse files

Provide go to matching brace command with shortcut Ctrl+M.

  • Loading branch information...
1 parent 16d2151 commit 5c3dc732d053aad1646c57ce4fde862919faebf1 @RaymondLim RaymondLim committed Apr 2, 2013
@@ -201,6 +201,9 @@
"navigate.gotoDefinition": [
"Ctrl-T"
],
+ "navigate.gotoMatchingBrace": [
+ "Ctrl-M"
+ ],
"navigate.nextDoc": [
{
"key": "Ctrl-Tab"
View
@@ -96,6 +96,7 @@ define(function (require, exports, module) {
exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen";
exports.NAVIGATE_GOTO_DEFINITION = "navigate.gotoDefinition";
exports.NAVIGATE_GOTO_LINE = "navigate.gotoLine";
+ exports.GOTO_MATCHING_BRACE = "navigate.gotoMatchingBrace";
exports.TOGGLE_QUICK_EDIT = "navigate.toggleQuickEdit";
exports.QUICK_EDIT_NEXT_MATCH = "navigate.nextMatch";
exports.QUICK_EDIT_PREV_MATCH = "navigate.previousMatch";
@@ -121,6 +121,7 @@ define(function (require, exports, module) {
menu.addMenuItem(Commands.NAVIGATE_QUICK_OPEN);
menu.addMenuItem(Commands.NAVIGATE_GOTO_LINE);
menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION);
+ menu.addMenuItem(Commands.GOTO_MATCHING_BRACE);
menu.addMenuDivider();
menu.addMenuItem(Commands.NAVIGATE_NEXT_DOC);
menu.addMenuItem(Commands.NAVIGATE_PREV_DOC);
@@ -785,21 +785,39 @@ define(function (require, exports, module) {
return result.promise();
}
+ /**
+ * Move the cursor to the matching brace if the character before/after is
+ * one of these characters -- ()[]{} --- and a match is found.
+ */
+ function findMatchingBrace() {
+ var editor = EditorManager.getFocusedEditor();
+ if (editor) {
+ var maxLinesToScan = 1500,
+ found = editor._codeMirror.findMatchingBracket(maxLinesToScan);
+
+ if (found && found.to) {
+ editor.setCursorPos(found.to.line, found.to.ch);
+ }
+ }
+ }
+
// Register commands
- CommandManager.register(Strings.CMD_INDENT, Commands.EDIT_INDENT, indentText);
- CommandManager.register(Strings.CMD_UNINDENT, Commands.EDIT_UNINDENT, unidentText);
- CommandManager.register(Strings.CMD_COMMENT, Commands.EDIT_LINE_COMMENT, lineComment);
- CommandManager.register(Strings.CMD_BLOCK_COMMENT, Commands.EDIT_BLOCK_COMMENT, blockComment);
- CommandManager.register(Strings.CMD_DUPLICATE, Commands.EDIT_DUPLICATE, duplicateText);
- CommandManager.register(Strings.CMD_DELETE_LINES, Commands.EDIT_DELETE_LINES, deleteCurrentLines);
- CommandManager.register(Strings.CMD_LINE_UP, Commands.EDIT_LINE_UP, moveLineUp);
- CommandManager.register(Strings.CMD_LINE_DOWN, Commands.EDIT_LINE_DOWN, moveLineDown);
- CommandManager.register(Strings.CMD_SELECT_LINE, Commands.EDIT_SELECT_LINE, selectLine);
+ CommandManager.register(Strings.CMD_INDENT, Commands.EDIT_INDENT, indentText);
+ CommandManager.register(Strings.CMD_UNINDENT, Commands.EDIT_UNINDENT, unidentText);
+ CommandManager.register(Strings.CMD_COMMENT, Commands.EDIT_LINE_COMMENT, lineComment);
+ CommandManager.register(Strings.CMD_BLOCK_COMMENT, Commands.EDIT_BLOCK_COMMENT, blockComment);
+ CommandManager.register(Strings.CMD_DUPLICATE, Commands.EDIT_DUPLICATE, duplicateText);
+ CommandManager.register(Strings.CMD_DELETE_LINES, Commands.EDIT_DELETE_LINES, deleteCurrentLines);
+ CommandManager.register(Strings.CMD_LINE_UP, Commands.EDIT_LINE_UP, moveLineUp);
+ CommandManager.register(Strings.CMD_LINE_DOWN, Commands.EDIT_LINE_DOWN, moveLineDown);
+ CommandManager.register(Strings.CMD_SELECT_LINE, Commands.EDIT_SELECT_LINE, selectLine);
+
+ CommandManager.register(Strings.CMD_UNDO, Commands.EDIT_UNDO, handleUndo);
+ CommandManager.register(Strings.CMD_REDO, Commands.EDIT_REDO, handleRedo);
+ CommandManager.register(Strings.CMD_CUT, Commands.EDIT_CUT, ignoreCommand);
+ CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, ignoreCommand);
+ CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, ignoreCommand);
+ CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll);
- CommandManager.register(Strings.CMD_UNDO, Commands.EDIT_UNDO, handleUndo);
- CommandManager.register(Strings.CMD_REDO, Commands.EDIT_REDO, handleRedo);
- CommandManager.register(Strings.CMD_CUT, Commands.EDIT_CUT, ignoreCommand);
- CommandManager.register(Strings.CMD_COPY, Commands.EDIT_COPY, ignoreCommand);
- CommandManager.register(Strings.CMD_PASTE, Commands.EDIT_PASTE, ignoreCommand);
- CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll);
+ CommandManager.register(Strings.CMD_GOTO_MATCHING_BRACE, Commands.GOTO_MATCHING_BRACE, findMatchingBrace);
});
View
@@ -229,6 +229,7 @@ define({
"CMD_QUICK_OPEN" : "Quick Open",
"CMD_GOTO_LINE" : "Go to Line",
"CMD_GOTO_DEFINITION" : "Go to Definition",
+ "CMD_GOTO_MATCHING_BRACE" : "Go to Matching Brace",
"CMD_JSLINT_FIRST_ERROR" : "Go to First JSLint Error",
"CMD_TOGGLE_QUICK_EDIT" : "Quick Edit",
"CMD_QUICK_EDIT_PREV_MATCH" : "Previous Match",

0 comments on commit 5c3dc73

Please sign in to comment.