!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.registerHelper("fold","brace",function(n,r){function t(t){for(var i=r.ch,s=0;;){var u=i<=0?-1:f.lastIndexOf(t,i-1);if(-1!=u){if(1==s&&u<r.ch)break;if(o=n.getTokenTypeAt(e.Pos(l,u+1)),!/^(comment|string)/.test(o))return u+1;i=u-1}else{if(1==s)break;s=1,i=f.length}}}var i,o,l=r.line,f=n.getLine(l),s="{",u="}",i=t("{");if(null==i&&(s="[",u="]",i=t("[")),null!=i){var a,d,c=1,g=n.lastLine();e:for(var v=l;v<=g;++v)for(var p=n.getLine(v),m=v==l?i:0;;){var P=p.indexOf(s,m),k=p.indexOf(u,m);if(P<0&&(P=p.length),k<0&&(k=p.length),(m=Math.min(P,k))==p.length)break;if(n.getTokenTypeAt(e.Pos(v,m+1))==o)if(m==P)++c;else if(!--c){a=v,d=m;break e}++m}if(null!=a&&(l!=a||d!=i))return{from:e.Pos(l,i),to:e.Pos(a,d)}}}),e.registerHelper("fold","import",function(n,r){function t(r){if(r<n.firstLine()||r>n.lastLine())return null;var t=n.getTokenAt(e.Pos(r,1));if(/\S/.test(t.string)||(t=n.getTokenAt(e.Pos(r,t.end+1))),"keyword"!=t.type||"import"!=t.string)return null;for(var i=r,o=Math.min(n.lastLine(),r+10);i<=o;++i){var l=n.getLine(i),f=l.indexOf(";");if(-1!=f)return{startCh:t.end,end:e.Pos(i,f)}}}var i,r=r.line,o=t(r);if(!o||t(r-1)||(i=t(r-2))&&i.end.line==r-1)return null;for(var l=o.end;;){var f=t(l.line+1);if(null==f)break;l=f.end}return{from:n.clipPos(e.Pos(r,o.startCh+1)),to:l}}),e.registerHelper("fold","include",function(n,r){function t(r){if(r<n.firstLine()||r>n.lastLine())return null;var t=n.getTokenAt(e.Pos(r,1));return/\S/.test(t.string)||(t=n.getTokenAt(e.Pos(r,t.end+1))),"meta"==t.type&&"#include"==t.string.slice(0,8)?t.start+8:void 0}var r=r.line,i=t(r);if(null==i||null!=t(r-1))return null;for(var o=r;;){if(null==t(o+1))break;++o}return{from:e.Pos(r,i+1),to:n.clipPos(e.Pos(o))}})});