Fix: merge conflict
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / addon / mode / overlay.js
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.
8
9 // overlayParser is the old, deprecated name
10 CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, combine) {
11   return {
12     startState: function() {
13       return {
14         base: CodeMirror.startState(base),
15         overlay: CodeMirror.startState(overlay),
16         basePos: 0, baseCur: null,
17         overlayPos: 0, overlayCur: null
18       };
19     },
20     copyState: function(state) {
21       return {
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
26       };
27     },
28
29     token: function(stream, state) {
30       if (stream.start == state.basePos) {
31         state.baseCur = base.token(stream, state.base);
32         state.basePos = stream.pos;
33       }
34       if (stream.start == state.overlayPos) {
35         stream.pos = stream.start;
36         state.overlayCur = overlay.token(stream, state.overlay);
37         state.overlayPos = stream.pos;
38       }
39       stream.pos = Math.min(state.basePos, state.overlayPos);
40       if (stream.eol()) state.basePos = state.overlayPos = 0;
41
42       if (state.overlayCur == null) return state.baseCur;
43       if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
44       else return state.overlayCur;
45     },
46
47     indent: base.indent && function(state, textAfter) {
48       return base.indent(state.base, textAfter);
49     },
50     electricChars: base.electricChars,
51
52     innerMode: function(state) { return {state: state.base, mode: base}; },
53
54     blankLine: function(state) {
55       if (base.blankLine) base.blankLine(state.base);
56       if (overlay.blankLine) overlay.blankLine(state.overlay);
57     }
58   };
59 };