Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/addon/mode/multiplex.js
1293 views
CodeMirror.multiplexingMode = function(outer /*, others */) {1// Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects2var others = Array.prototype.slice.call(arguments, 1);3var n_others = others.length;45function indexOf(string, pattern, from) {6if (typeof pattern == "string") return string.indexOf(pattern, from);7var m = pattern.exec(from ? string.slice(from) : string);8return m ? m.index + from : -1;9}1011return {12startState: function() {13return {14outer: CodeMirror.startState(outer),15innerActive: null,16inner: null17};18},1920copyState: function(state) {21return {22outer: CodeMirror.copyState(outer, state.outer),23innerActive: state.innerActive,24inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner)25};26},2728token: function(stream, state) {29if (!state.innerActive) {30var cutOff = Infinity, oldContent = stream.string;31for (var i = 0; i < n_others; ++i) {32var other = others[i];33var found = indexOf(oldContent, other.open, stream.pos);34if (found == stream.pos) {35stream.match(other.open);36state.innerActive = other;37state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0);38return other.delimStyle;39} else if (found != -1 && found < cutOff) {40cutOff = found;41}42}43if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff);44var outerToken = outer.token(stream, state.outer);45if (cutOff != Infinity) stream.string = oldContent;46return outerToken;47} else {48var curInner = state.innerActive, oldContent = stream.string;49if (!curInner.close && stream.sol()) {50state.innerActive = state.inner = null;51return this.token(stream, state);52}53var found = curInner.close ? indexOf(oldContent, curInner.close, stream.pos) : -1;54if (found == stream.pos) {55stream.match(curInner.close);56state.innerActive = state.inner = null;57return curInner.delimStyle;58}59if (found > -1) stream.string = oldContent.slice(0, found);60var innerToken = curInner.mode.token(stream, state.inner);61if (found > -1) stream.string = oldContent;6263if (curInner.innerStyle) {64if (innerToken) innerToken = innerToken + ' ' + curInner.innerStyle;65else innerToken = curInner.innerStyle;66}6768return innerToken;69}70},7172indent: function(state, textAfter) {73var mode = state.innerActive ? state.innerActive.mode : outer;74if (!mode.indent) return CodeMirror.Pass;75return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);76},7778blankLine: function(state) {79var mode = state.innerActive ? state.innerActive.mode : outer;80if (mode.blankLine) {81mode.blankLine(state.innerActive ? state.inner : state.outer);82}83if (!state.innerActive) {84for (var i = 0; i < n_others; ++i) {85var other = others[i];86if (other.open === "\n") {87state.innerActive = other;88state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);89}90}91} else if (state.innerActive.close === "\n") {92state.innerActive = state.inner = null;93}94},9596electricChars: outer.electricChars,9798innerMode: function(state) {99return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer};100}101};102};103104105