diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 8360b2ca..addbe66a 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -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); }