lua folding: do not show foldwidgets for keywords in comments

This commit is contained in:
nightwing 2012-10-13 14:53:49 +04:00
commit 704eae50c1

View file

@ -41,9 +41,42 @@ oop.inherits(FoldMode, BaseFoldMode);
(function() {
this.foldingStartMarker = /\b(function|local\s+function|then|do|repeat)\b|{[ \t]*$|\[\[/;
this.foldingStopMarker = /\bend\b|^\s*}|\]\]/;
this.foldingStartMarker = /\b(function|then|do|repeat)\b|{\s*$|(\[=*\[)/;
this.foldingStopMarker = /\bend\b|^\s*}|\]=*\]/;
this.getFoldWidget = function(session, foldStyle, row) {
var line = session.getLine(row);
var isStart = this.foldingStartMarker.test(line);
var isEnd = this.foldingStopMarker.test(line);
if (isStart && !isEnd) {
var match = line.match(this.foldingStartMarker);
if (match[1]) {
if (session.getTokenAt(row, match.index + 1).type == "keyword")
return "start";
} else if (match[2]) {
var type = session.getTokenAt(row + 1, 0).type
if (type == "comment" || type == "string")
return "start";
} else {
return "start";
}
}
if (foldStyle != "markbeginend" || !isEnd || isStart && isEnd)
return "";
var match = line.match(this.foldingStopMarker);
if (match[0] == "end") {
if (session.getTokenAt(row, match.index + 1).type == "keyword")
return "end";
} else if (match[0][0] == "]") {
var type = session.getTokenAt(row - 1, 0).type
if (type == "comment" || type == "string")
return "end";
} else
return "end";
};
this.getFoldWidgetRange = function(session, foldStyle, row) {
var lines = session.doc.getAllLines(row);
var line = lines[row];