Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/addon/fold/indent-fold.js
1294 views
1
CodeMirror.registerHelper("fold", "indent", function(cm, start) {
2
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
3
if (!/\S/.test(firstLine)) return;
4
var getIndent = function(line) {
5
return CodeMirror.countColumn(line, null, tabSize);
6
};
7
var myIndent = getIndent(firstLine);
8
var lastLineInFold = null;
9
// Go through lines until we find a line that definitely doesn't belong in
10
// the block we're folding, or to the end.
11
for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
12
var curLine = cm.getLine(i);
13
var curIndent = getIndent(curLine);
14
if (curIndent > myIndent) {
15
// Lines with a greater indent are considered part of the block.
16
lastLineInFold = i;
17
} else if (!/\S/.test(curLine)) {
18
// Empty lines might be breaks within the block we're trying to fold.
19
} else {
20
// A non-empty line at an indent equal to or less than ours marks the
21
// start of another block.
22
break;
23
}
24
}
25
if (lastLineInFold) return {
26
from: CodeMirror.Pos(start.line, firstLine.length),
27
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
28
};
29
});
30
CodeMirror.indentRangeFinder = CodeMirror.fold.indent; // deprecated
31
32