5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
function lineIndent(cm, lineNo) {
15
var text = cm.getLine(lineNo)
16
var spaceTo = text.search(/\S/)
17
if (spaceTo == -1 || /\bcomment\b/.test(cm.getTokenTypeAt(CodeMirror.Pos(lineNo, spaceTo + 1))))
19
return CodeMirror.countColumn(text, null, cm.getOption("tabSize"))
22
CodeMirror.registerHelper("fold", "indent", function(cm, start) {
23
var myIndent = lineIndent(cm, start.line)
24
if (myIndent < 0) return
25
var lastLineInFold = null
29
for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
30
var indent = lineIndent(cm, i)
32
} else if (indent > myIndent) {
42
if (lastLineInFold) return {
43
from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),
44
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)