// Copyright (C) 2011 by Marijn Haverbeke // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. var CodeMirror=function(){function a(b,c){function bw(a){return a>=0&&a<$.length}function by(a){ba=null;var b={line:0,ch:0};bI(b,{line:$.length-1,ch:$[$.length-1].text.length},N(a),b,b),ba=new j,bg=!0}function bz(a){var b=[];for(var c=0,d=$.length;c=c.to||b.line-1&&setTimeout(cV(function(){cs(bc.to.line,"smart")}),50)}var c=a.keyCode;c==13?(g.readOnly||cp(),m(a)):!a.ctrlKey&&!a.altKey&&!a.metaKey&&c==9&&g.tabMode!="default"?m(a):bU(bp)}function bG(){if(g.readOnly=="nocursor")return;bb||(g.onFocus&&g.onFocus(bx),bb=!0,w.className.search(/\bCodeMirror-focused\b/)==-1&&(w.className+=" CodeMirror-focused"),bk||bW()),bT(),cK()}function bH(){bb&&(g.onBlur&&g.onBlur(bx),bb=!1,w.className=w.className.replace(" CodeMirror-focused","")),clearInterval(Y),setTimeout(function(){bb||(bd=null)},150)}function bI(a,b,c,d,e){if(ba){var f=[];for(var h=a.line,i=b.line+1;hg.undoDepth)ba.done.shift()}bM(a,b,c,d,e)}function bJ(a,b){var c=a.pop();if(c){var d=[],e=c.start+c.added;for(var f=c.start;fg&&(bs=o,g=o.length,bt=null,f=!1)}if(f){g=0,bs="",bt=null;for(var i=0,n=$.length;ig&&(g=o.length,bs=o)}}var p=[],q=c.length-j-1;for(var i=0,o=_.length;ib.line&&p.push(r+q)}c.length<5?(cP(a.line,a.line+c.length),p.push(a.line+c.length)):p.push(a.line),_=p,cR(100),bh.push({from:a.line,to:b.line+1,diff:q}),bi={from:a,to:b,text:c},cg(d,e,s(bc.from.line),s(bc.to.line)),J.style.height=$.length*cF()+2*cG()+"px"}function bN(a,b,c){function d(d){if(H(d,b))return d;if(!H(c,d))return e;var f=d.line+a.length-(c.line-b.line)-1,g=d.ch;return d.line==c.line&&(g+=a[a.length-1].length-(c.ch-(c.line==b.line?b.ch:0))),{line:f,ch:g}}b=cj(b),c?c=cj(c):c=b,a=N(a);var e;return bP(a,b,c,function(a){return e=a,{from:d(bc.from),to:d(bc.to)}}),e}function bO(a,b){bP(N(a),bc.from,bc.to,function(a){return b=="end"?{from:a,to:a}:b=="start"?{from:bc.from,to:bc.from}:{from:bc.from,to:a}})}function bP(a,b,c,d){var e=a.length==1?a[0].length+b.ch:a[a.length-1].length,f=d({line:b.line+a.length-1,ch:e});bI(b,c,a,f.from,f.to)}function bQ(a,b){var c=a.line,d=b.line;if(c==d)return $[c].text.slice(a.ch,b.ch);var e=[$[c].text.slice(a.ch)];for(var f=c+1;f=a)return{line:c,ch:a-d};++c,d=e+1}}if(bk||!bb)return;var a=!1,b=C.value,c=O(C);if(!c)return!1;var a=bq.text!=b,d=be,e=a||c.start!=bq.start||c.end!=(d?bq.start:bq.end);if(!e&&!d)return!1;if(a){bd=be=null;if(g.readOnly)return bg=!0,"changed"}var h=f(c.start,bq.from),i=f(c.end,bq.from);if(d){var j=c.start==d.anchor?i:h,k=bd?bc.to:c.start==d.anchor?h:i;(bc.inverted=H(j,k))?(h=j,i=k):(be=null,h=k,i=j)}h.line==i.line&&h.line==bc.from.line&&h.line==bc.to.line&&!bd&&(bg=!1);if(a){var l=0,m=b.length,n=Math.min(m,bq.text.length),o,p=bq.from,q=-1;while(l-1?l-q:l,s=bq.to-1,t=bq.text.length;for(;;){o=bq.text.charAt(t);if(b.charAt(m)!=o){++m,++t;break}o=="\n"&&s--;if(t<=l||m<=l)break;--m,--t}var q=bq.text.lastIndexOf("\n",t-1),u=q==-1?t:t-q-1;bI({line:p,ch:r},{line:s,ch:u},N(b.slice(l,m)),h,i);if(p!=s||h.line!=p)bg=!0}else cg(h,i);return bq.text=b,bq.start=c.start,bq.end=c.end,a?"changed":e?"moved":!1}function bW(){var a=[],b=Math.max(0,bc.from.line-1),c=Math.min($.length,bc.to.line+2);for(var d=b;db)&&U.scrollIntoView()}function bZ(){var a=cD(bc.inverted?bc.from:bc.to);return b$(a.x,a.y,a.x,a.yBot)}function b$(a,b,c,d){var e=cH(),f=cG(),h=cF();b+=f,d+=f,a+=e,c+=e;var i=D.clientHeight,j=D.scrollTop,k=!1,l=!0;bj+i&&(D.scrollTop=d+h-i,k=!0);var m=D.clientWidth,n=D.scrollLeft,o=g.fixedGutter?R.clientWidth:0;return am+n&&(D.scrollLeft=c+10-m,k=!0,c>J.clientWidth&&(l=!1)),k&&g.onScroll&&g.onScroll(bx),l}function b_(){var a=cF(),b=D.scrollTop-cG();return{from:Math.min($.length,Math.max(0,Math.floor(b/a))),to:Math.min($.length,Math.ceil((b+D.clientHeight)/a))}}function ca(a){if(!D.clientWidth){bm=bn=0;return}var b=a===!0?[]:[{from:bm,to:bn,domStart:0}];for(var c=0,d=a.length||0;cj.from&&f.push({from:j.from,to:e.from,domStart:j.domStart}),e.to=m)break;if(j.domStart>o||j.from>q)n.push({from:q,to:j.from,domSize:j.domStart-o,domStart:o}),r+=j.from-q;q=j.to,o=j.domStart+(j.to-j.from)}if(o!=p||q!=m)r+=Math.abs(m-q),n.push({from:q,to:m,domSize:p-o,domStart:o}),m-q!=p-o&&(bl=!0);if(!n.length)return;V.style.display="none",r>(k.to-k.from)*.3?cb(l=Math.max(k.from-10,0),m=Math.min(k.to+7,$.length)):cc(n),V.style.display="";var s=l!=bm||m!=bn||bo!=D.clientHeight;bm=l,bn=m,Q.style.top=l*cF()+"px",s&&(bo=D.clientHeight,J.style.height=$.length*cF()+2*cG()+"px"),(s||bl)&&cd(),bt==null&&(bt=cA(bs)),bt>D.clientWidth?(T.style.width=bt+"px",J.style.width="",J.style.width=D.scrollWidth+"px"):T.style.width=J.style.width="";if(V.childNodes.length!=bn-bm)throw new Error("BAD PATCH! "+JSON.stringify(n)+" size="+(bn-bm)+" nodes="+V.childNodes.length);ce()}function cb(a,b){var c=[],d={line:a,ch:0},e=H(bc.from,d)&&!H(bc.to,d);for(var f=a;f0;--k)V.removeChild(j?j.previousSibling:V.lastChild);else if(i){for(var k=Math.max(0,i);k>0;--k)V.insertBefore(n.createElement("pre"),j);for(var k=Math.max(0,-i);k>0;--k)V.removeChild(j?j.previousSibling:V.lastChild)}var l=V.childNodes[h.domStart+d],m=b=h.from;for(var k=h.from;k':"
",f,"
")}R.style.display="none",S.innerHTML=c.join("");var h=String($.length).length,i=S.firstChild,j=F(i),k="";while(j.length+k.length=$.length)return{line:$.length-1,ch:$[$.length-1].text.length};var b=a.ch,c=$[a.line].text.length;return b==null||b>c?{line:a.line,ch:c}:b<0?{line:a.line,ch:0}:a}function ck(a){var b=Math.floor(D.clientHeight/cF()),c=bc.inverted?bc.from:bc.to;ch(c.line+Math.max(b-1,1)*(a?1:-1),c.ch,!0)}function cl(a){var b=a?{line:0,ch:0}:{line:$.length-1,ch:$[$.length-1].text.length};cf(b,b)}function cm(){var a=$.length-1;cg({line:0,ch:0},{line:a,ch:$[a].text.length})}function cn(a){var b=$[a.line].text,c=a.ch,d=a.ch;while(c>0&&/\w/.test(b.charAt(c-1)))--c;while(d-1&&(a==null&&(a=f),b=f)}a!=null&&bh.push({from:a,to:b+1})}}function cw(a,b,c){return typeof a=="number"&&(a=$[ci(a)]),a.gutterMarker={text:b,style:c},bl=!0,a}function cx(a){typeof a=="number"&&(a=$[ci(a)]),a.gutterMarker=null,bl=!0}function cy(a,b){if(typeof a=="number"){var c=a;a=$[ci(a)]}else{var c=M($,a);if(c==-1)return null}return a.className!=b&&(a.className=b,bh.push({from:c,to:c+1})),a}function cz(a){if(typeof a=="number"){var b=a;a=$[a];if(!a)return null}else{var b=M($,a);if(b==-1)return null}var c=a.gutterMarker;return{line:b,text:a.text,markerText:c&&c.text,markerClass:c&&c.style}}function cA(a){return K.innerHTML="
x
",K.firstChild.firstChild.firstChild.nodeValue=a,K.firstChild.firstChild.offsetWidth||10}function cB(a,b){return b==0?0:(K.innerHTML="
"+$[a].getHTML(null,null,!1,b)+"
",K.firstChild.firstChild.offsetWidth)}function cC(a,b){function e(a){return K.innerHTML="
"+c.getHTML(null,null,!1,a)+"
",K.firstChild.firstChild.offsetWidth}if(b<=0)return 0;var c=$[a],d=c.text,f=0,g=0,h=d.length,i,j=Math.min(h,Math.ceil(b/cA("x")));for(;;){var k=e(j);if(k<=b&&ji)return h;j=Math.floor(h*.8),k=e(j),kb-g?f:h;var l=Math.ceil((f+h)/2),m=e(l);m>b?(h=l,i=m):(f=l,g=m)}}function cD(a,b){var c=cF(),d=a.line-(b?bm:0);return{x:cB(a.line,a.ch),y:d*c,yBot:(d+1)*c}}function cE(a){var b=cD(a,!0),c=E(T);return{x:c.left+b.x,y:c.top+b.y,yBot:c.top+b.yBot}}function cF(){var a=V.childNodes.length;return a?V.offsetHeight/a||1:(K.innerHTML="
x
",K.firstChild.offsetHeight||1)}function cG(){return T.offsetTop}function cH(){return T.offsetLeft}function cI(a,b){var c=E(D,!0),d,e;try{d=a.clientX,e=a.clientY}catch(a){return null}if(!b&&(d-c.left>D.clientWidth||e-c.top>D.clientHeight))return null;var f=E(T,!0),g=bm+Math.floor((e-f.top)/cF());return cj({line:g,ch:cC(ci(g),d-f.left)})}function cJ(a){function e(){var a=N(C.value).join("\n");a!=d&&cV(bO)(a,"end"),B.style.position="relative",C.style.cssText=c,bk=!1,bW(),bT()}var b=cI(a);if(!b||window.opera)return;(G(bc.from,bc.to)||H(b,bc.from)||!H(b,bc.to))&&cV(ch)(b.line,b.ch);var c=C.style.cssText;B.style.position="absolute",C.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(a.clientY-5)+"px; left: "+(a.clientX-5)+"px; z-index: 1000; background: white; "+"border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",bk=!0;var d=C.value=bR();bX(),P(C,0,C.value.length);if(u){o(a);var f=r(window,"mouseup",function(){f(),setTimeout(e,20)},!0)}else setTimeout(e,50)}function cK(){clearInterval(Y);var a=!0;U.style.visibility="",Y=setInterval(function(){U.style.visibility=(a=!a)?"":"hidden"},650)}function cM(a){function p(a,b,c){if(!a.text)return;var d=a.styles,e=g?0:a.text.length-1,f;for(var i=g?0:d.length-2,j=g?d.length:-2;i!=j;i+=2*h){var k=d[i];if(d[i+1]!=null&&d[i+1]!=m){e+=h*k.length;continue}for(var l=g?0:k.length-1,p=g?k.length:-1;l!=p;l+=h,e+=h)if(e>=b&&e"==g)n.push(f);else{if(n.pop()!=q.charAt(0))return{pos:e,match:!1};if(!n.length)return{pos:e,match:!0}}}}}var b=bc.inverted?bc.from:bc.to,c=$[b.line],d=b.ch-1,e=d>=0&&cL[c.text.charAt(d)]||cL[c.text.charAt(++d)];if(!e)return;var f=e.charAt(0),g=e.charAt(1)==">",h=g?1:-1,i=c.styles;for(var j=d+1,k=0,l=i.length;ke;--d){if(d==0)return 0;var f=$[d-1];if(f.stateAfter)return d;var g=f.indentation();if(c==null||b>g)c=d-1,b=g}return c}function cO(a){var b=cN(a),c=b&&$[b-1].stateAfter;c?c=e(Z,c):c=f(Z);for(var d=b;d=$.length)continue;var d=cN(c),h=d&&$[d-1].stateAfter;h?h=e(Z,h):h=f(Z);var i=0,j=Z.compareStates,k=!1;for(var l=d,m=$.length;la){_.push(l),cR(g.workDelay),k&&bh.push({from:c,to:l+1});return}var p=n.highlight(Z,h);p&&(k=!0),n.stateAfter=e(Z,h);if(j){if(o&&j(o,h))break}else if(p!==!1||!o)i=0;else if(++i>3)break}k&&bh.push({from:c,to:l+1})}b&&g.onHighlightComplete&&g.onHighlightComplete(bx)}function cR(a){if(!_.length)return;X.set(a,cV(cQ))}function cS(){bg=null,bh=[],bi=bj=!1}function cT(){var a=!1;bj&&(a=!bZ()),bh.length?ca(bh):(bj&&ce(),bl&&cd()),a&&bZ(),bj&&(bY(),cK()),bb&&!bk&&(bg===!0||bg!==!1&&bj)&&bW(),bj&&g.matchBrackets&&setTimeout(cV(function(){br&&(br(),br=null),cM(!1)}),20);var b=bi;bj&&g.onCursorActivity&&g.onCursorActivity(bx),b&&g.onChange&&bx&&g.onChange(bx,b)}function cV(a){return function(){cU++||cS();try{var b=a.apply(this,arguments)}finally{--cU||cT()}return b}}function cW(a,b,c){this.atOccurrence=!1,c==null&&(c=typeof a=="string"&&a==a.toLowerCase()),b&&typeof b=="object"?b=cj(b):b={line:0,ch:0},this.pos={from:b,to:b};if(typeof a!="string")this.matches=function(b,c){if(b){var d=$[c.line].text.slice(0,c.ch),e=d.match(a),f=0;while(e){var g=d.indexOf(e[0]);f+=g,d=d.slice(g+1);var h=d.match(a);if(h)e=h;else break;f++}}else var d=$[c.line].text.slice(c.ch),e=d.match(a),f=e&&c.ch+d.indexOf(e[0]);if(e)return{from:{line:c.line,ch:f},to:{line:c.line,ch:f+e[0].length},match:e}};else{c&&(a=a.toLowerCase());var d=c?function(a){return a.toLowerCase()}:function(a){return a},e=a.split("\n");e.length==1?this.matches=function(b,c){var e=d($[c.line].text),f=a.length,g;if(b?c.ch>=f&&(g=e.lastIndexOf(a,c.ch-f))!=-1:(g=e.indexOf(a,c.ch))!=-1)return{from:{line:c.line,ch:g},to:{line:c.line,ch:g+f}}}:this.matches=function(a,b){var c=b.line,f=a?e.length-1:0,g=e[f],h=d($[c].text),i=a?h.indexOf(g)+g.length:h.lastIndexOf(g);if(a?i>=b.ch||i!=g.length:i<=b.ch||i!=h.length-g.length)return;for(;;){if(a?!c:c==$.length-1)return;h=d($[c+=a?-1:1].text),g=e[a?--f:++f];if(f>0&&f
'+'
'+'
'+'
'+'
'+'
'+'
 
'+"
"+"
",b.appendChild?b.appendChild(w):b(w);var B=w.firstChild,C=B.firstChild,D=w.lastChild,J=D.firstChild,K=J.firstChild,Q=K.nextSibling,R=Q.firstChild,S=R.firstChild,T=R.nextSibling.firstChild,U=T.firstChild,V=U.nextSibling;g.tabindex!=null&&(C.tabindex=g.tabindex),!g.gutter&&!g.lineNumbers&&(R.style.display="none");var W=new s,X=new s,Y,Z,$=[new h("")],_,ba=new j,bb;ct();var bc={from:{line:0,ch:0},to:{line:0,ch:0},inverted:!1},bd,be,bf,bg,bh,bi,bj,bk,bl,bm=0,bn=0,bo=0,bp=null,bq,br,bs="",bt;cV(function(){by(g.value||""),bg=!1})(),r(D,"mousedown",cV(bA)),u||r(D,"contextmenu",cJ),r(J,"dblclick",cV(bB)),r(D,"scroll",function(){ca([]),g.fixedGutter&&(R.style.left=D.scrollLeft+"px"),g.onScroll&&g.onScroll(bx)}),r(window,"resize",function(){ca(!0)}),r(C,"keyup",cV(bE)),r(C,"keydown",cV(bD)),r(C,"keypress",cV(bF)),r(C,"focus",bG),r(C,"blur",bH),r(D,"dragenter",o),r(D,"dragover",o),r(D,"drop",cV(bC)),r(D,"paste",function(){bX(),bU()}),r(C,"paste",function(){bU()}),r(C,"cut",function(){bU()});var bu;try{bu=n.activeElement==C}catch(bv){}bu?setTimeout(bG,20):bH();var bx=w.CodeMirror={getValue:bz,setValue:cV(by),getSelection:bR,replaceSelection:cV(bO),focus:function(){bX(),bG(),bU()},setOption:function(a,b){g[a]=b,a=="lineNumbers"||a=="gutter"||a=="firstLineNumber"?cV(cu)():a=="mode"||a=="indentUnit"?ct():a=="readOnly"&&b=="nocursor"?C.blur():a=="theme"&&(D.className=D.className.replace(/cm-s-\w+/,"cm-s-"+b))},getOption:function(a){return g[a]},undo:cV(bK),redo:cV(bL),indentLine:cV(function(a,b){bw(a)&&cs(a,b==null?"smart":b?"add":"subtract")}),historySize:function(){return{undo:ba.done.length,redo:ba.undone.length}},matchBrackets:cV(function(){cM(!0)}),getTokenAt:function(a){return a=cj(a),$[a.line].getTokenAt(Z,cO(a.line),a.ch)},getStateAfter:function(a){return a=ci(a==null?$.length-1:a),cO(a+1)},cursorCoords:function(a){return a==null&&(a=bc.inverted),cE(a?bc.from:bc.to)},charCoords:function(a){return cE(cj(a))},coordsChar:function(a){var b=E(T),c=ci(Math.min($.length-1,bm+Math.floor((a.y-b.top)/cF())));return cj({line:c,ch:cC(ci(c),a.x-b.left)})},getSearchCursor:function(a,b,c){return new cW(a,b,c)},markText:cV(function(a,b,c){return cV(cv(a,b,c))}),setMarker:cV(cw),clearMarker:cV(cx),setLineClass:cV(cy),lineInfo:cz,addWidget:function(a,b,c,d,e){a=cD(cj(a));var f=a.yBot,g=a.x;b.style.position="absolute",J.appendChild(b);if(d=="over")f=a.y;else if(d=="near"){var h=Math.max(D.offsetHeight,$.length*cF()),i=Math.max(J.clientWidth,T.clientWidth)-cH();a.yBot+b.offsetHeight>h&&a.y>b.offsetHeight&&(f=a.y-b.offsetHeight),g+b.offsetWidth>i&&(g=i-b.offsetWidth)}b.style.top=f+cG()+"px",b.style.left=b.style.right="",e=="right"?(g=J.clientWidth-b.offsetWidth,b.style.right="0px"):(e=="left"?g=0:e=="middle"&&(g=(J.clientWidth-b.offsetWidth)/2),b.style.left=g+cH()+"px"),c&&b$(g,f,g+b.offsetWidth,f+b.offsetHeight)},lineCount:function(){return $.length},getCursor:function(a){return a==null&&(a=bc.inverted),I(a?bc.from:bc.to)},somethingSelected:function(){return!G(bc.from,bc.to)},setCursor:cV(function(a,b){b==null&&typeof a.line=="number"?ch(a.line,a.ch):ch(a,b)}),setSelection:cV(function(a,b){cg(cj(a),cj(b||a))}),getLine:function(a){if(bw(a))return $[a].text},setLine:cV(function(a,b){bw(a)&&bN(b,{line:a,ch:0},{line:a,ch:$[a].text.length})}),removeLine:cV(function(a){bw(a)&&bN("",{line:a,ch:0},cj({line:a+1,ch:0}))}),replaceRange:cV(bN),getRange:function(a,b){return bQ(cj(a),cj(b))},operation:function(a){return cV(a)()},refresh:function(){ca(!0)},getInputField:function(){return C},getWrapperElement:function(){return w},getScrollerElement:function(){return D},getGutterElement:function(){return R}},bS=!1,cL={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},cU=0;cW.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(a){function d(a){var c={line:a,ch:0};return b.pos={from:c,to:c},b.atOccurrence=!1,!1}var b=this,c=cj(a?this.pos.from:this.pos.to);for(;;){if(this.pos=this.matches(a,c))return this.atOccurrence=!0,this.pos.match||!0;if(a){if(!c.line)return d(0);c={line:c.line-1,ch:$[c.line-1].text.length}}else{if(c.line==$.length-1)return d($.length);c={line:c.line+1,ch:0}}}},from:function(){if(this.atOccurrence)return I(this.pos.from)},to:function(){if(this.atOccurrence)return I(this.pos.to)},replace:function(a){var b=this;this.atOccurrence&&cV(function(){b.pos.to=bN(a,b.pos.from,b.pos.to)})()}};for(var cX in d)d.propertyIsEnumerable(cX)&&!bx.propertyIsEnumerable(cX)&&(bx[cX]=d[cX]);return bx}function e(a,b){if(b===!0)return b;if(a.copyState)return a.copyState(b);var c={};for(var d in b){var e=b[d];e instanceof Array&&(e=e.concat([])),c[d]=e}return c}function f(a,b,c){return a.startState?a.startState(b,c):!0}function g(a){this.pos=this.start=0,this.string=a}function h(a,b){this.styles=b||[a,null],this.stateAfter=null,this.text=a,this.marked=this.gutterMarker=this.className=null}function i(a,b,c,d){for(var e=0,f=0,g=0;fa&&d.push(h.slice(a-f,Math.min(h.length,b-f)),c[e+1]),i>=a&&(g=1)):g==1&&(i>b?d.push(h.slice(0,b-f),c[e+1]):d.push(h,c[e+1])),f=i}}function j(){this.time=0,this.done=[],this.undone=[]}function k(){o(this)}function l(a){return a.stop||(a.stop=k),a}function m(a){a.preventDefault?a.preventDefault():a.returnValue=!1}function n(a){a.stopPropagation?a.stopPropagation():a.cancelBubble=!0}function o(a){m(a),n(a)}function p(a){return a.target||a.srcElement}function q(a){if(a.which)return a.which;if(a.button&1)return 1;if(a.button&2)return 3;if(a.button&4)return 2}function r(a,b,c,d){function e(a){c(a||window.event)}if(typeof a.addEventListener=="function"){a.addEventListener(b,e,!1);if(d)return function(){a.removeEventListener(b,e,!1)}}else{a.attachEvent("on"+b,e);if(d)return function(){a.detachEvent("on"+b,e)}}}function s(){this.id=null}function C(a,b){b==null&&(b=a.search(/[^\s\u00a0]/),b==-1&&(b=a.length));for(var c=0,d=0;c=0&&d>=0;--c,--d)if(a.charAt(c)!=b.charAt(d))break;return d+1}function M(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;c=this.string.length},sol:function(){return this.pos==0},peek:function(){return this.string.charAt(this.pos)},next:function(){if(this.posb},eatSpace:function(){var a=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos)))++this.pos;return this.pos>a},skipToEnd:function(){this.pos=this.string.length},skipTo:function(a){var b=this.string.indexOf(a,this.pos);if(b>-1)return this.pos=b,!0},backUp:function(a){this.pos-=a},column:function(){return C(this.string,this.start)},indentation:function(){return C(this.string)},match:function(a,b,c){if(typeof a!="string"){var e=this.string.slice(this.pos).match(a);return e&&b!==!1&&(this.pos+=e[0].length),e}function d(a){return c?a.toLowerCase():a}if(d(this.string).indexOf(d(a),this.pos)==this.pos)return b!==!1&&(this.pos+=a.length),!0},current:function(){return this.string.slice(this.start,this.pos)}},a.StringStream=g,h.prototype={replace:function(a,b,c){var d=[],e=this.marked;i(0,a,this.styles,d),c&&d.push(c,null),i(b,this.text.length,this.styles,d),this.styles=d,this.text=this.text.slice(0,a)+c+this.text.slice(b),this.stateAfter=null;if(e){var f=c.length-(b-a),g=this.text.length;function h(a){return a<=Math.min(b,b+f)?a:a+f}for(var j=0;j=g?l=!0:(k.from=h(k.from),k.to!=null&&(k.to=h(k.to)));if(l||k.from>=k.to)e.splice(j,1),j--}}},split:function(a,b){var c=[b,null];return i(a,this.text.length,this.styles,c),new h(b+this.text.slice(a),c)},addMark:function(a,b,c){var d=this.marked,e={from:a,to:b,style:c};return this.marked==null&&(this.marked=[]),this.marked.push(e),this.marked.sort(function(a,b){return a.from-b.from}),e},removeMark:function(a){var b=this.marked;if(!b)return;for(var c=0;c5e3){d[e++]=this.text.slice(c.pos),d[e++]=null;break}}return d.length!=e&&(d.length=e,f=!0),e&&d[e-2]!=i&&(f=!0),f||(d.length<5&&this.text.length<10?null:!1)},getTokenAt:function(a,b,c){var d=this.text,e=new g(d);while(e.pos',K(a),""):e.push(K(a))}var e=[];c&&e.push(this.className?'
':"
");var g=this.styles,h=this.text,i=this.marked;a==b&&(a=null);var j=h.length;d!=null&&(j=Math.min(d,j));if(!h&&d==null)f(" ",a!=null&&b==null?"CodeMirror-selected":null);else if(!i&&a==null)for(var k=0,l=0;lj&&(m=m.slice(0,j-l)),l+=n,f(m,"cm-"+g[k+1])}else{var o=0,k=0,p="",q,r=0,s=-1,t=null;function u(){i&&(s+=1,t=so)v=a;else if(b==null||b>o)w=" CodeMirror-selected",b!=null&&(v=Math.min(v,b));while(t&&t.to!=null&&t.to<=o)u();t&&(t.from>o?v=Math.min(v,t.from):(w+=" "+t.style,t.to!=null&&(v=Math.min(v,t.to))));for(;;){var x=o+p.length,y=q;w&&(y=q?q+w:w),f(x>v?p.slice(0,v-o):p,y);if(x>=v){p=p.slice(v-o),o=v;break}o=x,p=g[k++],q="cm-"+g[k++]}}a!=null&&b==null&&f(" ","CodeMirror-selected")}return c&&e.push("
"),e.join("")}},j.prototype={addChange:function(a,b,c){this.undone.length=0;var d=+(new Date),e=this.done[this.done.length-1];if(d-this.time>400||!e||e.start>a+b||e.start+e.added=0;--g)e.old.unshift(c[g]);e.added+=e.start-a,e.start=a}else e.start-1&&(x="\r\n")})();var y=8,z=/Mac/.test(navigator.platform),A={};for(var B=35;B<=40;++B)A[B]=A["c"+B]=!0;var J=document.createElement("div");a.htmlEscape=K;var N,O,P;return"\n\nb".split(/\n/).length!=3?N=function(a){var b=0,c,d=[];while((c=a.indexOf("\n",b))>-1)d.push(a.slice(b,a.charAt(c-1)=="\r"?c-1:c)),b=c+1;return d.push(a.slice(b)),d}:N=function(a){return a.split(/\r?\n/)},a.splitLines=N,window.getSelection?(O=function(a){try{return{start:a.selectionStart,end:a.selectionEnd}}catch(b){return null}},w?P=function(a,b,c){b==c?a.setSelectionRange(b,c):(a.setSelectionRange(b,c-1),window.getSelection().modify("extend","forward","character"))}:P=function(a,b,c){try{a.setSelectionRange(b,c)}catch(d){}}):(O=function(a){try{var b=a.ownerDocument.selection.createRange()}catch(c){return null}if(!b||b.parentElement()!=a)return null;var d=a.value,e=d.length,f=a.createTextRange();f.moveToBookmark(b.getBookmark());var g=a.createTextRange();g.collapse(!1);if(f.compareEndPoints("StartToEnd",g)>-1)return{start:e,end:e};var h=-f.moveStart("character",-e);for(var i=d.indexOf("\r");i>-1&&i-1)return{start:h,end:e};var j=-f.moveEnd("character",-e);for(var i=d.indexOf("\r");i>-1&&i-1&&h-1&&h"):b?g.push(''+CodeMirror.htmlEscape(a)+""):g.push(CodeMirror.htmlEscape(a))}}var h=CodeMirror.splitLines(a),i=CodeMirror.startState(d);for(var j=0,k=h.length;j