LaravelTest
48 строк · 1.6 Кб
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
14function lineIndent(cm, lineNo) {15var text = cm.getLine(lineNo)16var spaceTo = text.search(/\S/)17if (spaceTo == -1 || /\bcomment\b/.test(cm.getTokenTypeAt(CodeMirror.Pos(lineNo, spaceTo + 1))))18return -119return CodeMirror.countColumn(text, null, cm.getOption("tabSize"))20}
21
22CodeMirror.registerHelper("fold", "indent", function(cm, start) {23var myIndent = lineIndent(cm, start.line)24if (myIndent < 0) return25var lastLineInFold = null26
27// Go through lines until we find a line that definitely doesn't belong in28// the block we're folding, or to the end.29for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {30var indent = lineIndent(cm, i)31if (indent == -1) {32} else if (indent > myIndent) {33// Lines with a greater indent are considered part of the block.34lastLineInFold = i;35} else {36// If this line has non-space, non-comment content, and is37// indented less or equal to the start line, it is the start of38// another block.39break;40}41}42if (lastLineInFold) return {43from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),44to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)45};46});47
48});49