improve comment folding
This commit is contained in:
parent
3bcb122a72
commit
ebd4b5bfaa
2 changed files with 20 additions and 21 deletions
|
|
@ -585,30 +585,34 @@ function Folding() {
|
|||
this.addFold(placeholder, range);
|
||||
};
|
||||
|
||||
this.getCommentFoldRange = function(row, column) {
|
||||
this.getCommentFoldRange = function(row, column, dir) {
|
||||
var iterator = new TokenIterator(this, row, column);
|
||||
var token = iterator.getCurrentToken();
|
||||
if (token && /^comment|string/.test(token.type)) {
|
||||
var range = new Range();
|
||||
var re = new RegExp(token.type.replace(/\..*/, "\\."));
|
||||
do {
|
||||
token = iterator.stepBackward();
|
||||
} while(token && re.test(token.type));
|
||||
|
||||
iterator.stepForward();
|
||||
if (dir != 1) {
|
||||
do {
|
||||
token = iterator.stepBackward();
|
||||
} while(token && re.test(token.type));
|
||||
iterator.stepForward();
|
||||
}
|
||||
|
||||
range.start.row = iterator.getCurrentTokenRow();
|
||||
range.start.column = iterator.getCurrentTokenColumn() + 2;
|
||||
|
||||
iterator = new TokenIterator(this, row, column);
|
||||
|
||||
do {
|
||||
token = iterator.stepForward();
|
||||
} while(token && re.test(token.type));
|
||||
|
||||
token = iterator.stepBackward();
|
||||
if (dir != -1) {
|
||||
do {
|
||||
token = iterator.stepForward();
|
||||
} while(token && re.test(token.type));
|
||||
token = iterator.stepBackward();
|
||||
} else
|
||||
token = iterator.getCurrentToken();
|
||||
|
||||
range.end.row = iterator.getCurrentTokenRow();
|
||||
range.end.column = iterator.getCurrentTokenColumn() + token.value.length;
|
||||
range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
|
||||
return range;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -52,9 +52,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
|||
if (match[1])
|
||||
return this.openingBracketBlock(session, match[1], row, i);
|
||||
|
||||
var range = session.getCommentFoldRange(row, i + match[0].length);
|
||||
range.end.column -= 2;
|
||||
return range;
|
||||
return session.getCommentFoldRange(row, i + match[0].length, 1);
|
||||
}
|
||||
|
||||
if (foldStyle !== "markbeginend")
|
||||
|
|
@ -64,13 +62,10 @@ oop.inherits(FoldMode, BaseFoldMode);
|
|||
if (match) {
|
||||
var i = match.index + match[0].length;
|
||||
|
||||
if (match[2]) {
|
||||
var range = session.getCommentFoldRange(row, i);
|
||||
range.end.column -= 2;
|
||||
return range;
|
||||
}
|
||||
if (match[1])
|
||||
return this.closingBracketBlock(session, match[1], row, i);
|
||||
|
||||
return this.closingBracketBlock(session, match[1], row, i);
|
||||
return session.getCommentFoldRange(row, i, -1);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue