LaravelTest
136 строк · 5.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.multiplexingMode = function(outer /*, others */) {15// Others should be {open, close, mode [, delimStyle] [, innerStyle] [, parseDelimiters]} objects16var others = Array.prototype.slice.call(arguments, 1);17
18function indexOf(string, pattern, from, returnEnd) {19if (typeof pattern == "string") {20var found = string.indexOf(pattern, from);21return returnEnd && found > -1 ? found + pattern.length : found;22}23var m = pattern.exec(from ? string.slice(from) : string);24return m ? m.index + from + (returnEnd ? m[0].length : 0) : -1;25}26
27return {28startState: function() {29return {30outer: CodeMirror.startState(outer),31innerActive: null,32inner: null,33startingInner: false34};35},36
37copyState: function(state) {38return {39outer: CodeMirror.copyState(outer, state.outer),40innerActive: state.innerActive,41inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner),42startingInner: state.startingInner43};44},45
46token: function(stream, state) {47if (!state.innerActive) {48var cutOff = Infinity, oldContent = stream.string;49for (var i = 0; i < others.length; ++i) {50var other = others[i];51var found = indexOf(oldContent, other.open, stream.pos);52if (found == stream.pos) {53if (!other.parseDelimiters) stream.match(other.open);54state.startingInner = !!other.parseDelimiters55state.innerActive = other;56
57// Get the outer indent, making sure to handle CodeMirror.Pass58var outerIndent = 0;59if (outer.indent) {60var possibleOuterIndent = outer.indent(state.outer, "", "");61if (possibleOuterIndent !== CodeMirror.Pass) outerIndent = possibleOuterIndent;62}63
64state.inner = CodeMirror.startState(other.mode, outerIndent);65return other.delimStyle && (other.delimStyle + " " + other.delimStyle + "-open");66} else if (found != -1 && found < cutOff) {67cutOff = found;68}69}70if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff);71var outerToken = outer.token(stream, state.outer);72if (cutOff != Infinity) stream.string = oldContent;73return outerToken;74} else {75var curInner = state.innerActive, oldContent = stream.string;76if (!curInner.close && stream.sol()) {77state.innerActive = state.inner = null;78return this.token(stream, state);79}80var found = curInner.close && !state.startingInner ?81indexOf(oldContent, curInner.close, stream.pos, curInner.parseDelimiters) : -1;82if (found == stream.pos && !curInner.parseDelimiters) {83stream.match(curInner.close);84state.innerActive = state.inner = null;85return curInner.delimStyle && (curInner.delimStyle + " " + curInner.delimStyle + "-close");86}87if (found > -1) stream.string = oldContent.slice(0, found);88var innerToken = curInner.mode.token(stream, state.inner);89if (found > -1) stream.string = oldContent;90else if (stream.pos > stream.start) state.startingInner = false91
92if (found == stream.pos && curInner.parseDelimiters)93state.innerActive = state.inner = null;94
95if (curInner.innerStyle) {96if (innerToken) innerToken = innerToken + " " + curInner.innerStyle;97else innerToken = curInner.innerStyle;98}99
100return innerToken;101}102},103
104indent: function(state, textAfter, line) {105var mode = state.innerActive ? state.innerActive.mode : outer;106if (!mode.indent) return CodeMirror.Pass;107return mode.indent(state.innerActive ? state.inner : state.outer, textAfter, line);108},109
110blankLine: function(state) {111var mode = state.innerActive ? state.innerActive.mode : outer;112if (mode.blankLine) {113mode.blankLine(state.innerActive ? state.inner : state.outer);114}115if (!state.innerActive) {116for (var i = 0; i < others.length; ++i) {117var other = others[i];118if (other.open === "\n") {119state.innerActive = other;120state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "", "") : 0);121}122}123} else if (state.innerActive.close === "\n") {124state.innerActive = state.inner = null;125}126},127
128electricChars: outer.electricChars,129
130innerMode: function(state) {131return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer};132}133};134};135
136});137