-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
36 lines (30 loc) · 1.1 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Brackets extension to select the block inside matching brackets by double clicking a bracket.
*
* Hugo Pessotti <hpessotti@gmail.com>
**/
define(function (require, exports, module) {
"use strict";
var AppInit = brackets.getModule("utils/AppInit"),
EditorManager = brackets.getModule("editor/EditorManager");
var checkMatching = function(editor, event) {
if (editor.doc.getSelection().match(/^[\s\[\]{}()]+$/)) {
var matchingBracket = editor.findMatchingBracket(editor.doc.getCursor());
if (matchingBracket && matchingBracket.match) {
matchingBracket.from.ch += 1;
editor.doc.setSelection(matchingBracket.from, matchingBracket.to);
}
}
}
var activeEditorChangeHandler = function ($event, focusedEditor, lostEditor) {
if (lostEditor) {
lostEditor._codeMirror.off("dblclick", checkMatching);
}
if (focusedEditor) {
focusedEditor._codeMirror.on("dblclick", checkMatching);
}
};
AppInit.appReady(function() {
$(EditorManager).on("activeEditorChange", activeEditorChangeHandler);
});
});