From ccfe285babfe89efe96f0d325e2ca0f1216964cf Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Mon, 25 Apr 2011 14:29:02 +0200 Subject: [PATCH] Implement EditSession.removeFold. --- lib/ace/edit_session.js | 44 +++++++++++++++++++++++++++++++++++++++++ lib/ace/editor.js | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 279519f8..7c0d1c91 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -1772,6 +1772,50 @@ var EditSession = function(text, mode) { this._dispatchEvent("changeFold"); }; + this.removeFold = function(fold, foldLine) { + if (foldLine.folds.indexOf(fold) == -1) { + throw "FoldLine doesn't contain fold."; + } + + var foldLines = this.$foldData, + folds = foldLine.folds; + // Simple case where there is only one fold in the FoldLine such that + // the entire fold line can get removed directly. + if (folds.length == 1) { + foldLines.splice(foldLines.indexOf(foldLine), 1); + } else + // If the fold is the last fold of the foldLine, just remove it. + if (foldLine.range.isEnd(fold.end.row, fold.end.column)) { + folds.pop(); + foldLine.end = folds[folds.length - 1].end; + } else + // If the fold is the first fold of the foldLine, just remove it. + if (foldLine.range.isStart(fold.start.row, fold.start.column)) { + folds.shift(); + foldLine.start = folds[0].start; + } else + // We know there are more then 2 folds and the fold is not at the edge. + // This means, the fold is somewhere in between. + // + // If the fold is in one row, we just can remove it. + if (fold.sameRow) { + folds.splice(folds.indexOf(fold), 1); + } else + // The fold goes over more then one row. This means remvoing this fold + // will cause the fold line to get splitted up. + { + var newFoldLine = foldLine.split(fold.start.row, fold.start.column); + newFoldLine.folds.shift(); + newFoldLine.start = newFoldLine.folds[0].start; + this.$addFoldLine(newFoldLine); + } + + // TODO: Update wrapData. + + // Notify that fold data has changed. + this._dispatchEvent("changeFold"); + } + /** * Checks if a given documentRow is folded. This is true if there are some * folded parts such that some parts of the line is still visible. diff --git a/lib/ace/editor.js b/lib/ace/editor.js index d8a57998..5fc99c51 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -384,7 +384,7 @@ var Editor =function(renderer, session) { this.onChangeFold = function() { // TODO: This might be too much updating. Okay for now. - this.render.updateFull(); + this.renderer.updateFull(); }; this.getCopyText = function() {