From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 27 Jan 2012 12:05:17 -0800 Subject: Merged old FileIO --- imports/codemirror/lib/util/foldcode.js | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 imports/codemirror/lib/util/foldcode.js (limited to 'imports/codemirror/lib/util/foldcode.js') diff --git a/imports/codemirror/lib/util/foldcode.js b/imports/codemirror/lib/util/foldcode.js new file mode 100755 index 00000000..18957792 --- /dev/null +++ b/imports/codemirror/lib/util/foldcode.js @@ -0,0 +1,66 @@ +CodeMirror.braceRangeFinder = function(cm, line) { + var lineText = cm.getLine(line); + var startChar = lineText.lastIndexOf("{"); + if (startChar < 0 || lineText.lastIndexOf("}") > startChar) return; + var tokenType = cm.getTokenAt({line: line, ch: startChar}).className; + var count = 1, lastLine = cm.lineCount(), end; + outer: for (var i = line + 1; i < lastLine; ++i) { + var text = cm.getLine(i), pos = 0; + for (;;) { + var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos); + if (nextOpen < 0) nextOpen = text.length; + if (nextClose < 0) nextClose = text.length; + pos = Math.min(nextOpen, nextClose); + if (pos == text.length) break; + if (cm.getTokenAt({line: i, ch: pos + 1}).className == tokenType) { + if (pos == nextOpen) ++count; + else if (!--count) { end = i; break outer; } + } + ++pos; + } + } + if (end == null || end == line + 1) return; + return end; +}; + + +CodeMirror.newFoldFunction = function(rangeFinder, markText) { + var folded = []; + if (markText == null) markText = '