Skip to content

Commit 9e4a3cd

Browse files
committed
Fix bug in lineIsHidden test
It would occasionally mark lines as hidden that were needed to display parts of other lines. Issue #1161
1 parent b1b1dd5 commit 9e4a3cd

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lib/codemirror.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,9 @@ window.CodeMirror = (function() {
10571057
var lineObj = getLine(doc, lineNo);
10581058
var found = coordsCharInner(cm, lineObj, lineNo, x, y);
10591059
var merged = collapsedSpanAtEnd(lineObj);
1060-
if (merged && found.ch == lineRight(lineObj))
1061-
lineNo = merged.find().to.line;
1060+
var mergedPos = merged && merged.find();
1061+
if (merged && found.ch >= mergedPos.from.ch)
1062+
lineNo = mergedPos.to.line;
10621063
else
10631064
return found;
10641065
}
@@ -3360,10 +3361,11 @@ window.CodeMirror = (function() {
33603361
else updateLineHeight(line, 0);
33613362
}
33623363
addMarkedSpan(line, span);
3363-
if (marker.collapsed && curLine == from.line && lineIsHidden(line))
3364-
updateLineHeight(line, 0);
33653364
++curLine;
33663365
});
3366+
if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
3367+
if (lineIsHidden(line)) updateLineHeight(line, 0);
3368+
});
33673369

33683370
if (marker.readOnly) {
33693371
sawReadOnlySpans = true;
@@ -3538,9 +3540,12 @@ window.CodeMirror = (function() {
35383540
return true;
35393541
}
35403542
}
3541-
window.lineIsHidden = lineIsHidden;
35423543
function lineIsHiddenInner(line, span) {
3543-
if (span.to == null || span.marker.inclusiveRight && span.to == line.text.length)
3544+
if (span.to == null) {
3545+
var end = span.marker.find().to, endLine = getLine(lineDoc(line), end.line);
3546+
return lineIsHiddenInner(endLine, getMarkedSpanFor(endLine.markedSpans, span.marker));
3547+
}
3548+
if (span.marker.inclusiveRight && span.to == line.text.length)
35443549
return true;
35453550
for (var sp, i = 0; i < line.markedSpans.length; ++i) {
35463551
sp = line.markedSpans[i];
@@ -4083,6 +4088,11 @@ window.CodeMirror = (function() {
40834088
return no;
40844089
}
40854090

4091+
function lineDoc(line) {
4092+
for (var d = line.parent; d.parent; d = d.parent) {}
4093+
return d;
4094+
}
4095+
40864096
function lineAtHeight(chunk, h) {
40874097
var n = 0;
40884098
outer: do {

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,20 @@ testCM("collapsedLines", function(cm) {
543543
eq(cleared, 1);
544544
});
545545

546+
testCM("collapsedRangeCoordsChar", function(cm) {
547+
var pos_1_3 = cm.charCoords({line: 1, ch: 3});
548+
var opts = {collapsed: true, inclusiveLeft: true, inclusiveRight: true};
549+
var m1 = cm.markText({line: 0, ch: 0}, {line: 2, ch: 0}, opts);
550+
eqPos(cm.coordsChar(pos_1_3), {line: 3, ch: 3});
551+
m1.clear();
552+
var m1 = cm.markText({line: 0, ch: 0}, {line: 1, ch: 1}, opts);
553+
var m2 = cm.markText({line: 1, ch: 1}, {line: 2, ch: 0}, opts);
554+
eqPos(cm.coordsChar(pos_1_3), {line: 3, ch: 3});
555+
m1.clear(); m2.clear();
556+
var m1 = cm.markText({line: 0, ch: 0}, {line: 1, ch: 6}, opts);
557+
eqPos(cm.coordsChar(pos_1_3), {line: 3, ch: 3});
558+
}, {value: "123456\nabcdef\nghijkl\nmnopqr\n"});
559+
546560
testCM("hiddenLinesAutoUnfold", function(cm) {
547561
var range = foldLines(cm, 1, 3, true), cleared = 0;
548562
CodeMirror.on(range, "clear", function() {cleared++;});

0 commit comments

Comments
 (0)