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