Refactor FoldLine.getStringAt out of fold line as the FoldLine should not be session depending.

This commit is contained in:
Julian Viereck 2011-04-25 13:42:58 +02:00
commit 9ff0df758a
2 changed files with 33 additions and 41 deletions

View file

@ -883,6 +883,8 @@ var EditSession = function(text, mode) {
// 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) {
@ -900,8 +902,6 @@ var EditSession = function(text, mode) {
}
// TODO: Expand folds here if needed.
// TODO: Split foldLine in case there are new lines added in
// between of a foldLine.
// If some new line is added inside of a foldLine, then split
// the fold line up.
@ -1569,37 +1569,6 @@ var EditSession = function(text, mode) {
return null;
}
this.getStringAt = function(session, row, column, trim) {
var fold, lastFold, cmp, str;
lastFold = {
end: { column: 0 }
};
// TODO: Refactor to use getNextFoldTo function.
for (var i = 0; i < this.folds.length; i++) {
fold = this.folds[i];
cmp = fold.range.compareEnd(row, column);
if (cmp == -1) {
str = session.getLine(fold.start.row).
substring(lastFold.end.column, fold.start.column);
break;
} else if (cmp == 0) {
return null;
}
lastFold = fold;
}
if (!str) {
str = session.getLine(fold.start.row).
substring(lastFold.end.column);
}
if (trim == -1) {
return str.substring(0, column - lastFold.end.column);
} else if (trim == 1) {
return str.substring(column - lastFold.end.column)
} else {
return str;
}
}
this.addRemoveChars = function(row, column, len) {
var ret = this.getNextFoldTo(row, column),
fold, folds;
@ -1691,12 +1660,39 @@ var EditSession = function(text, mode) {
* foo<fold>bar<fold>wol|rd -trim=+1> "rld"
* fo|o<fold>bar<fold>wolrd -trim=00> "foo"
*/
this.getFoldStringAt = function(row, column, trim) {
var foldLine = this.getFoldLine(row);
this.getFoldStringAt = function(row, column, trim, foldLine) {
var foldLine = foldLine || this.getFoldLine(row);
if (!foldLine) {
return null;
} else {
return foldLine.getStringAt(this, row, column, trim);
var fold, lastFold, cmp, str;
lastFold = {
end: { column: 0 }
};
// TODO: Refactor to use getNextFoldTo function.
for (var i = 0; i < foldLine.folds.length; i++) {
fold = foldLine.folds[i];
cmp = fold.range.compareEnd(row, column);
if (cmp == -1) {
str = this.getLine(fold.start.row).
substring(lastFold.end.column, fold.start.column);
break;
} else if (cmp == 0) {
return null;
}
lastFold = fold;
}
if (!str) {
str = this.getLine(fold.start.row).
substring(lastFold.end.column);
}
if (trim == -1) {
return str.substring(0, column - lastFold.end.column);
} else if (trim == 1) {
return str.substring(column - lastFold.end.column)
} else {
return str;
}
}
}

View file

@ -382,11 +382,7 @@ var Selection = function(session) {
return;
}
var str = null;
var foldLine = this.session.getFoldLine(row);
if (foldLine) {
str = foldLine.getStringAt(this.session, row, column, -1);
}
var str = this.session.getFoldStringAt(row, column, -1);
if (str == null) {
str = this.doc.getLine(row).substring(0, column)
}