Skip to content

Commit d9d9eb7

Browse files
committed
Update maxLine when adding or clearing a collapsed range
Closes #1161
1 parent 9e4a3cd commit d9d9eb7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/codemirror.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ window.CodeMirror = (function() {
19671967
if (!cm.options.lineWrapping) {
19681968
checkWidthStart = lineNo(visualLine(doc, firstLine));
19691969
doc.iter(checkWidthStart, to.line + 1, function(line) {
1970-
if (lineLength(doc, line) == view.maxLineLength) {
1970+
if (line == view.maxLine) {
19711971
recomputeMaxLength = true;
19721972
return true;
19731973
}
@@ -3288,7 +3288,7 @@ window.CodeMirror = (function() {
32883288
TextMarker.prototype.clear = function() {
32893289
if (this.explicitlyCleared) return;
32903290
startOperation(this.cm);
3291-
var min = null, max = null;
3291+
var view = this.cm.view, min = null, max = null;
32923292
for (var i = 0; i < this.lines.length; ++i) {
32933293
var line = this.lines[i];
32943294
var span = getMarkedSpanFor(line.markedSpans, this);
@@ -3299,6 +3299,15 @@ window.CodeMirror = (function() {
32993299
else if (this.collapsed && !lineIsHidden(line))
33003300
updateLineHeight(line, textHeight(this.cm.display));
33013301
}
3302+
if (this.collapsed && !this.cm.options.lineWrapping) for (var i = 0; i < this.lines.length; ++i) {
3303+
var visual = visualLine(view.doc, this.lines[i]), len = lineLength(view.doc, visual);
3304+
if (len > view.maxLineLength) {
3305+
view.maxLine = visual;
3306+
view.maxLineLength = len;
3307+
view.maxLineChanged = true;
3308+
}
3309+
}
3310+
33023311
if (min != null) regChange(this.cm, min, max + 1);
33033312
this.lines.length = 0;
33043313
this.explicitlyCleared = true;
@@ -3351,6 +3360,8 @@ window.CodeMirror = (function() {
33513360

33523361
var curLine = from.line, size = 0, collapsedAtStart, collapsedAtEnd;
33533362
doc.iter(curLine, to.line + 1, function(line) {
3363+
if (marker.collapsed && !cm.options.lineWrapping && visualLine(doc, line) == cm.view.maxLine)
3364+
cm.curOp.updateMaxLine = true;
33543365
var span = {from: null, to: null, marker: marker};
33553366
size += line.text.length;
33563367
if (curLine == from.line) {span.from = from.ch; size -= from.ch;}

0 commit comments

Comments
 (0)