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];