From 3e88268332d8dcb1f5ddadd4a24e3caf18fce218 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 19 Dec 2011 12:04:22 +0100 Subject: [PATCH] add jump to matching brace command --- lib/ace/commands/default_commands.js | 4 ++++ lib/ace/editor.js | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/ace/commands/default_commands.js b/lib/ace/commands/default_commands.js index 1340cafa..ecf3617a 100644 --- a/lib/ace/commands/default_commands.js +++ b/lib/ace/commands/default_commands.js @@ -380,6 +380,10 @@ exports.commands = [{ name: "tolowercase", bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"), exec: function(editor) { editor.toLowerCase(); } +}, { + name: "jumptomatching", + bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"), + exec: function(editor) { editor.jumpToMatching(); } }]; }); diff --git a/lib/ace/editor.js b/lib/ace/editor.js index e6eac8ef..08429e91 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -1005,7 +1005,24 @@ var Editor = function(renderer, session) { this.selection.moveCursorToPosition(pos); }; - + this.jumpToMatching = function() { + var cursor = this.getCursorPosition(); + var pos = this.session.findMatchingBracket(cursor); + if (!pos) { + cursor.column += 1; + pos = this.session.findMatchingBracket(cursor); + } + if (!pos) { + cursor.column -= 2; + pos = this.session.findMatchingBracket(cursor); + } + + if (pos) { + this.clearSelection(); + this.moveCursorTo(pos.row, pos.column); + } + }; + this.gotoLine = function(lineNumber, column) { this.selection.clearSelection(); this.session.unfold({row: lineNumber - 1, column: column || 0});