1 // Utility function that allows modes to be combined. The mode given
2 // as the base argument takes care of most of the normal mode
3 // functionality, but a second (typically simple) mode is used, which
4 // can override the style of text. Both modes get to parse all of the
5 // text, but when both assign a non-null style to a piece of code, the
6 // overlay wins, unless the combine argument was true, in which case
7 // the styles are combined.
9 // overlayParser is the old, deprecated name
10 CodeMirror
.overlayMode
= CodeMirror
.overlayParser = function(base
, overlay
, combine
) {
12 startState: function() {
14 base
: CodeMirror
.startState(base
),
15 overlay
: CodeMirror
.startState(overlay
),
16 basePos
: 0, baseCur
: null,
17 overlayPos
: 0, overlayCur
: null
20 copyState: function(state
) {
22 base
: CodeMirror
.copyState(base
, state
.base
),
23 overlay
: CodeMirror
.copyState(overlay
, state
.overlay
),
24 basePos
: state
.basePos
, baseCur
: null,
25 overlayPos
: state
.overlayPos
, overlayCur
: null
29 token: function(stream
, state
) {
30 if (stream
.start
== state
.basePos
) {
31 state
.baseCur
= base
.token(stream
, state
.base
);
32 state
.basePos
= stream
.pos
;
34 if (stream
.start
== state
.overlayPos
) {
35 stream
.pos
= stream
.start
;
36 state
.overlayCur
= overlay
.token(stream
, state
.overlay
);
37 state
.overlayPos
= stream
.pos
;
39 stream
.pos
= Math
.min(state
.basePos
, state
.overlayPos
);
40 if (stream
.eol()) state
.basePos
= state
.overlayPos
= 0;
42 if (state
.overlayCur
== null) return state
.baseCur
;
43 if (state
.baseCur
!= null && combine
) return state
.baseCur
+ " " + state
.overlayCur
;
44 else return state
.overlayCur
;
47 indent
: base
.indent
&& function(state
, textAfter
) {
48 return base
.indent(state
.base
, textAfter
);
50 electricChars
: base
.electricChars
,
52 innerMode: function(state
) { return {state
: state
.base
, mode
: base
}; },
54 blankLine: function(state
) {
55 if (base
.blankLine
) base
.blankLine(state
.base
);
56 if (overlay
.blankLine
) overlay
.blankLine(state
.overlay
);