14
if (typeof exports == "object" && typeof module == "object")
15
mod(require("../../lib/codemirror"));
16
else if (typeof define == "function" && define.amd)
17
define(["../../lib/codemirror"], mod);
20
})(function(CodeMirror) {
23
CodeMirror.overlayMode = function(base, overlay, combine) {
25
startState: function() {
27
base: CodeMirror.startState(base),
28
overlay: CodeMirror.startState(overlay),
29
basePos: 0, baseCur: null,
30
overlayPos: 0, overlayCur: null,
34
copyState: function(state) {
36
base: CodeMirror.copyState(base, state.base),
37
overlay: CodeMirror.copyState(overlay, state.overlay),
38
basePos: state.basePos, baseCur: null,
39
overlayPos: state.overlayPos, overlayCur: null
43
token: function(stream, state) {
44
if (stream != state.streamSeen ||
45
Math.min(state.basePos, state.overlayPos) < stream.start) {
46
state.streamSeen = stream;
47
state.basePos = state.overlayPos = stream.start;
50
if (stream.start == state.basePos) {
51
state.baseCur = base.token(stream, state.base);
52
state.basePos = stream.pos;
54
if (stream.start == state.overlayPos) {
55
stream.pos = stream.start;
56
state.overlayCur = overlay.token(stream, state.overlay);
57
state.overlayPos = stream.pos;
59
stream.pos = Math.min(state.basePos, state.overlayPos);
63
if (state.overlayCur == null) return state.baseCur;
64
else if (state.baseCur != null &&
65
state.overlay.combineTokens ||
66
combine && state.overlay.combineTokens == null)
67
return state.baseCur + " " + state.overlayCur;
68
else return state.overlayCur;
71
indent: base.indent && function(state, textAfter, line) {
72
return base.indent(state.base, textAfter, line);
74
electricChars: base.electricChars,
76
innerMode: function(state) { return {state: state.base, mode: base}; },
78
blankLine: function(state) {
79
var baseToken, overlayToken;
80
if (base.blankLine) baseToken = base.blankLine(state.base);
81
if (overlay.blankLine) overlayToken = overlay.blankLine(state.overlay);
83
return overlayToken == null ?
85
(combine && baseToken != null ? baseToken + " " + overlayToken : overlayToken);