toggleFold must fold strings and comments as well

This commit is contained in:
nightwing 2011-10-21 11:09:10 +05:00
commit 7ade415f25
2 changed files with 58 additions and 17 deletions

View file

@ -173,6 +173,27 @@ var EditSession = function(text, mode) {
return this.bgTokenizer.getTokens(firstRow, lastRow); return this.bgTokenizer.getTokens(firstRow, lastRow);
}; };
this.getTokenAt = function(row, column) {
var tokens = this.bgTokenizer.getTokens(row, row)[0].tokens;
var token, c = 0;
if (column == null) {
i = tokens.length - 1;
c = this.getLine(row).length;
} else {
for (var i = 0; i < tokens.length; i++) {
c += tokens[i].value.length;
if (c >= column)
break;
}
}
token = tokens[i];
if (!token)
return null;
token.index = i;
token.start = c - token.value.length;
return token;
};
this.setUndoManager = function(undoManager) { this.setUndoManager = function(undoManager) {
this.$undoManager = undoManager; this.$undoManager = undoManager;
this.$resetRowCache(0); this.$resetRowCache(0);

View file

@ -517,6 +517,26 @@ function Folding() {
range.start = bracketPos; range.start = bracketPos;
range.start.column++; range.start.column++;
} else {
var token = this.getTokenAt(cursor.row, cursor.column);
if (token && /^comment|string/.test(token.type)) {
var startRow = cursor.row;
var endRow = cursor.row;
var t = token;
while ((t = this.getTokenAt(startRow - 1)) && t.type == token.type) {
startRow --;
token = t;
}
range.start.row = startRow;
range.start.column = token.start + 2;
while ((t = this.getTokenAt(endRow + 1, 0)) && t.type == token.type) {
endRow ++;
token = t;
}
range.end.row = endRow;
range.end.column = token.start + token.value.length - 1;
}
} }
} else { } else {
var folds = this.getFoldsInRange(range); var folds = this.getFoldsInRange(range);