Skip to content

Commit d3aa982

Browse files
committed
[overlay addon] Fix bug when overlay mode is itself multiplexed
It assumed it saw all parts of the stream, and started doing bad things when that was not the case. Issue #2410
1 parent e5e07d8 commit d3aa982

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

addon/mode/overlay.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, comb
1414
base: CodeMirror.startState(base),
1515
overlay: CodeMirror.startState(overlay),
1616
basePos: 0, baseCur: null,
17-
overlayPos: 0, overlayCur: null
17+
overlayPos: 0, overlayCur: null,
18+
lineSeen: null
1819
};
1920
},
2021
copyState: function(state) {
@@ -27,6 +28,12 @@ CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, comb
2728
},
2829

2930
token: function(stream, state) {
31+
if (stream.sol() || stream.string != state.lineSeen ||
32+
Math.min(state.basePos, state.overlayPos) < stream.start) {
33+
state.lineSeen = stream.string;
34+
state.basePos = state.overlayPos = stream.start;
35+
}
36+
3037
if (stream.start == state.basePos) {
3138
state.baseCur = base.token(stream, state.base);
3239
state.basePos = stream.pos;
@@ -37,7 +44,6 @@ CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, comb
3744
state.overlayPos = stream.pos;
3845
}
3946
stream.pos = Math.min(state.basePos, state.overlayPos);
40-
if (stream.eol()) state.basePos = state.overlayPos = 0;
4147

4248
if (state.overlayCur == null) return state.baseCur;
4349
if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;

0 commit comments

Comments
 (0)