Fix EditSession.removeFolds: Using the folds of a foldLine might cause unexpected behavior. Clone the passed in array.

This commit is contained in:
Julian Viereck 2011-04-25 22:54:32 +02:00
commit 2be2386603

View file

@ -968,12 +968,6 @@ var EditSession = function(text, mode) {
this.removeFolds(this.getFoldsInRange(e.data.range));
len = -len;
}
// if (action.indexOf("insert") != -1) {
// column = start.column;
// } else {
// column = end.column;
// len = -len;
// }
var foldLine = this.getFoldLine(firstRow);
if (foldLine) {
foldLine.addRemoveChars(firstRow, start.column, len);
@ -1927,7 +1921,15 @@ var EditSession = function(text, mode) {
}
this.removeFolds = function(folds) {
folds.forEach(function(fold) {
// We need to clone the folds array passed in as it might be the folds
// array of a fold line and as we call this.removeFold(fold), folds
// are removed from folds and changes the current index.
var cloneFolds = [];
for (var i = 0; i < folds.length; i++) {
cloneFolds.push(folds[i]);
}
cloneFolds.forEach(function(fold) {
this.removeFold(fold);
}, this);
}