From 0e04fff0ea80fa5cbe96b8354db38bd334aea83a Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 16 Jul 2012 16:04:05 -0700 Subject: upgrade to codemirror 2.3 Signed-off-by: Ananya Sen Conflicts: js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css Signed-off-by: Ananya Sen --- imports/codemirror/lib/util/multiplex.js | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 imports/codemirror/lib/util/multiplex.js (limited to 'imports/codemirror/lib/util/multiplex.js') 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 @@ +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