diff options
author | Kruti Shah | 2012-07-17 12:40:00 -0700 |
---|---|---|
committer | Kruti Shah | 2012-07-17 12:40:00 -0700 |
commit | bf2d7bdb22c28089dc1067bc9094ebc590daac87 (patch) | |
tree | 2156d9920ea1b7db49ed6460545fea7cda121bae /imports/codemirror/lib/util/multiplex.js | |
parent | 7e2c2dbd040ed79a3f0678f91bd4b6db9cf69231 (diff) | |
parent | b4b3e45d6684e77d361b4f8ca5be4889428320c5 (diff) | |
download | ninja-bf2d7bdb22c28089dc1067bc9094ebc590daac87.tar.gz |
Merge branch 'refs/heads/TimelineUberJD' into Timeline-local-kruti
Diffstat (limited to 'imports/codemirror/lib/util/multiplex.js')
-rw-r--r-- | imports/codemirror/lib/util/multiplex.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/imports/codemirror/lib/util/multiplex.js b/imports/codemirror/lib/util/multiplex.js new file mode 100644 index 00000000..822ee62a --- /dev/null +++ b/imports/codemirror/lib/util/multiplex.js | |||
@@ -0,0 +1,72 @@ | |||
1 | CodeMirror.multiplexingMode = function(outer /*, others */) { | ||
2 | // Others should be {open, close, mode [, delimStyle]} objects | ||
3 | var others = Array.prototype.slice.call(arguments, 1); | ||
4 | var n_others = others.length; | ||
5 | |||
6 | return { | ||
7 | startState: function() { | ||
8 | return { | ||
9 | outer: CodeMirror.startState(outer), | ||
10 | innerActive: null, | ||
11 | inner: null | ||
12 | }; | ||
13 | }, | ||
14 | |||
15 | copyState: function(state) { | ||
16 | return { | ||
17 | outer: CodeMirror.copyState(outer, state.outer), | ||
18 | innerActive: state.innerActive, | ||
19 | inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner) | ||
20 | }; | ||
21 | }, | ||
22 | |||
23 | token: function(stream, state) { | ||
24 | if (!state.innerActive) { | ||
25 | for (var i = 0; i < n_others; ++i) { | ||
26 | var other = others[i]; | ||
27 | if (stream.match(other.open)) { | ||
28 | state.innerActive = other; | ||
29 | state.inner = CodeMirror.startState(other.mode); | ||
30 | return other.delimStyle; | ||
31 | } | ||
32 | } | ||
33 | var outerToken = outer.token(stream, state.outer); | ||
34 | var cur = stream.current(); | ||
35 | for (var i = 0; i < n_others; ++i) { | ||
36 | var other = others[i], found = cur.indexOf(other.open); | ||
37 | if (found > -1) { | ||
38 | stream.backUp(cur.length - found); | ||
39 | cur = cur.slice(0, found); | ||
40 | } | ||
41 | } | ||
42 | return outerToken; | ||
43 | } else { | ||
44 | var curInner = state.innerActive; | ||
45 | if (stream.match(curInner.close)) { | ||
46 | state.innerActive = state.inner = null; | ||
47 | return curInner.delimStyle; | ||
48 | } | ||
49 | var innerToken = curInner.mode.token(stream, state.inner); | ||
50 | var cur = stream.current(), found = cur.indexOf(curInner.close); | ||
51 | if (found > -1) stream.backUp(cur.length - found); | ||
52 | return innerToken; | ||
53 | } | ||
54 | }, | ||
55 | |||
56 | indent: function(state, textAfter) { | ||
57 | var mode = state.innerActive || outer; | ||
58 | if (!mode.indent) return CodeMirror.Pass; | ||
59 | return mode.indent(state.innerActive ? state.inner : state.outer, textAfter); | ||
60 | }, | ||
61 | |||
62 | compareStates: function(a, b) { | ||
63 | if (a.innerActive != b.innerActive) return false; | ||
64 | var mode = a.innerActive || outer; | ||
65 | if (!mode.compareStates) return CodeMirror.Pass; | ||
66 | return mode.compareStates(a.innerActive ? a.inner : a.outer, | ||
67 | b.innerActive ? b.inner : b.outer); | ||
68 | }, | ||
69 | |||
70 | electricChars: outer.electricChars | ||
71 | }; | ||
72 | }; | ||