!function(n){"object"==typeof exports&&"object"==typeof module?n(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],n):n(CodeMirror)}(function(a){"use strict";function i(i,t,n,l){if(n&&n.call){var f=n;n=null}else f=c(i,n,"rangeFinder");"number"==typeof t&&(t=a.Pos(t,0));var d=c(i,n,"minFoldSize");function e(n){var e=f(i,t);if(!e||e.to.line-e.from.line<d)return null;for(var o=i.findMarksAt(e.from),r=0;r<o.length;++r)if(o[r].__isFold&&"fold"!==l){if(!n)return null;e.cleared=!0,o[r].clear()}return e}var o=e(!0);if(c(i,n,"scanUp"))for(;!o&&t.line>i.firstLine();)t=a.Pos(t.line-1,0),o=e(!1);if(o&&!o.cleared&&"unfold"!==l){var r=function(n,e){var o=c(n,e,"widget");if("string"==typeof o){var r=document.createTextNode(o);(o=document.createElement("span")).appendChild(r),o.className="CodeMirror-foldmarker"}else o=o&&o.cloneNode(!0);return o}(i,n);a.on(r,"mousedown",function(n){u.clear(),a.e_preventDefault(n)});var u=i.markText(o.from,o.to,{replacedWith:r,clearOnEnter:c(i,n,"clearOnEnter"),__isFold:!0});u.on("clear",function(n,e){a.signal(i,"unfold",i,n,e)}),a.signal(i,"fold",i,o.from,o.to)}}a.newFoldFunction=function(o,r){return function(n,e){i(n,e,{rangeFinder:o,widget:r})}},a.defineExtension("foldCode",function(n,e,o){i(this,n,e,o)}),a.defineExtension("isFolded",function(n){for(var e=this.findMarksAt(n),o=0;o<e.length;++o)if(e[o].__isFold)return!0}),a.commands.toggleFold=function(n){n.foldCode(n.getCursor())},a.commands.fold=function(n){n.foldCode(n.getCursor(),null,"fold")},a.commands.unfold=function(n){n.foldCode(n.getCursor(),null,"unfold")},a.commands.foldAll=function(o){o.operation(function(){for(var n=o.firstLine(),e=o.lastLine();n<=e;n++)o.foldCode(a.Pos(n,0),null,"fold")})},a.commands.unfoldAll=function(o){o.operation(function(){for(var n=o.firstLine(),e=o.lastLine();n<=e;n++)o.foldCode(a.Pos(n,0),null,"unfold")})},a.registerHelper("fold","combine",function(){var i=Array.prototype.slice.call(arguments,0);return function(n,e){for(var o=0;o<i.length;++o){var r=i[o](n,e);if(r)return r}}}),a.registerHelper("fold","auto",function(n,e){for(var o=n.getHelpers(e,"fold"),r=0;r<o.length;r++){var i=o[r](n,e);if(i)return i}});var t={rangeFinder:a.fold.auto,widget:"↔",minFoldSize:0,scanUp:!1,clearOnEnter:!0};function c(n,e,o){if(e&&void 0!==e[o])return e[o];var r=n.options.foldOptions;return r&&void 0!==r[o]?r[o]:t[o]}a.defineOption("foldOptions",null),a.defineExtension("foldOption",function(n,e){return c(this,n,e)})});