Index: Source/devtools/front_end/cm/overlay.js |
diff --git a/Source/devtools/front_end/cm/overlay.js b/Source/devtools/front_end/cm/overlay.js |
index b7928a7bbf38bc5caf89dd4e7d7121425b9ae650..393054dfa441778fe8501d96bbe7cb8cf0167327 100644 |
--- a/Source/devtools/front_end/cm/overlay.js |
+++ b/Source/devtools/front_end/cm/overlay.js |
@@ -1,20 +1,34 @@ |
+// CodeMirror, copyright (c) by Marijn Haverbeke and others |
+// Distributed under an MIT license: http://codemirror.net/LICENSE |
+ |
// 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. |
+// overlay wins, unless the combine argument was true and not overridden, |
+// or state.overlay.combineTokens was true, in which case the styles are |
+// combined. |
+ |
+(function(mod) { |
+ if (typeof exports == "object" && typeof module == "object") // CommonJS |
+ mod(require("../../lib/codemirror")); |
+ else if (typeof define == "function" && define.amd) // AMD |
+ define(["../../lib/codemirror"], mod); |
+ else // Plain browser env |
+ mod(CodeMirror); |
+})(function(CodeMirror) { |
+"use strict"; |
-// overlayParser is the old, deprecated name |
-CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, combine) { |
+CodeMirror.overlayMode = function(base, overlay, combine) { |
return { |
startState: function() { |
return { |
base: CodeMirror.startState(base), |
overlay: CodeMirror.startState(overlay), |
basePos: 0, baseCur: null, |
- overlayPos: 0, overlayCur: null |
+ overlayPos: 0, overlayCur: null, |
+ lineSeen: null |
}; |
}, |
copyState: function(state) { |
@@ -27,6 +41,12 @@ CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, comb |
}, |
token: function(stream, state) { |
+ if (stream.sol() || stream.string != state.lineSeen || |
+ Math.min(state.basePos, state.overlayPos) < stream.start) { |
+ state.lineSeen = stream.string; |
+ state.basePos = state.overlayPos = stream.start; |
+ } |
+ |
if (stream.start == state.basePos) { |
state.baseCur = base.token(stream, state.base); |
state.basePos = stream.pos; |
@@ -37,10 +57,14 @@ CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, comb |
state.overlayPos = stream.pos; |
} |
stream.pos = Math.min(state.basePos, state.overlayPos); |
- if (stream.eol()) state.basePos = state.overlayPos = 0; |
+ // state.overlay.combineTokens always takes precedence over combine, |
+ // unless set to null |
if (state.overlayCur == null) return state.baseCur; |
- if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur; |
+ else if (state.baseCur != null && |
+ state.overlay.combineTokens || |
+ combine && state.overlay.combineTokens == null) |
+ return state.baseCur + " " + state.overlayCur; |
else return state.overlayCur; |
}, |
@@ -57,3 +81,5 @@ CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, comb |
} |
}; |
}; |
+ |
+}); |