add jump to matching brace command

This commit is contained in:
Fabian Jakobs 2011-12-19 12:04:22 +01:00
commit 3e88268332
2 changed files with 22 additions and 1 deletions

View file

@ -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(); }
}];
});

View file

@ -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});