fix #1337 bad interaction of removeFolds and updateWrapData

This commit is contained in:
nightwing 2013-03-30 01:39:52 +04:00
commit 4be0153e2b
4 changed files with 29 additions and 6 deletions

View file

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

View file

@ -384,11 +384,13 @@ function Folding() {
newFoldLine.start.column = folds[0].start.column;
}
if (this.$useWrapMode)
this.$updateWrapData(startRow, endRow);
else
this.$updateRowLengthCache(startRow, endRow);
if (!this.$updating) {
if (this.$useWrapMode)
this.$updateWrapData(startRow, endRow);
else
this.$updateRowLengthCache(startRow, endRow);
}
// Notify that fold data has changed.
this.$modified = true;
this._emit("changeFold", { data: fold });

View file

@ -899,7 +899,25 @@ module.exports = {
return session;
},
"test delete fold with wrap enabled": function() {
var session = new EditSession("");
session.setValue([
"This is some placeholder text that will be folded inline.",
"This is some placeholder text that will be folded inline.",
"More text.",
"<p>The cursor in this paragraph text will be offset by 1 row.<p>",
"<p>Everything after this will be offset as well due to the folds in the row before too.</p>"
].join("\n"));
session.addFold('...', new Range(0, 8, 0, 42));
session.addFold('...', new Range(1, 8, 1, 42));
session.addFold('...', new Range(3, 7, 3, 51));
session.setOption("wrap", 40);
session.remove(new Range(0,0, 2, 5));
assert.equal(session.$wrapData + "", [[], [], [40, 76]] + "");
},
"test add fold": function() {
var session = createFoldTestSession();
var fold;

View file

@ -1364,6 +1364,7 @@ var Editor = function(renderer, session) {
var sel = this.selection;
var doc = this.session;
var range = sel.getRange();
var reverse = sel.isBackwards();
if (range.isEmpty()) {
var row = range.start.row;
doc.duplicateLines(row, row);