Implement EditSession.removeFold.

This commit is contained in:
Julian Viereck 2011-04-25 14:29:02 +02:00
commit ccfe285bab
2 changed files with 45 additions and 1 deletions

View file

@ -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.

View file

@ -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() {