Merge pull request #2238 from sevin7676/master
cstyle Comment Folding (region and triple star single line block comment)
This commit is contained in:
commit
93bd34e1cf
2 changed files with 66 additions and 5 deletions
|
|
@ -110,8 +110,8 @@ oop.inherits(FoldMode, CFoldMode);
|
||||||
var maxRow = session.getLength();
|
var maxRow = session.getLength();
|
||||||
var startRow = row;
|
var startRow = row;
|
||||||
|
|
||||||
var re = /^\s*#(end)?region\b/
|
var re = /^\s*#(end)?region\b/;
|
||||||
var depth = 1
|
var depth = 1;
|
||||||
while (++row < maxRow) {
|
while (++row < maxRow) {
|
||||||
line = session.getLine(row);
|
line = session.getLine(row);
|
||||||
var m = re.exec(line);
|
var m = re.exec(line);
|
||||||
|
|
@ -128,8 +128,7 @@ oop.inherits(FoldMode, CFoldMode);
|
||||||
|
|
||||||
var endRow = row;
|
var endRow = row;
|
||||||
if (endRow > startRow) {
|
if (endRow > startRow) {
|
||||||
var endColumn = line.search(/\S/);
|
return new Range(startRow, startColumn, endRow, line.length);
|
||||||
return new Range(startRow, startColumn, endRow, endColumn);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,12 +48,51 @@ var FoldMode = exports.FoldMode = function(commentRegex) {
|
||||||
oop.inherits(FoldMode, BaseFoldMode);
|
oop.inherits(FoldMode, BaseFoldMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
|
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
|
||||||
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
|
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
|
||||||
|
this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
|
||||||
|
this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
|
||||||
|
this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
|
||||||
|
|
||||||
|
//prevent naming conflict with any modes that inherit from cstyle and override this (like csharp)
|
||||||
|
this._getFoldWidgetBase = this.getFoldWidget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets fold widget with some non-standard extras:
|
||||||
|
*
|
||||||
|
* @example lineCommentRegionStart
|
||||||
|
* //#region [optional description]
|
||||||
|
*
|
||||||
|
* @example blockCommentRegionStart
|
||||||
|
* /*#region [optional description] *[/]
|
||||||
|
*
|
||||||
|
* @example tripleStarFoldingSection
|
||||||
|
* /*** this folds even though 1 line because it has 3 stars ***[/]
|
||||||
|
*/
|
||||||
|
this.getFoldWidget = function(session, foldStyle, row) {
|
||||||
|
var line = session.getLine(row);
|
||||||
|
|
||||||
|
if (this.singleLineBlockCommentRe.test(line)) {
|
||||||
|
// No widget for single line block comment unless region or triple star
|
||||||
|
if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
var fw = this._getFoldWidgetBase(session, foldStyle, row);
|
||||||
|
|
||||||
|
if (!fw && this.startRegionRe.test(line))
|
||||||
|
return "start"; // lineCommentRegionStart
|
||||||
|
|
||||||
|
return fw;
|
||||||
|
};
|
||||||
|
|
||||||
this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
|
this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
|
||||||
var line = session.getLine(row);
|
var line = session.getLine(row);
|
||||||
|
|
||||||
|
if (this.startRegionRe.test(line))
|
||||||
|
return this.getCommentRegionBlock(session, line, row);
|
||||||
|
|
||||||
var match = line.match(this.foldingStartMarker);
|
var match = line.match(this.foldingStartMarker);
|
||||||
if (match) {
|
if (match) {
|
||||||
var i = match.index;
|
var i = match.index;
|
||||||
|
|
@ -118,6 +157,29 @@ oop.inherits(FoldMode, BaseFoldMode);
|
||||||
|
|
||||||
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
|
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getCommentRegionBlock = function(session, line, row) {
|
||||||
|
var startColumn = line.search(/\s*$/);
|
||||||
|
var maxRow = session.getLength();
|
||||||
|
var startRow = row;
|
||||||
|
|
||||||
|
var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
|
||||||
|
var depth = 1;
|
||||||
|
while (++row < maxRow) {
|
||||||
|
line = session.getLine(row);
|
||||||
|
var m = re.exec(line);
|
||||||
|
if (!m) continue;
|
||||||
|
if (m[1]) depth--;
|
||||||
|
else depth++;
|
||||||
|
|
||||||
|
if (!depth) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var endRow = row;
|
||||||
|
if (endRow > startRow) {
|
||||||
|
return new Range(startRow, startColumn, endRow, line.length);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}).call(FoldMode.prototype);
|
}).call(FoldMode.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue