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

@ -494,7 +494,7 @@ function Folding() {
var selection = this.selection;
var range = selection.getRange();
if(range.isEmpty()) {
if (range.isEmpty()) {
var cursor = range.start
var fold = this.getFoldAt(cursor.row, cursor.column);
var bracketPos, column;
@ -517,6 +517,26 @@ function Folding() {
range.start = bracketPos;
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 {
var folds = this.getFoldsInRange(range);