// CodeMirror version 3.20 // // CodeMirror is the only global var we claim window.CodeMirror=function(){"use strict";function x(e,n){if(!(this instanceof x))return new x(e,n);this.options=n=n||{};for(var r in er)!n.hasOwnProperty(r)&&er.hasOwnProperty(r)&&(n[r]=er[r]);H(n);var i=typeof n.value=="string"?0:n.value.first,s=this.display=T(e,i);s.wrapper.CodeMirror=this,_(this),n.autofocus&&!v&&It(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,draggingText:!1,highlight:new Qi},O(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap");var o=n.value;typeof o=="string"&&(o=new ui(n.value,n.mode)),Mt(this,ci)(this,o),t&&setTimeout(os(Ft,this,!0),20),Rt(this);var u;try{u=document.activeElement==s.input}catch(a){}u||n.autofocus&&!v?setTimeout(os(pn,this),20):dn(this),Mt(this,function(){for(var e in Zn)Zn.propertyIsEnumerable(e)&&Zn[e](this,n[e],nr);for(var t=0;tt.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function H(e){var t=ns(e.gutters,"CodeMirror-linenumbers");t==-1&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function B(e){var t=e.display,n=e.doc.height,r=n+ot(t);t.sizer.style.minHeight=t.heightForcer.style.top=r+"px",t.gutters.style.height=Math.max(r,t.scroller.clientHeight-Ji)+"px";var i=Math.max(r,t.scroller.scrollHeight),s=t.scroller.scrollWidth>t.scroller.clientWidth+1,o=i>t.scroller.clientHeight+1;o?(t.scrollbarV.style.display="block",t.scrollbarV.style.bottom=s?bs(t.measure)+"px":"0",t.scrollbarV.firstChild.style.height=i-t.scroller.clientHeight+t.scrollbarV.clientHeight+"px"):(t.scrollbarV.style.display="",t.scrollbarV.firstChild.style.height="0"),s?(t.scrollbarH.style.display="block",t.scrollbarH.style.right=o?bs(t.measure)+"px":"0",t.scrollbarH.firstChild.style.width=t.scroller.scrollWidth-t.scroller.clientWidth+t.scrollbarH.clientWidth+"px"):(t.scrollbarH.style.display="",t.scrollbarH.firstChild.style.width="0"),s&&o?(t.scrollbarFiller.style.display="block",t.scrollbarFiller.style.height=t.scrollbarFiller.style.width=bs(t.measure)+"px"):t.scrollbarFiller.style.display="",s&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(t.gutterFiller.style.display="block",t.gutterFiller.style.height=bs(t.measure)+"px",t.gutterFiller.style.width=t.gutters.offsetWidth+"px"):t.gutterFiller.style.display="",c&&bs(t.measure)===0&&(t.scrollbarV.style.minWidth=t.scrollbarH.style.minHeight=h?"18px":"12px",t.scrollbarV.style.pointerEvents=t.scrollbarH.style.pointerEvents="none")}function j(e,t,n){var r=e.scroller.scrollTop,i=e.wrapper.clientHeight;typeof n=="number"?r=n:n&&(r=n.top,i=n.bottom-n.top),r=Math.floor(r-st(e));var s=Math.ceil(r+i);return{from:gi(t,r),to:gi(t,s)}}function F(e){var t=e.display;if(!t.alignWidgets&&(!t.gutters.firstChild||!e.options.fixedGutter))return;var n=R(t)-t.scroller.scrollLeft+e.doc.scrollLeft,r=t.gutters.offsetWidth,i=n+"px";for(var s=t.lineDiv.firstChild;s;s=s.nextSibling)if(s.alignable)for(var o=0,u=s.alignable;o=e.display.showingFrom&&u.to<=e.display.showingTo)break}return o&&(zi(e,"update",e),(e.display.showingFrom!=i||e.display.showingTo!=s)&&zi(e,"viewportChange",e,e.display.showingFrom,e.display.showingTo)),o}function z(e,t,n,r){var i=e.display,s=e.doc;if(!i.wrapper.clientWidth){i.showingFrom=i.showingTo=s.first,i.viewOffset=0;return}if(!r&&t.length==0&&n.from>i.showingFrom&&n.toc&&i.showingTo-c<20&&(c=Math.min(f,i.showingTo));if(S){l=mi(_r(s,hi(s,l)));while(c=h[0].to?h=[]:h=V(h,t);if(S)for(var a=0;ap.from)){h.splice(a--,1);break}p.to=v}}var m=0;for(var a=0;ac&&(p.to=c),p.from>=p.to?h.splice(a--,1):m+=p.to-p.from}if(!r&&m==c-l&&l==i.showingFrom&&c==i.showingTo){X(e);return}h.sort(function(e,t){return e.from-t.from});try{var g=document.activeElement}catch(y){}m<(c-l)*.7&&(i.lineDiv.style.display="none"),J(e,l,c,h,u),i.lineDiv.style.display="",g&&document.activeElement!=g&&g.offsetHeight&&g.focus();var b=l!=i.showingFrom||c!=i.showingTo||i.lastSizeC!=i.wrapper.clientHeight;return b&&(i.lastSizeC=i.wrapper.clientHeight,tt(e,400)),i.showingFrom=l,i.showingTo=c,W(e),X(e),!0}function W(e){var t=e.display,r=t.lineDiv.offsetTop;for(var i=t.lineDiv.firstChild,s;i;i=i.nextSibling)if(i.lineObj){if(n){var o=i.offsetTop+i.offsetHeight;s=o-r,r=o}else{var u=vs(i);s=u.bottom-u.top}var a=i.lineObj.height-s;s<2&&(s=Ct(t));if(a>.001||a<-0.001){vi(i.lineObj,s);var f=i.lineObj.widgets;if(f)for(var l=0;l=f.to?s.push(f):(i.from>f.from&&s.push({from:f.from,to:i.from}),i.top){while(l.lineObj!=t)l=c(l);a&&i<=p&&l.lineNumber&&ds(l.lineNumber,q(e.options,p)),l=l.nextSibling}else{if(t.widgets)for(var m=0,g=l,y;g&&m<20;++m,g=g.nextSibling)if(g.lineObj==t&&/div/i.test(g.nodeName)){y=g;break}var b=K(e,t,p,o,y);if(b!=y)f.insertBefore(b,l);else{while(l!=y)l=c(l);l=l.nextSibling}b.lineObj=t}++p});while(l)l=c(l)}function K(e,t,r,i,s){var o=Qr(e,t),u=o.pre,a=t.gutterMarkers,f=e.display,l,c=o.bgClass?o.bgClass+" "+(t.bgClass||""):t.bgClass;if(!e.options.lineNumbers&&!a&&!c&&!t.wrapClass&&!t.widgets)return u;if(s){s.alignable=null;var h=!0,p=0,d=null;for(var v=s.firstChild,m;v;v=m){m=v.nextSibling;if(!/\bCodeMirror-linewidget\b/.test(v.className))s.removeChild(v);else{for(var g=0;g3&&(u(d,a.top,null,a.bottom),d=o,a.bottomc.bottom||p.bottom==c.bottom&&p.right>c.right)c=p;d0&&(t.blinker=setInterval(function(){t.cursor.style.visibility=t.otherCursor.style.visibility=(n=!n)?"":"hidden"},e.options.cursorBlinkRate))}function tt(e,t){e.doc.mode.startState&&e.doc.frontier=e.display.showingTo)return;var n=+(new Date)+e.options.workTime,r=ar(t.mode,it(e,t.frontier)),i=[],s;t.iter(t.frontier,Math.min(t.first+t.size,e.display.showingTo+500),function(o){if(t.frontier>=e.display.showingFrom){var u=o.styles;o.styles=Xr(e,o,r,!0);var a=!u||u.length!=o.styles.length;for(var f=0;!a&&fn)return tt(e,e.options.workDelay),!0}),i.length&&Mt(e,function(){for(var e=0;eo;--u){if(u<=s.first)return s.first;var a=hi(s,u-1);if(a.stateAfter&&(!n||u<=s.frontier))return u;var f=Gi(a.text,null,e.options.tabSize);if(i==null||r>f)i=u-1,r=f}return i}function it(e,t,n){var r=e.doc,i=e.display;if(!r.mode.startState)return!0;var s=rt(e,t,n),o=s>r.first&&hi(r,s-1).stateAfter;return o?o=ar(r.mode,o):o=fr(r.mode),r.iter(s,t,function(n){$r(e,n.text,o);var u=s==t-1||s%5==0||s>=i.showingFrom&&sn?"left":un?a.left:a.right,top:a.top,bottom:a.bottom}}function ft(e,t){var n=e.display.measureLineCache;for(var r=0;ry&&(n=y),t<0&&(t=0);for(var r=m.length-2;r>=0;r-=2){var i=m[r],s=m[r+1];if(i>n||s=n||t<=i&&n>=s||Math.min(n,s)-Math.max(t,i)>=n-t>>1){m[r]=Math.min(t,i),m[r+1]=Math.max(n,s);break}}return r<0&&(r=m.length,m.push(t,n)),{left:e.left-v.left,right:e.right-v.left,top:r,bottom:null}}function w(e){e.bottom=m[e.top+1],e.top=m[e.top]}if(!e.options.lineWrapping&&i.text.length>=e.options.crudeMeasuringFrom)return pt(e,i);var s=e.display,o=ss(i.text.length),u=Qr(e,i,o,!0).pre;if(t&&!n&&!e.options.lineWrapping&&u.childNodes.length>100){var a=document.createDocumentFragment(),f=10,l=u.childNodes.length;for(var c=0,h=Math.ceil(l/f);c1&&(x=g[c]=b(T[0]),x.rightSide=b(T[T.length-1]))}x||(x=g[c]=b(vs(S))),E.measureRight&&(x.right=vs(E.measureRight).left),E.leftSide&&(x.leftSide=b(vs(E.leftSide)))}hs(e.display.measure);for(var c=0,E;c=e.options.crudeMeasuringFrom)return at(e,t,t.text.length,s&&s.measure,"right").right;var o=Qr(e,t,null,!0).pre,u=o.appendChild(Es(e.display.measure));return ps(e.display.measure,o),vs(u).right-vs(e.display.lineDiv).left}function vt(e){e.display.measureLineCache.length=e.display.measureLineCachePos=0,e.display.cachedCharWidth=e.display.cachedTextHeight=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function mt(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function gt(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function yt(e,t,n,r){if(t.widgets)for(var i=0;in.from?s(e-1):s(e,r)}r=r||hi(e.doc,t.line),i||(i=ct(e,r));var u=bi(r),a=t.ch;if(!u)return s(a);var f=Hs(u,a),l=o(a,f);return Ps!=null&&(l.other=o(a,Ps)),l}function St(e,t,n,r){var i=new Ln(e,t);return i.xRel=r,n&&(i.outside=!0),i}function xt(e,t,n){var r=e.doc;n+=e.display.viewOffset;if(n<0)return St(r.first,0,!0,-1);var i=gi(r,n),s=r.first+r.size-1;if(i>s)return St(r.first+r.size-1,hi(r,s).text.length,!0,1);t<0&&(t=0);for(;;){var o=hi(r,i),u=Tt(e,o,i,t,n),a=Mr(o),f=a&&a.find();if(!a||!(u.ch>f.from.ch||u.ch==f.from.ch&&u.xRel>0))return u;i=f.to.line}}function Tt(e,t,n,r,i){function f(r){var i=Et(e,Ln(n,r),"line",t,a);return o=!0,s>i.bottom?i.left-u:sm)return St(n,p,g,1);for(;;){if(l?p==h||p==js(t,h,1):p-h<=1){var y=rr){p=S,m=T;if(g=o)m+=1e3;c=E}else h=S,d=T,v=o,c-=E}}function Ct(e){if(e.cachedTextHeight!=null)return e.cachedTextHeight;if(Nt==null){Nt=cs("pre");for(var t=0;t<49;++t)Nt.appendChild(document.createTextNode("x")),Nt.appendChild(cs("br"));Nt.appendChild(document.createTextNode("x"))}ps(e.measure,Nt);var n=Nt.offsetHeight/50;return n>3&&(e.cachedTextHeight=n),hs(e.measure),n||1}function kt(e){if(e.cachedCharWidth!=null)return e.cachedCharWidth;var t=cs("span","x"),n=cs("pre",[t]);ps(e.measure,n);var r=t.offsetWidth;return r>2&&(e.cachedCharWidth=r),r||10}function At(e){e.curOp={changes:[],forceUpdate:!1,updateInput:null,userSelChange:null,textChanged:null,selectionChanged:!1,cursorActivity:!1,updateMaxLine:!1,updateScrollPos:!1,id:++Lt},Ui++||(Ri=[])}function Ot(e){var t=e.curOp,n=e.doc,r=e.display;e.curOp=null,t.updateMaxLine&&P(e);if(r.maxLineChanged&&!e.options.lineWrapping&&r.maxLine){var i=dt(e,r.maxLine);r.sizer.style.minWidth=Math.max(0,i+3+Ji)+"px",r.maxLineChanged=!1;var s=Math.max(0,r.sizer.offsetLeft+r.sizer.offsetWidth-r.scroller.clientWidth);s1e3||u.indexOf("\n")>-1?n.value=e.display.prevInput="":e.display.prevInput=u,a&&Ot(e),e.state.pasteIncoming=!1,!0}function Ft(e,n){var i,s,o=e.doc;if(!An(o.sel.from,o.sel.to)){e.display.prevInput="",i=Ts&&(o.sel.to.line-o.sel.from.line>100||(s=e.getSelection()).length>1e3);var u=i?"-":s||e.getSelection();e.display.input.value=u,e.state.focused&&ts(e.display.input),t&&!r&&(e.display.inputHasSelection=u)}else n&&(e.display.prevInput=e.display.input.value="",t&&!r&&(e.display.inputHasSelection=null));e.display.inaccurateSelection=i}function It(e){e.options.readOnly!="nocursor"&&(!v||document.activeElement!=e.display.input)&&e.display.input.focus()}function qt(e){return e.options.readOnly||e.doc.cantEdit}function Rt(e){function i(){e.state.focused&&setTimeout(os(It,e),0)}function u(){o==null&&(o=setTimeout(function(){o=null,n.cachedCharWidth=n.cachedTextHeight=ys=null,vt(e),Dt(e,os(Pt,e))},100))}function a(){for(var e=n.wrapper.parentNode;e&&e!=document.body;e=e.parentNode);e?setTimeout(a,5e3):Ii(window,"resize",u)}function f(t){if(Wi(e,t)||e.options.onDragEvent&&e.options.onDragEvent(e,Mi(t)))return;Hi(t)}function c(){n.inaccurateSelection&&(n.prevInput="",n.inaccurateSelection=!1,n.input.value=e.getSelection(),ts(n.input))}var n=e.display;Fi(n.scroller,"mousedown",Mt(e,Vt)),t?Fi(n.scroller,"dblclick",Mt(e,function(t){if(Wi(e,t))return;var n=zt(e,t);if(!n||Kt(e,t)||Ut(e.display,t))return;_i(t);var r=Gn(hi(e.doc,n.line).text,n);Bn(e.doc,r.from,r.to)})):Fi(n.scroller,"dblclick",function(t){Wi(e,t)||_i(t)}),Fi(n.lineSpace,"selectstart",function(e){Ut(n,e)||_i(e)}),w||Fi(n.scroller,"contextmenu",function(t){mn(e,t)}),Fi(n.scroller,"scroll",function(){n.scroller.clientHeight&&(Zt(e,n.scroller.scrollTop),en(e,n.scroller.scrollLeft,!0),qi(e,"scroll",e))}),Fi(n.scrollbarV,"scroll",function(){n.scroller.clientHeight&&Zt(e,n.scrollbarV.scrollTop)}),Fi(n.scrollbarH,"scroll",function(){n.scroller.clientHeight&&en(e,n.scrollbarH.scrollLeft)}),Fi(n.scroller,"mousewheel",function(t){rn(e,t)}),Fi(n.scroller,"DOMMouseScroll",function(t){rn(e,t)}),Fi(n.scrollbarH,"mousedown",i),Fi(n.scrollbarV,"mousedown",i),Fi(n.wrapper,"scroll",function(){n.wrapper.scrollTop=n.wrapper.scrollLeft=0});var o;Fi(window,"resize",u),setTimeout(a,5e3),Fi(n.input,"keyup",Mt(e,function(t){if(Wi(e,t)||e.options.onKeyEvent&&e.options.onKeyEvent(e,Mi(t)))return;t.keyCode==16&&(e.doc.sel.shift=!1)})),Fi(n.input,"input",function(){t&&!r&&e.display.inputHasSelection&&(e.display.inputHasSelection=null),Bt(e)}),Fi(n.input,"keydown",Mt(e,cn)),Fi(n.input,"keypress",Mt(e,hn)),Fi(n.input,"focus",os(pn,e)),Fi(n.input,"blur",os(dn,e)),e.options.dragDrop&&(Fi(n.scroller,"dragstart",function(t){Yt(e,t)}),Fi(n.scroller,"dragenter",f),Fi(n.scroller,"dragover",f),Fi(n.scroller,"drop",Mt(e,Gt))),Fi(n.scroller,"paste",function(t){if(Ut(n,t))return;It(e),Bt(e)}),Fi(n.input,"paste",function(){if(s&&!e.state.fakedLastChar&&!(new Date-e.state.lastMiddleDown<200)){var t=n.input.selectionStart,r=n.input.selectionEnd;n.input.value+="$",n.input.selectionStart=t,n.input.selectionEnd=r,e.state.fakedLastChar=!0}e.state.pasteIncoming=!0,Bt(e)}),Fi(n.input,"cut",c),Fi(n.input,"copy",c),l&&Fi(n.sizer,"mouseup",function(){document.activeElement==n.input&&n.input.blur(),It(e)})}function Ut(e,t){for(var n=Bi(t);n!=e.wrapper;n=n.parentNode)if(!n||n.ignoreEvents||n.parentNode==e.sizer&&n!=e.mover)return!0}function zt(e,t,n){var r=e.display;if(!n){var i=Bi(t);if(i==r.scrollbarH||i==r.scrollbarH.firstChild||i==r.scrollbarV||i==r.scrollbarV.firstChild||i==r.scrollbarFiller||i==r.gutterFiller)return null}var s,o,u=vs(r.lineSpace);try{s=t.clientX,o=t.clientY}catch(t){return null}return xt(e,s-u.left,o-u.top)}function Vt(e){function m(e){if(An(v,e))return;v=e;if(f=="single"){Bn(n.doc,Dn(i,u),e);return}p=Dn(i,p),d=Dn(i,d);if(f=="double"){var t=Gn(hi(i,e.line).text,e);On(e,p)?Bn(n.doc,t.from,d):Bn(n.doc,p,t.to)}else f=="triple"&&(On(e,p)?Bn(n.doc,d,Dn(i,Ln(e.line,0))):Bn(n.doc,p,Dn(i,Ln(e.line+1,0))))}function b(e){var t=++y,s=zt(n,e,!0);if(!s)return;if(!An(s,c)){n.state.focused||pn(n),c=s,m(s);var o=j(r,i);(s.line>=o.to||s.lineg.bottom?20:0;u&&setTimeout (Mt(n,function(){if(y!=t)return;r.scroller.scrollTop+=u,b(e)}),50)}}function E(e){y=Infinity,_i(e),It(n),Ii(document,"mousemove",S),Ii(document,"mouseup",x)}if(Wi(this,e))return;var n=this,r=n.display,i=n.doc,o=i.sel;o.shift=e.shiftKey;if(Ut(r,e)){s||(r.scroller.draggable=!1,setTimeout(function(){r.scroller.draggable=!0},100));return}if(Kt(n,e))return;var u=zt(n,e);switch(ji(e)){case 3:w&&mn.call(n,n,e);return;case 2:s&&(n.state.lastMiddleDown=+(new Date)),u&&Bn(n.doc,u),setTimeout(os(It,n),20),_i(e);return}if(!u){Bi(e)==r.scroller&&_i(e);return}n.state.focused||pn(n);var a=+(new Date),f="single";if(Xt&&Xt.time>a-400&&An(Xt.pos,u))f="triple",_i(e),setTimeout(os(It,n),20),Yn(n,u.line);else if(Wt&&Wt.time>a-400&&An(Wt.pos,u)){f="double",Xt={time:a,pos:u},_i(e);var l=Gn(hi(i,u.line).text,u);Bn(n.doc,l.from,l.to)}else Wt={time:a,pos:u};var c=u;if(n.options.dragDrop&&ms&&!qt(n)&&!An(o.from,o.to)&&!On(u,o.from)&&!On(o.to,u)&&f=="single"){var h=Mt(n,function(t){s&&(r.scroller.draggable=!1),n.state.draggingText=!1,Ii(document,"mouseup",h),Ii(r.scroller,"drop",h),Math.abs(e.clientX-t.clientX)+Math.abs(e.clientY-t.clientY)<10&&(_i(t),Bn(n.doc,u),It(n))});s&&(r.scroller.draggable=!0),n.state.draggingText=h,r.scroller.dragDrop&&r.scroller.dragDrop(),Fi(document,"mouseup",h),Fi(r.scroller,"drop",h);return}_i(e),f=="single"&&Bn(n.doc,Dn(i,u));var p=o.from,d=o.to,v=u,g=vs(r.wrapper),y=0,S=Mt(n,function(e){!t&&!ji(e)?E(e):b(e)}),x=Mt(n,E);Fi(document,"mousemove",S),Fi(document,"mouseup",x)}function $t(e,t,n,r,i){try{var s=t.clientX,o=t.clientY}catch(t){return!1}if(s>=Math.floor(vs(e.display.gutters).right))return!1;r&&_i(t);var u=e.display,a=vs(u.lineDiv);if(o>a.bottom||!Vi(e,n))return Pi(t);o-=a.top-u.viewOffset;for(var f=0;f=s){var c=gi(e.doc,o),h=e.options.gutters[f];return i(e,n,e,c,h,t),Pi(t)}}}function Jt(e,t){return Vi(e,"gutterContextMenu")?$t(e,t,"gutterContextMenu",!1,qi):!1}function Kt(e,t){return $t(e,t,"gutterClick",!0,zi)}function Gt(e){var n=this;if(Wi(n,e)||Ut(n.display,e)||n.options.onDragEvent&&n.options.onDragEvent(n,Mi(e)))return;_i(e),t&&(Qt=+(new Date));var r=zt(n,e,!0),i=e.dataTransfer.files;if(!r||qt(n))return;if(i&&i.length&&window.FileReader&&window.File){var s=i.length,o=Array(s),u=0,a=function(e,t){var i=new FileReader;i.onload=function(){o[t]=i.result,++u==s&&(r=Dn(n.doc,r),En(n.doc,{from:r,to:r,text:Ss(o.join("\n")),origin:"paste"},"around"))},i.readAsText(e)};for(var f=0;fu.clientWidth||i&&u.scrollHeight>u.clientHeight))return;if(i&&m&&s)for(var f=n.target;f!=u;f=f.parentNode)if(f.lineObj){t.display.currentWheelTarget=f;break}if(r&&!e&&!a&&nn!=null){i&&Zt(t,Math.max(0,Math.min(u.scrollTop+i*nn,u.scrollHeight-u.clientHeight))),en(t,Math.max(0,Math.min(u.scrollLeft+r*nn,u.scrollWidth-u.clientWidth))),_i(n),o.wheelStartX=null;return}if(i&&nn!=null){var l=i*nn,c=t.doc.scrollTop,h=c+o.wrapper.clientHeight;l<0?c=Math.max(0,c+l-50):h=Math.min(t.doc.height,h+l+50),U(t,[],{top:c,bottom:h})}tn<20&&(o.wheelStartX==null?(o.wheelStartX=u.scrollLeft,o.wheelStartY=u.scrollTop,o.wheelDX=r,o.wheelDY=i,setTimeout(function(){if(o.wheelStartX==null)return;var e=u.scrollLeft-o.wheelStartX,t=u.scrollTop-o.wheelStartY,n=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null;if(!n)return;nn=(nn*tn+n)/(tn+1),++tn},200)):(o.wheelDX+=r,o.wheelDY+=i))}function sn(e,t,n){if(typeof t=="string"){t=lr[t];if(!t)return!1}e.display.pollingFast&&jt(e)&&(e.display.pollingFast=!1);var r=e.doc,i=r.sel.shift,s=!1;try{qt(e)&&(e.state.suppressEdits=!0),n&&(r.sel.shift=!1),s=t(e)!=Ki}finally{r.sel.shift=i,e.state.suppressEdits=!1}return s}function on(e){var t=e.state.keyMaps.slice(0);return e.options.extraKeys&&t.push(e.options.extraKeys),t.push(e.options.keyMap),t}function an(e,t){var n=hr(e.options.keyMap),i=n.auto;clearTimeout(un),i&&!dr(t)&&(un=setTimeout(function(){hr(e.options.keyMap)==n&&(e.options.keyMap=i.call?i.call(null,e):i,A(e))},50));var s=vr(t,!0),o=!1;if(!s)return!1;var u=on(e);return t.shiftKey?o=pr("Shift-"+s,u,function(t){return sn(e,t,!0)})||pr(s,u,function(t){if(typeof t=="string"?/^go[A-Z]/.test(t):t.motion)return sn(e,t)}):o=pr(s,u,function(t){return sn(e,t)}),o&&(_i(t),et(e),r&&(t.oldKeyCode=t.keyCode,t.keyCode=0),zi(e,"keyHandled",e,s,t)),o}function fn(e,t,n){var r=pr("'"+n+"'",on(e),function(t){return sn(e,t,!0)});return r&&(_i(t),et(e),zi(e,"keyHandled",e,"'"+n+"'",t)),r}function cn(e){var n=this;n.state.focused||pn(n);if(Wi(n,e)||n.options.onKeyEvent&&n.options.onKeyEvent(n,Mi(e)))return;t&&e.keyCode==27&&(e.returnValue=!1);var r=e.keyCode;n.doc.sel.shift=r==16||e.shiftKey;var i=an(n,e);a&&(ln=i?r:null,!i&&r==88&&!Ts&&(m?e.metaKey:e.ctrlKey)&&n.replaceSelection(""))}function hn(e){var n=this;if(Wi(n,e)||n.options.onKeyEvent&&n.options.onKeyEvent(n,Mi(e)))return;var i=e.keyCode,s=e.charCode;if(a&&i==ln){ln=null,_i(e);return}if((a&&(!e.which||e.which<10)||l)&&an(n,e))return;var o=String.fromCharCode(s==null?i:s);this.options.electricChars&&this.doc.mode.electricChars&&this.options.smartIndent&&!qt(this)&&this.doc.mode.electricChars.indexOf(o)>-1&&setTimeout(Mt(n,function(){$n(n,n.doc.sel.to.line,"smart")}),75);if(fn(n,e,o))return;t&&!r&&(n.display.inputHasSelection=null),Bt(n)}function pn(e){if(e.options.readOnly=="nocursor")return;e.state.focused||(qi(e,"focus",e),e.state.focused=!0,e.display.wrapper.className.search(/\bCodeMirror-focused\b/)==-1&&(e.display.wrapper.className+=" CodeMirror-focused"),e.curOp||(Ft(e,!0),s&&setTimeout(os(Ft,e,!0),0))),Ht(e),et(e)}function dn(e){e.state.focused&&(qi(e,"blur",e),e.state.focused=!1,e.display.wrapper.className=e.display.wrapper.className.replace(" CodeMirror-focused","")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.doc.sel.shift=!1)},150)}function mn(e,n){function c(){if(i.input.selectionStart!=null){var e=i.input.value="鈥�"+(An(s.from,s.to)?"":i.input.value);i.prevInput="鈥�",i.input.selectionStart=1,i.input.selectionEnd=e.length}}function h(){i.inputDiv.style.position="relative",i.input.style.cssText=l,r&&(i.scrollbarV.scrollTop=i.scroller.scrollTop=u),Ht(e);if(i.input.selectionStart!=null){(!t||r)&&c(),clearTimeout(vn);var n=0,s=function(){i.prevInput==" "&&i.input.selectionStart==0?Mt(e,lr.selectAll)(e):n++<10?vn=setTimeout(s,500):Ft(e)};vn=setTimeout(s,200)}}if(Wi(e,n,"contextmenu"))return;var i=e.display,s=e.doc.sel;if(Ut(i,n)||Jt(e,n))return;var o=zt(e,n),u=i.scroller.scrollTop;if(!o||a)return;var f=e.options.resetSelectionOnContextMenu;f&&(An(s.from,s.to)||On(o,s.from)||!On(o,s.to))&&Mt(e,Fn)(e.doc,o,o);var l=i.input.style.cssText;i.inputDiv.style.position="absolute",i.input.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(n.clientY-5)+"px; left: "+(n.clientX-5)+"px; z-index: 1000; background: white; outline: none;"+"border-width: 0; outline: none; overflow: hidden; opacity: .05; -ms-opacity: .05; filter: alpha(opacity=5);",It(e),Ft(e,!0),An(s.from,s.to)&&(i.input.value=i.prevInput=" "),t&&!r&&c();if(w){Hi(n);var p=function(){Ii(window,"mouseup",p),setTimeout(h,20)};Fi(window,"mouseup",p)}else setTimeout(h,50)}function yn(e,t,n){if(!On(t.from,n))return Dn(e,n);var r=t.text.length-1-(t.to.line-t.from.line);if(n.line>t.to.line+r){var i=n.line-r,s=e.first+e.size-1;return i>s?Ln(s,hi(e,s).text.length):Pn(n,hi(e,i).text.length)}if(n.line==t.to.line+r)return Pn(n,es(t.text).length+(t.text.length==1?t.from.ch:0)+hi(e,t.to.line).text.length-t.to.ch);var o=n.line-t.from.line;return Pn(n,t.text[o].length+(o?0:t.from.ch))}function bn(e,t,n){if(n&&typeof n=="object")return{anchor:yn(e,t,n.anchor),head:yn(e,t,n.head)};if(n=="start")return{anchor:t.from,head:t.from};var r=gn(t);if(n=="around")return{anchor:t.from,head:r};if(n=="end")return{anchor:r,head:r};var i=function(e){if(On(e,t.from))return e;if(!On(t.to,e))return r;var n=e.line+t.text.length-(t.to.line-t.from.line)-1,i=e.ch;return e.line==t.to.line&&(i+=r.ch-t.to.ch),Ln(n,i)};return{anchor:i(e.sel.anchor),head:i(e.sel.head)}}function wn(e,t,n){var r={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){this.canceled=!0}};return n&&(r.update=function(t,n,r,i){t&&(this.from=Dn(e,t)),n&&(this.to=Dn(e,n)),r&&(this.text=r),i!==undefined&&(this.origin=i)}),qi(e,"beforeChange",e,r),e.cm&&qi(e.cm,"beforeChange",e.cm,r),r.canceled?null:{from:r.from,to:r.to,text:r.text,origin:r.origin}}function En(e,t,n,r){if(e.cm){if(!e.cm.curOp)return Mt(e.cm,En)(e,t,n,r);if(e.cm.state.suppressEdits)return}if(Vi(e,"beforeChange")||e.cm&&Vi(e.cm,"beforeChange")){t=wn(e,t,!0);if(!t)return}var i=E&&!r&&Lr(e,t.from,t.to);if(i){for(var s=i.length-1;s>=1;--s)Sn(e,{from:i[s].from,to:i[s].to,text:[""]});i.length&&Sn(e,{from:i[0].from,to:i[0].to,text:t.text},n)}else Sn(e,t,n)}function Sn(e,t,n){if(t.text.length==1&&t.text[0]==""&&An(t.from,t.to))return;var r=bn(e,t,n);xi(e,t,r,e.cm?e.cm.curOp.id:NaN),Nn(e,t,r,Cr(e,t));var i=[];li(e,function(e,n){!n&&ns(i,e.history)==-1&&(Ai(e.history,t),i.push(e.history)),Nn(e,t,null,Cr(e,t))})}function xn(e,t){if(e.cm&&e.cm.state.suppressEdits)return;var n=e.history,r=(t=="undo"?n.done:n.undone).pop();if(!r)return;var i={changes:[],anchorBefore:r.anchorAfter,headBefore:r.headAfter,anchorAfter:r.anchorBefore,headAfter:r.headBefore,generation:n.generation};(t=="undo"?n.undone:n.done).push(i),n.generation=r.generation||++n.maxGeneration;var s=Vi(e,"beforeChange")||e.cm&&Vi(e.cm,"beforeChange");for(var o=r.changes.length-1;o>=0;--o){var u=r.changes[o];u.origin=t;if(s&&!wn(e,u,!1)){(t=="undo"?n.done:n.undone).length=0;return}i.changes.push(Si(e,u));var a=o?bn(e,u,null):{anchor:r.anchorBefore,head:r.headBefore};Nn(e,u,a,kr(e,u));var f=[];li(e,function(e,t){!t&&ns(f,e.history)==-1&&(Ai(e.history,u),f.push(e.history)),Nn(e,u,null,kr(e,u))})}}function Tn(e,t){function n(e){return Ln(e.line+t,e.ch)}e.first+=t,e.cm&&Pt(e.cm,e.first,e.first,t),e.sel.head=n(e.sel.head),e.sel.anchor=n(e.sel.anchor),e.sel.from=n(e.sel.from),e.sel.to=n(e.sel.to)}function Nn(e,t,n,r){if(e.cm&&!e.cm.curOp)return Mt(e.cm,Nn)(e,t,n,r);if(t.to.linee.lastLine())return;if(t.from.lines&&(t={from:t.from,to:Ln(s,hi(e,s).text.length),text:[t.text[0]],origin:t.origin}),t.removed=pi(e,t.from,t.to),n||(n=bn(e,t,null)),e.cm?Cn(e.cm,t,r,n):ri(e,t,r,n)}function Cn(e,t,n,r){var i=e.doc,s=e.display,o=t.from,u=t.to,a=!1,f=o.line;e.options.lineWrapping||(f=mi(_r(i,hi(i,o.line))),i.iter(f,u.line+1,function(e){if(e==s.maxLine)return a=!0,!0})),!On(i.sel.head,t.from)&&!On(t.to,i.sel.head)&&(e.curOp.cursorActivity=!0),ri(i,t,n,r,k(e)),e.options.lineWrapping||(i.iter(f,o.line+t.text.length,function(e){var t=D(i,e);t>s.maxLineLength&&(s.maxLine=e,s.maxLineLength=t,s.maxLineChanged=!0,a=!1)}),a&&(e.curOp.updateMaxLine=!0)),i.frontier=Math.min(i.frontier,o.line),tt(e,400);var l=t.text.length-(u.line-o.line)-1;Pt(e,o.line,u.line+1,l);if(Vi(e,"change")){var c={from:o,to:u,text:t.text,removed:t.removed,origin:t.origin};if(e.curOp.textChanged){for(var h=e.curOp.textChanged;h.next;h=h.next);h.next=c}else e.curOp.textChanged=c}}function kn(e,t,n,r,i){r||(r=n);if(On(r,n)){var s=r;r=n,n=s}typeof t=="string"&&(t=Ss(t)),En(e,{from:n,to:r,text:t,origin:i},null)}function Ln(e,t){if(!(this instanceof Ln))return new Ln(e,t);this.line=e,this.ch=t}function An(e,t){return e.line==t.line&&e.ch==t.ch}function On(e,t){return e.linen?Ln(n,hi(e,n).text.length):Pn(t,hi(e,t.line).text.length)}function Pn(e,t){var n=e.ch;return n==null||n>t?Ln(e.line,t):n<0?Ln(e.line,0):e}function Hn(e,t){return t>=e.first&&t=s.ch:f.to>s.ch))){if(r){qi(l,"beforeCursorEnter");if(l.explicitlyCleared){if(!u.markedSpans)break;--a;continue}}if(!l.atomic)continue;var c=l.find()[o<0?"from":"to"];if(An(c,s)){c.ch+=o,c.ch<0?c.line>e.first?c=Dn(e,Ln(c.line-1)):c=null:c.ch>u.text.length&&(c.line(window.innerHeight||document.documentElement.clientHeight)&&(i=!1);if(i!=null&&!p){var s=n.cursor.style.display=="none";s&&(n.cursor.style.display="",n.cursor.style.left=t.left+"px",n.cursor.style.top=t.top-n.viewOffset+"px"),n.cursor.scrollIntoView(i),s&&(n.cursor.style.display="none")}}function Un(e,t,n,r){r==null&&(r=0);for(;;){var i=!1,s=Et(e,t),o=!n||n==t?s:Et(e,n),u=Wn(e,Math.min(s.left,o.left),Math.min(s.top,o.top)-r,Math.max(s.left,o.left),Math.max(s.bottom,o.bottom)+r),a=e.doc.scrollTop,f=e.doc.scrollLeft;u.scrollTop!=null&&(Zt(e,u.scrollTop),Math.abs(e.doc.scrollTop-a)>1&&(i=!0)),u.scrollLeft!=null&&(en(e,u.scrollLeft),Math.abs(e.doc.scrollLeft-f)>1&&(i=!0));if(!i)return s}}function zn(e,t,n,r,i){var s=Wn(e,t,n,r,i);s.scrollTop!=null&&Zt(e,s.scrollTop),s.scrollLeft!=null&&en(e,s.scrollLeft)}function Wn(e,t,n,r,i){var s=e.display,o=Ct(e.display);n<0&&(n=0);var u=s.scroller.clientHeight-Ji,a=s.scroller.scrollTop,f={},l=e.doc.height+ot(s),c=nl-o;if(na+u){var p=Math.min(n,(h?l:i)-u);p!=a&&(f.scrollTop=p)}var d=s.scroller.clientWidth-Ji,v=s.scroller.scrollLeft;t+=s.gutters.offsetWidth,r+=s.gutters.offsetWidth;var m=s.gutters.offsetWidth,g=td+v-3&&(f.scrollLeft=r+10-d),f}function Xn(e,t,n){e.curOp.updateScrollPos={scrollLeft:t==null?e.doc.scrollLeft:t,scrollTop:n==null?e.doc.scrollTop:n}}function Vn(e,t,n){var r=e.curOp.updateScrollPos||(e.curOp.updateScrollPos={scrollLeft:e.doc.scrollLeft,scrollTop:e.doc.scrollTop}),i=e.display.scroller;r.scrollTop=Math.max(0,Math.min(i.scrollHeight-i.clientHeight,r.scrollTop+n)),r.scrollLeft=Math.max(0,Math.min(i.scrollWidth-i.clientWidth,r.scrollLeft+t))}function $n(e,t,n,r){var i=e.doc;n==null&&(n="add");if(n=="smart")if(!e.doc.mode.indent)n="prev";else var s=it(e,t);var o=e.options.tabSize,u=hi(i,t),a=Gi(u.text,null,o),f=u.text.match(/^\s*/)[0],l;if(n=="smart"){l=e.doc.mode.indent(s,u.text.slice(f.length),u.text);if(l==Ki){if(!r)return;n="prev"}}n=="prev"?t>i.first?l=Gi(hi(i,t-1).text,null,o):l=0:n=="add"?l=a+e.options.indentUnit:n=="subtract"?l=a-e.options.indentUnit:typeof n=="number"&&(l=a+n),l=Math.max(0,l);var c="",h=0;if(e.options.indentWithTabs)for(var p=Math.floor(l/o);p;--p)h+=o,c+=" ";h=e.first+e.size?f=!1:(s=t,a=hi(e,t))}function c(e){var t=(i?js:Fs)(a,o,n,!0);if(t==null){if(!!e||!l())return f=!1;i?o=(n<0?Os:As)(a):o=n<0?a.text.length:0}else o=t;return!0}var s=t.line,o=t.ch,u=n,a=hi(e,s),f=!0;if(r=="char")c();else if(r=="column")c(!0);else if(r=="word"||r=="group"){var h=null,p=r=="group";for(var d=!0;;d=!1){if(n<0&&!c(!d))break;var v=a.text.charAt(o)||"\n",m=as(v)?"w":p?/\s/.test(v)?null:"p":null;if(h&&h!=m){n<0&&(n=1,c());break}m&&(h=m);if(n>0&&!c(!d))break}}var g=qn(e,Ln(s,o),u,!0);return f||(g.hitSide=!0),g}function Qn(e,t,n,r){var i=e.doc,s=t.left,o;if(r=="page"){var u=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight);o=t.top+n*(u-(n<0?1.5:.5)*Ct(e.display))}else r=="line"&&(o=n>0?t.bottom+3:t.top-3);for(;;){var a=xt(e,s,o);if(!a.outside)break;if(n<0?o<=0:o>=i.height){a.hitSide=!0;break}o+=n*5}return a}function Gn(e,t){var n=t.ch,r=t.ch;if(e){(t.xRel<0||r==e.length)&&n?--n:++r;var i=e.charAt(n),s=as(i)?as:/\s/.test(i)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!as(e)};while(n>0&&s(e.charAt(n-1)))--n;while(r=t:s.to>t);(i||(i=[])).push({from:s.from,to:a?null:s.to,marker:o})}}return i}function Nr(e,t,n){if(e)for(var r=0,i;r=t:s.to>t);if(u||o.type=="bookmark"&&s.from==t&&(!n||s.marker.insertLeft)){var a=s.from==null||(o.inclusiveLeft?s.from<=t:s.from0&&u)for(var c=0;ct)&&(!r||r.widthe.options.maxHighlightLength?(o=!1,s&&$r(e,t,r,f.pos),f.pos=t.length,l=null):l=n.token(f,r);if(!o||a!=l)ue&&i.splice(u,1,e,i[u+1],r),u+=2,a=Math.min(e,r)}if(!t)return;if(o.opaque)i.splice(n,u-n,e,t),u=n+2;else for(;n="頎€"&&a<"懑�"&&ua)?(b.to!=null&&c>b.to&&(c=b.to,p=""),w.className&&(h+=" "+w.className),w.startStyle&&b.from==a&&(d+=" "+w.startStyle),w.endStyle&&b.to==c&&(p+=" "+w.endStyle),w.title&&!v&&(v=w.title),w.collapsed&&(!m||m.marker.sizea&&c>b.from&&(c=b.from),w.type=="bookmark"&&b.from==a&&w.replacedWith&&g.push(w)}if(m&&(m.from||0)==a){ti(t,(m.to==null?u:m.to)-a,m.marker,m.from==null);if(m.to==null)return m.marker.find()}if(!m&&g.length)for(var y=0;y=u)break;var E=Math.min(u,c);for(;;){if(f){var S=a+f.length;if(!m){var x=S>E?f.slice(0,E-a):f;t.addToken(t,x,l?l+h:h,d,a+x.length==c?p:"",v)}if(S>=E){f=f.slice(E-a),a=E;break}a=S,d=""}f=i.slice(s,s=n[o++]),l=Kr(n[o++],t)}}}function ri(e,t,n,r,i){function s(e){return n?n[e]:null}function o(e,n,r){Ur(e,n,r,i),zi(e,"change",e,t)}var u=t.from,a=t.to,f=t.text,l=hi(e,u.line),c=hi(e,a.line),h=es(f),p=s(f.length-1),d=a.line-u.line;if(u.ch==0&&a.ch==0&&h==""&&(!e.cm||e.cm.options.wholeLineUpdateBefore)){for(var v=0,m=f.length-1,g=[];v1&&e.remove(u.line+1,d-1),e.insert(u.line+1,g)}zi(e,"change",e,t),Fn(e,r.anchor,r.head,null,!0)}function ii(e){this.lines=e,this.parent=null;for(var t=0,n=e.length,r=0;ts-e.cm.options.historyEventDelay||t.origin.charAt(0)=="*"))){var u=es(o.changes);An(t.from,t.to)&&An(t.from,u.to)?u.to=gn(t):o.changes.push(Si(e,t)),o.anchorAfter=n.anchor,o.headAfter=n.head}else{o={changes:[Si(e,t)],generation:i.generation,anchorBefore:e.sel.anchor,headBefore:e.sel.head,anchorAfter:n.anchor,headAfter:n.head},i.done.push(o),i.generation=++i.maxGeneration;while(i.done.length>i.undoDepth)i.done.shift()}i.lastTime=s,i.lastOp=r,i.lastOrigin=t.origin}function Ti(e){if(!e)return null;for(var t=0,n;t-1&&(es(o)[l]=a[l],delete a[l])}}return r}function ki(e,t,n,r){n0}function $i(e){e.prototype.on=function(e,t){Fi(this,e,t)},e.prototype.off=function(e,t){Ii(this,e,t)}}function Qi(){this.id=null}function Gi(e,t,n,r,i){t==null&&(t=e.search(/[^\s\u00a0]/),t==-1&&(t=e.length));for(var s=r||0,o=i||0;s"聙"&&(e.toUpperCase()!=e.toLowerCase()||us.test(e))}function fs(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function cs(e,t,n,r){var i=document.createElement(e);n&&(i.className=n),r&&(i.style.cssText=r);if(typeof t=="string")ds(i,t);else if(t)for(var s=0;s0;--t)e.removeChild(e.firstChild);return e}function ps(e,t){return hs(e).appendChild(t)}function ds(e,t){r?(e.innerHTML="",e.appendChild(document.createTextNode(t))):e.textContent=t}function vs(e){return e.getBoundingClientRect()}function gs(){return!1}function bs(e){if(ys!=null)return ys;var t=cs("div",null,null,"width: 50px; height: 50px; overflow-x: scroll");return ps(e,t),t.offsetWidth&&(ys=t.offsetHeight-t.clientHeight),ys||0}function Es(e){if(ws==null){var t=cs("span","鈥�");ps(e,cs("span",[t,document.createTextNode("x")])),e.firstChild.offsetHeight!=0&&(ws=t.offsetWidth<=1&&t.offsetHeight>2&&!n)}return ws?cs("span","鈥�"):cs("span","聽",null,"display: inline-block; width: 1px; margin-right: -1px")}function Cs(e,t,n,r){if(!e)return r(t,n,"ltr");var i=!1;for(var s=0;st||t==n&&o.to==t)r(Math.max(o.from,t),Math.min(o.to,n),o.level==1?"rtl":"ltr"),i=!0}i||r(t,n,"ltr")}function ks(e){return e.level%2?e.to:e.from}function Ls(e){return e.level%2?e.from:e.to}function As(e){var t=bi(e);return t?ks(t[0]):0}function Os(e){var t=bi(e);return t?Ls(es(t)):e.text.length}function Ms(e,t){var n=hi(e.doc,t),r=_r(e.doc,n);r!=n&&(t=mi(r));var i=bi(r),s=i?i[0].level%2?Os(r):As(r):0;return Ln(t,s)}function _s(e,t){var n,r;while(n=Mr(r=hi(e.doc,t)))t=n.find().to.line;var i=bi(r),s=i?i[0].level%2?As(r):Os(r):r.text.length;return Ln(t,s)}function Ds(e,t,n){var r=e[0].level;return t==r?!0:n==r?!1:tt)return Ps=null,n;if(i.from==t||i.to==t){if(r!=null)return Ds(e,i.level,e[r].level)?(Ps=r,n):(Ps=n,r);r=n}}return Ps=null,r}function Bs(e,t,n,r){if(!r)return t+n;do t+=n;while(t>0&&ls.test(e.text.charAt(t)));return t}function js(e,t,n,r){var i=bi(e);if(!i)return Fs(e,t,n,r);var s=Hs(i,t),o=i[s],u=Bs(e,t,o.level%2?-n:n,r);for(;;){if(u>o.from&&u0==o.level%2?o.to:o.from);o=i[s+=n];if(!o)return null;n>0==o.level%2?u=Bs(e,o.to,-1,r):u=Bs(e,o.from,1,r)}}function Fs(e,t,n,r){var i=t+n;if(r)while(i>0&&ls.test(e.text.charAt(i)))i+=n;return i<0||i>e.text.length?null:i}var e=/gecko\/\d/i.test(navigator.userAgent),t=/MSIE \d/.test(navigator.userAgent),n=t&&(document.documentMode==null||document.documentMode<8),r=t&&(document.documentMode==null||document.documentMode<9),i=/Trident\/([7-9]|\d{2,})\./.test(navigator.userAgent),s=/WebKit\//.test(navigator.userAgent),o=s&&/Qt\/\d+\.\d+/.test(navigator.userAgent),u=/Chrome\//.test(navigator.userAgent),a=/Opera\//.test(navigator.userAgent),f=/Apple Computer/.test(navigator.vendor),l=/KHTML\//.test(navigator.userAgent),c=/Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent),h=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),p=/PhantomJS/.test(navigator.userAgent),d=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),v=d||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),m=d||/Mac/.test(navigator.platform),g=/win/i.test(navigator.platform),y=a&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);y&&(y=Number(y[1])),y&&y>=15&&(a=!1,s=!0);var b=m&&(o||a&&(y==null||y<12.11)),w=e||t&&!r,E=!1,S=!1,Nt,Lt=0,Wt,Xt,Qt=0,tn=0,nn=null;t?nn=-0.53:e?nn=15:u?nn=-0.7:f&&(nn=-1/3);var un,ln=null,vn,gn=x.changeEnd=function(e){return e.text?Ln(e.from.line+e.text.length-1,es(e.text).length+(e.text.length==1?e.from.ch:0)):e.to};x.Pos=Ln,x.prototype={constructor:x,focus:function(){window.focus(),It(this),Bt(this)},setOption:function(e,t){var n=this.options,r=n[e];if(n[e]==t&&e!="mode")return;n[e]=t,Zn.hasOwnProperty(e)&&Mt(this,Zn[e])(this,t,r)},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](e)},removeKeyMap:function(e){var t=this.state.keyMaps;for(var n=0;n>1;if((s?t[s*2-1]:0)>=i)r=s;else{if(!(t[s*2+1]r&&(e=r,n=!0);var i=hi(this.doc,e);return yt(this,hi(this.doc,e),{top:0,left:0},t||"page").top+(n?i.height:0)},defaultTextHeight:function(){return Ct(this.display)},defaultCharWidth:function(){return kt(this.display)},setGutterMarker:Mt(null,function(e,t,n){return Jn(this,e,function(e){var r=e.gutterMarkers||(e.gutterMarkers={});return r[t]=n,!n&&fs(r)&&(e.gutterMarkers=null),!0})}),clearGutter:Mt(null,function(e){var t=this,n=t.doc,r=n.first;n.iter(function(n){n.gutterMarkers&&n.gutterMarkers[e]&&(n.gutterMarkers[e]=null,Pt(t,r,r+1),fs(n.gutterMarkers)&&(n.gutterMarkers=null)),++r})}),addLineClass:Mt(null,function(e,t,n){return Jn(this,e,function(e){var r=t=="text"?"textClass":t=="background"?"bgClass":"wrapClass";if(!e[r])e[r]=n;else{if((new RegExp("(?:^|\\s)"+n+"(?:$|\\s)")).test(e[r]))return!1;e[r]+=" "+n}return!0})}),removeLineClass:Mt(null,function(e,t,n){return Jn(this,e,function(e){var r=t=="text"?"textClass":t=="background"?"bgClass":"wrapClass",i=e[r];if(!i)return!1;if(n==null)e[r]=null;else{var s=i.match(new RegExp("(?:^|\\s+)"+n+"(?:$|\\s+)"));if(!s)return!1;var o=s.index+s[0].length;e[r]=i.slice(0,s.index)+(!s.index||o==i.length?"":" ")+i.slice(o)||null}return!0})}),addLineWidget:Mt(null,function(e,t,n){return qr(this,e,t,n)}),removeLineWidget:function(e){e.clear()},lineInfo:function(e){if(typeof e=="number"){if(!Hn(this.doc,e))return null;var t=e;e=hi(this.doc,e);if(!e)return null}else{var t=mi(e);if(t==null)return null}return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},getViewport:function(){return{from:this.display.showingFrom,to:this.display.showingTo}},addWidget:function(e,t,n,r,i){var s=this.display;e=Et(this,Dn(this.doc,e));var o=e.bottom,u=e.left;t.style.position="absolute",s.sizer.appendChild(t);if(r=="over")o=e.top;else if(r=="above"||r=="near"){var a=Math.max(s.wrapper.clientHeight,this.doc.height),f=Math.max(s.sizer.clientWidth,s.lineSpace.clientWidth);(r=="above"||e.bottom+t.offsetHeight>a)&&e.top>t.offsetHeight?o=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=a&&(o=e.bottom),u+t.offsetWidth>f&&(u=f-t.offsetWidth)}t.style.top=o+"px",t.style.left=t.style.right="",i=="right"?(u=s.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):(i=="left"?u=0:i=="middle"&&(u=(s.sizer.clientWidth-t.offsetWidth)/2),t.style.left=u+"px"),n&&zn(this,u,o,u+t.offsetWidth,o+t.offsetHeight)},triggerOnKeyDown:Mt(null,cn),execCommand:function(e){return lr[e](this)},findPosH:function(e,t,n,r){var i=1;t<0&&(i=-1,t=-t);for(var s=0,o=Dn(this.doc,e);s2){t.dependencies=[];for(var n=2;n0&&t.ch=this.string.length},sol:function(){return this.pos==0},peek:function(){return this.string.charAt(this.pos)||undefined},next:function(){if(this.post},eatSpace:function(){var e=this.pos;while(/[\s\u00a0]/.test(this.string.charAt(this.pos)))++this.pos;return this.pos>e},skipToEnd:function(){this.pos=this.string.length},skipTo:function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},backUp:function(e){this.pos-=e},column:function(){return this.lastColumnPos0?null:(s&&t!==!1&&(this.pos+=s[0].length),s)}var r=function(e){return n?e.toLowerCase():e},i=this.string.substr(this.pos,e.length);if(r(i)==r(e))return t!==!1&&(this.pos+=e.length),!0},current:function(){return this.string.slice(this.start,this.pos)}},x.StringStream=mr,x.TextMarker=gr,$i(gr),gr.prototype.clear=function(){if(this.explicitlyCleared)return;var e=this.doc.cm,t=e&&!e.curOp;t&&At(e);if(Vi(this,"clear")){var n=this.find();n&&zi(this,"clear",n.from,n.to)}var r=null,i=null;for(var s=0;se.display.maxLineLength&&(e.display.maxLine=a,e.display.maxLineLength=f,e.display.maxLineChanged=!0)}r!=null&&e&&Pt(e,r,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&In(e)),t&&Ot(e)},gr.prototype.find=function(){var e,t;for(var n=0;n=t.display.showingFrom&&e.line50){while(s.lines.length>50){var u=s.lines.splice(s.lines.length-25,25),a=new ii(u);s.height-=a.height,this.children.splice(r+1,0,a),a.parent=this}this.maybeSpill()}break}e-=o}},maybeSpill:function(){if(this.children.length<=10)return;var e=this;do{var t=e.children.splice(e.children.length-5,5),n=new si(t);if(!e.parent){var r=new si(e.children);r.parent=e,e.children=[r,n],e=r}else{e.size-=n.size,e.height-=n.height;var i=ns(e.parent.children,e);e.parent.children.splice(i+1,0,n)}n.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()},iterN:function(e,t,n){for(var r=0,i=this.children.length;r=e.ch)&&t.push(i.marker.parent||i.marker)}return t},getAllMarks:function(){var e=[];return this.iter(function(t){var n=t.markedSpans;if(n)for(var r=0;re)return t=e,!0;e-=i,++n}),Dn(this,Ln(n,t))},indexFromPos:function(e){e=Dn(this,e);var t=e.ch;return e.linet&&(t=e.from),e.to!=null&&e.to=8208&&n<=8212}:s&&(gs=function(e,t){if(t>1&&e.charCodeAt(t-1)==45){if(/\w/.test(e.charAt(t-2))&&/[^\-?\.]/.test(e.charAt(t)))return!0;if(t>2&&/[\d\.,]/.test(e.charAt(t-2))&&/[\d\.,]/.test(e.charAt(t)))return!1}return/[~!#%&*)=+}\]\\|\"\.>,:;][({[<]|-[^\-?\.\u2010-\u201f\u2026]|\?[\w~`@#$%\^&*(_=+{[|><]|鈥\w~`@#$%\^&*(_=+{[><]/.test(e.slice(t-1,t+1))});var ys,ws,Ss="\n\nb".split(/\n/).length!=3?function(e){var t=0,n=[],r=e.length;while(t<=r){var i=e.indexOf("\n",t);i==-1&&(i=e.length);var s=e.slice(t,e.charAt(i-1)=="\r"?i-1:i),o=s.indexOf("\r");o!=-1?(n.push(s.slice(0,o)),t+=o+1):(n.push(s),t=i+1)}return n}:function(e){return e.split(/\r\n?|\n/)};x.splitLines=Ss;var xs=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(t){return!1}}:function(e){try{var t=e.ownerDocument.selection.createRange()}catch(n){}return!t||t.parentElement()!=e?!1:t.compareEndPoints("StartToEnd",t)!=0},Ts=function(){var e=cs("div");return"oncopy"in e?!0:(e.setAttribute("oncopy","return;"),typeof e.oncopy=="function")}(),Ns={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"};x.keyNames=Ns,function(){for(var e=0;e<10;e++)Ns[e+48]=String(e);for(var e=65;e<=90;e++)Ns[e]=String.fromCharCode(e);for(var e=1;e<=12;e++)Ns[e+111]=Ns[e+63235]="F"+e}();var Ps,Is=function(){function n(n){return n<=255?e.charAt(n):1424<=n&&n<=1524?"R":1536<=n&&n<=1791?t.charAt(n-1536):1792<=n&&n<=2220?"r":"L"}var e="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLL",t="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmmrrrrrrrrrrrrrrrrrr",r=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,i=/[stwN]/,s=/[LRr]/,o=/[Lb1n]/,u=/[1n]/,a="L";return function(e){if(!r.test(e))return!1;var t=e.length,f=[];for(var l=0,c;l