From 704eae50c1ef78c901053d405263f3acf8d9036a Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 13 Oct 2012 14:53:49 +0400 Subject: [PATCH] lua folding: do not show foldwidgets for keywords in comments --- lib/ace/mode/folding/lua.js | 39 ++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/ace/mode/folding/lua.js b/lib/ace/mode/folding/lua.js index c01f1e9f..73a6a37c 100644 --- a/lib/ace/mode/folding/lua.js +++ b/lib/ace/mode/folding/lua.js @@ -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];