changes per nightwing recommendations

Rename this.getFoldWidgetBase to avoid conflict with C# mode.

Use regex instead of substring and trim to determine single line block
comment.

Fixed formatting.

Renamed this.getRegionBlock to this.getCommentRegionBlock to prevent C#
mode conflict.

Updated this.getCommentRegionBlock regex to make nested regions work
properly.

Cleaned up this.startRegionRe (had unneeded parenthesis).
This commit is contained in:
sevin7676 2014-11-25 06:58:45 -05:00
commit 1869024de6

View file

@ -48,11 +48,13 @@ var FoldMode = exports.FoldMode = function(commentRegex) {
oop.inherits(FoldMode, BaseFoldMode);
(function() {
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
this.startRegionRe = /^\s*((\/\*)|(\/\/))#region\b/;
this.getFoldWidgetBase = this.getFoldWidget;
this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
this._getFoldWidgetBase = this.getFoldWidget;
/**
* Gets fold widget with some non-standard extras:
@ -67,19 +69,17 @@ oop.inherits(FoldMode, BaseFoldMode);
* /*** this folds even though 1 line because it has 3 stars ***[/]
*/
this.getFoldWidget = function(session, foldStyle, row) {
var line = session.getLine(row).trim();
var line = session.getLine(row);
var isRegionStart = this.startRegionRe.test(line);
if (line.length > 3 && line.substring(0, 2) === '/*' && line.substring(line.length - 2) === '*/') {
if (this.singleLineBlockCommentRe.test(line)) {
// No widget for single line block comment unless region or triple star
if (!isRegionStart && line.substring(0, 4) !== '/***')
if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
return "";
}
var fw = this.getFoldWidgetBase(session, foldStyle, row);
if (!fw && isRegionStart)
var fw = this._getFoldWidgetBase(session, foldStyle, row);
if (!fw && this.startRegionRe.test(line))
return "start"; // lineCommentRegionStart
return fw;
@ -88,8 +88,8 @@ oop.inherits(FoldMode, BaseFoldMode);
this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
var line = session.getLine(row);
if(this.startRegionRe.test(line))
return this.getRegionBlock(session, line, row);
if (this.startRegionRe.test(line))
return this.getCommentRegionBlock(session, line, row);
var match = line.match(this.foldingStartMarker);
if (match) {
@ -156,12 +156,12 @@ oop.inherits(FoldMode, BaseFoldMode);
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
};
this.getRegionBlock = function(session, line, row) {
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 re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
var depth = 1;
while (++row < maxRow) {
line = session.getLine(row);