PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.0.4
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.0.4
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / assets / lib / codemirror / addon / mode / multiplex.js

multiplex.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.0.4, at assets/lib/codemirror/addon/mode/multiplex.js

102 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 CodeMirror.multiplexingMode = function(outer /*, others */) {
2 // Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
3 var others = Array.prototype.slice.call(arguments, 1);
4 var n_others = others.length;
5
6 function indexOf(string, pattern, from) {
7 if (typeof pattern == "string") return string.indexOf(pattern, from);
8 var m = pattern.exec(from ? string.slice(from) : string);
9 return m ? m.index + from : -1;
10 }
11
12 return {
13 startState: function() {
14 return {
15 outer: CodeMirror.startState(outer),
16 innerActive: null,
17 inner: null
18 };
19 },
20
21 copyState: function(state) {
22 return {
23 outer: CodeMirror.copyState(outer, state.outer),
24 innerActive: state.innerActive,
25 inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner)
26 };
27 },
28
29 token: function(stream, state) {
30 if (!state.innerActive) {
31 var cutOff = Infinity, oldContent = stream.string;
32 for (var i = 0; i < n_others; ++i) {
33 var other = others[i];
34 var found = indexOf(oldContent, other.open, stream.pos);
35 if (found == stream.pos) {
36 stream.match(other.open);
37 state.innerActive = other;
38 state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0);
39 return other.delimStyle;
40 } else if (found != -1 && found < cutOff) {
41 cutOff = found;
42 }
43 }
44 if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff);
45 var outerToken = outer.token(stream, state.outer);
46 if (cutOff != Infinity) stream.string = oldContent;
47 return outerToken;
48 } else {
49 var curInner = state.innerActive, oldContent = stream.string;
50 var found = indexOf(oldContent, curInner.close, stream.pos);
51 if (found == stream.pos) {
52 stream.match(curInner.close);
53 state.innerActive = state.inner = null;
54 return curInner.delimStyle;
55 }
56 if (found > -1) stream.string = oldContent.slice(0, found);
57 var innerToken = curInner.mode.token(stream, state.inner);
58 if (found > -1) stream.string = oldContent;
59 var cur = stream.current(), found = cur.indexOf(curInner.close);
60 if (found > -1) stream.backUp(cur.length - found);
61
62 if (curInner.innerStyle) {
63 if (innerToken) innerToken = innerToken + ' ' + curInner.innerStyle;
64 else innerToken = curInner.innerStyle;
65 }
66
67 return innerToken;
68 }
69 },
70
71 indent: function(state, textAfter) {
72 var mode = state.innerActive ? state.innerActive.mode : outer;
73 if (!mode.indent) return CodeMirror.Pass;
74 return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
75 },
76
77 blankLine: function(state) {
78 var mode = state.innerActive ? state.innerActive.mode : outer;
79 if (mode.blankLine) {
80 mode.blankLine(state.innerActive ? state.inner : state.outer);
81 }
82 if (!state.innerActive) {
83 for (var i = 0; i < n_others; ++i) {
84 var other = others[i];
85 if (other.open === "\n") {
86 state.innerActive = other;
87 state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);
88 }
89 }
90 } else if (state.innerActive.close === "\n") {
91 state.innerActive = state.inner = null;
92 }
93 },
94
95 electricChars: outer.electricChars,
96
97 innerMode: function(state) {
98 return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer};
99 }
100 };
101 };
102