Add handling for simple adding/removing of content to realign the folds
This commit is contained in:
parent
145030972c
commit
c22d80398a
1 changed files with 78 additions and 1 deletions
|
|
@ -879,6 +879,15 @@ var EditSession = function(text, mode) {
|
||||||
useWrapMode && this.$wrapData.splice(firstRow, len);
|
useWrapMode && this.$wrapData.splice(firstRow, len);
|
||||||
// TODO: Remove no longer needed folds here.
|
// TODO: Remove no longer needed folds here.
|
||||||
// TODO: Update row data on folds.
|
// TODO: Update row data on folds.
|
||||||
|
|
||||||
|
var foldLines = this.$foldData;
|
||||||
|
for (var i = 0; i < foldLines.length; i++) {
|
||||||
|
var foldLine = foldLines[i];
|
||||||
|
if (foldLine.start.row >= firstRow + len) {
|
||||||
|
foldLine.shiftRow(-len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lastRow = firstRow;
|
lastRow = firstRow;
|
||||||
} else {
|
} else {
|
||||||
var args;
|
var args;
|
||||||
|
|
@ -889,7 +898,45 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Expand folds here if needed.
|
// TODO: Expand folds here if needed.
|
||||||
// TODO: Update row data on folds.
|
// TODO: Split foldLine in case there are new lines added in
|
||||||
|
// between of a foldLine.
|
||||||
|
var foldLines = this.$foldData;
|
||||||
|
for (var i = 0; i < foldLines.length; i++) {
|
||||||
|
var foldLine = foldLines[i];
|
||||||
|
if (foldLine.start.row >= firstRow) {
|
||||||
|
foldLine.shiftRow(len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
len = Math.abs(e.data.range.start.column - e.data.range.end.column);
|
||||||
|
var column;
|
||||||
|
if (action.indexOf("insert") != -1) {
|
||||||
|
column = e.data.range.start.column;
|
||||||
|
} else {
|
||||||
|
column = e.data.range.end.column;
|
||||||
|
len = -len;
|
||||||
|
}
|
||||||
|
var foldLine = this.getFoldLine(firstRow);
|
||||||
|
if (foldLine) {
|
||||||
|
// TODO: Adding new characters into a fold range should
|
||||||
|
// expand/remove the fold.
|
||||||
|
// for (var i = 0; i <= )
|
||||||
|
var ret = foldLine.getNextFoldTo(firstRow, column);
|
||||||
|
if (ret) {
|
||||||
|
if (ret.kind == "inside") {
|
||||||
|
// TODO
|
||||||
|
} else if (ret.fold.start.row == firstRow){
|
||||||
|
var folds = foldLine.folds;
|
||||||
|
for (var i = folds.indexOf(ret.fold); i < folds.length; i++) {
|
||||||
|
folds[i].start.column += len;
|
||||||
|
if (!folds[i].sameLine) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
folds[i].end.column += len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1410,6 +1457,15 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
this.shiftRow = function(shift) {
|
||||||
|
this.start.row += shift;
|
||||||
|
this.end.row += shift;
|
||||||
|
this.folds.forEach(function(fold) {
|
||||||
|
fold.start.row += shift;
|
||||||
|
fold.end.row += shift;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.addFold = function(fold) {
|
this.addFold = function(fold) {
|
||||||
if (fold.sameLine) {
|
if (fold.sameLine) {
|
||||||
if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
|
if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
|
||||||
|
|
@ -1483,11 +1539,32 @@ var EditSession = function(text, mode) {
|
||||||
callback(null, endRow, endColumn, lastEnd, isNewRow);
|
callback(null, endRow, endColumn, lastEnd, isNewRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getNextFoldTo = function(row, column) {
|
||||||
|
var fold;
|
||||||
|
for (var i = 0; i < this.folds.length; i++) {
|
||||||
|
fold = this.folds[i];
|
||||||
|
cmp = fold.compare(row, column);
|
||||||
|
if (cmp == -1) {
|
||||||
|
return {
|
||||||
|
fold: fold,
|
||||||
|
kind: "after"
|
||||||
|
};
|
||||||
|
} else if (cmp == 0) {
|
||||||
|
return {
|
||||||
|
fold: fold,
|
||||||
|
kind: "inside"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
this.getStringAt = function(session, row, column, trim) {
|
this.getStringAt = function(session, row, column, trim) {
|
||||||
var fold, lastFold, cmp, str;
|
var fold, lastFold, cmp, str;
|
||||||
lastFold = {
|
lastFold = {
|
||||||
end: { column: 0 }
|
end: { column: 0 }
|
||||||
};
|
};
|
||||||
|
// TODO: Refactor to use getNextFoldTo function.
|
||||||
for (var i = 0; i < this.folds.length; i++) {
|
for (var i = 0; i < this.folds.length; i++) {
|
||||||
fold = this.folds[i];
|
fold = this.folds[i];
|
||||||
cmp = fold.compare(row, column);
|
cmp = fold.compare(row, column);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue