Skip to content

Commit 4be0153

Browse files
committed
fix ajaxorg#1337 bad interaction of removeFolds and updateWrapData
1 parent cf74db8 commit 4be0153

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

lib/ace/edit_session.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ var EditSession = function(text, mode) {
16421642
len = lastRow - firstRow;
16431643
}
16441644

1645+
this.$updating = true;
16451646
if (len != 0) {
16461647
if (action.indexOf("remove") != -1) {
16471648
this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
@@ -1734,6 +1735,7 @@ var EditSession = function(text, mode) {
17341735
if (useWrapMode && this.$wrapData.length != this.doc.getLength()) {
17351736
console.error("doc.getLength() and $wrapData.length have to be the same!");
17361737
}
1738+
this.$updating = false;
17371739

17381740
if (useWrapMode)
17391741
this.$updateWrapData(firstRow, lastRow);

lib/ace/edit_session/folding.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,13 @@ function Folding() {
384384
newFoldLine.start.column = folds[0].start.column;
385385
}
386386

387-
if (this.$useWrapMode)
388-
this.$updateWrapData(startRow, endRow);
389-
else
390-
this.$updateRowLengthCache(startRow, endRow);
391-
387+
if (!this.$updating) {
388+
if (this.$useWrapMode)
389+
this.$updateWrapData(startRow, endRow);
390+
else
391+
this.$updateRowLengthCache(startRow, endRow);
392+
}
393+
392394
// Notify that fold data has changed.
393395
this.$modified = true;
394396
this._emit("changeFold", { data: fold });

lib/ace/edit_session_test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,25 @@ module.exports = {
899899

900900
return session;
901901
},
902-
902+
903+
"test delete fold with wrap enabled": function() {
904+
var session = new EditSession("");
905+
session.setValue([
906+
"This is some placeholder text that will be folded inline.",
907+
"This is some placeholder text that will be folded inline.",
908+
"More text.",
909+
"<p>The cursor in this paragraph text will be offset by 1 row.<p>",
910+
"<p>Everything after this will be offset as well due to the folds in the row before too.</p>"
911+
].join("\n"));
912+
session.addFold('...', new Range(0, 8, 0, 42));
913+
session.addFold('...', new Range(1, 8, 1, 42));
914+
session.addFold('...', new Range(3, 7, 3, 51));
915+
session.setOption("wrap", 40);
916+
session.remove(new Range(0,0, 2, 5));
917+
918+
assert.equal(session.$wrapData + "", [[], [], [40, 76]] + "");
919+
},
920+
903921
"test add fold": function() {
904922
var session = createFoldTestSession();
905923
var fold;

lib/ace/editor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ var Editor = function(renderer, session) {
13641364
var sel = this.selection;
13651365
var doc = this.session;
13661366
var range = sel.getRange();
1367+
var reverse = sel.isBackwards();
13671368
if (range.isEmpty()) {
13681369
var row = range.start.row;
13691370
doc.duplicateLines(row, row);

0 commit comments

Comments
 (0)