From 1bed3ec9513bb04d9c96d985fa2b4ee6eb80697f Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Sat, 15 Nov 2014 08:38:21 -0500 Subject: [PATCH 01/11] Javscript region folding --- lib/ace/mode/folding/javascript_folding.js | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 lib/ace/mode/folding/javascript_folding.js diff --git a/lib/ace/mode/folding/javascript_folding.js b/lib/ace/mode/folding/javascript_folding.js new file mode 100644 index 00000000..4ba3897f --- /dev/null +++ b/lib/ace/mode/folding/javascript_folding.js @@ -0,0 +1,106 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../../lib/oop"); +var Range = require("../../range").Range; +var CFoldMode = require("./cstyle").FoldMode; + +var FoldMode = exports.FoldMode = function(commentRegex) { + if (commentRegex) { + this.foldingStartMarker = new RegExp( + this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start) + ); + this.foldingStopMarker = new RegExp( + this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end) + ); + } +}; +oop.inherits(FoldMode, CFoldMode); + +(function() { + this.usingRe = /^\s*using \S/; + + this.getFoldWidgetRangeBase = this.getFoldWidgetRange; + this.getFoldWidgetBase = this.getFoldWidget; + + this.getFoldWidget = function(session, foldStyle, row) { + var fw = this.getFoldWidgetBase(session, foldStyle, row); + if (!fw) { + var line = session.getLine(row); + if (/^\s*\/\/#region\b/.test(line)) + return "start"; + } + return fw; + }; + + this.getFoldWidgetRange = function(session, foldStyle, row) { + var range = this.getFoldWidgetRangeBase(session, foldStyle, row); + if (range) + return range; + + var line = session.getLine(row); + if (/^\s*\/\/#region\b/.test(line)) + return this.getRegionBlock(session, line, row); + }; + + this.getRegionBlock = 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) { + var endColumn = line.search(/\S/); + return new Range(startRow, startColumn, endRow, endColumn); + } + }; + +}).call(FoldMode.prototype); + +}); From 11bbc03e1dea7245f5878cec26d52d4c8deba6cf Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Sat, 15 Nov 2014 08:48:20 -0500 Subject: [PATCH 02/11] Javascript region folding --- lib/ace/mode/folding/{javascript_folding.js => javascript.js} | 0 lib/ace/mode/javascript.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/ace/mode/folding/{javascript_folding.js => javascript.js} (100%) diff --git a/lib/ace/mode/folding/javascript_folding.js b/lib/ace/mode/folding/javascript.js similarity index 100% rename from lib/ace/mode/folding/javascript_folding.js rename to lib/ace/mode/folding/javascript.js diff --git a/lib/ace/mode/javascript.js b/lib/ace/mode/javascript.js index af62ae76..4e7f0dac 100644 --- a/lib/ace/mode/javascript.js +++ b/lib/ace/mode/javascript.js @@ -38,7 +38,7 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd var Range = require("../range").Range; var WorkerClient = require("../worker/worker_client").WorkerClient; var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; -var CStyleFoldMode = require("./folding/cstyle").FoldMode; +var CStyleFoldMode = require("./folding/javascript").FoldMode; var Mode = function() { this.HighlightRules = JavaScriptHighlightRules; From a70a9a88a9f50bdc27c2926e8cafa100b42bca4b Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Sat, 15 Nov 2014 09:03:31 -0500 Subject: [PATCH 03/11] new javascript folding in html mode --- lib/ace/mode/folding/html.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/mode/folding/html.js b/lib/ace/mode/folding/html.js index 5edbe0b8..a84f4478 100644 --- a/lib/ace/mode/folding/html.js +++ b/lib/ace/mode/folding/html.js @@ -34,7 +34,7 @@ define(function(require, exports, module) { var oop = require("../../lib/oop"); var MixedFoldMode = require("./mixed").FoldMode; var XmlFoldMode = require("./xml").FoldMode; -var CStyleFoldMode = require("./cstyle").FoldMode; +var CStyleFoldMode = require("./javascript").FoldMode; var FoldMode = exports.FoldMode = function(voidElements, optionalTags) { MixedFoldMode.call(this, new XmlFoldMode(voidElements, optionalTags), { From ef856d0f617b40ea043f293ac8b6ef3817e8679d Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Sat, 15 Nov 2014 09:15:25 -0500 Subject: [PATCH 04/11] Javascript fixes added forceMultiline parameter and removed line copied from C# folding --- lib/ace/mode/folding/javascript.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/ace/mode/folding/javascript.js b/lib/ace/mode/folding/javascript.js index 4ba3897f..e92c6c3c 100644 --- a/lib/ace/mode/folding/javascript.js +++ b/lib/ace/mode/folding/javascript.js @@ -48,8 +48,6 @@ var FoldMode = exports.FoldMode = function(commentRegex) { oop.inherits(FoldMode, CFoldMode); (function() { - this.usingRe = /^\s*using \S/; - this.getFoldWidgetRangeBase = this.getFoldWidgetRange; this.getFoldWidgetBase = this.getFoldWidget; @@ -63,8 +61,8 @@ oop.inherits(FoldMode, CFoldMode); return fw; }; - this.getFoldWidgetRange = function(session, foldStyle, row) { - var range = this.getFoldWidgetRangeBase(session, foldStyle, row); + this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) { + var range = this.getFoldWidgetRangeBase(session, foldStyle, row, forceMultiline); if (range) return range; From fb32897b85d58906916eb35e4593731e932f5538 Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Mon, 24 Nov 2014 09:29:37 -0500 Subject: [PATCH 05/11] progress appears to be working, need to clean up still --- lib/ace/mode/folding/cstyle.js | 63 ++++++++++++++++++++++++++++++++++ lib/ace/mode/folding/html.js | 2 +- lib/ace/mode/javascript.js | 2 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/lib/ace/mode/folding/cstyle.js b/lib/ace/mode/folding/cstyle.js index dd151e24..d7541f06 100644 --- a/lib/ace/mode/folding/cstyle.js +++ b/lib/ace/mode/folding/cstyle.js @@ -51,9 +51,48 @@ oop.inherits(FoldMode, BaseFoldMode); this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/; this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/; + // this.startBlockRegionRe = /^\s*\/\*#region\b/; + // this.startLineRegionRe = /^\s*\/\/#region\b/; + this.startRegionRe = /^\s*((\/\*)|(\/\/))#region\b/; + this.getFoldWidgetBase = this.getFoldWidget; + + this.getFoldWidget = function(session, foldStyle, row) { + var line = session.getLine(row).trim(); + + var isRegionStart = this.startRegionRe.test(line); + + if (line.length > 3 && line.substring(0, 2) === '/*' && line.substring(line.length - 2) === '*/') { + // Don't create fold widgets for single line block comments + // unless its a region start comment, or it starts with 3 stars [/***] + if (line.substring(0, 4) !== '/***' && !isRegionStart /*!this.startBlockRegionRe.test(line)*/) + return ""; + } + + var fw = this.getFoldWidgetBase(session, foldStyle, row); + if (!fw) { + // check for block comment region start + if(isRegionStart) /*if (this.startLineRegionRe.test(line)) */ + return "start"; + } + + return fw; + }; this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) { var line = session.getLine(row); + + if(this.startRegionRe.test(line)) + return this.getRegionBlock(session, line, row); + + /*// first check for block comment region + if (this.startBlockRegionRe.test(line)) + return this.getRegionBlock(session, line, row, true); + + // now check for line comment region + if (this.startLineRegionRe.test(line)) + return this.getRegionBlock(session, line, row, false);*/ + + var match = line.match(this.foldingStartMarker); if (match) { var i = match.index; @@ -118,6 +157,30 @@ oop.inherits(FoldMode, BaseFoldMode); return new Range(startRow, startColumn, endRow, session.getLine(endRow).length); }; + + this.getRegionBlock = function(session, line, row) { + var startColumn = line.search(/\s*$/); + var maxRow = session.getLength(); + var startRow = row; + + var re = /^\s*((\/\*)|(\/\/))#(end)?region\b/;// isBlock? /^\s*\/\*#(end)?region\b/ : /^\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) { + var endColumn = line.search(/\S/); + return new Range(startRow, startColumn, endRow, endColumn); + } + }; }).call(FoldMode.prototype); diff --git a/lib/ace/mode/folding/html.js b/lib/ace/mode/folding/html.js index a84f4478..5edbe0b8 100644 --- a/lib/ace/mode/folding/html.js +++ b/lib/ace/mode/folding/html.js @@ -34,7 +34,7 @@ define(function(require, exports, module) { var oop = require("../../lib/oop"); var MixedFoldMode = require("./mixed").FoldMode; var XmlFoldMode = require("./xml").FoldMode; -var CStyleFoldMode = require("./javascript").FoldMode; +var CStyleFoldMode = require("./cstyle").FoldMode; var FoldMode = exports.FoldMode = function(voidElements, optionalTags) { MixedFoldMode.call(this, new XmlFoldMode(voidElements, optionalTags), { diff --git a/lib/ace/mode/javascript.js b/lib/ace/mode/javascript.js index 4e7f0dac..af62ae76 100644 --- a/lib/ace/mode/javascript.js +++ b/lib/ace/mode/javascript.js @@ -38,7 +38,7 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd var Range = require("../range").Range; var WorkerClient = require("../worker/worker_client").WorkerClient; var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; -var CStyleFoldMode = require("./folding/javascript").FoldMode; +var CStyleFoldMode = require("./folding/cstyle").FoldMode; var Mode = function() { this.HighlightRules = JavaScriptHighlightRules; From f26841da41ab94ba1aef8a8eff11fde51915d009 Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Mon, 24 Nov 2014 09:48:41 -0500 Subject: [PATCH 06/11] tested and cleaned up --- lib/ace/mode/folding/cstyle.js | 45 ++++++------- lib/ace/mode/folding/javascript.js | 104 ----------------------------- 2 files changed, 21 insertions(+), 128 deletions(-) delete mode 100644 lib/ace/mode/folding/javascript.js diff --git a/lib/ace/mode/folding/cstyle.js b/lib/ace/mode/folding/cstyle.js index d7541f06..d9821d1b 100644 --- a/lib/ace/mode/folding/cstyle.js +++ b/lib/ace/mode/folding/cstyle.js @@ -51,30 +51,36 @@ oop.inherits(FoldMode, BaseFoldMode); this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/; this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/; - // this.startBlockRegionRe = /^\s*\/\*#region\b/; - // this.startLineRegionRe = /^\s*\/\/#region\b/; this.startRegionRe = /^\s*((\/\*)|(\/\/))#region\b/; 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).trim(); - + var isRegionStart = this.startRegionRe.test(line); - + if (line.length > 3 && line.substring(0, 2) === '/*' && line.substring(line.length - 2) === '*/') { - // Don't create fold widgets for single line block comments - // unless its a region start comment, or it starts with 3 stars [/***] - if (line.substring(0, 4) !== '/***' && !isRegionStart /*!this.startBlockRegionRe.test(line)*/) + if (!isRegionStart && line.substring(0, 4) !== '/***') return ""; } - + var fw = this.getFoldWidgetBase(session, foldStyle, row); - if (!fw) { - // check for block comment region start - if(isRegionStart) /*if (this.startLineRegionRe.test(line)) */ - return "start"; - } + if (!fw && isRegionStart) + return "start"; // lineCommentRegionStart + return fw; }; @@ -84,15 +90,6 @@ oop.inherits(FoldMode, BaseFoldMode); if(this.startRegionRe.test(line)) return this.getRegionBlock(session, line, row); - /*// first check for block comment region - if (this.startBlockRegionRe.test(line)) - return this.getRegionBlock(session, line, row, true); - - // now check for line comment region - if (this.startLineRegionRe.test(line)) - return this.getRegionBlock(session, line, row, false);*/ - - var match = line.match(this.foldingStartMarker); if (match) { var i = match.index; @@ -163,7 +160,7 @@ oop.inherits(FoldMode, BaseFoldMode); var maxRow = session.getLength(); var startRow = row; - var re = /^\s*((\/\*)|(\/\/))#(end)?region\b/;// isBlock? /^\s*\/\*#(end)?region\b/ : /^\s*\/\/#(end)?region\b/; + var re = /^\s*((\/\*)|(\/\/))#(end)?region\b/; var depth = 1; while (++row < maxRow) { line = session.getLine(row); @@ -178,7 +175,7 @@ oop.inherits(FoldMode, BaseFoldMode); var endRow = row; if (endRow > startRow) { var endColumn = line.search(/\S/); - return new Range(startRow, startColumn, endRow, endColumn); + return new Range(startRow, startColumn, endRow, line.length); } }; diff --git a/lib/ace/mode/folding/javascript.js b/lib/ace/mode/folding/javascript.js deleted file mode 100644 index e92c6c3c..00000000 --- a/lib/ace/mode/folding/javascript.js +++ /dev/null @@ -1,104 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Distributed under the BSD license: - * - * Copyright (c) 2010, Ajax.org B.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Ajax.org B.V. nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ***** END LICENSE BLOCK ***** */ - -define(function(require, exports, module) { -"use strict"; - -var oop = require("../../lib/oop"); -var Range = require("../../range").Range; -var CFoldMode = require("./cstyle").FoldMode; - -var FoldMode = exports.FoldMode = function(commentRegex) { - if (commentRegex) { - this.foldingStartMarker = new RegExp( - this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start) - ); - this.foldingStopMarker = new RegExp( - this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end) - ); - } -}; -oop.inherits(FoldMode, CFoldMode); - -(function() { - this.getFoldWidgetRangeBase = this.getFoldWidgetRange; - this.getFoldWidgetBase = this.getFoldWidget; - - this.getFoldWidget = function(session, foldStyle, row) { - var fw = this.getFoldWidgetBase(session, foldStyle, row); - if (!fw) { - var line = session.getLine(row); - if (/^\s*\/\/#region\b/.test(line)) - return "start"; - } - return fw; - }; - - this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) { - var range = this.getFoldWidgetRangeBase(session, foldStyle, row, forceMultiline); - if (range) - return range; - - var line = session.getLine(row); - if (/^\s*\/\/#region\b/.test(line)) - return this.getRegionBlock(session, line, row); - }; - - this.getRegionBlock = 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) { - var endColumn = line.search(/\S/); - return new Range(startRow, startColumn, endRow, endColumn); - } - }; - -}).call(FoldMode.prototype); - -}); From 03730ce381dde221842c32b53598e02b9588b7aa Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Mon, 24 Nov 2014 09:52:57 -0500 Subject: [PATCH 07/11] extra comment to help explain code --- lib/ace/mode/folding/cstyle.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ace/mode/folding/cstyle.js b/lib/ace/mode/folding/cstyle.js index d9821d1b..f5f6a0de 100644 --- a/lib/ace/mode/folding/cstyle.js +++ b/lib/ace/mode/folding/cstyle.js @@ -72,6 +72,7 @@ oop.inherits(FoldMode, BaseFoldMode); var isRegionStart = this.startRegionRe.test(line); if (line.length > 3 && line.substring(0, 2) === '/*' && line.substring(line.length - 2) === '*/') { + // No widget for single line block comment unless region or triple star if (!isRegionStart && line.substring(0, 4) !== '/***') return ""; } From 602a7efd5fc45f0859657705a723967c3e629204 Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Mon, 24 Nov 2014 10:18:00 -0500 Subject: [PATCH 08/11] removed unused line the end of the range should be the end of the line as we don't want to see [//#endreigon] in our fold widget. --- lib/ace/mode/folding/cstyle.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ace/mode/folding/cstyle.js b/lib/ace/mode/folding/cstyle.js index f5f6a0de..caeb606a 100644 --- a/lib/ace/mode/folding/cstyle.js +++ b/lib/ace/mode/folding/cstyle.js @@ -175,7 +175,6 @@ oop.inherits(FoldMode, BaseFoldMode); var endRow = row; if (endRow > startRow) { - var endColumn = line.search(/\S/); return new Range(startRow, startColumn, endRow, line.length); } }; From 1869024de6f51153525a77822510c1cdb2408bb1 Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Tue, 25 Nov 2014 06:58:45 -0500 Subject: [PATCH 09/11] 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). --- lib/ace/mode/folding/cstyle.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/ace/mode/folding/cstyle.js b/lib/ace/mode/folding/cstyle.js index caeb606a..c2f302c2 100644 --- a/lib/ace/mode/folding/cstyle.js +++ b/lib/ace/mode/folding/cstyle.js @@ -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); From 41df1f265f1afb85a82db0e9b68d12809312bdb5 Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Tue, 25 Nov 2014 07:01:09 -0500 Subject: [PATCH 10/11] Fix fold widget range for region End range should be at end of line as we don't want to display the '#endregion' text after the fold widget (this is consistent with cstyle region comment folding). Added missing semi-colons. --- lib/ace/mode/folding/csharp.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ace/mode/folding/csharp.js b/lib/ace/mode/folding/csharp.js index c4507534..ec9a2f48 100644 --- a/lib/ace/mode/folding/csharp.js +++ b/lib/ace/mode/folding/csharp.js @@ -110,8 +110,8 @@ oop.inherits(FoldMode, CFoldMode); var maxRow = session.getLength(); var startRow = row; - var re = /^\s*#(end)?region\b/ - var depth = 1 + var re = /^\s*#(end)?region\b/; + var depth = 1; while (++row < maxRow) { line = session.getLine(row); var m = re.exec(line); @@ -128,8 +128,7 @@ oop.inherits(FoldMode, CFoldMode); var endRow = row; if (endRow > startRow) { - var endColumn = line.search(/\S/); - return new Range(startRow, startColumn, endRow, endColumn); + return new Range(startRow, startColumn, endRow, line.length); } }; From c1a8e777606bc03cab10bb08247490785aa49215 Mon Sep 17 00:00:00 2001 From: sevin7676 Date: Fri, 28 Nov 2014 08:18:33 -0500 Subject: [PATCH 11/11] Add comment to explain unusual naming and remove ending whitespace --- lib/ace/mode/folding/cstyle.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ace/mode/folding/cstyle.js b/lib/ace/mode/folding/cstyle.js index c2f302c2..a98807ab 100644 --- a/lib/ace/mode/folding/cstyle.js +++ b/lib/ace/mode/folding/cstyle.js @@ -54,6 +54,8 @@ oop.inherits(FoldMode, BaseFoldMode); 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; /** @@ -61,10 +63,10 @@ oop.inherits(FoldMode, BaseFoldMode); * * @example lineCommentRegionStart * //#region [optional description] - * + * * @example blockCommentRegionStart * /*#region [optional description] *[/] - * + * * @example tripleStarFoldingSection * /*** this folds even though 1 line because it has 3 stars ***[/] */ @@ -73,13 +75,13 @@ oop.inherits(FoldMode, BaseFoldMode); 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)) + if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line)) return ""; } var fw = this._getFoldWidgetBase(session, foldStyle, row); - if (!fw && this.startRegionRe.test(line)) + if (!fw && this.startRegionRe.test(line)) return "start"; // lineCommentRegionStart return fw;