From 99f904adcc37d93c90defcd8ce898598e25be212 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Wed, 11 Mar 2015 16:55:04 +0100 Subject: Lot of plugins --- .../lib/CodeMirror-2.3/lib/util/multiplex.js | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js (limited to 'codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js') diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js new file mode 100644 index 0000000..822ee62 --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/multiplex.js @@ -0,0 +1,72 @@ +CodeMirror.multiplexingMode = function(outer /*, others */) { + // Others should be {open, close, mode [, delimStyle]} objects + var others = Array.prototype.slice.call(arguments, 1); + var n_others = others.length; + + return { + startState: function() { + return { + outer: CodeMirror.startState(outer), + innerActive: null, + inner: null + }; + }, + + copyState: function(state) { + return { + outer: CodeMirror.copyState(outer, state.outer), + innerActive: state.innerActive, + inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner) + }; + }, + + token: function(stream, state) { + if (!state.innerActive) { + for (var i = 0; i < n_others; ++i) { + var other = others[i]; + if (stream.match(other.open)) { + state.innerActive = other; + state.inner = CodeMirror.startState(other.mode); + return other.delimStyle; + } + } + var outerToken = outer.token(stream, state.outer); + var cur = stream.current(); + for (var i = 0; i < n_others; ++i) { + var other = others[i], found = cur.indexOf(other.open); + if (found > -1) { + stream.backUp(cur.length - found); + cur = cur.slice(0, found); + } + } + return outerToken; + } else { + var curInner = state.innerActive; + if (stream.match(curInner.close)) { + state.innerActive = state.inner = null; + return curInner.delimStyle; + } + var innerToken = curInner.mode.token(stream, state.inner); + var cur = stream.current(), found = cur.indexOf(curInner.close); + if (found > -1) stream.backUp(cur.length - found); + return innerToken; + } + }, + + indent: function(state, textAfter) { + var mode = state.innerActive || outer; + if (!mode.indent) return CodeMirror.Pass; + return mode.indent(state.innerActive ? state.inner : state.outer, textAfter); + }, + + compareStates: function(a, b) { + if (a.innerActive != b.innerActive) return false; + var mode = a.innerActive || outer; + if (!mode.compareStates) return CodeMirror.Pass; + return mode.compareStates(a.innerActive ? a.inner : a.outer, + b.innerActive ? b.inner : b.outer); + }, + + electricChars: outer.electricChars + }; +}; -- cgit v1.2.3