Refactor FoldLine.getStringAt out of fold line as the FoldLine should not be session depending.
This commit is contained in:
parent
e9f3ba7b56
commit
9ff0df758a
2 changed files with 33 additions and 41 deletions
|
|
@ -883,6 +883,8 @@ var EditSession = function(text, mode) {
|
||||||
// TODO: Update row data on folds.
|
// TODO: Update row data on folds.
|
||||||
|
|
||||||
var foldLines = this.$foldData;
|
var foldLines = this.$foldData;
|
||||||
|
|
||||||
|
|
||||||
for (var i = 0; i < foldLines.length; i++) {
|
for (var i = 0; i < foldLines.length; i++) {
|
||||||
var foldLine = foldLines[i];
|
var foldLine = foldLines[i];
|
||||||
if (foldLine.start.row >= firstRow + len) {
|
if (foldLine.start.row >= firstRow + len) {
|
||||||
|
|
@ -900,8 +902,6 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Expand folds here if needed.
|
// 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
|
// If some new line is added inside of a foldLine, then split
|
||||||
// the fold line up.
|
// the fold line up.
|
||||||
|
|
@ -1569,37 +1569,6 @@ var EditSession = function(text, mode) {
|
||||||
return null;
|
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) {
|
this.addRemoveChars = function(row, column, len) {
|
||||||
var ret = this.getNextFoldTo(row, column),
|
var ret = this.getNextFoldTo(row, column),
|
||||||
fold, folds;
|
fold, folds;
|
||||||
|
|
@ -1691,12 +1660,39 @@ var EditSession = function(text, mode) {
|
||||||
* foo<fold>bar<fold>wol|rd -trim=+1> "rld"
|
* foo<fold>bar<fold>wol|rd -trim=+1> "rld"
|
||||||
* fo|o<fold>bar<fold>wolrd -trim=00> "foo"
|
* fo|o<fold>bar<fold>wolrd -trim=00> "foo"
|
||||||
*/
|
*/
|
||||||
this.getFoldStringAt = function(row, column, trim) {
|
this.getFoldStringAt = function(row, column, trim, foldLine) {
|
||||||
var foldLine = this.getFoldLine(row);
|
var foldLine = foldLine || this.getFoldLine(row);
|
||||||
if (!foldLine) {
|
if (!foldLine) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -382,11 +382,7 @@ var Selection = function(session) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var str = null;
|
var str = this.session.getFoldStringAt(row, column, -1);
|
||||||
var foldLine = this.session.getFoldLine(row);
|
|
||||||
if (foldLine) {
|
|
||||||
str = foldLine.getStringAt(this.session, row, column, -1);
|
|
||||||
}
|
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
str = this.doc.getLine(row).substring(0, column)
|
str = this.doc.getLine(row).substring(0, column)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue