summaryrefslogtreecommitdiff
path: root/codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js
diff options
context:
space:
mode:
authorHugues Hiegel <root@paranoid>2015-03-11 16:55:04 +0100
committerHugues Hiegel <root@paranoid>2015-03-11 16:55:04 +0100
commit99f904adcc37d93c90defcd8ce898598e25be212 (patch)
tree60a6c7b7b9cf012d6c0e8dcf5c7f4fe0a5b6fc49 /codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js
parentb2034fdfec040a67988e543a911208ef2491ce7a (diff)
Lot of pluginsHEADmaster
Diffstat (limited to 'codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js')
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js b/codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js
new file mode 100644
index 0000000..1d5df6c
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/lib/util/overlay.js
@@ -0,0 +1,52 @@
+// Utility function that allows modes to be combined. The mode given
+// as the base argument takes care of most of the normal mode
+// functionality, but a second (typically simple) mode is used, which
+// can override the style of text. Both modes get to parse all of the
+// text, but when both assign a non-null style to a piece of code, the
+// overlay wins, unless the combine argument was true, in which case
+// the styles are combined.
+
+// overlayParser is the old, deprecated name
+CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, combine) {
+ return {
+ startState: function() {
+ return {
+ base: CodeMirror.startState(base),
+ overlay: CodeMirror.startState(overlay),
+ basePos: 0, baseCur: null,
+ overlayPos: 0, overlayCur: null
+ };
+ },
+ copyState: function(state) {
+ return {
+ base: CodeMirror.copyState(base, state.base),
+ overlay: CodeMirror.copyState(overlay, state.overlay),
+ basePos: state.basePos, baseCur: null,
+ overlayPos: state.overlayPos, overlayCur: null
+ };
+ },
+
+ token: function(stream, state) {
+ if (stream.start == state.basePos) {
+ state.baseCur = base.token(stream, state.base);
+ state.basePos = stream.pos;
+ }
+ if (stream.start == state.overlayPos) {
+ stream.pos = stream.start;
+ state.overlayCur = overlay.token(stream, state.overlay);
+ state.overlayPos = stream.pos;
+ }
+ stream.pos = Math.min(state.basePos, state.overlayPos);
+ if (stream.eol()) state.basePos = state.overlayPos = 0;
+
+ if (state.overlayCur == null) return state.baseCur;
+ if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
+ else return state.overlayCur;
+ },
+
+ indent: base.indent && function(state, textAfter) {
+ return base.indent(state.base, textAfter);
+ },
+ electricChars: base.electricChars
+ };
+};