codemirror.js 56.7 KB
var CodeMirror=function(){function t(l,h){function y(t){Je.onDragEvent&&Je.onDragEvent(Qn,x(t))||b(t)}function M(t){return t>=0&&t<kn.size}function T(t){return d(kn,t)}function E(t,e){zn=!0;for(var n=e-t.height,r=t;r;r=r.parent)r.height+=n}function R(t){var e={line:0,ch:0};kt(e,{line:kn.size-1,ch:T(kn.size-1).text.length},st(t),e,e),Tn=!0}function F(){var t=[];return kn.iter(0,kn.size,function(e){t.push(e.text)}),t.join("\n")}function V(t){Bn==gn.scrollTop&&Pn==rn.scrollLeft||(Bn=gn.scrollTop,Pn=rn.scrollLeft,jt([]),Je.fixedGutter&&(an.style.left=rn.scrollLeft+"px"),Je.onScroll&&Je.onScroll(Qn))}function nt(t){function e(e){Q&&(rn.draggable=!1),Ln=!1,f(),h(),Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)<10&&(C(e),ne(o.line,o.ch,!0),Kt())}function n(t){var e=Be(t,!0);if(e&&!W(e,s)){Cn||xt(),s=e,Qt(o,e),Tn=!1;var r=Yt();(e.line>=r.to||e.line<r.from)&&(a=setTimeout($e(function(){n(t)}),150))}}function r(t){clearTimeout(a);var e=Be(t);e&&Qt(o,e),C(t),Kt(),Tn=!0,u(),f()}qt(w(t,"shiftKey"));for(var i=k(t);i!=tn;i=i.parentNode)if(i.parentNode==on&&i!=ln)return;for(var i=k(t);i!=tn;i=i.parentNode)if(i.parentNode==sn)return Je.onGutterClick&&Je.onGutterClick(Qn,B(sn.childNodes,i)+Vn,t),C(t);var o=Be(t);switch(S(t)){case 3:return void(Z&&!U&&Pe(t));case 2:return o&&ne(o.line,o.ch,!0),setTimeout(Kt,20),void C(t)}if(!o)return void(k(t)==rn&&C(t));Cn||xt();var l=+new Date;if(An&&An.time>l-400&&W(An.pos,o))return C(t),setTimeout(Kt,20),he(o.line);if(wn&&wn.time>l-400&&W(wn.pos,o))return An={time:l,pos:o},C(t),fe(o);wn={time:l,pos:o};var a,s=o;if(Je.dragDrop&&ot&&!Je.readOnly&&!W(In.from,In.to)&&!z(o,In.from)&&!z(In.to,o)){Q&&(rn.draggable=!0);var f=A(document,"mouseup",$e(e),!0),h=A(rn,"drop",$e(e),!0);return Ln=!0,void(rn.dragDrop&&rn.dragDrop())}C(t),ne(o.line,o.ch,!0);var u=A(document,"mousemove",$e(function(t){clearTimeout(a),C(t),$||S(t)?n(t):r(t)}),!0),f=A(document,"mouseup",$e(r),!0)}function at(t){for(var e=k(t);e!=tn;e=e.parentNode)if(e.parentNode==sn)return C(t);var n=Be(t);n&&(An={time:+new Date,pos:n},C(t),fe(n))}function ut(t){function e(t,e){var r=new FileReader;r.onload=function(){o[e]=r.result,++l==i&&(n=ie(n),$e(function(){var t=Ht(o.join(""),n,n);Qt(n,t)})())},r.readAsText(t)}if(!Je.onDragEvent||!Je.onDragEvent(Qn,x(t))){t.preventDefault();var n=Be(t,!0),r=t.dataTransfer.files;if(n&&!Je.readOnly)if(r&&r.length&&window.FileReader&&window.File)for(var i=r.length,o=Array(i),l=0,a=0;a<i;++a)e(r[a],a);else{if(Ln&&!z(n,In.from)&&!z(In.to,n))return;try{var o=t.dataTransfer.getData("Text");o&&_e(function(){var t=In.from,e=In.to;Qt(n,n),Ln&&Ht("",t,e),Nt(o),Kt()})}catch(t){}}}}function ct(t){var e=Ot();if(t.dataTransfer.setData("Text",e),Z||tt||et){var n=document.createElement("img");n.scr="data:image/gif;base64,R0lGODdhAgACAIAAAAAAAP///ywAAAAAAgACAAACAoRRADs=",t.dataTransfer.setDragImage(n,0,0)}}function dt(t,e){if("string"==typeof t&&(t=X[t],!t))return!1;var n=Sn;try{Je.readOnly&&(Un=!0),e&&(Sn=null),t(Qn)}catch(t){if(t!=j)throw t;return!1}finally{Sn=n,Un=!1}return!0}function pt(t){function i(){f=!0}var o=e(Je.keyMap),l=o.auto;clearTimeout(qn),l&&!r(t)&&(qn=setTimeout(function(){e(Je.keyMap)==o&&(Je.keyMap=l.call?l.call(null,Qn):l)},50));var a=ht[w(t,"keyCode")],s=!1;if(null==a||t.altGraphKey)return!1;w(t,"altKey")&&(a="Alt-"+a),w(t,"ctrlKey")&&(a="Ctrl-"+a),w(t,"metaKey")&&(a="Cmd-"+a);var f=!1;return s=w(t,"shiftKey")?n("Shift-"+a,Je.extraKeys,Je.keyMap,function(t){return dt(t,!0)},i)||n(a,Je.extraKeys,Je.keyMap,function(t){if("string"==typeof t&&/^go[A-Z]/.test(t))return dt(t)},i):n(a,Je.extraKeys,Je.keyMap,dt,i),f&&(s=!1),s&&(C(t),Ke(),$&&(t.oldKeyCode=t.keyCode,t.keyCode=0)),s}function gt(t,e){var r=n("'"+e+"'",Je.extraKeys,Je.keyMap,function(t){return dt(t,!0)});return r&&(C(t),Ke()),r}function mt(t){if(Cn||xt(),$&&27==t.keyCode&&(t.returnValue=!1),er&&Bt()&&(er=!1),!Je.onKeyEvent||!Je.onKeyEvent(Qn,x(t))){var e=w(t,"keyCode");qt(16==e||w(t,"shiftKey"));var n=pt(t);et&&(tr=n?e:null,!n&&88==e&&w(t,U?"metaKey":"ctrlKey")&&Nt(""))}}function vt(t){if(er&&Bt(),!Je.onKeyEvent||!Je.onKeyEvent(Qn,x(t))){var e=w(t,"keyCode"),n=w(t,"charCode");if(et&&e==tr)return tr=null,void C(t);if(!(et&&(!t.which||t.which<10)||rt)||!pt(t)){var r=String.fromCharCode(null==n?e:n);Je.electricChars&&yn.electricChars&&Je.smartIndent&&!Je.readOnly&&yn.electricChars.indexOf(r)>-1&&setTimeout($e(function(){ce(In.to.line,"smart")}),75),gt(t,r)||It()}}}function yt(t){Je.onKeyEvent&&Je.onKeyEvent(Qn,x(t))||16==w(t,"keyCode")&&(Sn=null)}function xt(){"nocursor"!=Je.readOnly&&(Cn||(Je.onFocus&&Je.onFocus(Qn),Cn=!0,rn.className.search(/\bCodeMirror-focused\b/)==-1&&(rn.className+=" CodeMirror-focused"),Wn||Pt(!0)),Rt(),Ke())}function Ct(){Cn&&(Je.onBlur&&Je.onBlur(Qn),Cn=!1,Rn&&$e(function(){Rn&&(Rn(),Rn=null)})(),rn.className=rn.className.replace(" CodeMirror-focused","")),clearInterval(vn),setTimeout(function(){Cn||(Sn=null)},150)}function Mt(t){return t>0&&t<1?1:t>-1&&t<0?-1:Math.round(t)}function bt(t){var e=0,n=0;if("DOMMouseScroll"==t.type){var r=8*-t.detail;t.axis==t.HORIZONTAL_AXIS?e=r:t.axis==t.VERTICAL_AXIS&&(n=r)}else void 0!==t.wheelDeltaX&&void 0!==t.wheelDeltaY?(e=t.wheelDeltaX/3,n=t.wheelDeltaY/3):void 0!==t.wheelDelta&&(n=t.wheelDelta/3);var i=!1;e=Mt(e),n=Mt(n),(e>0&&rn.scrollLeft>0||e<0&&rn.scrollLeft+rn.clientWidth<rn.scrollWidth)&&(rn.scrollLeft-=e,i=!0),(n>0&&gn.scrollTop>0||n<0&&gn.scrollTop+gn.clientHeight<gn.scrollHeight)&&(gn.scrollTop-=n,i=!0),i&&b(t)}function kt(t,e,n,r,i){if(!Un){if(_n){var o=[];for(kn.iter(t.line,e.line+1,function(t){o.push(t.text)}),_n.addChange(t.line,n.length,o);_n.done.length>Je.undoDepth;)_n.done.shift()}Lt(t,e,n,r,i)}}function St(t,e){if(t.length){for(var n=t.pop(),r=[],i=n.length-1;i>=0;i-=1){var o=n[i],l=[],a=o.start+o.added;kn.iter(o.start,a,function(t){l.push(t.text)}),r.push({start:o.start,added:o.old.length,old:l});var s={line:o.start+o.old.length-1,ch:I(l[l.length-1],o.old[o.old.length-1])};Lt({line:o.start,ch:0},{line:a-1,ch:T(a-1).text.length},o.old,s,s)}Tn=!0,e.push(r)}}function wt(){St(_n.done,_n.undone)}function At(){St(_n.undone,_n.done)}function Lt(t,e,n,r,i){function o(t){return t<=Math.min(e.line,e.line+y)?t:t+y}if(!Un){var l=!1,a=Yn.length;Je.lineWrapping||kn.iter(t.line,e.line+1,function(t){if(!t.hidden&&t.text.length==a)return l=!0,!0}),(t.line!=e.line||n.length>1)&&(zn=!0);var s=e.line-t.line,h=T(t.line),u=T(e.line);if(0==t.ch&&0==e.ch&&""==n[n.length-1]){var c=[],d=null;t.line?(d=T(t.line-1),d.fixMarkEnds(u)):u.fixMarkStarts();for(var p=0,g=n.length-1;p<g;++p)c.push(f.inheritMarks(n[p],d));s&&kn.remove(t.line,s,On),c.length&&kn.insert(t.line,c)}else if(h==u)if(1==n.length)h.replace(t.ch,e.ch,n[0]);else{u=h.split(e.ch,n[n.length-1]),h.replace(t.ch,null,n[0]),h.fixMarkEnds(u);for(var c=[],p=1,g=n.length-1;p<g;++p)c.push(f.inheritMarks(n[p],h));c.push(u),kn.insert(t.line+1,c)}else if(1==n.length)h.replace(t.ch,null,n[0]),u.replace(null,e.ch,""),h.append(u),kn.remove(t.line+1,s,On);else{var c=[];h.replace(t.ch,null,n[0]),u.replace(null,e.ch,n[n.length-1]),h.fixMarkEnds(u);for(var p=1,g=n.length-1;p<g;++p)c.push(f.inheritMarks(n[p],h));s>1&&kn.remove(t.line+1,s-1,On),kn.insert(t.line+1,c)}if(Je.lineWrapping){var m=Math.max(5,rn.clientWidth/Oe()-3);kn.iter(t.line,t.line+n.length,function(t){if(!t.hidden){var e=Math.ceil(t.text.length/m)||1;e!=t.height&&E(t,e)}})}else kn.iter(t.line,t.line+n.length,function(t){var e=t.text;!t.hidden&&e.length>a&&(Yn=e,a=e.length,Zn=!0,l=!1)}),l&&(jn=!0);for(var v=[],y=n.length-s-1,p=0,x=xn.length;p<x;++p){var C=xn[p];C<t.line?v.push(C):C>e.line&&v.push(C+y)}var M=t.line+Math.min(n.length,500);Ge(t.line,M),v.push(M),xn=v,Ye(100),Dn.push({from:t.line,to:e.line+1,diff:y});var b={from:t,to:e,text:n};if(Hn){for(var k=Hn;k.next;k=k.next);k.next=b}else Hn=b;te(ie(r),ie(i),o(In.from.line),o(In.to.line))}}function Tt(t){var e=ze(),n=Math.floor(kn.height*e+2*Re()),r=rn.clientHeight;gn.style.height=r+"px",rn.clientHeight&&(mn.style.height=n+"px"),null!=t&&(gn.scrollTop=t),ln.style.top=Fn*e-gn.scrollTop+"px",gn.style.display=n>r?"block":"none"}function Et(){var t=document.createElement("div"),e=document.createElement("div");t.className="CodeMirror-scrollbar",t.style.cssText="position: absolute; left: -9999px; height: 100px;",e.className="CodeMirror-scrollbar-inner",e.style.height="200px",t.appendChild(e),document.body.appendChild(t);var n=t.offsetWidth<=1;return document.body.removeChild(t),n}function Dt(){var t=0;Yn="",Zn=!0,kn.iter(0,kn.size,function(e){var n=e.text;!e.hidden&&n.length>t&&(t=n.length,Yn=n)}),jn=!1}function Ht(t,e,n){function r(r){if(z(r,e))return r;if(!z(n,r))return i;var o=r.line+t.length-(n.line-e.line)-1,l=r.ch;return r.line==n.line&&(l+=t[t.length-1].length-(n.ch-(n.line==e.line?e.ch:0))),{line:o,ch:l}}e=ie(e),n=n?ie(n):e,t=st(t);var i;return Wt(t,e,n,function(t){return i=t,{from:r(In.from),to:r(In.to)}}),i}function Nt(t,e){Wt(st(t),In.from,In.to,function(t){return"end"==e?{from:t,to:t}:"start"==e?{from:In.from,to:In.from}:{from:In.from,to:t}})}function Wt(t,e,n,r){var i=1==t.length?t[0].length+e.ch:t[t.length-1].length,o=r({line:e.line+t.length-1,ch:i});kt(e,n,t,o.from,o.to)}function zt(t,e){var n=t.line,r=e.line;if(n==r)return T(n).text.slice(t.ch,e.ch);var i=[T(n).text.slice(t.ch)];return kn.iter(n+1,r,function(t){i.push(t.text)}),i.push(T(r).text.slice(0,e.ch)),i.join("\n")}function Ot(){return zt(In.from,In.to)}function Rt(){er||Mn.set(Je.pollInterval,function(){je(),Bt(),Cn&&Rt(),Ze()})}function It(){function t(){je();var n=Bt();n||e?(er=!1,Rt()):(e=!0,Mn.set(60,t)),Ze()}var e=!1;er=!0,Mn.set(20,t)}function Bt(){if(Wn||!Cn||ft(nn)||Je.readOnly)return!1;var t=nn.value;if(t==nr)return!1;Sn=null;for(var e=0,n=Math.min(nr.length,t.length);e<n&&nr[e]==t[e];)++e;return e<nr.length?In.from={line:In.from.line,ch:In.from.ch-(nr.length-e)}:Kn&&W(In.from,In.to)&&(In.to={line:In.to.line,ch:Math.min(T(In.to.line).text.length,In.to.ch+(t.length-e))}),Nt(t.slice(e),"end"),t.length>1e3?nn.value=nr="":nr=t,!0}function Pt(t){W(In.from,In.to)?t&&(nr=nn.value=""):(nr="",nn.value=Ot(),N(nn))}function Kt(){"nocursor"!=Je.readOnly&&nn.focus()}function Ut(){if(un.getBoundingClientRect){var t=un.getBoundingClientRect();if(!$||t.top!=t.bottom){var e=window.innerHeight||Math.max(document.body.offsetHeight,document.documentElement.offsetHeight);(t.top<0||t.bottom>e)&&Ft()}}}function Ft(){var t=Vt();return Gt(t.x,t.y,t.x,t.yBot)}function Vt(){var t=He(In.inverted?In.from:In.to),e=Je.lineWrapping?Math.min(t.x,fn.offsetWidth):t.x;return{x:e,y:t.y,yBot:t.yBot}}function Gt(t,e,n,r){var i=Xt(t,e,n,r),o=!1;null!=i.scrollLeft&&(rn.scrollLeft=i.scrollLeft,o=!0),null!=i.scrollTop&&(gn.scrollTop=i.scrollTop,o=!0),o&&Je.onScroll&&Je.onScroll(Qn)}function Xt(t,e,n,r){var i=Ie(),o=Re();e+=o,r+=o,t+=i,n+=i;var l=rn.clientHeight,a=gn.scrollTop,s={},f=e<Re()+10;e<a?s.scrollTop=f?0:Math.max(0,e):r>a+l&&(s.scrollTop=r-l);var h=rn.clientWidth,u=rn.scrollLeft,c=Je.fixedGutter?an.clientWidth:0,d=t<c+i+10;return t<u+c||d?(d&&(t=0),s.scrollLeft=Math.max(0,t-10-c)):n>h+u-3&&(s.scrollLeft=n+10-h),s}function Yt(t){var e=ze(),n=(null!=t?t:gn.scrollTop)-Re(),r=Math.max(0,Math.floor(n/e)),i=Math.ceil((n+rn.clientHeight)/e);return{from:g(kn,r),to:g(kn,i)}}function jt(t,e,n){function r(){var t=pn.firstChild,e=!1;return kn.iter(Vn,Gn,function(n){if(!n.hidden){var r=Math.round(t.offsetHeight/u)||1;n.height!=r&&(E(n,r),zn=e=!0)}t=t.nextSibling}),e}if(!rn.clientWidth)return void(Vn=Gn=Fn=0);var i=Yt(n);if(t!==!0&&0==t.length&&i.from>Vn&&i.to<Gn)return void Tt(n);var o=Math.max(i.from-100,0),l=Math.min(kn.size,i.to+100);Vn<o&&o-Vn<20&&(o=Vn),Gn>l&&Gn-l<20&&(l=Math.min(kn.size,Gn));for(var a=t===!0?[]:Zt([{from:Vn,to:Gn,domStart:0}],t),s=0,f=0;f<a.length;++f){var h=a[f];h.from<o&&(h.domStart+=o-h.from,h.from=o),h.to>l&&(h.to=l),h.from>=h.to?a.splice(f--,1):s+=h.to-h.from}if(s==l-o&&o==Vn&&l==Gn)return void Tt(n);a.sort(function(t,e){return t.domStart-e.domStart});var u=ze(),c=an.style.display;pn.style.display="none",$t(o,l,a),pn.style.display=an.style.display="";var d=o!=Vn||l!=Gn||Xn!=rn.clientHeight+u;if(d&&(Xn=rn.clientHeight+u),Vn=o,Gn=l,Fn=m(kn,o),pn.childNodes.length!=Gn-Vn)throw new Error("BAD PATCH! "+JSON.stringify(a)+" size="+(Gn-Vn)+" nodes="+pn.childNodes.length);if(Je.lineWrapping){var p=Math.floor(kn.height*u+2*Re()),g=rn.clientHeight;p>g&&(gn.style.display="block"),r()}return an.style.display=c,(d||zn)&&_t()&&Je.lineWrapping&&r()&&_t(),Jt(),Tt(n),!e&&Je.onUpdate&&Je.onUpdate(Qn),!0}function Zt(t,e){for(var n=0,r=e.length||0;n<r;++n){for(var i=e[n],o=[],l=i.diff||0,a=0,s=t.length;a<s;++a){var f=t[a];i.to<=f.from&&i.diff?o.push({from:f.from+l,to:f.to+l,domStart:f.domStart}):i.to<=f.from||i.from>=f.to?o.push(f):(i.from>f.from&&o.push({from:f.from,to:i.from,domStart:f.domStart}),i.to<f.to&&o.push({from:i.to+l,to:f.to+l,domStart:f.domStart+(i.to-f.from)}))}t=o}return t}function $t(t,e,n){function r(t){var e=t.nextSibling;return t.parentNode.removeChild(t),e}if(n.length){for(var i=0,o=pn.firstChild,l=0;l<n.length;++l){for(var a=n[l];a.domStart>i;)o=r(o),i++;for(var s=0,f=a.to-a.from;s<f;++s)o=o.nextSibling,i++}for(;o;)o=r(o)}else pn.innerHTML="";var h=n.shift(),o=pn.firstChild,s=t,u=document.createElement("div");kn.iter(t,e,function(t){if(h&&h.to==s&&(h=n.shift()),!h||h.from>s){if(t.hidden)var e=u.innerHTML="<pre></pre>";else{var e="<pre"+(t.className?' class="'+t.className+'"':"")+">"+t.getHTML(me)+"</pre>";t.bgClassName&&(e='<div style="position: relative"><pre class="'+t.bgClassName+'" style="position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: -2">&#160;</pre>'+e+"</div>")}u.innerHTML=e,pn.insertBefore(u.firstChild,o)}else o=o.nextSibling;++s})}function _t(){if(Je.gutter||Je.lineNumbers){var t=ln.offsetHeight,e=rn.clientHeight;an.style.height=(t-e<2?e:t)+"px";var n,r=[],i=Vn;if(kn.iter(Vn,Math.max(Gn,Vn+1),function(t){if(t.hidden)r.push("<pre></pre>");else{var e=t.gutterMarker,o=Je.lineNumbers?i+Je.firstLineNumber:null;e&&e.text?o=e.text.replace("%N%",null!=o?o:""):null==o&&(o=" "),r.push(e&&e.style?'<pre class="'+e.style+'">':"<pre>",o);for(var l=1;l<t.height;++l)r.push("<br/>&#160;");r.push("</pre>"),e||(n=i)}++i}),an.style.display="none",sn.innerHTML=r.join(""),null!=n&&Je.lineNumbers){for(var o=sn.childNodes[n-Vn],l=String(kn.size).length,a=H(o.firstChild),s="";a.length+s.length<l;)s+=" ";s&&o.insertBefore(document.createTextNode(s),o.firstChild)}an.style.display="";var f=Math.abs((parseInt(fn.style.marginLeft)||0)-an.offsetWidth)>2;return fn.style.marginLeft=an.offsetWidth+"px",zn=!1,f}}function Jt(){function t(t,e,n,r){var i=q?"width: "+(n?h-n-t:h)+"px":"right: "+n+"px";f+='<div class="CodeMirror-selected" style="position: absolute; left: '+t+"px; top: "+e+"px; "+i+"; height: "+r+'px"></div>'}var e=W(In.from,In.to),n=He(In.from,!0),r=e?n:He(In.to,!0),i=In.inverted?n:r,o=ze(),l=D(tn),a=D(pn);if(en.style.top=Math.max(0,Math.min(rn.offsetHeight,i.y+a.top-l.top))+"px",en.style.left=Math.max(0,Math.min(rn.offsetWidth,i.x+a.left-l.left))+"px",e)un.style.top=i.y+"px",un.style.left=(Je.lineWrapping?Math.min(i.x,fn.offsetWidth):i.x)+"px",un.style.display="",dn.style.display="none";else{var s=n.y==r.y,f="",h=fn.clientWidth||fn.offsetWidth,u=fn.clientHeight||fn.offsetHeight;if(In.from.ch&&n.y>=0){var c=s?h-r.x:0;t(n.x,n.y,c,o)}var d=Math.max(0,n.y+(In.from.ch?o:0)),p=Math.min(r.y,u)-d;p>.2*o&&t(0,d,0,p),s&&In.from.ch||!(r.y<u-.5*o)||t(0,r.y,h-r.x,o),dn.innerHTML=f,un.style.display="none",dn.style.display=""}}function qt(t){Sn=t?Sn||(In.inverted?In.to:In.from):null}function Qt(t,e){var n=Sn&&ie(Sn);n&&(z(n,t)?t=n:z(e,n)&&(e=n)),te(t,e),En=!0}function te(t,e,n,r){if(rr=null,null==n&&(n=In.from.line,r=In.to.line),!W(In.from,t)||!W(In.to,e)){if(z(e,t)){var i=e;e=t,t=i}if(t.line!=n){var o=ee(t,n,In.from.ch);o?t=o:Le(t.line,!1)}if(e.line!=r&&(e=ee(e,r,In.to.ch)),W(t,e)?In.inverted=!1:W(t,In.to)?In.inverted=!1:W(e,In.from)&&(In.inverted=!0),Je.autoClearEmptyLines&&W(In.from,In.to)){var l=In.inverted?t:e;if(l.line!=In.from.line&&In.from.line<kn.size){var a=T(In.from.line);/^\s+$/.test(a.text)&&setTimeout($e(function(){if(a.parent&&/^\s+$/.test(a.text)){var t=p(a);Ht("",{line:t,ch:0},{line:t,ch:a.text.length})}},10))}}In.from=t,In.to=e,Nn=!0}}function ee(t,e,n){function r(e){for(var r=t.line+e,i=1==e?kn.size:-1;r!=i;){var l=T(r);if(!l.hidden){var a=t.ch;return(o||a>n||a>l.text.length)&&(a=l.text.length),{line:r,ch:a}}r+=e}}var i=T(t.line),o=t.ch==i.text.length&&t.ch!=n;return i.hidden?t.line>=e?r(1)||r(-1):r(-1)||r(1):t}function ne(t,e,n){var r=ie({line:t,ch:e||0});(n?Qt:te)(r,r)}function re(t){return Math.max(0,Math.min(t,kn.size-1))}function ie(t){if(t.line<0)return{line:0,ch:0};if(t.line>=kn.size)return{line:kn.size-1,ch:T(kn.size-1).text.length};var e=t.ch,n=T(t.line).text.length;return null==e||e>n?{line:t.line,ch:n}:e<0?{line:t.line,ch:0}:t}function oe(t,e){function n(){for(var e=o+t,n=t<0?-1:kn.size;e!=n;e+=t){var r=T(e);if(!r.hidden)return o=e,a=r,!0}}function r(e){if(l==(t<0?0:a.text.length)){if(e||!n())return!1;l=t<0?a.text.length:0}else l+=t;return!0}var i=In.inverted?In.from:In.to,o=i.line,l=i.ch,a=T(o);if("char"==e)r();else if("column"==e)r(!0);else if("word"==e)for(var s=!1;!(t<0)||r();){if(P(a.text.charAt(l)))s=!0;else if(s){t<0&&(t=1,r());break}if(t>0&&!r())break}return{line:o,ch:l}}function le(t,e){var n=t<0?In.from:In.to;(Sn||W(In.from,In.to))&&(n=oe(t,e)),ne(n.line,n.ch,!0)}function ae(t,e){W(In.from,In.to)?t<0?Ht("",oe(t,e),In.to):Ht("",In.from,oe(t,e)):Ht("",In.from,In.to),En=!0}function se(t,e){var n=0,r=He(In.inverted?In.from:In.to,!0);null!=rr&&(r.x=rr),"page"==e?n=Math.min(rn.clientHeight,window.innerHeight||document.documentElement.clientHeight):"line"==e&&(n=ze());var i=Ne(r.x,r.y+n*t+2);"page"==e&&(gn.scrollTop+=He(i,!0).y-r.y),ne(i.line,i.ch,!0),rr=r.x}function fe(t){for(var e=T(t.line).text,n=t.ch,r=t.ch;n>0&&P(e.charAt(n-1));)--n;for(;r<e.length&&P(e.charAt(r));)++r;Qt({line:t.line,ch:n},{line:t.line,ch:r})}function he(t){Qt({line:t,ch:0},ie({line:t+1,ch:0}))}function ue(t){if(W(In.from,In.to))return ce(In.from.line,t);for(var e=In.to.line-(In.to.ch?0:1),n=In.from.line;n<=e;++n)ce(n,t)}function ce(t,e){if(e||(e="add"),"smart"==e)if(yn.indent)var n=Ve(t);else e="prev";var r,i=T(t),o=i.indentation(Je.tabSize),l=i.text.match(/^\s*/)[0];"smart"==e&&(r=yn.indent(n,i.text.slice(l.length),i.text),r==j&&(e="prev")),"prev"==e?r=t?T(t-1).indentation(Je.tabSize):0:"add"==e?r=o+Je.indentUnit:"subtract"==e&&(r=o-Je.indentUnit),r=Math.max(0,r);var a=r-o;if(a){var s="",f=0;if(Je.indentWithTabs)for(var h=Math.floor(r/Je.tabSize);h;--h)f+=Je.tabSize,s+="\t";for(;f<r;)++f,s+=" "}else{if(In.from.line!=t&&In.to.line!=t)return;var s=l}Ht(s,{line:t,ch:0},{line:t,ch:l.length})}function de(){yn=t.getMode(Je,Je.mode),kn.iter(0,kn.size,function(t){t.stateAfter=null}),xn=[0],Ye()}function pe(){var t=Je.gutter||Je.lineNumbers;an.style.display=t?"":"none",t?zn=!0:pn.parentNode.style.marginLeft=0}function ge(t,e){if(Je.lineWrapping){tn.className+=" CodeMirror-wrap";var n=rn.clientWidth/Oe()-3;kn.iter(0,kn.size,function(t){if(!t.hidden){var e=Math.ceil(t.text.length/n)||1;1!=e&&E(t,e)}}),fn.style.width=on.style.width="",cn.style.left=""}else tn.className=tn.className.replace(" CodeMirror-wrap",""),Yn="",Zn=!0,kn.iter(0,kn.size,function(t){1==t.height||t.hidden||E(t,1),t.text.length>Yn.length&&(Yn=t.text)});Dn.push({from:0,to:kn.size})}function me(t){var e=Je.tabSize-t%Je.tabSize,n=$n[e];if(n)return n;for(var r='<span class="cm-tab">',i=0;i<e;++i)r+=" ";return $n[e]={html:r+"</span>",width:e}}function ve(){rn.className=rn.className.replace(/\s*cm-s-\S+/g,"")+Je.theme.replace(/(^|\s)\s*/g," cm-s-")}function ye(){var t=Y[Je.keyMap].style;tn.className=tn.className.replace(/\s*cm-keymap-\S+/g,"")+(t?" cm-keymap-"+t:"")}function xe(){this.set=[]}function Ce(t,e,n){function r(t,e,n,r){T(t).addMark(new a(e,n,r,i))}t=ie(t),e=ie(e);var i=new xe;if(!z(t,e))return i;if(t.line==e.line)r(t.line,t.ch,e.ch,n);else{r(t.line,t.ch,null,n);for(var o=t.line+1,l=e.line;o<l;++o)r(o,null,null,n);r(e.line,null,e.ch,n)}return Dn.push({from:t.line,to:e.line+1}),i}function Me(t){t=ie(t);var e=new s(t.ch);return T(t.line).addMark(e),e}function be(t){t=ie(t);var e=[],n=T(t.line).marked;if(!n)return e;for(var r=0,i=n.length;r<i;++r){var o=n[r];(null==o.from||o.from<=t.ch)&&(null==o.to||o.to>=t.ch)&&e.push(o.marker||o)}return e}function ke(t,e,n){return"number"==typeof t&&(t=T(re(t))),t.gutterMarker={text:e,style:n},zn=!0,t}function Se(t){"number"==typeof t&&(t=T(re(t))),t.gutterMarker=null,zn=!0}function we(t,e){var n=t,r=t;return"number"==typeof t?r=T(re(t)):n=p(t),null==n?null:e(r,n)?(Dn.push({from:n,to:n+1}),r):null}function Ae(t,e,n){return we(t,function(t){if(t.className!=e||t.bgClassName!=n)return t.className=e,t.bgClassName=n,!0})}function Le(t,e){return we(t,function(t,n){if(t.hidden!=e){if(t.hidden=e,!Je.lineWrapping){var r=t.text;e&&r.length==Yn.length?jn=!0:!e&&r.length>Yn.length&&(Yn=r,maxWidth=null,jn=!1)}E(t,e?0:1);var i=In.from.line,o=In.to.line;if(e&&(i==n||o==n)){var l=i==n?ee({line:i,ch:0},i,0):In.from,a=o==n?ee({line:o,ch:0},o,0):In.to;if(!a)return;te(l,a)}return zn=!0}})}function Te(t){if("number"==typeof t){if(!M(t))return null;var e=t;if(t=T(t),!t)return null}else{var e=p(t);if(null==e)return null}var n=t.gutterMarker;return{line:e,handle:t,text:t.text,markerText:n&&n.text,markerClass:n&&n.style,lineClass:t.className,bgClass:t.bgClassName}}function Ee(t){return hn.innerHTML="<pre><span>x</span></pre>",hn.firstChild.firstChild.firstChild.nodeValue=t,hn.firstChild.firstChild.offsetWidth||10}function De(t,e){if(0==e)return{top:0,left:0};var n=Je.lineWrapping&&e<t.text.length&&lt.test(t.text.slice(e-1,e+1));hn.innerHTML="<pre>"+t.getHTML(me,e,sr,n)+"</pre>";var r=document.getElementById(sr),i=r.offsetTop,o=r.offsetLeft;if($&&0==i&&0==o){var l=document.createElement("span");l.innerHTML="x",r.parentNode.insertBefore(l,r.nextSibling),i=l.offsetTop}return{top:i,left:o}}function He(t,e){var n,r=ze(),i=r*(m(kn,t.line)-(e?Fn:0));if(0==t.ch)n=0;else{var o=De(T(t.line),t.ch);n=o.left,Je.lineWrapping&&(i+=Math.max(0,o.top))}return{x:n,y:i,yBot:i+r}}function Ne(t,e){function n(t){var e=De(a,t);if(f){var n=Math.round(e.top/r);return Math.max(0,e.left+(n-h)*rn.clientWidth)}return e.left}e<0&&(e=0);var r=ze(),i=Oe(),o=Fn+Math.floor(e/r),l=g(kn,o);if(l>=kn.size)return{line:kn.size-1,ch:T(kn.size-1).text.length};var a=T(l),s=a.text,f=Je.lineWrapping,h=f?o-m(kn,l):0;if(t<=0&&0==h)return{line:l,ch:0};for(var u,c=0,d=0,p=s.length,v=Math.min(p,Math.ceil((t+h*rn.clientWidth*.9)/i));;){var y=n(v);if(!(y<=t&&v<p)){u=y,p=v;break}v=Math.min(p,Math.ceil(1.2*v))}if(t>u)return{line:l,ch:p};for(v=Math.floor(.8*p),y=n(v),y<t&&(c=v,d=y);;){if(p-c<=1)return{line:l,ch:u-t>t-d?c:p};var x=Math.ceil((c+p)/2),C=n(x);C>t?(p=x,u=C):(c=x,d=C)}}function We(t){var e=He(t,!0),n=D(fn);return{x:n.left+e.x,y:n.top+e.y,yBot:n.top+e.yBot}}function ze(){if(null==lr){lr="<pre>";for(var t=0;t<49;++t)lr+="x<br/>";lr+="x</pre>"}var e=pn.clientHeight;return e==or?ir:(or=e,hn.innerHTML=lr,ir=hn.firstChild.offsetHeight/50||1,hn.innerHTML="",ir)}function Oe(){return rn.clientWidth==fr?ar:(fr=rn.clientWidth,ar=Ee("x"))}function Re(){return fn.offsetTop}function Ie(){return fn.offsetLeft}function Be(t,e){var n,r,i=D(rn,!0);try{n=t.clientX,r=t.clientY}catch(t){return null}if(!e&&(n-i.left>rn.clientWidth||r-i.top>rn.clientHeight))return null;var o=D(fn,!0);return Ne(n-o.left,r-o.top)}function Pe(t){function e(){var t=st(nn.value).join("\n");t==o||Je.readOnly||$e(Nt)(t,"end"),en.style.position="relative",nn.style.cssText=i,J&&(gn.scrollTop=r),Wn=!1,Pt(!0),Rt()}var n=Be(t),r=gn.scrollTop;if(n&&!et){(W(In.from,In.to)||z(n,In.from)||!z(n,In.to))&&$e(ne)(n.line,n.ch);var i=nn.style.cssText;en.style.position="absolute",nn.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(t.clientY-5)+"px; left: "+(t.clientX-5)+"px; z-index: 1000; background: white; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",Wn=!0;var o=nn.value=Ot();if(Kt(),N(nn),Z){b(t);var l=A(window,"mouseup",function(){l(),setTimeout(e,20)},!0)}else setTimeout(e,50)}}function Ke(){clearInterval(vn);var t=!0;un.style.visibility="",vn=setInterval(function(){un.style.visibility=(t=!t)?"":"hidden"},650)}function Ue(t){function e(t,e,n){if(t.text)for(var r,i=t.styles,o=l?0:t.text.length-1,s=l?0:i.length-2,f=l?i.length:-2;s!=f;s+=2*a){var h=i[s];if(i[s+1]==c){for(var u=l?0:h.length-1,g=l?h.length:-1;u!=g;u+=a,o+=a)if(o>=e&&o<n&&p.test(r=h.charAt(u))){var m=hr[r];if(">"==m.charAt(1)==l)d.push(r);else{if(d.pop()!=m.charAt(0))return{pos:o,match:!1};if(!d.length)return{pos:o,match:!0}}}}else o+=a*h.length}}var n=In.inverted?In.from:In.to,r=T(n.line),i=n.ch-1,o=i>=0&&hr[r.text.charAt(i)]||hr[r.text.charAt(++i)];if(o){for(var l=(o.charAt(0),">"==o.charAt(1)),a=l?1:-1,s=r.styles,f=i+1,h=0,u=s.length;h<u;h+=2)if((f-=s[h].length)<=0){var c=s[h+1];break}for(var d=[r.text.charAt(i)],p=/[(){}[\]]/,h=n.line,u=l?Math.min(h+100,kn.size):Math.max(-1,h-100);h!=u;h+=a){var r=T(h),g=h==n.line,m=e(r,g&&l?i+1:0,g&&!l?i:r.text.length);if(m)break}m||(m={pos:null,match:!1});var c=m.match?"CodeMirror-matchingbracket":"CodeMirror-nonmatchingbracket",v=Ce({line:n.line,ch:i},{line:n.line,ch:i+1},c),y=null!=m.pos&&Ce({line:h,ch:m.pos},{line:h,ch:m.pos+1},c),x=$e(function(){v.clear(),y&&y.clear()});t?setTimeout(x,800):Rn=x}}function Fe(t){for(var e,n,r=t,i=t-40;r>i;--r){if(0==r)return 0;var o=T(r-1);if(o.stateAfter)return r;var l=o.indentation(Je.tabSize);(null==n||e>l)&&(n=r-1,e=l)}return n}function Ve(t){var e=Fe(t),n=e&&T(e-1).stateAfter;return n=n?i(yn,n):o(yn),kn.iter(e,t,function(t){t.highlight(yn,n,Je.tabSize),t.stateAfter=i(yn,n)}),e<t&&Dn.push({from:e,to:t}),t<kn.size&&!T(t).stateAfter&&xn.push(t),n}function Ge(t,e){var n=Ve(t);kn.iter(t,e,function(t){t.highlight(yn,n,Je.tabSize),t.stateAfter=i(yn,n)})}function Xe(){for(var t=+new Date+Je.workTime,e=xn.length;xn.length;){if(T(Vn).stateAfter)var n=xn.pop();else var n=Vn;if(!(n>=kn.size)){var r=Fe(n),l=r&&T(r-1).stateAfter;l=l?i(yn,l):o(yn);var a=0,s=yn.compareStates,f=!1,h=r,u=!1;if(kn.iter(h,kn.size,function(e){var r=e.stateAfter;if(+new Date>t)return xn.push(h),Ye(Je.workDelay),f&&Dn.push({from:n,to:h+1}),u=!0;var o=e.highlight(yn,l,Je.tabSize);o&&(f=!0),e.stateAfter=i(yn,l);var c=null;if(s){var d=r&&s(r,l);d!=j&&(c=!!d)}return null==c&&(o===!1&&r?++a>3&&(!yn.indent||yn.indent(r,"")==yn.indent(l,""))&&(c=!0):a=0),!!c||void++h}),u)return;f&&Dn.push({from:n,to:h+1})}}e&&Je.onHighlightComplete&&Je.onHighlightComplete(Qn)}function Ye(t){xn.length&&bn.set(t,$e(Xe))}function je(){Tn=En=Hn=null,Dn=[],Nn=!1,On=[]}function Ze(){jn&&Dt(),Zn&&!Je.lineWrapping&&(cn.style.left=Ee(Yn)+"px",Zn=!1);var t,e;if(Nn){var n=Vt();t=Xt(n.x,n.y,n.x,n.yBot)}Dn.length?e=jt(Dn,!0,t?t.scrollTop:null):(Nn&&Jt(),zn&&_t()),t&&Ft(),Nn&&(Ut(),Ke()),Cn&&!Wn&&(Tn===!0||Tn!==!1&&Nn)&&Pt(En),Nn&&Je.matchBrackets&&setTimeout($e(function(){Rn&&(Rn(),Rn=null),W(In.from,In.to)&&Ue(!1)}),20);var r=Nn,i=On;Hn&&Je.onChange&&Qn&&Je.onChange(Qn,Hn),r&&Je.onCursorActivity&&Je.onCursorActivity(Qn);for(var o=0;o<i.length;++o)i[o](Qn);e&&Je.onUpdate&&Je.onUpdate(Qn)}function $e(t){return function(){ur++||je();try{var e=t.apply(this,arguments)}finally{--ur||Ze()}return e}}function _e(t){_n.startCompound();try{return t()}finally{_n.endCompound()}}var Je={},qe=t.defaults;for(var Qe in qe)qe.hasOwnProperty(Qe)&&(Je[Qe]=(h&&h.hasOwnProperty(Qe)?h:qe)[Qe]);var tn=document.createElement("div");tn.className="CodeMirror"+(Je.lineWrapping?" CodeMirror-wrap":""),tn.innerHTML='<div style="overflow: hidden; position: relative; width: 3px; height: 0px;"><textarea style="position: absolute; padding: 0; width: 1px; height: 1em" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scrollbar"><div class="CodeMirror-scrollbar-inner"></div></div><div class="CodeMirror-scroll" tabindex="-1"><div style="position: relative"><div style="position: relative"><div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative; z-index: 0"><div style="position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden;"></div><pre class="CodeMirror-cursor">&#160;</pre><pre class="CodeMirror-cursor" style="visibility: hidden">&#160;</pre><div style="position: relative; z-index: -1"></div><div></div></div></div></div></div></div>',l.appendChild?l.appendChild(tn):l(tn);var en=tn.firstChild,nn=en.firstChild,rn=tn.lastChild,on=rn.firstChild,ln=on.firstChild,an=ln.firstChild,sn=an.firstChild,fn=an.nextSibling.firstChild,hn=fn.firstChild,un=hn.nextSibling,cn=un.nextSibling,dn=cn.nextSibling,pn=dn.nextSibling,gn=en.nextSibling,mn=gn.firstChild;ve(),ye(),K&&(nn.style.width="0px"),Q||(rn.draggable=!0),fn.style.outline="none",null!=Je.tabindex&&(nn.tabIndex=Je.tabindex),Je.autofocus&&Kt(),Je.gutter||Je.lineNumbers||(an.style.display="none"),rt&&(en.style.height="1px",en.style.position="absolute"),it?gn.className+=Et()?" cm-sb-overlap":" cm-sb-nonoverlap":_&&(gn.className+=" cm-sb-ie7");try{Ee("x")}catch(t){throw t.message.match(/runtime/i)&&(t=new Error("A CodeMirror inside a P-style element does not work in Internet Explorer. (innerHTML bug)")),t}var vn,yn,xn,Cn,Mn=new L,bn=new L,kn=new c([new u([new f("")])]);de();var Sn,wn,An,Ln,Tn,En,Dn,Hn,Nn,Wn,zn,On,Rn,In={from:{line:0,ch:0},to:{line:0,ch:0},inverted:!1},Bn=0,Pn=0,Kn=!1,Un=!1,Fn=0,Vn=0,Gn=0,Xn=0,Yn="",jn=!1,Zn=!0,$n={};$e(function(){R(Je.value||""),Tn=!1})();var _n=new v;A(rn,"mousedown",$e(nt)),A(rn,"dblclick",$e(at)),A(fn,"selectstart",C),Z||A(rn,"contextmenu",Pe),A(rn,"scroll",V),A(gn,"scroll",V),A(gn,"mousedown",function(){setTimeout(Kt,0)}),A(rn,"mousewheel",bt),A(rn,"DOMMouseScroll",bt),A(window,"resize",function(){jt(!0)}),A(nn,"keyup",$e(yt)),A(nn,"input",It),A(nn,"keydown",$e(mt)),A(nn,"keypress",$e(vt)),A(nn,"focus",xt),A(nn,"blur",Ct),Je.dragDrop&&(A(rn,"dragstart",ct),A(rn,"dragenter",y),A(rn,"dragover",y),A(rn,"drop",$e(ut))),A(rn,"paste",function(){Kt(),It()}),A(nn,"paste",It),A(nn,"cut",$e(function(){Je.readOnly||Nt("")})),rt&&A(on,"mouseup",function(){document.activeElement==nn&&nn.blur(),Kt()});var Jn;try{Jn=document.activeElement==nn}catch(t){}Jn||Je.autofocus?setTimeout(xt,20):Ct();var qn,Qn=tn.CodeMirror={getValue:F,setValue:$e(R),getSelection:Ot,replaceSelection:$e(Nt),focus:function(){window.focus(),Kt(),xt(),It()},setOption:function(t,e){var n=Je[t];Je[t]=e,"mode"==t||"indentUnit"==t?de():"readOnly"==t&&"nocursor"==e?(Ct(),nn.blur()):"readOnly"!=t||e?"theme"==t?ve():"lineWrapping"==t&&n!=e?$e(ge)():"tabSize"==t?jt(!0):"keyMap"==t&&ye():Pt(!0),"lineNumbers"!=t&&"gutter"!=t&&"firstLineNumber"!=t&&"theme"!=t||(pe(),jt(!0))},getOption:function(t){return Je[t]},undo:$e(wt),redo:$e(At),indentLine:$e(function(t,e){"string"!=typeof e&&(e=null==e?Je.smartIndent?"smart":"prev":e?"add":"subtract"),M(t)&&ce(t,e)}),indentSelection:$e(ue),historySize:function(){return{undo:_n.done.length,redo:_n.undone.length}},clearHistory:function(){_n=new v},matchBrackets:$e(function(){Ue(!0)}),getTokenAt:$e(function(t){return t=ie(t),T(t.line).getTokenAt(yn,Ve(t.line),t.ch)}),getStateAfter:function(t){return t=re(null==t?kn.size-1:t),Ve(t+1)},cursorCoords:function(t,e){return null==t&&(t=In.inverted),this.charCoords(t?In.from:In.to,e)},charCoords:function(t,e){return t=ie(t),"local"==e?He(t,!1):"div"==e?He(t,!0):We(t)},coordsChar:function(t){var e=D(fn);return Ne(t.x-e.left,t.y-e.top)},markText:$e(Ce),setBookmark:Me,findMarksAt:be,setMarker:$e(ke),clearMarker:$e(Se),setLineClass:$e(Ae),hideLine:$e(function(t){return Le(t,!0)}),showLine:$e(function(t){return Le(t,!1)}),onDeleteLine:function(t,e){if("number"==typeof t){if(!M(t))return null;t=T(t)}return(t.handlers||(t.handlers=[])).push(e),t},lineInfo:Te,addWidget:function(t,e,n,r,i){t=He(ie(t));var o=t.yBot,l=t.x;if(e.style.position="absolute",on.appendChild(e),"over"==r)o=t.y;else if("near"==r){var a=Math.max(rn.offsetHeight,kn.height*ze()),s=Math.max(on.clientWidth,fn.clientWidth)-Ie();
t.yBot+e.offsetHeight>a&&t.y>e.offsetHeight&&(o=t.y-e.offsetHeight),l+e.offsetWidth>s&&(l=s-e.offsetWidth)}e.style.top=o+Re()+"px",e.style.left=e.style.right="","right"==i?(l=on.clientWidth-e.offsetWidth,e.style.right="0px"):("left"==i?l=0:"middle"==i&&(l=(on.clientWidth-e.offsetWidth)/2),e.style.left=l+Ie()+"px"),n&&Gt(l,o,l+e.offsetWidth,o+e.offsetHeight)},lineCount:function(){return kn.size},clipPos:ie,getCursor:function(t){return null==t&&(t=In.inverted),O(t?In.from:In.to)},somethingSelected:function(){return!W(In.from,In.to)},setCursor:$e(function(t,e,n){null==e&&"number"==typeof t.line?ne(t.line,t.ch,n):ne(t,e,n)}),setSelection:$e(function(t,e,n){(n?Qt:te)(ie(t),ie(e||t))}),getLine:function(t){if(M(t))return T(t).text},getLineHandle:function(t){if(M(t))return T(t)},setLine:$e(function(t,e){M(t)&&Ht(e,{line:t,ch:0},{line:t,ch:T(t).text.length})}),removeLine:$e(function(t){M(t)&&Ht("",{line:t,ch:0},ie({line:t+1,ch:0}))}),replaceRange:$e(Ht),getRange:function(t,e){return zt(ie(t),ie(e))},triggerOnKeyDown:$e(mt),execCommand:function(t){return X[t](Qn)},moveH:$e(le),deleteH:$e(ae),moveV:$e(se),toggleOverwrite:function(){Kn?(Kn=!1,un.className=un.className.replace(" CodeMirror-overwrite","")):(Kn=!0,un.className+=" CodeMirror-overwrite")},posFromIndex:function(t){var e,n=0;return kn.iter(0,kn.size,function(r){var i=r.text.length+1;return i>t?(e=t,!0):(t-=i,void++n)}),ie({line:n,ch:e})},indexFromPos:function(t){if(t.line<0||t.ch<0)return 0;var e=t.ch;return kn.iter(0,t.line,function(t){e+=t.text.length+1}),e},scrollTo:function(t,e){null!=t&&(rn.scrollLeft=t),null!=e&&(gn.scrollTop=e),jt([])},getScrollInfo:function(){return{x:rn.scrollLeft,y:gn.scrollTop,height:gn.scrollHeight,width:rn.scrollWidth}},operation:function(t){return $e(t)()},compoundChange:function(t){return _e(t)},refresh:function(){jt(!0),gn.scrollHeight>Bn&&(gn.scrollTop=Bn)},getInputField:function(){return nn},getWrapperElement:function(){return tn},getScrollerElement:function(){return rn},getGutterElement:function(){return an}},tr=null,er=!1,nr="",rr=null;xe.prototype.clear=$e(function(){for(var t=1/0,e=-(1/0),n=0,r=this.set.length;n<r;++n){var i=this.set[n],o=i.marked;if(o&&i.parent){var l=p(i);t=Math.min(t,l),e=Math.max(e,l);for(var a=0;a<o.length;++a)o[a].marker==this&&o.splice(a--,1)}}t!=1/0&&Dn.push({from:t,to:e+1})}),xe.prototype.find=function(){for(var t,e,n=0,r=this.set.length;n<r;++n)for(var i=this.set[n],o=i.marked,l=0;l<o.length;++l){var a=o[l];if(a.marker==this&&(null!=a.from||null!=a.to)){var s=p(i);null!=s&&(null!=a.from&&(t={line:s,ch:a.from}),null!=a.to&&(e={line:s,ch:a.to}))}}return{from:t,to:e}};var ir,or,lr,ar,sr="CodeMirror-temp-"+Math.floor(16777215*Math.random()).toString(16),fr=0,hr={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},ur=0;for(var cr in G)G.propertyIsEnumerable(cr)&&!Qn.propertyIsEnumerable(cr)&&(Qn[cr]=G[cr]);return Qn}function e(t){return"string"==typeof t?Y[t]:t}function n(t,n,r,i,o){function l(n){n=e(n);var r=n[t];if(null!=r&&i(r))return!0;if(n.nofallthrough)return o&&o(),!0;var a=n.fallthrough;if(null==a)return!1;if("[object Array]"!=Object.prototype.toString.call(a))return l(a);for(var s=0,f=a.length;s<f;++s)if(l(a[s]))return!0;return!1}return!(!n||!l(n))||l(r)}function r(t){var e=ht[w(t,"keyCode")];return"Ctrl"==e||"Alt"==e||"Shift"==e||"Mod"==e}function i(t,e){if(e===!0)return e;if(t.copyState)return t.copyState(e);var n={};for(var r in e){var i=e[r];i instanceof Array&&(i=i.concat([])),n[r]=i}return n}function o(t,e,n){return!t.startState||t.startState(e,n)}function l(t,e){this.pos=this.start=0,this.string=t,this.tabSize=e||8}function a(t,e,n,r){this.from=t,this.to=e,this.style=n,this.marker=r}function s(t){this.from=t,this.to=t,this.line=null}function f(t,e){this.styles=e||[t,null],this.text=t,this.height=1,this.marked=this.gutterMarker=this.className=this.bgClassName=this.handlers=null,this.stateAfter=this.parent=this.hidden=null}function h(t,e,n,r){for(var i=0,o=0,l=0;o<e;i+=2){var a=n[i],s=o+a.length;0==l?(s>t&&r.push(a.slice(t-o,Math.min(a.length,e-o)),n[i+1]),s>=t&&(l=1)):1==l&&(s>e?r.push(a.slice(0,e-o),n[i+1]):r.push(a,n[i+1])),o=s}}function u(t){this.lines=t,this.parent=null;for(var e=0,n=t.length,r=0;e<n;++e)t[e].parent=this,r+=t[e].height;this.height=r}function c(t){this.children=t;for(var e=0,n=0,r=0,i=t.length;r<i;++r){var o=t[r];e+=o.chunkSize(),n+=o.height,o.parent=this}this.size=e,this.height=n,this.parent=null}function d(t,e){for(;!t.lines;)for(var n=0;;++n){var r=t.children[n],i=r.chunkSize();if(e<i){t=r;break}e-=i}return t.lines[e]}function p(t){if(null==t.parent)return null;for(var e=t.parent,n=B(e.lines,t),r=e.parent;r;e=r,r=r.parent){var i=0;for(r.children.length;r.children[i]!=e;++i)n+=r.children[i].chunkSize()}return n}function g(t,e){var n=0;t:do{for(var r=0,i=t.children.length;r<i;++r){var o=t.children[r],l=o.height;if(e<l){t=o;continue t}e-=l,n+=o.chunkSize()}return n}while(!t.lines);for(var r=0,i=t.lines.length;r<i;++r){var a=t.lines[r],s=a.height;if(e<s)break;e-=s}return n+r}function m(t,e){var n=0;t:do{for(var r=0,i=t.children.length;r<i;++r){var o=t.children[r],l=o.chunkSize();if(e<l){t=o;continue t}e-=l,n+=o.height}return n}while(!t.lines);for(var r=0;r<e;++r)n+=t.lines[r].height;return n}function v(){this.time=0,this.done=[],this.undone=[],this.compound=0,this.closed=!1}function y(){b(this)}function x(t){return t.stop||(t.stop=y),t}function C(t){t.preventDefault?t.preventDefault():t.returnValue=!1}function M(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0}function b(t){C(t),M(t)}function k(t){return t.target||t.srcElement}function S(t){return t.which?t.which:1&t.button?1:2&t.button?3:4&t.button?2:void 0}function w(t,e){var n=t.override&&t.override.hasOwnProperty(e);return n?t.override[e]:t[e]}function A(t,e,n,r){if("function"==typeof t.addEventListener){if(t.addEventListener(e,n,!1),r)return function(){t.removeEventListener(e,n,!1)}}else{var i=function(t){n(t||window.event)};if(t.attachEvent("on"+e,i),r)return function(){t.detachEvent("on"+e,i)}}}function L(){this.id=null}function T(t,e,n){null==e&&(e=t.search(/[^\s\u00a0]/),e==-1&&(e=t.length));for(var r=0,i=0;r<e;++r)"\t"==t.charAt(r)?i+=n-i%n:++i;return i}function E(t){return t.currentStyle?t.currentStyle:window.getComputedStyle(t,null)}function D(t,e){for(var n=t.ownerDocument.body,r=0,i=0,o=!1,l=t;l;l=l.offsetParent){var a=l.offsetLeft,s=l.offsetTop;l==n?(r+=Math.abs(a),i+=Math.abs(s)):(r+=a,i+=s),e&&"fixed"==E(l).position&&(o=!0)}for(var f=e&&!o?null:n,l=t.parentNode;l!=f;l=l.parentNode)null!=l.scrollLeft&&(r-=l.scrollLeft,i-=l.scrollTop);return{left:r,top:i}}function H(t){return t.textContent||t.innerText||t.nodeValue||""}function N(t){K?(t.selectionStart=0,t.selectionEnd=t.value.length):t.select()}function W(t,e){return t.line==e.line&&t.ch==e.ch}function z(t,e){return t.line<e.line||t.line==e.line&&t.ch<e.ch}function O(t){return{line:t.line,ch:t.ch}}function R(t){return at.textContent=t,at.innerHTML}function I(t,e){if(!e)return 0;if(!t)return e.length;for(var n=t.length,r=e.length;n>=0&&r>=0&&t.charAt(n)==e.charAt(r);--n,--r);return r+1}function B(t,e){if(t.indexOf)return t.indexOf(e);for(var n=0,r=t.length;n<r;++n)if(t[n]==e)return n;return-1}function P(t){return/\w/.test(t)||t.toUpperCase()!=t.toLowerCase()}t.defaults={value:"",mode:null,theme:"default",indentUnit:2,indentWithTabs:!1,smartIndent:!0,tabSize:4,keyMap:"default",extraKeys:null,electricChars:!0,autoClearEmptyLines:!1,onKeyEvent:null,onDragEvent:null,lineWrapping:!1,lineNumbers:!1,gutter:!1,fixedGutter:!1,firstLineNumber:1,readOnly:!1,dragDrop:!0,onChange:null,onCursorActivity:null,onGutterClick:null,onHighlightComplete:null,onUpdate:null,onFocus:null,onBlur:null,onScroll:null,matchBrackets:!1,workTime:100,workDelay:200,pollInterval:100,undoDepth:40,tabindex:null,autofocus:null};var K=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),U=K||/Mac/.test(navigator.platform),F=(/Win/.test(navigator.platform),t.modes={}),V=t.mimeModes={};t.defineMode=function(e,n){if(t.defaults.mode||"null"==e||(t.defaults.mode=e),arguments.length>2){n.dependencies=[];for(var r=2;r<arguments.length;++r)n.dependencies.push(arguments[r])}F[e]=n},t.defineMIME=function(t,e){V[t]=e},t.resolveMode=function(e){if("string"==typeof e&&V.hasOwnProperty(e))e=V[e];else if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return t.resolveMode("application/xml");return"string"==typeof e?{name:e}:e||{name:"null"}},t.getMode=function(e,n){var n=t.resolveMode(n),r=F[n.name];return r?r(e,n):t.getMode(e,"text/plain")},t.listModes=function(){var t=[];for(var e in F)F.propertyIsEnumerable(e)&&t.push(e);return t},t.listMIMEs=function(){var t=[];for(var e in V)V.propertyIsEnumerable(e)&&t.push({mime:e,mode:V[e]});return t};var G=t.extensions={};t.defineExtension=function(t,e){G[t]=e};var X=t.commands={selectAll:function(t){t.setSelection({line:0,ch:0},{line:t.lineCount()-1})},killLine:function(t){var e=t.getCursor(!0),n=t.getCursor(!1),r=!W(e,n);r||t.getLine(e.line).length!=e.ch?t.replaceRange("",e,r?n:{line:e.line}):t.replaceRange("",e,{line:e.line+1,ch:0})},deleteLine:function(t){var e=t.getCursor().line;t.replaceRange("",{line:e,ch:0},{line:e})},undo:function(t){t.undo()},redo:function(t){t.redo()},goDocStart:function(t){t.setCursor(0,0,!0)},goDocEnd:function(t){t.setSelection({line:t.lineCount()-1},null,!0)},goLineStart:function(t){t.setCursor(t.getCursor().line,0,!0)},goLineStartSmart:function(t){var e=t.getCursor(),n=t.getLine(e.line),r=Math.max(0,n.search(/\S/));t.setCursor(e.line,e.ch<=r&&e.ch?0:r,!0)},goLineEnd:function(t){t.setSelection({line:t.getCursor().line},null,!0)},goLineUp:function(t){t.moveV(-1,"line")},goLineDown:function(t){t.moveV(1,"line")},goPageUp:function(t){t.moveV(-1,"page")},goPageDown:function(t){t.moveV(1,"page")},goCharLeft:function(t){t.moveH(-1,"char")},goCharRight:function(t){t.moveH(1,"char")},goColumnLeft:function(t){t.moveH(-1,"column")},goColumnRight:function(t){t.moveH(1,"column")},goWordLeft:function(t){t.moveH(-1,"word")},goWordRight:function(t){t.moveH(1,"word")},delCharLeft:function(t){t.deleteH(-1,"char")},delCharRight:function(t){t.deleteH(1,"char")},delWordLeft:function(t){t.deleteH(-1,"word")},delWordRight:function(t){t.deleteH(1,"word")},indentAuto:function(t){t.indentSelection("smart")},indentMore:function(t){t.indentSelection("add")},indentLess:function(t){t.indentSelection("subtract")},insertTab:function(t){t.replaceSelection("\t","end")},defaultTab:function(t){t.somethingSelected()?t.indentSelection("add"):t.replaceSelection("\t","end")},transposeChars:function(t){var e=t.getCursor(),n=t.getLine(e.line);e.ch>0&&e.ch<n.length-1&&t.replaceRange(n.charAt(e.ch)+n.charAt(e.ch-1),{line:e.line,ch:e.ch-1},{line:e.line,ch:e.ch+1})},newlineAndIndent:function(t){t.replaceSelection("\n","end"),t.indentLine(t.getCursor().line)},toggleOverwrite:function(t){t.toggleOverwrite()}},Y=t.keyMap={};Y.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharRight",Backspace:"delCharLeft",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite"},Y.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Alt-Up":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Down":"goDocEnd","Ctrl-Left":"goWordLeft","Ctrl-Right":"goWordRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delWordLeft","Ctrl-Delete":"delWordRight","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore",fallthrough:"basic"},Y.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goWordLeft","Alt-Right":"goWordRight","Cmd-Left":"goLineStart","Cmd-Right":"goLineEnd","Alt-Backspace":"delWordLeft","Ctrl-Alt-Backspace":"delWordRight","Alt-Delete":"delWordRight","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore",fallthrough:["basic","emacsy"]},Y.default=U?Y.macDefault:Y.pcDefault,Y.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageUp","Shift-Ctrl-V":"goPageDown","Ctrl-D":"delCharRight","Ctrl-H":"delCharLeft","Alt-D":"delWordRight","Alt-Backspace":"delWordLeft","Ctrl-K":"killLine","Ctrl-T":"transposeChars"},t.fromTextArea=function(e,n){function r(){e.value=a.getValue()}function i(){r(),e.form.submit=l,e.form.submit(),e.form.submit=i}if(n||(n={}),n.value=e.value,!n.tabindex&&e.tabindex&&(n.tabindex=e.tabindex),null==n.autofocus&&null!=e.getAttribute("autofocus")&&(n.autofocus=!0),e.form){var o=A(e.form,"submit",r,!0);if("function"==typeof e.form.submit){var l=e.form.submit;e.form.submit=i}}e.style.display="none";var a=t(function(t){e.parentNode.insertBefore(t,e.nextSibling)},n);return a.save=r,a.getTextArea=function(){return e},a.toTextArea=function(){r(),e.parentNode.removeChild(a.getWrapperElement()),e.style.display="",e.form&&(o(),"function"==typeof e.form.submit&&(e.form.submit=l))},a},t.copyState=i,t.startState=o,l.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return 0==this.pos},peek:function(){return this.string.charAt(this.pos)},next:function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},eat:function(t){var e=this.string.charAt(this.pos);if("string"==typeof t)var n=e==t;else var n=e&&(t.test?t.test(e):t(e));if(n)return++this.pos,e},eatWhile:function(t){for(var e=this.pos;this.eat(t););return this.pos>e},eatSpace:function(){for(var t=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t},skipToEnd:function(){this.pos=this.string.length},skipTo:function(t){var e=this.string.indexOf(t,this.pos);if(e>-1)return this.pos=e,!0},backUp:function(t){this.pos-=t},column:function(){return T(this.string,this.start,this.tabSize)},indentation:function(){return T(this.string,null,this.tabSize)},match:function(t,e,n){function r(t){return n?t.toLowerCase():t}if("string"!=typeof t){var i=this.string.slice(this.pos).match(t);return i&&e!==!1&&(this.pos+=i[0].length),i}if(r(this.string).indexOf(r(t),this.pos)==this.pos)return e!==!1&&(this.pos+=t.length),!0},current:function(){return this.string.slice(this.start,this.pos)}},t.StringStream=l,a.prototype={attach:function(t){this.marker.set.push(t)},detach:function(t){var e=B(this.marker.set,t);e>-1&&this.marker.set.splice(e,1)},split:function(t,e){if(this.to<=t&&null!=this.to)return null;var n=this.from<t||null==this.from?null:this.from-t+e,r=null==this.to?null:this.to-t+e;return new a(n,r,this.style,this.marker)},dup:function(){return new a(null,null,this.style,this.marker)},clipTo:function(t,e,n,r,i){t&&r>this.from&&(r<this.to||null==this.to)?this.from=null:null!=this.from&&this.from>=e&&(this.from=Math.max(r,this.from)+i),n&&(e<this.to||null==this.to)&&(e>this.from||null==this.from)?this.to=null:null!=this.to&&this.to>e&&(this.to=r<this.to?this.to+i:e)},isDead:function(){return null!=this.from&&null!=this.to&&this.from>=this.to},sameSet:function(t){return this.marker==t.marker}},s.prototype={attach:function(t){this.line=t},detach:function(t){this.line==t&&(this.line=null)},split:function(t,e){if(t<this.from)return this.from=this.to=this.from-t+e,this},isDead:function(){return this.from>this.to},clipTo:function(t,e,n,r,i){(t||e<this.from)&&(n||r>this.to)?(this.from=0,this.to=-1):this.from>e&&(this.from=this.to=Math.max(r,this.from)+i)},sameSet:function(t){return!1},find:function(){return this.line&&this.line.parent?{line:p(this.line),ch:this.from}:null},clear:function(){if(this.line){var t=B(this.line.marked,this);t!=-1&&this.line.marked.splice(t,1),this.line=null}}},f.inheritMarks=function(t,e){var n=new f(t),r=e&&e.marked;if(r)for(var i=0;i<r.length;++i)if(null==r[i].to&&r[i].style){var o=n.marked||(n.marked=[]),l=r[i],a=l.dup();o.push(a),a.attach(n)}return n},f.prototype={replace:function(t,e,n){var r=[],i=this.marked,o=null==e?this.text.length:e;if(h(0,t,this.styles,r),n&&r.push(n,null),h(o,this.text.length,this.styles,r),this.styles=r,this.text=this.text.slice(0,t)+n+this.text.slice(o),this.stateAfter=null,i)for(var l=n.length-(o-t),a=0;a<i.length;++a){var s=i[a];s.clipTo(null==t,t||0,null==e,o,l),s.isDead()&&(s.detach(this),i.splice(a--,1))}},split:function(t,e){var n=[e,null],r=this.marked;h(t,this.text.length,this.styles,n);var i=new f(e+this.text.slice(t),n);if(r)for(var o=0;o<r.length;++o){var l=r[o],a=l.split(t,e.length);a&&(i.marked||(i.marked=[]),i.marked.push(a),a.attach(i),a==l&&r.splice(o--,1))}return i},append:function(t){var e=this.text.length,n=t.marked,r=this.marked;if(this.text+=t.text,h(0,t.text.length,t.styles,this.styles),r)for(var i=0;i<r.length;++i)null==r[i].to&&(r[i].to=e);if(n&&n.length){r||(this.marked=r=[]);t:for(var i=0;i<n.length;++i){var o=n[i];if(!o.from)for(var l=0;l<r.length;++l){var a=r[l];if(a.to==e&&a.sameSet(o)){a.to=null==o.to?null:o.to+e,a.isDead()&&(a.detach(this),n.splice(i--,1));continue t}}r.push(o),o.attach(this),o.from+=e,null!=o.to&&(o.to+=e)}}},fixMarkEnds:function(t){var e=this.marked,n=t.marked;if(e)for(var r=0;r<e.length;++r){var i=e[r],o=null==i.to;if(o&&n)for(var l=0;l<n.length;++l)if(n[l].sameSet(i)){o=!1;break}o&&(i.to=this.text.length)}},fixMarkStarts:function(){var t=this.marked;if(t)for(var e=0;e<t.length;++e)null==t[e].from&&(t[e].from=0)},addMark:function(t){t.attach(this),null==this.marked&&(this.marked=[]),this.marked.push(t),this.marked.sort(function(t,e){return(t.from||0)-(e.from||0)})},highlight:function(t,e,n){var r,i=new l(this.text,n),o=this.styles,a=0,s=!1,f=o[0];for(""==this.text&&t.blankLine&&t.blankLine(e);!i.eol();){var h=t.token(i,e),u=this.text.slice(i.start,i.pos);if(i.start=i.pos,a&&o[a-1]==h?o[a-2]+=u:u&&(!s&&(o[a+1]!=h||a&&o[a-2]!=r)&&(s=!0),o[a++]=u,o[a++]=h,r=f,f=o[a]),i.pos>5e3){o[a++]=this.text.slice(i.pos),o[a++]=null;break}}return o.length!=a&&(o.length=a,s=!0),a&&o[a-2]!=r&&(s=!0),s||o.length<5&&this.text.length<10&&null},getTokenAt:function(t,e,n){for(var r=this.text,i=new l(r);i.pos<n&&!i.eol();){i.start=i.pos;var o=t.token(i,e)}return{start:i.start,end:i.pos,string:i.current(),className:o||null,state:e}},indentation:function(t){return T(this.text,null,t)},getHTML:function(t,e,n,r){function i(e,n){if(e){if(s&&$&&" "==e.charAt(0)&&(e=" "+e.slice(1)),s=!1,e.indexOf("\t")==-1){f+=e.length;var r=R(e)}else for(var r="",i=0;;){var o=e.indexOf("\t",i);if(o==-1){r+=R(e.slice(i)),f+=e.length-i;break}f+=o-i;var l=t(f);r+=R(e.slice(i,o))+l.html,f+=l.width,i=o+1}n?a.push('<span class="',n,'">',r,"</span>"):a.push(r)}}function o(t){return t?"cm-"+t.replace(/ +/g," cm-"):null}function l(){for(var t;k<g.length&&((t=g[k]).from==y||null==t.from);)null!=t.style&&b.push(t),++k;M=k<g.length?g[k].from:1/0;for(var e=0;e<b.length;++e){var n=b[e].to||1/0;n==y?b.splice(e--,1):M=Math.min(n,M)}}var a=[],s=!0,f=0,h=i;if(null!=e){var u=0,c='<span id="'+n+'">';h=function(t,n){var o=t.length;if(e>=u&&e<u+o){e>u&&(i(t.slice(0,e-u),n),r&&a.push("<wbr>")),a.push(c);var l=e-u;i(et?t.slice(l,l+1):t.slice(l),n),a.push("</span>"),et&&i(t.slice(l+1),n),e--,u+=o}else u+=o,i(t,n),u==e&&u==m?a.push(c+" </span>"):u>e+10&&/\s/.test(t)&&(h=function(){})}}var d=this.styles,p=this.text,g=this.marked,m=p.length;if(p||null!=e)if(g&&g.length)for(var v,y=0,x=0,C="",M=g[0].from||0,b=[],k=0;y<m;){M==y&&l();for(var S=Math.min(m,M);;){if(C){for(var w=y+C.length,A=v,L=0;L<b.length;++L)A=(A?A+" ":"")+b[L].style;if(h(w>S?C.slice(0,S-y):C,A),w>=S){C=C.slice(S-y),y=S;break}y=w}C=d[x++],v=o(d[x++])}}else for(var x=0,T=0;T<m;x+=2){var E=d[x],v=d[x+1],D=E.length;T+D>m&&(E=E.slice(0,m-T)),T+=D,h(E,o(v))}else h(" ");return a.join("")},cleanUp:function(){if(this.parent=null,this.marked)for(var t=0,e=this.marked.length;t<e;++t)this.marked[t].detach(this)}},u.prototype={chunkSize:function(){return this.lines.length},remove:function(t,e,n){for(var r=t,i=t+e;r<i;++r){var o=this.lines[r];if(this.height-=o.height,o.cleanUp(),o.handlers)for(var l=0;l<o.handlers.length;++l)n.push(o.handlers[l])}this.lines.splice(t,e)},collapse:function(t){t.splice.apply(t,[t.length,0].concat(this.lines))},insertHeight:function(t,e,n){this.height+=n,this.lines=this.lines.slice(0,t).concat(e).concat(this.lines.slice(t));for(var r=0,i=e.length;r<i;++r)e[r].parent=this},iterN:function(t,e,n){for(var r=t+e;t<r;++t)if(n(this.lines[t]))return!0}},c.prototype={chunkSize:function(){return this.size},remove:function(t,e,n){this.size-=e;for(var r=0;r<this.children.length;++r){var i=this.children[r],o=i.chunkSize();if(t<o){var l=Math.min(e,o-t),a=i.height;if(i.remove(t,l,n),this.height-=a-i.height,o==l&&(this.children.splice(r--,1),i.parent=null),0==(e-=l))break;t=0}else t-=o}if(this.size-e<25){var s=[];this.collapse(s),this.children=[new u(s)],this.children[0].parent=this}},collapse:function(t){for(var e=0,n=this.children.length;e<n;++e)this.children[e].collapse(t)},insert:function(t,e){for(var n=0,r=0,i=e.length;r<i;++r)n+=e[r].height;this.insertHeight(t,e,n)},insertHeight:function(t,e,n){this.size+=e.length,this.height+=n;for(var r=0,i=this.children.length;r<i;++r){var o=this.children[r],l=o.chunkSize();if(t<=l){if(o.insertHeight(t,e,n),o.lines&&o.lines.length>50){for(;o.lines.length>50;){var a=o.lines.splice(o.lines.length-25,25),s=new u(a);o.height-=s.height,this.children.splice(r+1,0,s),s.parent=this}this.maybeSpill()}break}t-=l}},maybeSpill:function(){if(!(this.children.length<=10)){var t=this;do{var e=t.children.splice(t.children.length-5,5),n=new c(e);if(t.parent){t.size-=n.size,t.height-=n.height;var r=B(t.parent.children,t);t.parent.children.splice(r+1,0,n)}else{var i=new c(t.children);i.parent=t,t.children=[i,n],t=i}n.parent=t.parent}while(t.children.length>10);t.parent.maybeSpill()}},iter:function(t,e,n){this.iterN(t,e-t,n)},iterN:function(t,e,n){for(var r=0,i=this.children.length;r<i;++r){var o=this.children[r],l=o.chunkSize();if(t<l){var a=Math.min(e,l-t);if(o.iterN(t,a,n))return!0;if(0==(e-=a))break;t=0}else t-=l}}},v.prototype={addChange:function(t,e,n){this.undone.length=0;var r=+new Date,i=this.done[this.done.length-1],o=i&&i[i.length-1],l=r-this.time;if(this.compound&&i&&!this.closed)i.push({start:t,added:e,old:n});else if(l>400||!o||this.closed||o.start>t+n.length||o.start+o.added<t)this.done.push([{start:t,added:e,old:n}]),this.closed=!1;else{for(var a=Math.max(0,o.start-t),s=Math.max(0,t+n.length-(o.start+o.added)),f=a;f>0;--f)o.old.unshift(n[f-1]);for(var f=s;f>0;--f)o.old.push(n[n.length-f]);a&&(o.start=t),o.added+=e-(n.length-a-s)}this.time=r},startCompound:function(){this.compound++||(this.closed=!0)},endCompound:function(){--this.compound||(this.closed=!0)}},t.e_stop=b,t.e_preventDefault=C,t.e_stopPropagation=M,t.connect=A,L.prototype={set:function(t,e){clearTimeout(this.id),this.id=setTimeout(e,t)}};var j=t.Pass={toString:function(){return"CodeMirror.Pass"}},Z=/gecko\/\d{7}/i.test(navigator.userAgent),$=/MSIE \d/.test(navigator.userAgent),_=/MSIE [1-7]\b/.test(navigator.userAgent),J=/MSIE [1-8]\b/.test(navigator.userAgent),q=$&&5==document.documentMode,Q=/WebKit\//.test(navigator.userAgent),tt=/Chrome\//.test(navigator.userAgent),et=/Opera\//.test(navigator.userAgent),nt=/Apple Computer/.test(navigator.vendor),rt=/KHTML\//.test(navigator.userAgent),it=/Mac OS X 10\D([7-9]|\d\d)\D/.test(navigator.userAgent),ot=function(){if(J)return!1;var t=document.createElement("div");return"draggable"in t||"dragDrop"in t}(),lt=(function(){var t=document.createElement("textarea");return t.value="foo\nbar",t.value.indexOf("\r")>-1?"\r\n":"\n"}(),/^$/);Z?lt=/$'/:nt?lt=/\-[^ \-?]|\?[^ !'\"\),.\-\/:;\?\]\}]/:tt&&(lt=/\-[^ \-\.?]|\?[^ \-\.?\]\}:;!'\"\),\/]|[\.!\"#&%\)*+,:;=>\]|\}~][\(\{\[<]|\$'/),null!=document.documentElement.getBoundingClientRect&&(D=function(t,e){try{var n=t.getBoundingClientRect();n={top:n.top,left:n.left}}catch(t){n={top:0,left:0}}if(!e)if(null==window.pageYOffset){var r=document.documentElement||document.body.parentNode;null==r.scrollTop&&(r=document.body),n.top+=r.scrollTop,n.left+=r.scrollLeft}else n.top+=window.pageYOffset,n.left+=window.pageXOffset;return n});var at=document.createElement("pre");"\na"==R("a")?R=function(t){return at.textContent=t,at.innerHTML.slice(1)}:"\t"!=R("\t")&&(R=function(t){return at.innerHTML="",at.appendChild(document.createTextNode(t)),at.innerHTML}),t.htmlEscape=R;var st=3!="\n\nb".split(/\n/).length?function(t){for(var e,n=0,r=[];(e=t.indexOf("\n",n))>-1;)r.push(t.slice(n,"\r"==t.charAt(e-1)?e-1:e)),n=e+1;return r.push(t.slice(n)),r}:function(t){return t.split(/\r?\n/)};t.splitLines=st;var ft=window.getSelection?function(t){try{return t.selectionStart!=t.selectionEnd}catch(t){return!1}}:function(t){try{var e=t.ownerDocument.selection.createRange()}catch(t){}return!(!e||e.parentElement()!=t)&&0!=e.compareEndPoints("StartToEnd",e)};t.defineMode("null",function(){return{token:function(t){t.skipToEnd()}}}),t.defineMIME("text/plain","null");var ht={3:"Enter",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",91:"Mod",92:"Mod",93:"Mod",109:"-",107:"=",127:"Delete",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63276:"PageUp",63277:"PageDown",63275:"End",63273:"Home",63234:"Left",63232:"Up",63235:"Right",63233:"Down",63302:"Insert",63272:"Delete"};return t.keyNames=ht,function(){for(var t=0;t<10;t++)ht[t+48]=String(t);for(var t=65;t<=90;t++)ht[t]=String.fromCharCode(t);for(var t=1;t<=12;t++)ht[t+111]=ht[t+63235]="F"+t}(),t}();