LaravelTest
90 строк · 3.2 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4// Utility function that allows modes to be combined. The mode given
5// as the base argument takes care of most of the normal mode
6// functionality, but a second (typically simple) mode is used, which
7// can override the style of text. Both modes get to parse all of the
8// text, but when both assign a non-null style to a piece of code, the
9// overlay wins, unless the combine argument was true and not overridden,
10// or state.overlay.combineTokens was true, in which case the styles are
11// combined.
12
13(function(mod) {14if (typeof exports == "object" && typeof module == "object") // CommonJS15mod(require("../../lib/codemirror"));16else if (typeof define == "function" && define.amd) // AMD17define(["../../lib/codemirror"], mod);18else // Plain browser env19mod(CodeMirror);20})(function(CodeMirror) {21"use strict";22
23CodeMirror.overlayMode = function(base, overlay, combine) {24return {25startState: function() {26return {27base: CodeMirror.startState(base),28overlay: CodeMirror.startState(overlay),29basePos: 0, baseCur: null,30overlayPos: 0, overlayCur: null,31streamSeen: null32};33},34copyState: function(state) {35return {36base: CodeMirror.copyState(base, state.base),37overlay: CodeMirror.copyState(overlay, state.overlay),38basePos: state.basePos, baseCur: null,39overlayPos: state.overlayPos, overlayCur: null40};41},42
43token: function(stream, state) {44if (stream != state.streamSeen ||45Math.min(state.basePos, state.overlayPos) < stream.start) {46state.streamSeen = stream;47state.basePos = state.overlayPos = stream.start;48}49
50if (stream.start == state.basePos) {51state.baseCur = base.token(stream, state.base);52state.basePos = stream.pos;53}54if (stream.start == state.overlayPos) {55stream.pos = stream.start;56state.overlayCur = overlay.token(stream, state.overlay);57state.overlayPos = stream.pos;58}59stream.pos = Math.min(state.basePos, state.overlayPos);60
61// state.overlay.combineTokens always takes precedence over combine,62// unless set to null63if (state.overlayCur == null) return state.baseCur;64else if (state.baseCur != null &&65state.overlay.combineTokens ||66combine && state.overlay.combineTokens == null)67return state.baseCur + " " + state.overlayCur;68else return state.overlayCur;69},70
71indent: base.indent && function(state, textAfter, line) {72return base.indent(state.base, textAfter, line);73},74electricChars: base.electricChars,75
76innerMode: function(state) { return {state: state.base, mode: base}; },77
78blankLine: function(state) {79var baseToken, overlayToken;80if (base.blankLine) baseToken = base.blankLine(state.base);81if (overlay.blankLine) overlayToken = overlay.blankLine(state.overlay);82
83return overlayToken == null ?84baseToken :85(combine && baseToken != null ? baseToken + " " + overlayToken : overlayToken);86}87};88};89
90});91