LaravelTest
59 строк · 2.1 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {15return mode.blockCommentStart && mode.blockCommentEnd;16}, function(cm, start) {17var mode = cm.getModeAt(start), startToken = mode.blockCommentStart, endToken = mode.blockCommentEnd;18if (!startToken || !endToken) return;19var line = start.line, lineText = cm.getLine(line);20
21var startCh;22for (var at = start.ch, pass = 0;;) {23var found = at <= 0 ? -1 : lineText.lastIndexOf(startToken, at - 1);24if (found == -1) {25if (pass == 1) return;26pass = 1;27at = lineText.length;28continue;29}30if (pass == 1 && found < start.ch) return;31if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1))) &&32(found == 0 || lineText.slice(found - endToken.length, found) == endToken ||33!/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found))))) {34startCh = found + startToken.length;35break;36}37at = found - 1;38}39
40var depth = 1, lastLine = cm.lastLine(), end, endCh;41outer: for (var i = line; i <= lastLine; ++i) {42var text = cm.getLine(i), pos = i == line ? startCh : 0;43for (;;) {44var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);45if (nextOpen < 0) nextOpen = text.length;46if (nextClose < 0) nextClose = text.length;47pos = Math.min(nextOpen, nextClose);48if (pos == text.length) break;49if (pos == nextOpen) ++depth;50else if (!--depth) { end = i; endCh = pos; break outer; }51++pos;52}53}54if (end == null || line == end && endCh == startCh) return;55return {from: CodeMirror.Pos(line, startCh),56to: CodeMirror.Pos(end, endCh)};57});58
59});60