github.com/cayleygraph/cayley@v0.7.7/static/third_party/codemirror/codemirror.min.js (about) 1 // CodeMirror version 3.21 2 // 3 // CodeMirror is the only global var we claim 4 window.CodeMirror=function(){"use strict";function T(e,n){if(!(this instanceof T))return new T(e,n);this.options=n=n||{};for(var r in rr)!n.hasOwnProperty(r)&&rr.hasOwnProperty(r)&&(n[r]=rr[r]);j(n);var i=typeof n.value=="string"?0:n.value.first,s=this.display=N(e,i);s.wrapper.CodeMirror=this,P(this),n.autofocus&&!m&&Rt(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,draggingText:!1,highlight:new os},_(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap");var o=n.value;typeof o=="string"&&(o=new gi(n.value,n.mode)),Dt(this,Ei)(this,o),t&&setTimeout(ms(qt,this,!0),20),zt(this);var u;try{u=document.activeElement==s.input}catch(a){}u||n.autofocus&&!m?setTimeout(ms(vn,this),20):mn(this),Dt(this,function(){for(var e in nr)nr.propertyIsEnumerable(e)&&nr[e](this,n[e],sr);for(var t=0;t<fr.length;++t)fr[t](this)})()}function N(e,t){var r={},i=r.input=Ss("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none; font-size: 4px;");return o?i.style.width="1000px":i.setAttribute("wrap","off"),v&&(i.style.border="1px solid black"),i.setAttribute("autocorrect","off"),i.setAttribute("autocapitalize","off"),i.setAttribute("spellcheck","false"),r.inputDiv=Ss("div",[i],null,"overflow: hidden; position: relative; width: 3px; height: 0px;"),r.scrollbarH=Ss("div",[Ss("div",null,null,"height: 1px")],"CodeMirror-hscrollbar"),r.scrollbarV=Ss("div",[Ss("div",null,null,"width: 1px")],"CodeMirror-vscrollbar"),r.scrollbarFiller=Ss("div",null,"CodeMirror-scrollbar-filler"),r.gutterFiller=Ss("div",null,"CodeMirror-gutter-filler"),r.lineDiv=Ss("div",null,"CodeMirror-code"),r.selectionDiv=Ss("div",null,null,"position: relative; z-index: 1"),r.cursor=Ss("div"," ","CodeMirror-cursor"),r.otherCursor=Ss("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"),r.measure=Ss("div",null,"CodeMirror-measure"),r.lineSpace=Ss("div",[r.measure,r.selectionDiv,r.lineDiv,r.cursor,r.otherCursor],null,"position: relative; outline: none"),r.mover=Ss("div",[Ss("div",[r.lineSpace],"CodeMirror-lines")],null,"position: relative"),r.sizer=Ss("div",[r.mover],"CodeMirror-sizer"),r.heightForcer=Ss("div",null,null,"position: absolute; height: "+is+"px; width: 1px;"),r.gutters=Ss("div",null,"CodeMirror-gutters"),r.lineGutter=null,r.scroller=Ss("div",[r.sizer,r.heightForcer,r.gutters],"CodeMirror-scroll"),r.scroller.setAttribute("tabIndex","-1"),r.wrapper=Ss("div",[r.inputDiv,r.scrollbarH,r.scrollbarV,r.scrollbarFiller,r.gutterFiller,r.scroller],"CodeMirror"),n&&(r.gutters.style.zIndex=-1,r.scroller.style.paddingRight=0),e.appendChild?e.appendChild(r.wrapper):e(r.wrapper),v&&(i.style.width="0px"),o||(r.scroller.draggable=!0),c?(r.inputDiv.style.height="1px",r.inputDiv.style.position="absolute"):n&&(r.scrollbarH.style.minWidth=r.scrollbarV.style.minWidth="18px"),r.viewOffset=r.lastSizeC=0,r.showingFrom=r.showingTo=t,r.lineNumWidth=r.lineNumInnerWidth=r.lineNumChars=null,r.prevInput="",r.alignWidgets=!1,r.pollingFast=!1,r.poll=new os,r.cachedCharWidth=r.cachedTextHeight=null,r.measureLineCache=[],r.measureLineCachePos=0,r.inaccurateSelection=!1,r.maxLine=null,r.maxLineLength=0,r.maxLineChanged=!1,r.wheelDX=r.wheelDY=r.wheelStartX=r.wheelStartY=null,r}function C(e){e.doc.mode=T.getMode(e.options,e.doc.modeOption),k(e)}function k(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,rt(e,100),e.state.modeGen++,e.curOp&&Bt(e)}function L(e){e.options.lineWrapping?(e.display.wrapper.className+=" CodeMirror-wrap",e.display.sizer.style.minWidth=""):(e.display.wrapper.className=e.display.wrapper.className.replace(" CodeMirror-wrap",""),B(e)),O(e),Bt(e),gt(e),setTimeout(function(){F(e)},100)}function A(e){var t=Lt(e.display),n=e.options.lineWrapping,r=n&&Math.max(5,e.display.scroller.clientWidth/At(e.display)-3);return function(i){return Ur(e.doc,i)?0:n?(Math.ceil(i.text.length/r)||1)*t:t}}function O(e){var t=e.doc,n=A(e);t.iter(function(e){var t=n(e);t!=e.height&&Ni(e,t)})}function M(e){var t=dr[e.options.keyMap],n=t.style;e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-keymap-\S+/g,"")+(n?" cm-keymap-"+n:"")}function _(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),gt(e)}function D(e){P(e),Bt(e),setTimeout(function(){q(e)},20)}function P(e){var t=e.display.gutters,n=e.options.gutters;xs(t);for(var r=0;r<n.length;++r){var i=n[r],s=t.appendChild(Ss("div",null,"CodeMirror-gutter "+i));i=="CodeMirror-linenumbers"&&(e.display.lineGutter=s,s.style.width=(e.display.lineNumWidth||1)+"px")}t.style.display=r?"":"none"}function H(e,t){if(t.height==0)return 0;var n=t.text.length,r,i=t;while(r=Fr(i)){var s=r.find();i=Si(e,s.from.line),n+=s.from.ch-s.to.ch}i=t;while(r=Ir(i)){var s=r.find();n-=i.text.length-s.from.ch,i=Si(e,s.to.line),n+=i.text.length-s.to.ch}return n}function B(e){var t=e.display,n=e.doc;t.maxLine=Si(n,n.first),t.maxLineLength=H(n,t.maxLine),t.maxLineChanged=!0,n.iter(function(e){var r=H(n,e);r>t.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function j(e){var t=hs(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 F(e){var t=e.display,n=e.doc.height,r=n+at(t);t.sizer.style.minHeight=t.heightForcer.style.top=r+"px",t.gutters.style.height=Math.max(r,t.scroller.clientHeight-is)+"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?Os(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?Os(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=Os(t.measure)+"px"):t.scrollbarFiller.style.display="",s&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(t.gutterFiller.style.display="block",t.gutterFiller.style.height=Os(t.measure)+"px",t.gutterFiller.style.width=t.gutters.offsetWidth+"px"):t.gutterFiller.style.display="",h&&Os(t.measure)===0&&(t.scrollbarV.style.minWidth=t.scrollbarH.style.minHeight=p?"18px":"12px",t.scrollbarV.style.pointerEvents=t.scrollbarH.style.pointerEvents="none")}function I(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-ut(e));var s=Math.ceil(r+i);return{from:ki(t,r),to:ki(t,s)}}function q(e){var t=e.display;if(!t.alignWidgets&&(!t.gutters.firstChild||!e.options.fixedGutter))return;var n=z(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<u.length;++o)u[o].style.left=i;e.options.fixedGutter&&(t.gutters.style.left=n+r+"px")}function R(e){if(!e.options.lineNumbers)return!1;var t=e.doc,n=U(e.options,t.first+t.size-1),r=e.display;if(n.length!=r.lineNumChars){var i=r.measure.appendChild(Ss("div",[Ss("div",n)],"CodeMirror-linenumber CodeMirror-gutter-elt")),s=i.firstChild.offsetWidth,o=i.offsetWidth-s;return r.lineGutter.style.width="",r.lineNumInnerWidth=Math.max(s,r.lineGutter.offsetWidth-o),r.lineNumWidth=r.lineNumInnerWidth+o,r.lineNumChars=r.lineNumInnerWidth?n.length:-1,r.lineGutter.style.width=r.lineNumWidth+"px",!0}return!1}function U(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function z(e){return Cs(e.scroller).left-Cs(e.sizer).left}function W(e,t,n,r){var i=e.display.showingFrom,s=e.display.showingTo,o,u=I(e.display,e.doc,n);for(var a=!0;;a=!1){var f=e.display.scroller.clientWidth;if(!X(e,t,u,r))break;o=!0,t=[],Z(e),F(e);if(a&&e.options.lineWrapping&&f!=e.display.scroller.clientWidth){r=!0;continue}r=!1,n&&(n=Math.min(e.display.scroller.scrollHeight-e.display.scroller.clientHeight,typeof n=="number"?n:n.top)),u=I(e.display,e.doc,n);if(u.from>=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 X(e,t,n,r){var i=e.display,s=e.doc;if(!i.wrapper.offsetWidth){i.showingFrom=i.showingTo=s.first,i.viewOffset=0;return}if(!r&&t.length==0&&n.from>i.showingFrom&&n.to<i.showingTo)return;R(e)&&(t=[{from:s.first,to:s.first+s.size}]);var o=i.sizer.style.marginLeft=i.gutters.offsetWidth+"px";i.scrollbarH.style.left=e.options.fixedGutter?o:"0";var u=Infinity;if(e.options.lineNumbers)for(var a=0;a<t.length;++a)t[a].diff&&t[a].from<u&&(u=t[a].from);var f=s.first+s.size,l=Math.max(n.from-e.options.viewportMargin,s.first),c=Math.min(f,n.to+e.options.viewportMargin);i.showingFrom<l&&l-i.showingFrom<20&&(l=Math.max(s.first,i.showingFrom)),i.showingTo>c&&i.showingTo-c<20&&(c=Math.min(f,i.showingTo));if(x){l=Ci(Rr(s,Si(s,l)));while(c<f&&Ur(s,Si(s,c)))++c}var h=[{from:Math.max(i.showingFrom,s.first),to:Math.min(i.showingTo,f)}];h[0].from>=h[0].to?h=[]:h=J(h,t);if(x)for(var a=0;a<h.length;++a){var p=h[a],d;while(d=Ir(Si(s,p.to-1))){var v=d.find().from.line;if(!(v>p.from)){h.splice(a--,1);break}p.to=v}}var m=0;for(var a=0;a<h.length;++a){var p=h[a];p.from<l&&(p.from=l),p.to>c&&(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){$(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"),Q(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,rt(e,400)),i.showingFrom=l,i.showingTo=c,i.gutters.style.height="",V(e),$(e),!0}function V(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=Cs(i);s=u.bottom-u.top}var a=i.lineObj.height-s;s<2&&(s=Lt(t));if(a>.001||a<-0.001){Ni(i.lineObj,s);var f=i.lineObj.widgets;if(f)for(var l=0;l<f.length;++l)f[l].height=f[l].node.offsetHeight}}}function $(e){var t=e.display.viewOffset=Li(e,Si(e.doc,e.display.showingFrom));e.display.mover.style.top=t+"px"}function J(e,t){for(var n=0,r=t.length||0;n<r;++n){var i=t[n],s=[],o=i.diff||0;for(var u=0,a=e.length;u<a;++u){var f=e[u];i.to<=f.from&&i.diff?s.push({from:f.from+o,to:f.to+o}):i.to<=f.from||i.from>=f.to?s.push(f):(i.from>f.from&&s.push({from:f.from,to:i.from}),i.to<f.to&&s.push({from:i.to+o,to:f.to+o}))}e=s}return e}function K(e){var t=e.display,n={},r={};for(var i=t.gutters.firstChild,s=0;i;i=i.nextSibling,++s)n[e.options.gutters[s]]=i.offsetLeft,r[e.options.gutters[s]]=i.offsetWidth;return{fixedPos:z(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:r,wrapperWidth:t.wrapper.clientWidth}}function Q(e,t,n,r,i){function c(t){var n=t.nextSibling;return o&&g&&e.display.currentWheelTarget==t?(t.style.display="none",t.lineObj=null):t.parentNode.removeChild(t),n}var s=K(e),u=e.display,a=e.options.lineNumbers;!r.length&&(!o||!e.display.currentWheelTarget)&&xs(u.lineDiv);var f=u.lineDiv,l=f.firstChild,h=r.shift(),p=t;e.doc.iter(t,n,function(t){h&&h.to==p&&(h=r.shift());if(Ur(e.doc,t)){t.height!=0&&Ni(t,0);if(t.widgets&&l&&l.previousSibling)for(var n=0;n<t.widgets.length;++n){var o=t.widgets[n];if(o.showIfHidden){var u=l.previousSibling;if(/pre/i.test(u.nodeName)){var d=Ss("div",null,null,"position: relative");u.parentNode.replaceChild(d,u),d.appendChild(u),u=d}var v=u.appendChild(Ss("div",[o.node],"CodeMirror-linewidget"));o.handleMouseEvents||(v.ignoreEvents=!0),Y(o,v,u,s)}}}else if(h&&h.from<=p&&h.to>p){while(l.lineObj!=t)l=c(l);a&&i<=p&&l.lineNumber&&Ns(l.lineNumber,U(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=G(e,t,p,s,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 G(e,t,r,i,s){var o=oi(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;g<t.widgets.length;++g){var y=t.widgets[g];if(y.node==v.firstChild){!y.above&&!d&&(d=v),Y(y,v,s,i),++p;break}}if(g==t.widgets.length){h=!1;break}}}s.insertBefore(u,d),h&&p==t.widgets.length&&(l=s,s.className=t.wrapClass||"")}l||(l=Ss("div",null,t.wrapClass,"position: relative"),l.appendChild(u)),c&&l.insertBefore(Ss("div",null,c+" CodeMirror-linebackground"),l.firstChild);if(e.options.lineNumbers||a){var b=l.insertBefore(Ss("div",null,"CodeMirror-gutter-wrapper","position: absolute; left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px"),u);e.options.fixedGutter&&(l.alignable||(l.alignable=[])).push(b),e.options.lineNumbers&&(!a||!a["CodeMirror-linenumbers"])&&(l.lineNumber=b.appendChild(Ss("div",U(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+i.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+f.lineNumInnerWidth+"px")));if(a)for(var w=0;w<e.options.gutters.length;++w){var E=e.options.gutters[w],S=a.hasOwnProperty(E)&&a[E];S&&b.appendChild(Ss("div",[S],"CodeMirror-gutter-elt","left: "+i.gutterLeft[E]+"px; width: "+i.gutterWidth[E]+"px"))}}n&&(l.style.zIndex=2);if(t.widgets&&l!=s)for(var g=0,x=t.widgets;g<x.length;++g){var y=x[g],T=Ss("div",[y.node],"CodeMirror-linewidget");y.handleMouseEvents||(T.ignoreEvents=!0),Y(y,T,l,i),y.above?l.insertBefore(T,e.options.lineNumbers&&t.height!=0?b:u):l.appendChild(T),Zi(y,"redraw")}return l}function Y(e,t,n,r){if(e.noHScroll){(n.alignable||(n.alignable=[])).push(t);var i=r.wrapperWidth;t.style.left=r.fixedPos+"px",e.coverGutter||(i-=r.gutterTotalWidth,t.style.paddingLeft=r.gutterTotalWidth+"px"),t.style.width=i+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-r.gutterTotalWidth+"px"))}function Z(e){var t=e.display,n=Mn(e.doc.sel.from,e.doc.sel.to);n||e.options.showCursorWhenSelecting?et(e):t.cursor.style.display=t.otherCursor.style.display="none",n?t.selectionDiv.style.display="none":tt(e);if(e.options.moveInputWithCursor){var r=xt(e,e.doc.sel.head,"div"),i=Cs(t.wrapper),s=Cs(t.lineDiv);t.inputDiv.style.top=Math.max(0,Math.min(t.wrapper.clientHeight-10,r.top+s.top-i.top))+"px",t.inputDiv.style.left=Math.max(0,Math.min(t.wrapper.clientWidth-10,r.left+s.left-i.left))+"px"}}function et(e){var t=e.display,n=xt(e,e.doc.sel.head,"div");t.cursor.style.left=n.left+"px",t.cursor.style.top=n.top+"px",t.cursor.style.height=Math.max(0,n.bottom-n.top)*e.options.cursorHeight+"px",t.cursor.style.display="",n.other?(t.otherCursor.style.display="",t.otherCursor.style.left=n.other.left+"px",t.otherCursor.style.top=n.other.top+"px",t.otherCursor.style.height=(n.other.bottom-n.other.top)*.85+"px"):t.otherCursor.style.display="none"}function tt(e){function u(e,t,n,r){t<0&&(t=0),i.appendChild(Ss("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(n==null?s-e:n)+"px; height: "+(r-t)+"px"))}function a(t,r,i){function h(n,r){return St(e,On(t,n),"div",a,r)}var a=Si(n,t),f=a.text.length,l,c;return js(Ai(a),r||0,i==null?f:i,function(e,t,n){var a=h(e,"left"),p,d,v;if(e==t)p=a,d=v=a.left;else{p=h(t-1,"right");if(n=="rtl"){var m=a;a=p,p=m}d=a.left,v=p.right}r==null&&e==0&&(d=o),p.top-a.top>3&&(u(d,a.top,null,a.bottom),d=o,a.bottom<p.top&&u(d,a.bottom,null,p.top)),i==null&&t==f&&(v=s);if(!l||a.top<l.top||a.top==l.top&&a.left<l.left)l=a;if(!c||p.bottom>c.bottom||p.bottom==c.bottom&&p.right>c.right)c=p;d<o+1&&(d=o),u(d,p.top,v-d,p.bottom)}),{start:l,end:c}}var t=e.display,n=e.doc,r=e.doc.sel,i=document.createDocumentFragment(),s=t.lineSpace.offsetWidth,o=ft(e.display);if(r.from.line==r.to.line)a(r.from.line,r.from.ch,r.to.ch);else{var f=Si(n,r.from.line),l=Si(n,r.to.line),c=Rr(n,f)==Rr(n,l),h=a(r.from.line,r.from.ch,c?f.text.length:null).end,p=a(r.to.line,c?0:null,r.to.ch).start;c&&(h.top<p.top-2?(u(h.right,h.top,null,h.bottom),u(o,p.top,p.left,p.bottom)):u(h.right,h.top,p.left-h.right,h.bottom)),h.bottom<p.top&&u(o,h.bottom,null,p.top)}Ts(t.selectionDiv,i),t.selectionDiv.style.display=""}function nt(e){if(!e.state.focused)return;var t=e.display;clearInterval(t.blinker);var n=!0;t.cursor.style.visibility=t.otherCursor.style.visibility="",e.options.cursorBlinkRate>0&&(t.blinker=setInterval(function(){t.cursor.style.visibility=t.otherCursor.style.visibility=(n=!n)?"":"hidden"},e.options.cursorBlinkRate))}function rt(e,t){e.doc.mode.startState&&e.doc.frontier<e.display.showingTo&&e.state.highlight.set(t,ms(it,e))}function it(e){var t=e.doc;t.frontier<t.first&&(t.frontier=t.first);if(t.frontier>=e.display.showingTo)return;var n=+(new Date)+e.options.workTime,r=cr(t.mode,ot(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=ei(e,o,r,!0);var a=!u||u.length!=o.styles.length;for(var f=0;!a&&f<u.length;++f)a=u[f]!=o.styles[f];a&&(s&&s.end==t.frontier?s.end++:i.push(s={start:t.frontier,end:t.frontier+1})),o.stateAfter=cr(t.mode,r)}else ni(e,o.text,r),o.stateAfter=t.frontier%5==0?cr(t.mode,r):null;++t.frontier;if(+(new Date)>n)return rt(e,e.options.workDelay),!0}),i.length&&Dt(e,function(){for(var e=0;e<i.length;++e)Bt(this,i[e].start,i[e].end)})()}function st(e,t,n){var r,i,s=e.doc,o=n?-1:t-(e.doc.mode.innerMode?1e3:100);for(var u=t;u>o;--u){if(u<=s.first)return s.first;var a=Si(s,u-1);if(a.stateAfter&&(!n||u<=s.frontier))return u;var f=us(a.text,null,e.options.tabSize);if(i==null||r>f)i=u-1,r=f}return i}function ot(e,t,n){var r=e.doc,i=e.display;if(!r.mode.startState)return!0;var s=st(e,t,n),o=s>r.first&&Si(r,s-1).stateAfter;return o?o=cr(r.mode,o):o=hr(r.mode),r.iter(s,t,function(n){ni(e,n.text,o);var u=s==t-1||s%5==0||s>=i.showingFrom&&s<i.showingTo;n.stateAfter=u?cr(r.mode,o):null,++s}),n&&(r.frontier=s),o}function ut(e){return e.lineSpace.offsetTop}function at(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function ft(e){var t=Ts(e.measure,Ss("pre",null,null,"text-align: left")).appendChild(Ss("span","x"));return t.offsetLeft}function lt(e,t,n,r,i){var s=-1;r=r||pt(e,t);if(r.crude){var o=r.left+n*r.width;return{left:o,right:o+r.width,top:r.top,bottom:r.bottom}}for(var u=n;;u+=s){var a=r[u];if(a)break;s<0&&u==0&&(s=1)}return i=u>n?"left":u<n?"right":i,i=="left"&&a.leftSide?a=a.leftSide:i=="right"&&a.rightSide&&(a=a.rightSide),{left:u<n?a.right:a.left,right:u>n?a.left:a.right,top:a.top,bottom:a.bottom}}function ct(e,t){var n=e.display.measureLineCache;for(var r=0;r<n.length;++r){var i=n[r];if(i.text==t.text&&i.markedSpans==t.markedSpans&&e.display.scroller.clientWidth==i.width&&i.classes==t.textClass+"|"+t.wrapClass)return i}}function ht(e,t){var n=ct(e,t);n&&(n.text=n.measure=n.markedSpans=null)}function pt(e,t){var n=ct(e,t);if(n)return n.measure;var r=dt(e,t),i=e.display.measureLineCache,s={text:t.text,width:e.display.scroller.clientWidth,markedSpans:t.markedSpans,measure:r,classes:t.textClass+"|"+t.wrapClass};return i.length==16?i[++e.display.measureLineCachePos%16]=s:i.push(s),r}function dt(e,i){function b(e){var t=e.top-v.top,n=e.bottom-v.top;n>y&&(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<t)continue;if(i<=t&&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 vt(e,i);var s=e.display,o=vs(i.text.length),u=oi(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);c<h;++c){var p=Ss("div",null,null,"display: inline-block");for(var d=0;d<f&&l;++d)p.appendChild(u.firstChild),--l;a.appendChild(p)}u.appendChild(a)}Ts(s.measure,u);var v=Cs(s.lineDiv),m=[],g=vs(i.text.length),y=u.offsetHeight;r&&s.measure.first!=u&&Ts(s.measure,u);for(var c=0,E;c<o.length;++c)if(E=o[c]){var S=E,x=null;if(/\bCodeMirror-widget\b/.test(E.className)&&E.getClientRects){E.firstChild.nodeType==1&&(S=E.firstChild);var T=S.getClientRects();T.length>1&&(x=g[c]=b(T[0]),x.rightSide=b(T[T.length-1]))}x||(x=g[c]=b(Cs(S))),E.measureRight&&(x.right=Cs(E.measureRight).left-v.left),E.leftSide&&(x.leftSide=b(Cs(E.leftSide)))}xs(e.display.measure);for(var c=0,E;c<g.length;++c)if(E=g[c])w(E),E.leftSide&&w(E.leftSide),E.rightSide&&w(E.rightSide);return g}function vt(e,t){var n=new Qr(t.text.slice(0,100),null);t.textClass&&(n.textClass=t.textClass);var r=dt(e,n),i=lt(e,n,0,r,"left"),s=lt(e,n,99,r,"right");return{crude:!0,top:i.top,left:i.left,bottom:i.bottom,width:(s.right-i.left)/100}}function mt(e,t){var n=!1;if(t.markedSpans)for(var r=0;r<t.markedSpans;++r){var i=t.markedSpans[r];i.collapsed&&(i.to==null||i.to==t.text.length)&&(n=!0)}var s=!n&&ct(e,t);if(s||t.text.length>=e.options.crudeMeasuringFrom)return lt(e,t,t.text.length,s&&s.measure,"right").right;var o=oi(e,t,null,!0).pre,u=o.appendChild(_s(e.display.measure));return Ts(e.display.measure,o),Cs(u).right-Cs(e.display.lineDiv).left}function gt(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 yt(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function bt(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function wt(e,t,n,r){if(t.widgets)for(var i=0;i<t.widgets.length;++i)if(t.widgets[i].above){var s=Jr(t.widgets[i]);n.top+=s,n.bottom+=s}if(r=="line")return n;r||(r="local");var o=Li(e,t);r=="local"?o+=ut(e.display):o-=e.display.viewOffset;if(r=="page"||r=="window"){var u=Cs(e.display.lineSpace);o+=u.top+(r=="window"?0:bt());var a=u.left+(r=="window"?0:yt());n.left+=a,n.right+=a}return n.top+=o,n.bottom+=o,n}function Et(e,t,n){if(n=="div")return t;var r=t.left,i=t.top;if(n=="page")r-=yt(),i-=bt();else if(n=="local"||!n){var s=Cs(e.display.sizer);r+=s.left,i+=s.top}var o=Cs(e.display.lineSpace);return{left:r-o.left,top:i-o.top}}function St(e,t,n,r,i){return r||(r=Si(e.doc,t.line)),wt(e,r,lt(e,r,t.ch,null,i),n)}function xt(e,t,n,r,i){function s(t,s){var o=lt(e,r,t,i,s?"right":"left");return s?o.left=o.right:o.right=o.left,wt(e,r,o,n)}function o(e,t){var n=u[t],r=n.level%2;return e==Fs(n)&&t&&n.level<u[t-1].level?(n=u[--t],e=Is(n)-(n.level%2?0:1),r=!0):e==Is(n)&&t<u.length-1&&n.level<u[t+1].level&&(n=u[++t],e=Fs(n)-n.level%2,r=!1),r&&e==n.to&&e>n.from?s(e-1):s(e,r)}r=r||Si(e.doc,t.line),i||(i=pt(e,r));var u=Ai(r),a=t.ch;if(!u)return s(a);var f=Vs(u,a),l=o(a,f);return Xs!=null&&(l.other=o(a,Xs)),l}function Tt(e,t,n,r){var i=new On(e,t);return i.xRel=r,n&&(i.outside=!0),i}function Nt(e,t,n){var r=e.doc;n+=e.display.viewOffset;if(n<0)return Tt(r.first,0,!0,-1);var i=ki(r,n),s=r.first+r.size-1;if(i>s)return Tt(r.first+r.size-1,Si(r,s).text.length,!0,1);t<0&&(t=0);for(;;){var o=Si(r,i),u=Ct(e,o,i,t,n),a=Ir(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 Ct(e,t,n,r,i){function f(r){var i=xt(e,On(n,r),"line",t,a);return o=!0,s>i.bottom?i.left-u:s<i.top?i.left+u:(o=!1,i.left)}var s=i-Li(e,t),o=!1,u=2*e.display.wrapper.clientWidth,a=pt(e,t),l=Ai(t),c=t.text.length,h=qs(t),p=Rs(t),d=f(h),v=o,m=f(p),g=o;if(r>m)return Tt(n,p,g,1);for(;;){if(l?p==h||p==Js(t,h,1):p-h<=1){var y=r<d||r-d<=m-r?h:p,b=r-(y==h?d:m);while(Es(t.text.charAt(y)))++y;var w=Tt(n,y,y==h?v:g,b<0?-1:b?1:0);return w}var E=Math.ceil(c/2),S=h+E;if(l){S=h;for(var x=0;x<E;++x)S=Js(t,S,1)}var T=f(S);if(T>r){p=S,m=T;if(g=o)m+=1e3;c=E}else h=S,d=T,v=o,c-=E}}function Lt(e){if(e.cachedTextHeight!=null)return e.cachedTextHeight;if(kt==null){kt=Ss("pre");for(var t=0;t<49;++t)kt.appendChild(document.createTextNode("x")),kt.appendChild(Ss("br"));kt.appendChild(document.createTextNode("x"))}Ts(e.measure,kt);var n=kt.offsetHeight/50;return n>3&&(e.cachedTextHeight=n),xs(e.measure),n||1}function At(e){if(e.cachedCharWidth!=null)return e.cachedCharWidth;var t=Ss("span","x"),n=Ss("pre",[t]);Ts(e.measure,n);var r=t.offsetWidth;return r>2&&(e.cachedCharWidth=r),r||10}function Mt(e){e.curOp={changes:[],forceUpdate:!1,updateInput:null,userSelChange:null,textChanged:null,selectionChanged:!1,cursorActivity:!1,updateMaxLine:!1,updateScrollPos:!1,id:++Ot},Yi++||(Gi=[])}function _t(e){var t=e.curOp,n=e.doc,r=e.display;e.curOp=null,t.updateMaxLine&&B(e);if(r.maxLineChanged&&!e.options.lineWrapping&&r.maxLine){var i=mt(e,r.maxLine);r.sizer.style.minWidth=Math.max(0,i+3+is)+"px",r.maxLineChanged=!1;var s=Math.max(0,r.sizer.offsetLeft+r.sizer.offsetWidth-r.scroller.clientWidth);s<n.scrollLeft&&!t.updateScrollPos&&nn(e,Math.min(r.scroller.scrollLeft,s),!0)}var o,u;if(t.updateScrollPos)o=t.updateScrollPos;else if(t.selectionChanged&&r.scroller.clientHeight){var a=xt(e,n.sel.head);o=$n(e,a.left,a.top,a.left,a.bottom)}if(t.changes.length||t.forceUpdate||o&&o.scrollTop!=null)u=W(e,t.changes,o&&o.scrollTop,t.forceUpdate),e.display.scroller.offsetHeight&&(e.doc.scrollTop=e.display.scroller.scrollTop);!u&&t.selectionChanged&&Z(e);if(t.updateScrollPos){var f=Math.max(0,Math.min(r.scroller.scrollHeight-r.scroller.clientHeight,o.scrollTop)),l=Math.max(0,Math.min(r.scroller.scrollWidth-r.scroller.clientWidth,o.scrollLeft));r.scroller.scrollTop=r.scrollbarV.scrollTop=n.scrollTop=f,r.scroller.scrollLeft=r.scrollbarH.scrollLeft=n.scrollLeft=l,q(e),t.scrollToPos&&Xn(e,Bn(e.doc,t.scrollToPos.from),Bn(e.doc,t.scrollToPos.to),t.scrollToPos.margin)}else o&&Wn(e);t.selectionChanged&&nt(e),e.state.focused&&t.updateInput&&qt(e,t.userSelChange);var c=t.maybeHiddenMarkers,h=t.maybeUnhiddenMarkers;if(c)for(var p=0;p<c.length;++p)c[p].lines.length||Qi(c[p],"hide");if(h)for(var p=0;p<h.length;++p)h[p].lines.length&&Qi(h[p],"unhide");var d;--Yi||(d=Gi,Gi=null),t.textChanged&&Qi(e,"change",e,t.textChanged),t.cursorActivity&&Qi(e,"cursorActivity",e);if(d)for(var p=0;p<d.length;++p)d[p]()}function Dt(e,t){return function(){var n=e||this,r=!n.curOp;r&&Mt(n);try{var i=t.apply(n,arguments)}finally{r&&_t(n)}return i}}function Pt(e){return function(){var t=this.cm&&!this.cm.curOp,n;t&&Mt(this.cm);try{n=e.apply(this,arguments)}finally{t&&_t(this.cm)}return n}}function Ht(e,t){var n=!e.curOp,r;n&&Mt(e);try{r=t()}finally{n&&_t(e)}return r}function Bt(e,t,n,r){t==null&&(t=e.doc.first),n==null&&(n=e.doc.first+e.doc.size),e.curOp.changes.push({from:t,to:n,diff:r})}function jt(e){if(e.display.pollingFast)return;e.display.poll.set(e.options.pollInterval,function(){It(e),e.state.focused&&jt(e)})}function Ft(e){function n(){var r=It(e);!r&&!t?(t=!0,e.display.poll.set(60,n)):(e.display.pollingFast=!1,jt(e))}var t=!1;e.display.pollingFast=!0,e.display.poll.set(20,n)}function It(e){var t=e.display.input,n=e.display.prevInput,i=e.doc,o=i.sel;if(!e.state.focused||Ps(t)||Ut(e)||e.options.disableInput)return!1;e.state.pasteIncoming&&e.state.fakedLastChar&&(t.value=t.value.substring(0,t.value.length-1),e.state.fakedLastChar=!1);var u=t.value;if(u==n&&Mn(o.from,o.to))return!1;if(s&&!r&&e.display.inputHasSelection===u)return qt(e,!0),!1;var a=!e.curOp;a&&Mt(e),o.shift=!1;var f=0,l=Math.min(n.length,u.length);while(f<l&&n.charCodeAt(f)==u.charCodeAt(f))++f;var c=o.from,h=o.to,p=u.slice(f);f<n.length?c=On(c.line,c.ch-(n.length-f)):e.state.overwrite&&Mn(c,h)&&!e.state.pasteIncoming&&(h=On(h.line,Math.min(Si(i,h.line).text.length,h.ch+p.length)));var d=e.curOp.updateInput,v={from:c,to:h,text:Ds(p),origin:e.state.pasteIncoming?"paste":e.state.cutIncoming?"cut":"+input"};xn(e.doc,v,"end"),e.curOp.updateInput=d,Zi(e,"inputRead",e,v);if(p&&!e.state.pasteIncoming&&e.options.electricChars&&e.options.smartIndent&&o.head.ch<100){var m=e.getModeAt(o.head).electricChars;if(m)for(var g=0;g<m.length;g++)if(p.indexOf(m.charAt(g))>-1){Qn(e,o.head.line,"smart");break}}return u.length>1e3||u.indexOf("\n")>-1?t.value=e.display.prevInput="":e.display.prevInput=u,a&&_t(e),e.state.pasteIncoming=e.state.cutIncoming=!1,!0}function qt(e,t){var n,i,o=e.doc;if(!Mn(o.sel.from,o.sel.to)){e.display.prevInput="",n=Hs&&(o.sel.to.line-o.sel.from.line>100||(i=e.getSelection()).length>1e3);var u=n?"-":i||e.getSelection();e.display.input.value=u,e.state.focused&&cs(e.display.input),s&&!r&&(e.display.inputHasSelection=u)}else t&&(e.display.prevInput=e.display.input.value="",s&&!r&&(e.display.inputHasSelection=null));e.display.inaccurateSelection=n}function Rt(e){e.options.readOnly!="nocursor"&&(!m||document.activeElement!=e.display.input)&&e.display.input.focus()}function Ut(e){return e.options.readOnly||e.doc.cantEdit}function zt(e){function i(){e.state.focused&&setTimeout(ms(Rt,e),0)}function a(){u==null&&(u=setTimeout(function(){u=null,n.cachedCharWidth=n.cachedTextHeight=As=null,gt(e),Ht(e,ms(Bt,e))},100))}function f(){for(var e=n.wrapper.parentNode;e&&e!=document.body;e=e.parentNode);e?setTimeout(f,5e3):Ki(window,"resize",a)}function l(t){if(es(e,t)||e.options.onDragEvent&&e.options.onDragEvent(e,Ri(t)))return;Xi(t)}function h(t){n.inaccurateSelection&&(n.prevInput="",n.inaccurateSelection=!1,n.input.value=e.getSelection(),cs(n.input)),t.type=="cut"&&(e.state.cutIncoming=!0)}var n=e.display;Ji(n.scroller,"mousedown",Dt(e,Jt)),t?Ji(n.scroller,"dblclick",Dt(e,function(t){if(es(e,t))return;var n=Xt(e,t);if(!n||Gt(e,t)||Wt(e.display,t))return;Ui(t);var r=er(Si(e.doc,n.line).text,n);In(e.doc,r.from,r.to)})):Ji(n.scroller,"dblclick",function(t){es(e,t)||Ui(t)}),Ji(n.lineSpace,"selectstart",function(e){Wt(n,e)||Ui(e)}),E||Ji(n.scroller,"contextmenu",function(t){yn(e,t)}),Ji(n.scroller,"scroll",function(){n.scroller.clientHeight&&(tn(e,n.scroller.scrollTop),nn(e,n.scroller.scrollLeft,!0),Qi(e,"scroll",e))}),Ji(n.scrollbarV,"scroll",function(){n.scroller.clientHeight&&tn(e,n.scrollbarV.scrollTop)}),Ji(n.scrollbarH,"scroll",function(){n.scroller.clientHeight&&nn(e,n.scrollbarH.scrollLeft)}),Ji(n.scroller,"mousewheel",function(t){on(e,t)}),Ji(n.scroller,"DOMMouseScroll",function(t){on(e,t)}),Ji(n.scrollbarH,"mousedown",i),Ji(n.scrollbarV,"mousedown",i),Ji(n.wrapper,"scroll",function(){n.wrapper.scrollTop=n.wrapper.scrollLeft=0});var u;Ji(window,"resize",a),setTimeout(f,5e3),Ji(n.input,"keyup",Dt(e,function(t){if(es(e,t)||e.options.onKeyEvent&&e.options.onKeyEvent(e,Ri(t)))return;t.keyCode==16&&(e.doc.sel.shift=!1)})),Ji(n.input,"input",function(){s&&!r&&e.display.inputHasSelection&&(e.display.inputHasSelection=null),Ft(e)}),Ji(n.input,"keydown",Dt(e,pn)),Ji(n.input,"keypress",Dt(e,dn)),Ji(n.input,"focus",ms(vn,e)),Ji(n.input,"blur",ms(mn,e)),e.options.dragDrop&&(Ji(n.scroller,"dragstart",function(t){en(e,t)}),Ji(n.scroller,"dragenter",l),Ji(n.scroller,"dragover",l),Ji(n.scroller,"drop",Dt(e,Zt))),Ji(n.scroller,"paste",function(t){if(Wt(n,t))return;Rt(e),Ft(e)}),Ji(n.input,"paste",function(){if(o&&!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,Ft(e)}),Ji(n.input,"cut",h),Ji(n.input,"copy",h),c&&Ji(n.sizer,"mouseup",function(){document.activeElement==n.input&&n.input.blur(),Rt(e)})}function Wt(e,t){for(var n=Vi(t);n!=e.wrapper;n=n.parentNode)if(!n||n.ignoreEvents||n.parentNode==e.sizer&&n!=e.mover)return!0}function Xt(e,t,n){var r=e.display;if(!n){var i=Vi(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=Cs(r.lineSpace);try{s=t.clientX,o=t.clientY}catch(t){return null}return Nt(e,s-u.left,o-u.top)}function Jt(e){function g(e){if(Mn(m,e))return;m=e;if(l=="single"){In(n.doc,Bn(s,a),e);return}d=Bn(s,d),v=Bn(s,v);if(l=="double"){var t=er(Si(s,e.line).text,e);_n(e,d)?In(n.doc,t.from,v): 5 In(n.doc,d,t.to)}else l=="triple"&&(_n(e,d)?In(n.doc,v,Bn(s,On(e.line,0))):In(n.doc,d,Bn(s,On(e.line+1,0))))}function w(e){var t=++b,r=Xt(n,e,!0);if(!r)return;if(!Mn(r,h)){n.state.focused||vn(n),h=r,g(r);var o=I(i,s);(r.line>=o.to||r.line<o.from)&&setTimeout(Dt(n,function(){b==t&&w(e)}),150)}else{var u=e.clientY<y.top?-20:e.clientY>y.bottom?20:0;u&&setTimeout(Dt(n,function(){if(b!=t)return;i.scroller.scrollTop+=u,w(e)}),50)}}function S(e){b=Infinity,Ui(e),Rt(n),Ki(document,"mousemove",x),Ki(document,"mouseup",T)}if(es(this,e))return;var n=this,i=n.display,s=n.doc,u=s.sel;u.shift=e.shiftKey;if(Wt(i,e)){o||(i.scroller.draggable=!1,setTimeout(function(){i.scroller.draggable=!0},100));return}if(Gt(n,e))return;var a=Xt(n,e);switch($i(e)){case 3:E&&yn.call(n,n,e);return;case 2:o&&(n.state.lastMiddleDown=+(new Date)),a&&In(n.doc,a),setTimeout(ms(Rt,n),20),Ui(e);return}if(!a){Vi(e)==i.scroller&&Ui(e);return}n.state.focused||vn(n);var f=+(new Date),l="single";if($t&&$t.time>f-400&&Mn($t.pos,a))l="triple",Ui(e),setTimeout(ms(Rt,n),20),tr(n,a.line);else if(Vt&&Vt.time>f-400&&Mn(Vt.pos,a)){l="double",$t={time:f,pos:a},Ui(e);var c=er(Si(s,a.line).text,a);In(n.doc,c.from,c.to)}else Vt={time:f,pos:a};var h=a;if(n.options.dragDrop&&ks&&!Ut(n)&&!Mn(u.from,u.to)&&!_n(a,u.from)&&!_n(u.to,a)&&l=="single"){var p=Dt(n,function(s){o&&(i.scroller.draggable=!1),n.state.draggingText=!1,Ki(document,"mouseup",p),Ki(i.scroller,"drop",p),Math.abs(e.clientX-s.clientX)+Math.abs(e.clientY-s.clientY)<10&&(Ui(s),In(n.doc,a),Rt(n),t&&!r&&setTimeout(function(){document.body.focus(),Rt(n)},20))});o&&(i.scroller.draggable=!0),n.state.draggingText=p,i.scroller.dragDrop&&i.scroller.dragDrop(),Ji(document,"mouseup",p),Ji(i.scroller,"drop",p);return}Ui(e),l=="single"&&In(n.doc,Bn(s,a));var d=u.from,v=u.to,m=a,y=Cs(i.wrapper),b=0,x=Dt(n,function(e){!t&&!$i(e)?S(e):w(e)}),T=Dt(n,S);Ji(document,"mousemove",x),Ji(document,"mouseup",T)}function Kt(e,t,n,r,i){try{var s=t.clientX,o=t.clientY}catch(t){return!1}if(s>=Math.floor(Cs(e.display.gutters).right))return!1;r&&Ui(t);var u=e.display,a=Cs(u.lineDiv);if(o>a.bottom||!ns(e,n))return Wi(t);o-=a.top-u.viewOffset;for(var f=0;f<e.options.gutters.length;++f){var l=u.gutters.childNodes[f];if(l&&Cs(l).right>=s){var c=ki(e.doc,o),h=e.options.gutters[f];return i(e,n,e,c,h,t),Wi(t)}}}function Qt(e,t){return ns(e,"gutterContextMenu")?Kt(e,t,"gutterContextMenu",!1,Qi):!1}function Gt(e,t){return Kt(e,t,"gutterClick",!0,Zi)}function Zt(e){var t=this;if(es(t,e)||Wt(t.display,e)||t.options.onDragEvent&&t.options.onDragEvent(t,Ri(e)))return;Ui(e),s&&(Yt=+(new Date));var n=Xt(t,e,!0),r=e.dataTransfer.files;if(!n||Ut(t))return;if(r&&r.length&&window.FileReader&&window.File){var i=r.length,o=Array(i),u=0,a=function(e,r){var s=new FileReader;s.onload=function(){o[r]=s.result,++u==i&&(n=Bn(t.doc,n),xn(t.doc,{from:n,to:n,text:Ds(o.join("\n")),origin:"paste"},"around"))},s.readAsText(e)};for(var f=0;f<i;++f)a(r[f],f)}else{if(t.state.draggingText&&!_n(n,t.doc.sel.from)&&!_n(t.doc.sel.to,n)){t.state.draggingText(e),setTimeout(ms(Rt,t),20);return}try{var o=e.dataTransfer.getData("Text");if(o){var l=t.doc.sel.from,c=t.doc.sel.to;Rn(t.doc,n,n),t.state.draggingText&&An(t.doc,"",l,c,"paste"),t.replaceSelection(o,null,"paste"),Rt(t)}}catch(e){}}}function en(e,t){if(s&&(!e.state.draggingText||+(new Date)-Yt<100)){Xi(t);return}if(es(e,t)||Wt(e.display,t))return;var n=e.getSelection();t.dataTransfer.setData("Text",n);if(t.dataTransfer.setDragImage&&!l){var r=Ss("img",null,null,"position: fixed; left: 0; top: 0;");r.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",f&&(r.width=r.height=1,e.display.wrapper.appendChild(r),r._top=r.offsetTop),t.dataTransfer.setDragImage(r,0,0),f&&r.parentNode.removeChild(r)}}function tn(t,n){if(Math.abs(t.doc.scrollTop-n)<2)return;t.doc.scrollTop=n,e||W(t,[],n),t.display.scroller.scrollTop!=n&&(t.display.scroller.scrollTop=n),t.display.scrollbarV.scrollTop!=n&&(t.display.scrollbarV.scrollTop=n),e&&W(t,[]),rt(t,100)}function nn(e,t,n){if(n?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)return;t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth),e.doc.scrollLeft=t,q(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbarH.scrollLeft!=t&&(e.display.scrollbarH.scrollLeft=t)}function on(t,n){var r=n.wheelDeltaX,i=n.wheelDeltaY;r==null&&n.detail&&n.axis==n.HORIZONTAL_AXIS&&(r=n.detail),i==null&&n.detail&&n.axis==n.VERTICAL_AXIS?i=n.detail:i==null&&(i=n.wheelDelta);var s=t.display,u=s.scroller;if(!(r&&u.scrollWidth>u.clientWidth||i&&u.scrollHeight>u.clientHeight))return;if(i&&g&&o)for(var a=n.target;a!=u;a=a.parentNode)if(a.lineObj){t.display.currentWheelTarget=a;break}if(r&&!e&&!f&&sn!=null){i&&tn(t,Math.max(0,Math.min(u.scrollTop+i*sn,u.scrollHeight-u.clientHeight))),nn(t,Math.max(0,Math.min(u.scrollLeft+r*sn,u.scrollWidth-u.clientWidth))),Ui(n),s.wheelStartX=null;return}if(i&&sn!=null){var l=i*sn,c=t.doc.scrollTop,h=c+s.wrapper.clientHeight;l<0?c=Math.max(0,c+l-50):h=Math.min(t.doc.height,h+l+50),W(t,[],{top:c,bottom:h})}rn<20&&(s.wheelStartX==null?(s.wheelStartX=u.scrollLeft,s.wheelStartY=u.scrollTop,s.wheelDX=r,s.wheelDY=i,setTimeout(function(){if(s.wheelStartX==null)return;var e=u.scrollLeft-s.wheelStartX,t=u.scrollTop-s.wheelStartY,n=t&&s.wheelDY&&t/s.wheelDY||e&&s.wheelDX&&e/s.wheelDX;s.wheelStartX=s.wheelStartY=null;if(!n)return;sn=(sn*rn+n)/(rn+1),++rn},200)):(s.wheelDX+=r,s.wheelDY+=i))}function un(e,t,n){if(typeof t=="string"){t=pr[t];if(!t)return!1}e.display.pollingFast&&It(e)&&(e.display.pollingFast=!1);var r=e.doc,i=r.sel.shift,s=!1;try{Ut(e)&&(e.state.suppressEdits=!0),n&&(r.sel.shift=!1),s=t(e)!=ss}finally{r.sel.shift=i,e.state.suppressEdits=!1}return s}function an(e){var t=e.state.keyMaps.slice(0);return e.options.extraKeys&&t.push(e.options.extraKeys),t.push(e.options.keyMap),t}function ln(e,t){var n=vr(e.options.keyMap),i=n.auto;clearTimeout(fn),i&&!gr(t)&&(fn=setTimeout(function(){vr(e.options.keyMap)==n&&(e.options.keyMap=i.call?i.call(null,e):i,M(e))},50));var s=yr(t,!0),o=!1;if(!s)return!1;var u=an(e);return t.shiftKey?o=mr("Shift-"+s,u,function(t){return un(e,t,!0)})||mr(s,u,function(t){if(typeof t=="string"?/^go[A-Z]/.test(t):t.motion)return un(e,t)}):o=mr(s,u,function(t){return un(e,t)}),o&&(Ui(t),nt(e),r&&(t.oldKeyCode=t.keyCode,t.keyCode=0),Zi(e,"keyHandled",e,s,t)),o}function cn(e,t,n){var r=mr("'"+n+"'",an(e),function(t){return un(e,t,!0)});return r&&(Ui(t),nt(e),Zi(e,"keyHandled",e,"'"+n+"'",t)),r}function pn(e){var n=this;n.state.focused||vn(n);if(es(n,e)||n.options.onKeyEvent&&n.options.onKeyEvent(n,Ri(e)))return;t&&e.keyCode==27&&(e.returnValue=!1);var r=e.keyCode;n.doc.sel.shift=r==16||e.shiftKey;var i=ln(n,e);f&&(hn=i?r:null,!i&&r==88&&!Hs&&(g?e.metaKey:e.ctrlKey)&&n.replaceSelection(""))}function dn(e){var t=this;if(es(t,e)||t.options.onKeyEvent&&t.options.onKeyEvent(t,Ri(e)))return;var n=e.keyCode,i=e.charCode;if(f&&n==hn){hn=null,Ui(e);return}if((f&&(!e.which||e.which<10)||c)&&ln(t,e))return;var o=String.fromCharCode(i==null?n:i);if(cn(t,e,o))return;s&&!r&&(t.display.inputHasSelection=null),Ft(t)}function vn(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||(qt(e,!0),o&&setTimeout(ms(qt,e,!0),0))),jt(e),nt(e)}function mn(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 yn(e,n){function c(){if(i.input.selectionStart!=null){var e=i.input.value=""+(Mn(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),jt(e);if(i.input.selectionStart!=null){(!t||r)&&c(),clearTimeout(gn);var n=0,s=function(){i.prevInput==""&&i.input.selectionStart==0?Dt(e,pr.selectAll)(e):n++<10?gn=setTimeout(s,500):qt(e)};gn=setTimeout(s,200)}}if(es(e,n,"contextmenu"))return;var i=e.display,s=e.doc.sel;if(Wt(i,n)||Qt(e,n))return;var o=Xt(e,n),u=i.scroller.scrollTop;if(!o||f)return;var a=e.options.resetSelectionOnContextMenu;a&&(Mn(s.from,s.to)||_n(o,s.from)||!_n(o,s.to))&&Dt(e,Rn)(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: transparent; outline: none;"+"border-width: 0; outline: none; overflow: hidden; opacity: .05; -ms-opacity: .05; filter: alpha(opacity=5);",Rt(e),qt(e,!0),Mn(s.from,s.to)&&(i.input.value=i.prevInput=" "),t&&!r&&c();if(E){Xi(n);var p=function(){Ki(window,"mouseup",p),setTimeout(h,20)};Ji(window,"mouseup",p)}else setTimeout(h,50)}function wn(e,t,n){if(!_n(t.from,n))return Bn(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?On(s,Si(e,s).text.length):jn(n,Si(e,i).text.length)}if(n.line==t.to.line+r)return jn(n,ls(t.text).length+(t.text.length==1?t.from.ch:0)+Si(e,t.to.line).text.length-t.to.ch);var o=n.line-t.from.line;return jn(n,t.text[o].length+(o?0:t.from.ch))}function En(e,t,n){if(n&&typeof n=="object")return{anchor:wn(e,t,n.anchor),head:wn(e,t,n.head)};if(n=="start")return{anchor:t.from,head:t.from};var r=bn(t);if(n=="around")return{anchor:t.from,head:r};if(n=="end")return{anchor:r,head:r};var i=function(e){if(_n(e,t.from))return e;if(!_n(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),On(n,i)};return{anchor:i(e.sel.anchor),head:i(e.sel.head)}}function Sn(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=Bn(e,t)),n&&(this.to=Bn(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 xn(e,t,n,r){if(e.cm){if(!e.cm.curOp)return Dt(e.cm,xn)(e,t,n,r);if(e.cm.state.suppressEdits)return}if(ns(e,"beforeChange")||e.cm&&ns(e.cm,"beforeChange")){t=Sn(e,t,!0);if(!t)return}var i=S&&!r&&Dr(e,t.from,t.to);if(i){for(var s=i.length-1;s>=1;--s)Tn(e,{from:i[s].from,to:i[s].to,text:[""]});i.length&&Tn(e,{from:i[0].from,to:i[0].to,text:t.text},n)}else Tn(e,t,n)}function Tn(e,t,n){if(t.text.length==1&&t.text[0]==""&&Mn(t.from,t.to))return;var r=En(e,t,n);Di(e,t,r,e.cm?e.cm.curOp.id:NaN),kn(e,t,r,Or(e,t));var i=[];wi(e,function(e,n){!n&&hs(i,e.history)==-1&&(Ii(e.history,t),i.push(e.history)),kn(e,t,null,Or(e,t))})}function Nn(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=ns(e,"beforeChange")||e.cm&&ns(e.cm,"beforeChange");for(var o=r.changes.length-1;o>=0;--o){var u=r.changes[o];u.origin=t;if(s&&!Sn(e,u,!1)){(t=="undo"?n.done:n.undone).length=0;return}i.changes.push(_i(e,u));var a=o?En(e,u,null):{anchor:r.anchorBefore,head:r.headBefore};kn(e,u,a,_r(e,u));var f=[];wi(e,function(e,t){!t&&hs(f,e.history)==-1&&(Ii(e.history,u),f.push(e.history)),kn(e,u,null,_r(e,u))})}}function Cn(e,t){function n(e){return On(e.line+t,e.ch)}e.first+=t,e.cm&&Bt(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 kn(e,t,n,r){if(e.cm&&!e.cm.curOp)return Dt(e.cm,kn)(e,t,n,r);if(t.to.line<e.first){Cn(e,t.text.length-1-(t.to.line-t.from.line));return}if(t.from.line>e.lastLine())return;if(t.from.line<e.first){var i=t.text.length-1-(e.first-t.from.line);Cn(e,i),t={from:On(e.first,0),to:On(t.to.line+i,t.to.ch),text:[ls(t.text)],origin:t.origin}}var s=e.lastLine();t.to.line>s&&(t={from:t.from,to:On(s,Si(e,s).text.length),text:[t.text[0]],origin:t.origin}),t.removed=xi(e,t.from,t.to),n||(n=En(e,t,null)),e.cm?Ln(e.cm,t,r,n):pi(e,t,r,n)}function Ln(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=Ci(Rr(i,Si(i,o.line))),i.iter(f,u.line+1,function(e){if(e==s.maxLine)return a=!0,!0})),!_n(i.sel.head,t.from)&&!_n(t.to,i.sel.head)&&(e.curOp.cursorActivity=!0),pi(i,t,n,r,A(e)),e.options.lineWrapping||(i.iter(f,o.line+t.text.length,function(e){var t=H(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),rt(e,400);var l=t.text.length-(u.line-o.line)-1;Bt(e,o.line,u.line+1,l);if(ns(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 An(e,t,n,r,i){r||(r=n);if(_n(r,n)){var s=r;r=n,n=s}typeof t=="string"&&(t=Ds(t)),xn(e,{from:n,to:r,text:t,origin:i},null)}function On(e,t){if(!(this instanceof On))return new On(e,t);this.line=e,this.ch=t}function Mn(e,t){return e.line==t.line&&e.ch==t.ch}function _n(e,t){return e.line<t.line||e.line==t.line&&e.ch<t.ch}function Dn(e,t){return e.line-t.line||e.ch-t.ch}function Pn(e){return On(e.line,e.ch)}function Hn(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function Bn(e,t){if(t.line<e.first)return On(e.first,0);var n=e.first+e.size-1;return t.line>n?On(n,Si(e,n).text.length):jn(t,Si(e,t.line).text.length)}function jn(e,t){var n=e.ch;return n==null||n>t?On(e.line,t):n<0?On(e.line,0):e}function Fn(e,t){return t>=e.first&&t<e.first+e.size}function In(e,t,n,r){if(e.sel.shift||e.sel.extend){var i=e.sel.anchor;if(n){var s=_n(t,i);s!=_n(n,i)?(i=t,t=n):s!=_n(t,n)&&(t=n)}Rn(e,i,t,r)}else Rn(e,t,n||t,r);e.cm&&(e.cm.curOp.userSelChange=!0)}function qn(e,t,n){var r={anchor:t,head:n};return Qi(e,"beforeSelectionChange",e,r),e.cm&&Qi(e.cm,"beforeSelectionChange",e.cm,r),r.anchor=Bn(e,r.anchor),r.head=Bn(e,r.head),r}function Rn(e,t,n,r,i){if(!i&&ns(e,"beforeSelectionChange")||e.cm&&ns(e.cm,"beforeSelectionChange")){var s=qn(e,t,n);n=s.head,t=s.anchor}var o=e.sel;o.goalColumn=null,r==null&&(r=_n(n,o.head)?-1:1);if(i||!Mn(t,o.anchor))t=zn(e,t,r,i!="push");if(i||!Mn(n,o.head))n=zn(e,n,r,i!="push");if(Mn(o.anchor,t)&&Mn(o.head,n))return;o.anchor=t,o.head=n;var u=_n(n,t);o.from=u?n:t,o.to=u?t:n,e.cm&&(e.cm.curOp.updateInput=e.cm.curOp.selectionChanged=e.cm.curOp.cursorActivity=!0),Zi(e,"cursorActivity",e)}function Un(e){Rn(e.doc,e.doc.sel.from,e.doc.sel.to,null,"push")}function zn(e,t,n,r){var i=!1,s=t,o=n||1;e.cantEdit=!1;e:for(;;){var u=Si(e,s.line);if(u.markedSpans)for(var a=0;a<u.markedSpans.length;++a){var f=u.markedSpans[a],l=f.marker;if((f.from==null||(l.inclusiveLeft?f.from<=s.ch:f.from<s.ch))&&(f.to==null||(l.inclusiveRight?f.to>=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(Mn(c,s)){c.ch+=o,c.ch<0?c.line>e.first?c=Bn(e,On(c.line-1)):c=null:c.ch>u.text.length&&(c.line<e.first+e.size-1?c=On(c.line+1,0):c=null);if(!c){if(i)return r?(e.cantEdit=!0,On(e.first,0)):zn(e,t,n,!0);i=!0,c=t,o=-o}}s=c;continue e}}return s}}function Wn(e){var t=Xn(e,e.doc.sel.head,null,e.options.cursorScrollMargin);if(!e.state.focused)return;var n=e.display,r=Cs(n.sizer),i=null;t.top+r.top<0?i=!0:t.bottom+r.top>(window.innerHeight||document.documentElement.clientHeight)&&(i=!1);if(i!=null&&!d){var s=Ss("div","",null,"position: absolute; top: "+(t.top-n.viewOffset)+"px; height: "+(t.bottom-t.top+is)+"px; left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(s),s.scrollIntoView(i),e.display.lineSpace.removeChild(s)}}function Xn(e,t,n,r){r==null&&(r=0);for(;;){var i=!1,s=xt(e,t),o=!n||n==t?s:xt(e,n),u=$n(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&&(tn(e,u.scrollTop),Math.abs(e.doc.scrollTop-a)>1&&(i=!0)),u.scrollLeft!=null&&(nn(e,u.scrollLeft),Math.abs(e.doc.scrollLeft-f)>1&&(i=!0));if(!i)return s}}function Vn(e,t,n,r,i){var s=$n(e,t,n,r,i);s.scrollTop!=null&&tn(e,s.scrollTop),s.scrollLeft!=null&&nn(e,s.scrollLeft)}function $n(e,t,n,r,i){var s=e.display,o=Lt(e.display);n<0&&(n=0);var u=s.scroller.clientHeight-is,a=s.scroller.scrollTop,f={},l=e.doc.height+at(s),c=n<o,h=i>l-o;if(n<a)f.scrollTop=c?0:n;else if(i>a+u){var p=Math.min(n,(h?l:i)-u);p!=a&&(f.scrollTop=p)}var d=s.scroller.clientWidth-is,v=s.scroller.scrollLeft;t+=s.gutters.offsetWidth,r+=s.gutters.offsetWidth;var m=s.gutters.offsetWidth,g=t<m+10;return t<v+m||g?(g&&(t=0),f.scrollLeft=Math.max(0,t-10-m)):r>d+v-3&&(f.scrollLeft=r+10-d),f}function Jn(e,t,n){e.curOp.updateScrollPos={scrollLeft:t==null?e.doc.scrollLeft:t,scrollTop:n==null?e.doc.scrollTop:n}}function Kn(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 Qn(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=ot(e,t);var o=e.options.tabSize,u=Si(i,t),a=us(u.text,null,o),f=u.text.match(/^\s*/)[0],l;if(!r&&!/\S/.test(u.text))l=0,n="not";else if(n=="smart"){l=e.doc.mode.indent(s,u.text.slice(f.length),u.text);if(l==ss){if(!r)return;n="prev"}}n=="prev"?t>i.first?l=us(Si(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<l&&(c+=fs(l-h)),c!=f?An(e.doc,c,On(t,0),On(t,f.length),"+input"):i.sel.head.line==t&&i.sel.head.ch<f.length&&Rn(i,On(t,f.length),On(t,f.length),1),u.stateAfter=null}function Gn(e,t,n){var r=t,i=t,s=e.doc;return typeof t=="number"?i=Si(s,Hn(s,t)):r=Ci(t),r==null?null:n(i,r)?(Bt(e,r,r+1),i):null}function Yn(e,t,n,r,i){function l(){var t=s+n;return t<e.first||t>=e.first+e.size?f=!1:(s=t,a=Si(e,t))}function c(e){var t=(i?Js:Ks)(a,o,n,!0);if(t==null){if(!!e||!l())return f=!1;i?o=(n<0?Rs:qs)(a):o=n<0?a.text.length:0}else o=t;return!0}var s=t.line,o=t.ch,u=n,a=Si(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=ys(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=zn(e,On(s,o),u,!0);return f||(g.hitSide=!0),g}function Zn(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)*Lt(e.display))}else r=="line"&&(o=n>0?t.bottom+3:t.top-3);for(;;){var a=Nt(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 er(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=ys(i)?ys:/\s/.test(i)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!ys(e)};while(n>0&&s(e.charAt(n-1)))--n;while(r<e.length&&s(e.charAt(r)))++r}return{from:On(t.line,n),to:On(t.line,r)}}function tr(e,t){In(e.doc,On(t,0),Bn(e.doc,On(t+1,0)))}function ir(e,t,n,r){T.defaults[e]=t,n&&(nr[e]=r?function(e,t,r){r!=sr&&n(e,t,r)}:n)}function cr(e,t){if(t===!0)return t;if(e.copyState)return e.copyState(t);var n={};for(var r in t){var i=t[r];i instanceof Array&&(i=i.concat([])),n[r]=i}return n}function hr(e,t,n){return e.startState?e.startState(t,n):!0}function vr(e){return typeof e=="string"?dr[e]:e}function mr(e,t,n){function r(t){t=vr(t);var i=t[e];if(i===!1)return"stop";if(i!=null&&n(i))return!0;if(t.nofallthrough)return"stop";var s=t.fallthrough;if(s==null)return!1;if(Object.prototype.toString.call(s)!="[object Array]")return r(s);for(var o=0,u=s.length;o<u;++o){var a=r(s[o]);if(a)return a}return!1}for(var i=0;i<t.length;++i){var s=r(t[i]);if(s)return s!="stop"}}function gr(e){var t=Bs[e.keyCode];return t=="Ctrl"||t=="Alt"||t=="Shift"||t=="Mod"}function yr(e,t){if(f&&e.keyCode==34&&e["char"])return!1;var n=Bs[e.keyCode];if(n==null||e.altGraphKey)return!1;e.altKey&&(n="Alt-"+n);if(w?e.metaKey:e.ctrlKey)n="Ctrl-"+n;if(w?e.ctrlKey:e.metaKey)n="Cmd-"+n;return!t&&e.shiftKey&&(n="Shift-"+n),n}function br(e,t){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0}function wr(e,t){this.lines=[],this.type=t,this.doc=e}function Sr(e,t,n,r,i){if(r&&r.shared)return Tr(e,t,n,r,i);if(e.cm&&!e.cm.curOp)return Dt(e.cm,Sr)(e,t,n,r,i);var s=new wr(e,i);r&&ds(r,s);if(_n(n,t)||Mn(t,n)&&s.clearWhenEmpty!==!1)return s;s.replacedWith&&(s.collapsed=!0,s.replacedWith=Ss("span",[s.replacedWith],"CodeMirror-widget"),r.handleMouseEvents||(s.replacedWith.ignoreEvents=!0));if(s.collapsed){if(qr(e,t.line,t,n,s)||t.line!=n.line&&qr(e,n.line,t,n,s))throw new Error("Inserting collapsed marker partially overlapping an existing one");x=!0}s.addToHistory&&Di(e,{from:t,to:n,origin:"markText"},{head:e.sel.head,anchor:e.sel.anchor},NaN);var o=t.line,u=e.cm,a;return e.iter(o,n.line+1,function(r){u&&s.collapsed&&!u.options.lineWrapping&&Rr(e,r)==u.display.maxLine&&(a=!0);var i={from:null,to:null,marker:s};o==t.line&&(i.from=t.ch),o==n.line&&(i.to=n.ch),s.collapsed&&o!=t.line&&Ni(r,0),kr(r,i),++o}),s.collapsed&&e.iter(t.line,n.line+1,function(t){Ur(e,t)&&Ni(t,0)}),s.clearOnEnter&&Ji(s,"beforeCursorEnter",function(){s.clear()}),s.readOnly&&(S=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),s.collapsed&&(s.id=++Er,s.atomic=!0),u&&(a&&(u.curOp.updateMaxLine=!0),(s.className||s.title||s.startStyle||s.endStyle||s.collapsed)&&Bt(u,t.line,n.line+1),s.atomic&&Un(u)),s}function xr(e,t){this.markers=e,this.primary=t;for(var n=0,r=this;n<e.length;++n)e[n].parent=this,Ji(e[n],"clear",function(){r.clear()})}function Tr(e,t,n,r,i){r=ds(r),r.shared=!1;var s=[Sr(e,t,n,r,i)],o=s[0],u=r.replacedWith;return wi(e,function(e){u&&(r.replacedWith=u.cloneNode(!0)),s.push(Sr(e,Bn(e,t),Bn(e,n),r,i));for(var a=0;a<e.linked.length;++a)if(e.linked[a].isParent)return;o=ls(s)}),new xr(s,o)}function Nr(e,t){if(e)for(var n=0;n<e.length;++n){var r=e[n];if(r.marker==t)return r}}function Cr(e,t){for(var n,r=0;r<e.length;++r)e[r]!=t&&(n||(n=[])).push(e[r]);return n}function kr(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}function Lr(e,t,n){if(e)for(var r=0,i;r<e.length;++r){var s=e[r],o=s.marker,u=s.from==null||(o.inclusiveLeft?s.from<=t:s.from<t);if(u||s.from==t&&o.type=="bookmark"&&(!n||!s.marker.insertLeft)){var a=s.to==null||(o.inclusiveRight?s.to>=t:s.to>t);(i||(i=[])).push({from:s.from,to:a?null:s.to,marker:o})}}return i}function Ar(e,t,n){if(e)for(var r=0,i;r<e.length;++r){var s=e[r],o=s.marker,u=s.to==null||(o.inclusiveRight?s.to>=t:s.to>t);if(u||s.from==t&&o.type=="bookmark"&&(!n||s.marker.insertLeft)){var a=s.from==null||(o.inclusiveLeft?s.from<=t:s.from<t);(i||(i=[])).push({from:a?null:s.from-t,to:s.to==null?null:s.to-t,marker:o})}}return i}function Or(e,t){var n=Fn(e,t.from.line)&&Si(e,t.from.line).markedSpans,r=Fn(e,t.to.line)&&Si(e,t.to.line).markedSpans;if(!n&&!r)return null;var i=t.from.ch,s=t.to.ch,o=Mn(t.from,t.to),u=Lr(n,i,o),a=Ar(r,s,o),f=t.text.length==1,l=ls(t.text).length+(f?i:0);if(u)for(var c=0;c<u.length;++c){var h=u[c];if(h.to==null){var p=Nr(a,h.marker);p?f&&(h.to=p.to==null?null:p.to+l):h.to=i}}if(a)for(var c=0;c<a.length;++c){var h=a[c];h.to!=null&&(h.to+=l);if(h.from==null){var p=Nr(u,h.marker);p||(h.from=l,f&&(u||(u=[])).push(h))}else h.from+=l,f&&(u||(u=[])).push(h)}u&&(u=Mr(u)),a&&a!=u&&(a=Mr(a));var d=[u];if(!f){var v=t.text.length-2,m;if(v>0&&u)for(var c=0;c<u.length;++c)u[c].to==null&&(m||(m=[])).push({from:null,to:null,marker:u[c].marker});for(var c=0;c<v;++c)d.push(m);d.push(a)}return d}function Mr(e){for(var t=0;t<e.length;++t){var n=e[t];n.from!=null&&n.from==n.to&&n.marker.clearWhenEmpty!==!1&&e.splice(t--,1)}return e.length?e:null}function _r(e,t){var n=Hi(e,t),r=Or(e,t);if(!n)return r;if(!r)return n;for(var i=0;i<n.length;++i){var s=n[i],o=r[i];if(s&&o)e:for(var u=0;u<o.length;++u){var a=o[u];for(var f=0;f<s.length;++f)if(s[f].marker==a.marker)continue e;s.push(a)}else o&&(n[i]=o)}return n}function Dr(e,t,n){var r=null;e.iter(t.line,n.line+1,function(e){if(e.markedSpans)for(var t=0;t<e.markedSpans.length;++t){var n=e.markedSpans[t].marker;n.readOnly&&(!r||hs(r,n)==-1)&&(r||(r=[])).push(n)}});if(!r)return null;var i=[{from:t,to:n}];for(var s=0;s<r.length;++s){var o=r[s],u=o.find();for(var a=0;a<i.length;++a){var f=i[a];if(_n(f.to,u.from)||_n(u.to,f.from))continue;var l=[a,1];(_n(f.from,u.from)||!o.inclusiveLeft&&Mn(f.from,u.from))&&l.push({from:f.from,to:u.from}),(_n(u.to,f.to)||!o.inclusiveRight&&Mn(f.to,u.to))&&l.push({from:u.to,to:f.to}),i.splice.apply(i,l),a+=l.length-1}}return i}function Pr(e){return e.inclusiveLeft?-1:0}function Hr(e){return e.inclusiveRight?1:0}function Br(e,t){var n=e.lines.length-t.lines.length;if(n!=0)return n;var r=e.find(),i=t.find(),s=Dn(r.from,i.from)||Pr(e)-Pr(t);if(s)return-s;var o=Dn(r.to,i.to)||Hr(e)-Hr(t);return o?o:t.id-e.id}function jr(e,t){var n=x&&e.markedSpans,r;if(n)for(var i,s=0;s<n.length;++s)i=n[s],i.marker.collapsed&&(t?i.from:i.to)==null&&(!r||Br(r,i.marker)<0)&&(r=i.marker);return r}function Fr(e){return jr(e,!0)}function Ir(e){return jr(e,!1)}function qr(e,t,n,r,i){var s=Si(e,t),o=x&&s.markedSpans;if(o)for(var u=0;u<o.length;++u){var a=o[u];if(!a.marker.collapsed)continue;var f=a.marker.find(!0),l=Dn(f.from,n)||Pr(a.marker)-Pr(i),c=Dn(f.to,r)||Hr(a.marker)-Hr(i);if(l>=0&&c<=0||l<=0&&c>=0)continue;if(l<=0&&(Dn(f.to,n)||Hr(a.marker)-Pr(i))>0||l>=0&&(Dn(f.from,r)||Pr(a.marker)-Hr(i))<0)return!0}}function Rr(e,t){var n;while(n=Fr(t))t=Si(e,n.find().from.line);return t}function Ur(e,t){var n=x&&t.markedSpans;if(n)for(var r,i=0;i<n.length;++i){r=n[i];if(!r.marker.collapsed)continue;if(r.from==null)return!0;if(r.marker.replacedWith)continue;if(r.from==0&&r.marker.inclusiveLeft&&zr(e,t,r))return!0}}function zr(e,t,n){if(n.to==null){var r=n.marker.find().to,i=Si(e,r.line);return zr(e,i,Nr(i.markedSpans,n.marker))}if(n.marker.inclusiveRight&&n.to==t.text.length)return!0;for(var s,o=0;o<t.markedSpans.length;++o){s=t.markedSpans[o];if(s.marker.collapsed&&!s.marker.replacedWith&&s.from==n.to&&(s.to==null||s.to!=n.from)&&(s.marker.inclusiveLeft||n.marker.inclusiveRight)&&zr(e,t,s))return!0}}function Wr(e){var t=e.markedSpans;if(!t)return;for(var n=0;n<t.length;++n)t[n].marker.detachLine(e);e.markedSpans=null}function Xr(e,t){if(!t)return;for(var n=0;n<t.length;++n)t[n].marker.attachLine(e);e.markedSpans=t}function $r(e){return function(){var t=!this.cm.curOp;t&&Mt(this.cm);try{var n=e.apply(this,arguments)}finally{t&&_t(this.cm)}return n}}function Jr(e){return e.height!=null?e.height:((!e.node.parentNode||e.node.parentNode.nodeType!=1)&&Ts(e.cm.display.measure,Ss("div",[e.node],null,"position: relative")),e.height=e.node.offsetHeight)}function Kr(e,t,n,r){var i=new Vr(e,n,r);return i.noHScroll&&(e.display.alignWidgets=!0),Gn(e,t,function(t){var n=t.widgets||(t.widgets=[]);i.insertAt==null?n.push(i):n.splice(Math.min(n.length-1,Math.max(0,i.insertAt)),0,i),i.line=t;if(!Ur(e.doc,t)||i.showIfHidden){var r=Li(e,t)<e.doc.scrollTop;Ni(t,t.height+Jr(i)),r&&Kn(e,0,i.height)}return!0}),i}function Gr(e,t,n,r){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),e.order!=null&&(e.order=null),Wr(e),Xr(e,n);var i=r?r(e):1;i!=e.height&&Ni(e,i)}function Yr(e){e.parent=null,Wr(e)}function Zr(e,t,n,r,i,s){var o=n.flattenSpans;o==null&&(o=e.options.flattenSpans);var u=0,a=null,f=new br(t,e.options.tabSize),l;t==""&&n.blankLine&&n.blankLine(r);while(!f.eol()){f.pos>e.options.maxHighlightLength?(o=!1,s&&ni(e,t,r,f.pos),f.pos=t.length,l=null):l=n.token(f,r);if(e.options.addModeClass){var c=T.innerMode(n,r).mode.name;c&&(l="m-"+(l?c+" "+l:c))}if(!o||a!=l)u<f.start&&i(f.start,a),u=f.start,a=l;f.start=f.pos}while(u<f.pos){var h=Math.min(f.pos,u+5e4);i(h,a),u=h}}function ei(e,t,n,r){var i=[e.state.modeGen];Zr(e,t.text,e.doc.mode,n,function(e,t){i.push(e,t)},r);for(var s=0;s<e.state.overlays.length;++s){var o=e.state.overlays[s],u=1,a=0;Zr(e,t.text,o.mode,!0,function(e,t){var n=u;while(a<e){var r=i[u];r>e&&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<u;n+=2){var s=i[n+1];i[n+1]=s?s+" "+t:t}})}return i}function ti(e,t){if(!t.styles||t.styles[0]!=e.state.modeGen)t.styles=ei(e,t,t.stateAfter=ot(e,Ci(t)));return t.styles}function ni(e,t,n,r){var i=e.doc.mode,s=new br(t,e.options.tabSize);s.start=s.pos=r||0,t==""&&i.blankLine&&i.blankLine(n);while(!s.eol()&&s.pos<=e.options.maxHighlightLength)i.token(s,n),s.start=s.pos}function si(e,t){if(!e)return null;for(;;){var n=e.match(/(?:^|\s)line-(background-)?(\S+)/);if(!n)break;e=e.slice(0,n.index)+e.slice(n.index+n[0].length);var r=n[1]?"bgClass":"textClass";t[r]==null?t[r]=n[2]:(new RegExp("(?:^|s)"+n[2]+"(?:$|s)")).test(t[r])||(t[r]+=" "+n[2])}var i=t.cm.options.addModeClass?ii:ri;return i[e]||(i[e]="cm-"+e.replace(/ +/g," cm-"))}function oi(e,n,r,i){var u,a=n,f=!0;while(u=Fr(a))a=Si(e.doc,u.find().from.line);var l={pre:Ss("pre"),col:0,pos:0,measure:null,measuredSomething:!1,cm:e,copyWidgets:i};do{a.text&&(f=!1),l.measure=a==n&&r,l.pos=0,l.addToken=l.measure?fi:ai,(t||o)&&e.getOption("lineWrapping")&&(l.addToken=li(l.addToken));var c=hi(a,l,ti(e,a));r&&a==n&&!l.measuredSomething&&(r[0]=l.pre.appendChild(_s(e.display.measure)),l.measuredSomething=!0),c&&(a=Si(e.doc,c.to.line))}while(c);r&&!l.measuredSomething&&!r[0]&&(r[0]=l.pre.appendChild(f?Ss("span"," "):_s(e.display.measure))),!l.pre.firstChild&&!Ur(e.doc,n)&&l.pre.appendChild(document.createTextNode(" "));var h;if(r&&s&&(h=Ai(a))){var p=h.length-1;h[p].from==h[p].to&&--p;var d=h[p],v=h[p-1];if(d.from+1==d.to&&v&&d.level<v.level){var m=r[l.pos-1];m&&m.parentNode.insertBefore(m.measureRight=_s(e.display.measure),m.nextSibling)}}var g=l.textClass?l.textClass+" "+(n.textClass||""):n.textClass;return g&&(l.pre.className=g),Qi(e,"renderLine",e,n,l.pre),l}function ui(e){var t=Ss("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t}function ai(e,t,n,r,i,s){if(!t)return;var o=e.cm.options.specialChars;if(!o.test(t)){e.col+=t.length;var u=document.createTextNode(t)}else{var u=document.createDocumentFragment(),a=0;for(;;){o.lastIndex=a;var f=o.exec(t),l=f?f.index-a:t.length-a;l&&(u.appendChild(document.createTextNode(t.slice(a,a+l))),e.col+=l);if(!f)break;a+=l+1;if(f[0]==" "){var c=e.cm.options.tabSize,h=c-e.col%c;u.appendChild(Ss("span",fs(h),"cm-tab")),e.col+=h}else{var p=e.cm.options.specialCharPlaceholder(f[0]);u.appendChild(p),e.col+=1}}}if(n||r||i||e.measure){var d=n||"";r&&(d+=r),i&&(d+=i);var p=Ss("span",[u],d);return s&&(p.title=s),e.pre.appendChild(p)}e.pre.appendChild(u)}function fi(e,n,r,i,s){var o=e.cm.options.lineWrapping;for(var u=0;u<n.length;++u){var a=u==0,f=u+1;while(f<n.length&&Es(n.charAt(f)))++f;var l=n.slice(u,f);u=f-1,u&&o&&Ls(n,u)&&e.pre.appendChild(Ss("wbr"));var c=e.measure[e.pos],h=e.measure[e.pos]=ai(e,l,r,a&&i,u==n.length-1&&s);c&&(h.leftSide=c.leftSide||c),t&&o&&l==" "&&u&&!/\s/.test(n.charAt(u-1))&&u<n.length-1&&!/\s/.test(n.charAt(u+1))&&(h.style.whiteSpace="normal"),e.pos+=l.length}n.length&&(e.measuredSomething=!0)}function li(e){function t(e){var t=" ";for(var n=0;n<e.length-2;++n)t+=n%2?" ":" ";return t+=" ",t}return function(n,r,i,s,o,u){return e(n,r.replace(/ {3,}/g,t),i,s,o,u)}}function ci(e,t,n,r){var i=!r&&n.replacedWith;if(i){e.copyWidgets&&(i=i.cloneNode(!0)),e.pre.appendChild(i);if(e.measure){if(t)e.measure[e.pos]=i;else{var s=_s(e.cm.display.measure);if(n.type=="bookmark"&&!n.insertLeft)e.measure[e.pos]=e.pre.appendChild(s);else{if(e.measure[e.pos])return;e.measure[e.pos]=e.pre.insertBefore(s,i)}}e.measuredSomething=!0}}e.pos+=t}function hi(e,t,n){var r=e.markedSpans,i=e.text,s=0;if(!r){for(var o=1;o<n.length;o+=2)t.addToken(t,i.slice(s,s=n[o]),si(n[o+1],t));return}var u=i.length,a=0,o=1,f="",l,c=0,h,p,d,v,m;for(;;){if(c==a){h=p=d=v="",m=null,c=Infinity;var g=[];for(var y=0;y<r.length;++y){var b=r[y],w=b.marker;b.from<=a&&(b.to==null||b.to>a)?(b.to!=null&&c>b.to&&(c=b.to,p=""),w.className&&(h+=" "+w.className),w.startStyle&&b. 6 from==a&&(d+=" "+w.startStyle),w.endStyle&&b.to==c&&(p+=" "+w.endStyle),w.title&&!v&&(v=w.title),w.collapsed&&(!m||Br(m.marker,w)<0)&&(m=b)):b.from>a&&c>b.from&&(c=b.from),w.type=="bookmark"&&b.from==a&&w.replacedWith&&g.push(w)}if(m&&(m.from||0)==a){ci(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<g.length;++y)ci(t,0,g[y])}if(a>=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=si(n[o++],t)}}}function pi(e,t,n,r,i){function s(e){return n?n[e]:null}function o(e,n,r){Gr(e,n,r,i),Zi(e,"change",e,t)}var u=t.from,a=t.to,f=t.text,l=Si(e,u.line),c=Si(e,a.line),h=ls(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=[];v<m;++v)g.push(new Qr(f[v],s(v),i));o(c,c.text,p),d&&e.remove(u.line,d),g.length&&e.insert(u.line,g)}else if(l==c)if(f.length==1)o(l,l.text.slice(0,u.ch)+h+l.text.slice(a.ch),p);else{for(var g=[],v=1,m=f.length-1;v<m;++v)g.push(new Qr(f[v],s(v),i));g.push(new Qr(h+l.text.slice(a.ch),p,i)),o(l,l.text.slice(0,u.ch)+f[0],s(0)),e.insert(u.line+1,g)}else if(f.length==1)o(l,l.text.slice(0,u.ch)+f[0]+c.text.slice(a.ch),s(0)),e.remove(u.line+1,d);else{o(l,l.text.slice(0,u.ch)+f[0],s(0)),o(c,h+c.text.slice(a.ch),p);for(var v=1,m=f.length-1,g=[];v<m;++v)g.push(new Qr(f[v],s(v),i));d>1&&e.remove(u.line+1,d-1),e.insert(u.line+1,g)}Zi(e,"change",e,t),Rn(e,r.anchor,r.head,null,!0)}function di(e){this.lines=e,this.parent=null;for(var t=0,n=e.length,r=0;t<n;++t)e[t].parent=this,r+=e[t].height;this.height=r}function vi(e){this.children=e;var t=0,n=0;for(var r=0,i=e.length;r<i;++r){var s=e[r];t+=s.chunkSize(),n+=s.height,s.parent=this}this.size=t,this.height=n,this.parent=null}function wi(e,t,n){function r(e,i,s){if(e.linked)for(var o=0;o<e.linked.length;++o){var u=e.linked[o];if(u.doc==i)continue;var a=s&&u.sharedHist;if(n&&!a)continue;t(u.doc,a),r(u.doc,e,a)}}r(e,null,!0)}function Ei(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,O(e),C(e),e.options.lineWrapping||B(e),e.options.mode=t.modeOption,Bt(e)}function Si(e,t){t-=e.first;while(!e.lines)for(var n=0;;++n){var r=e.children[n],i=r.chunkSize();if(t<i){e=r;break}t-=i}return e.lines[t]}function xi(e,t,n){var r=[],i=t.line;return e.iter(t.line,n.line+1,function(e){var s=e.text;i==n.line&&(s=s.slice(0,n.ch)),i==t.line&&(s=s.slice(t.ch)),r.push(s),++i}),r}function Ti(e,t,n){var r=[];return e.iter(t,n,function(e){r.push(e.text)}),r}function Ni(e,t){var n=t-e.height;for(var r=e;r;r=r.parent)r.height+=n}function Ci(e){if(e.parent==null)return null;var t=e.parent,n=hs(t.lines,e);for(var r=t.parent;r;t=r,r=r.parent)for(var i=0;;++i){if(r.children[i]==t)break;n+=r.children[i].chunkSize()}return n+t.first}function ki(e,t){var n=e.first;e:do{for(var r=0,i=e.children.length;r<i;++r){var s=e.children[r],o=s.height;if(t<o){e=s;continue e}t-=o,n+=s.chunkSize()}return n}while(!e.lines);for(var r=0,i=e.lines.length;r<i;++r){var u=e.lines[r],a=u.height;if(t<a)break;t-=a}return n+r}function Li(e,t){t=Rr(e.doc,t);var n=0,r=t.parent;for(var i=0;i<r.lines.length;++i){var s=r.lines[i];if(s==t)break;n+=s.height}for(var o=r.parent;o;r=o,o=r.parent)for(var i=0;i<o.children.length;++i){var u=o.children[i];if(u==r)break;n+=u.height}return n}function Ai(e){var t=e.order;return t==null&&(t=e.order=Qs(e.text)),t}function Oi(e){return{done:[],undone:[],undoDepth:Infinity,lastTime:0,lastOp:null,lastOrigin:null,generation:e||1,maxGeneration:e||1}}function Mi(e,t,n,r){var i=t["spans_"+e.id],s=0;e.iter(Math.max(e.first,n),Math.min(e.first+e.size,r),function(n){n.markedSpans&&((i||(i=t["spans_"+e.id]={}))[s]=n.markedSpans),++s})}function _i(e,t){var n={line:t.from.line,ch:t.from.ch},r={from:n,to:bn(t),text:xi(e,t.from,t.to)};return Mi(e,r,t.from.line,t.to.line+1),wi(e,function(e){Mi(e,r,t.from.line,t.to.line+1)},!0),r}function Di(e,t,n,r){var i=e.history;i.undone.length=0;var s=+(new Date),o=ls(i.done);if(o&&(i.lastOp==r||i.lastOrigin==t.origin&&t.origin&&(t.origin.charAt(0)=="+"&&e.cm&&i.lastTime>s-e.cm.options.historyEventDelay||t.origin.charAt(0)=="*"))){var u=ls(o.changes);Mn(t.from,t.to)&&Mn(t.from,u.to)?u.to=bn(t):o.changes.push(_i(e,t)),o.anchorAfter=n.anchor,o.headAfter=n.head}else{o={changes:[_i(e,t)],generation:i.generation,anchorBefore:e.sel.anchor,headBefore:e.sel.head,anchorAfter:n.anchor,headAfter:n.head},i.done.push(o);while(i.done.length>i.undoDepth)i.done.shift()}i.generation=++i.maxGeneration,i.lastTime=s,i.lastOp=r,i.lastOrigin=t.origin}function Pi(e){if(!e)return null;for(var t=0,n;t<e.length;++t)e[t].marker.explicitlyCleared?n||(n=e.slice(0,t)):n&&n.push(e[t]);return n?n.length?n:null:e}function Hi(e,t){var n=t["spans_"+e.id];if(!n)return null;for(var r=0,i=[];r<t.text.length;++r)i.push(Pi(n[r]));return i}function Bi(e,t){for(var n=0,r=[];n<e.length;++n){var i=e[n],s=i.changes,o=[];r.push({changes:o,anchorBefore:i.anchorBefore,headBefore:i.headBefore,anchorAfter:i.anchorAfter,headAfter:i.headAfter});for(var u=0;u<s.length;++u){var a=s[u],f;o.push({from:a.from,to:a.to,text:a.text});if(t)for(var l in a)(f=l.match(/^spans_(\d+)$/))&&hs(t,Number(f[1]))>-1&&(ls(o)[l]=a[l],delete a[l])}}return r}function ji(e,t,n,r){n<e.line?e.line+=r:t<e.line&&(e.line=t,e.ch=0)}function Fi(e,t,n,r){for(var i=0;i<e.length;++i){var s=e[i],o=!0;for(var u=0;u<s.changes.length;++u){var a=s.changes[u];s.copied||(a.from=Pn(a.from),a.to=Pn(a.to));if(n<a.from.line)a.from.line+=r,a.to.line+=r;else if(t<=a.to.line){o=!1;break}}s.copied||(s.anchorBefore=Pn(s.anchorBefore),s.headBefore=Pn(s.headBefore),s.anchorAfter=Pn(s.anchorAfter),s.readAfter=Pn(s.headAfter),s.copied=!0),o?(ji(s.anchorBefore),ji(s.headBefore),ji(s.anchorAfter),ji(s.headAfter)):(e.splice(0,i+1),i=0)}}function Ii(e,t){var n=t.from.line,r=t.to.line,i=t.text.length-(r-n)-1;Fi(e.done,n,r,i),Fi(e.undone,n,r,i)}function qi(){Xi(this)}function Ri(e){return e.stop||(e.stop=qi),e}function Ui(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function zi(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function Wi(e){return e.defaultPrevented!=null?e.defaultPrevented:e.returnValue==0}function Xi(e){Ui(e),zi(e)}function Vi(e){return e.target||e.srcElement}function $i(e){var t=e.which;return t==null&&(e.button&1?t=1:e.button&2?t=3:e.button&4&&(t=2)),g&&e.ctrlKey&&t==1&&(t=3),t}function Ji(e,t,n){if(e.addEventListener)e.addEventListener(t,n,!1);else if(e.attachEvent)e.attachEvent("on"+t,n);else{var r=e._handlers||(e._handlers={}),i=r[t]||(r[t]=[]);i.push(n)}}function Ki(e,t,n){if(e.removeEventListener)e.removeEventListener(t,n,!1);else if(e.detachEvent)e.detachEvent("on"+t,n);else{var r=e._handlers&&e._handlers[t];if(!r)return;for(var i=0;i<r.length;++i)if(r[i]==n){r.splice(i,1);break}}}function Qi(e,t){var n=e._handlers&&e._handlers[t];if(!n)return;var r=Array.prototype.slice.call(arguments,2);for(var i=0;i<n.length;++i)n[i].apply(null,r)}function Zi(e,t){function i(e){return function(){e.apply(null,r)}}var n=e._handlers&&e._handlers[t];if(!n)return;var r=Array.prototype.slice.call(arguments,2);Gi||(++Yi,Gi=[],setTimeout(ts,0));for(var s=0;s<n.length;++s)Gi.push(i(n[s]))}function es(e,t,n){return Qi(e,n||t.type,e,t),Wi(t)||t.codemirrorIgnore}function ts(){--Yi;var e=Gi;Gi=null;for(var t=0;t<e.length;++t)e[t]()}function ns(e,t){var n=e._handlers&&e._handlers[t];return n&&n.length>0}function rs(e){e.prototype.on=function(e,t){Ji(this,e,t)},e.prototype.off=function(e,t){Ki(this,e,t)}}function os(){this.id=null}function us(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<t;++s)e.charAt(s)==" "?o+=n-o%n:++o;return o}function fs(e){while(as.length<=e)as.push(ls(as)+" ");return as[e]}function ls(e){return e[e.length-1]}function cs(e){if(v)e.selectionStart=0,e.selectionEnd=e.value.length;else try{e.select()}catch(t){}}function hs(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;n<r;++n)if(e[n]==t)return n;return-1}function ps(e,t){function n(){}n.prototype=e;var r=new n;return t&&ds(t,r),r}function ds(e,t){t||(t={});for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function vs(e){for(var t=[],n=0;n<e;++n)t.push(undefined);return t}function ms(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function ys(e){return/\w/.test(e)||e>""&&(e.toUpperCase()!=e.toLowerCase()||gs.test(e))}function bs(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function Es(e){return e.charCodeAt(0)>=768&&ws.test(e)}function Ss(e,t,n,r){var i=document.createElement(e);n&&(i.className=n),r&&(i.style.cssText=r);if(typeof t=="string")Ns(i,t);else if(t)for(var s=0;s<t.length;++s)i.appendChild(t[s]);return i}function xs(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function Ts(e,t){return xs(e).appendChild(t)}function Ns(e,t){r?(e.innerHTML="",e.appendChild(document.createTextNode(t))):e.textContent=t}function Cs(e){return e.getBoundingClientRect()}function Ls(){return!1}function Os(e){if(As!=null)return As;var t=Ss("div",null,null,"width: 50px; height: 50px; overflow-x: scroll");return Ts(e,t),t.offsetWidth&&(As=t.offsetHeight-t.clientHeight),As||0}function _s(e){if(Ms==null){var t=Ss("span","");Ts(e,Ss("span",[t,document.createTextNode("x")])),e.firstChild.offsetHeight!=0&&(Ms=t.offsetWidth<=1&&t.offsetHeight>2&&!n)}return Ms?Ss("span",""):Ss("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px")}function js(e,t,n,r){if(!e)return r(t,n,"ltr");var i=!1;for(var s=0;s<e.length;++s){var o=e[s];if(o.from<n&&o.to>t||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 Fs(e){return e.level%2?e.to:e.from}function Is(e){return e.level%2?e.from:e.to}function qs(e){var t=Ai(e);return t?Fs(t[0]):0}function Rs(e){var t=Ai(e);return t?Is(ls(t)):e.text.length}function Us(e,t){var n=Si(e.doc,t),r=Rr(e.doc,n);r!=n&&(t=Ci(r));var i=Ai(r),s=i?i[0].level%2?Rs(r):qs(r):0;return On(t,s)}function zs(e,t){var n,r;while(n=Ir(r=Si(e.doc,t)))t=n.find().to.line;var i=Ai(r),s=i?i[0].level%2?qs(r):Rs(r):r.text.length;return On(t,s)}function Ws(e,t,n){var r=e[0].level;return t==r?!0:n==r?!1:t<n}function Vs(e,t){Xs=null;for(var n=0,r;n<e.length;++n){var i=e[n];if(i.from<t&&i.to>t)return n;if(i.from==t||i.to==t){if(r!=null)return Ws(e,i.level,e[r].level)?(i.from!=i.to&&(Xs=r),n):(i.from!=i.to&&(Xs=n),r);r=n}}return r}function $s(e,t,n,r){if(!r)return t+n;do t+=n;while(t>0&&Es(e.text.charAt(t)));return t}function Js(e,t,n,r){var i=Ai(e);if(!i)return Ks(e,t,n,r);var s=Vs(i,t),o=i[s],u=$s(e,t,o.level%2?-n:n,r);for(;;){if(u>o.from&&u<o.to)return u;if(u==o.from||u==o.to)return Vs(i,u)==s?u:(o=i[s+=n],n>0==o.level%2?o.to:o.from);o=i[s+=n];if(!o)return null;n>0==o.level%2?u=$s(e,o.to,-1,r):u=$s(e,o.from,1,r)}}function Ks(e,t,n,r){var i=t+n;if(r)while(i>0&&Es(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=t||i,o=/WebKit\//.test(navigator.userAgent),u=o&&/Qt\/\d+\.\d+/.test(navigator.userAgent),a=/Chrome\//.test(navigator.userAgent),f=/Opera\//.test(navigator.userAgent),l=/Apple Computer/.test(navigator.vendor),c=/KHTML\//.test(navigator.userAgent),h=/Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent),p=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),d=/PhantomJS/.test(navigator.userAgent),v=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),m=v||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),g=v||/Mac/.test(navigator.platform),y=/win/i.test(navigator.platform),b=f&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);b&&(b=Number(b[1])),b&&b>=15&&(f=!1,o=!0);var w=g&&(u||f&&(b==null||b<12.11)),E=e||t&&!r,S=!1,x=!1,kt,Ot=0,Vt,$t,Yt=0,rn=0,sn=null;t?sn=-0.53:e?sn=15:a?sn=-0.7:l&&(sn=-1/3);var fn,hn=null,gn,bn=T.changeEnd=function(e){return e.text?On(e.from.line+e.text.length-1,ls(e.text).length+(e.text.length==1?e.from.ch:0)):e.to};T.Pos=On,T.prototype={constructor:T,focus:function(){window.focus(),Rt(this),Ft(this)},setOption:function(e,t){var n=this.options,r=n[e];if(n[e]==t&&e!="mode")return;n[e]=t,nr.hasOwnProperty(e)&&Dt(this,nr[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<t.length;++n)if(t[n]==e||typeof t[n]!="string"&&t[n].name==e)return t.splice(n,1),!0},addOverlay:Dt(null,function(e,t){var n=e.token?e:T.getMode(this.options,e);if(n.startState)throw new Error("Overlays may not be stateful.");this.state.overlays.push({mode:n,modeSpec:e,opaque:t&&t.opaque}),this.state.modeGen++,Bt(this)}),removeOverlay:Dt(null,function(e){var t=this.state.overlays;for(var n=0;n<t.length;++n){var r=t[n].modeSpec;if(r==e||typeof e=="string"&&r.name==e){t.splice(n,1),this.state.modeGen++,Bt(this);return}}}),indentLine:Dt(null,function(e,t,n){typeof t!="string"&&typeof t!="number"&&(t==null?t=this.options.smartIndent?"smart":"prev":t=t?"add":"subtract"),Fn(this.doc,e)&&Qn(this,e,t,n)}),indentSelection:Dt(null,function(e){var t=this.doc.sel;if(Mn(t.from,t.to))return Qn(this,t.from.line,e,!0);var n=t.to.line-(t.to.ch?0:1);for(var r=t.from.line;r<=n;++r)Qn(this,r,e)}),getTokenAt:function(e,t){var n=this.doc;e=Bn(n,e);var r=ot(this,e.line,t),i=this.doc.mode,s=Si(n,e.line),o=new br(s.text,this.options.tabSize);while(o.pos<e.ch&&!o.eol()){o.start=o.pos;var u=i.token(o,r)}return{start:o.start,end:o.pos,string:o.current(),className:u||null,type:u||null,state:r}},getTokenTypeAt:function(e){e=Bn(this.doc,e);var t=ti(this,Si(this.doc,e.line)),n=0,r=(t.length-1)/2,i=e.ch;if(i==0)return t[2];for(;;){var s=n+r>>1;if((s?t[s*2-1]:0)>=i)r=s;else{if(!(t[s*2+1]<i))return t[s*2+2];n=s+1}}},getModeAt:function(e){var t=this.doc.mode;return t.innerMode?T.innerMode(t,this.getTokenAt(e).state).mode:t},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var n=[];if(!lr.hasOwnProperty(t))return lr;var r=lr[t],i=this.getModeAt(e);if(typeof i[t]=="string")r[i[t]]&&n.push(r[i[t]]);else if(i[t])for(var s=0;s<i[t].length;s++){var o=r[i[t][s]];o&&n.push(o)}else i.helperType&&r[i.helperType]?n.push(r[i.helperType]):r[i.name]&&n.push(r[i.name]);for(var s=0;s<r._global.length;s++){var u=r._global[s];u.pred(i,this)&&hs(n,u.val)==-1&&n.push(u.val)}return n},getStateAfter:function(e,t){var n=this.doc;return e=Hn(n,e==null?n.first+n.size-1:e),ot(this,e+1,t)},cursorCoords:function(e,t){var n,r=this.doc.sel;return e==null?n=r.head:typeof e=="object"?n=Bn(this.doc,e):n=e?r.from:r.to,xt(this,n,t||"page")},charCoords:function(e,t){return St(this,Bn(this.doc,e),t||"page")},coordsChar:function(e,t){return e=Et(this,e,t||"page"),Nt(this,e.left,e.top)},lineAtHeight:function(e,t){return e=Et(this,{top:e,left:0},t||"page").top,ki(this.doc,e+this.display.viewOffset)},heightAtLine:function(e,t){var n=!1,r=this.doc.first+this.doc.size-1;e<this.doc.first?e=this.doc.first:e>r&&(e=r,n=!0);var i=Si(this.doc,e);return wt(this,Si(this.doc,e),{top:0,left:0},t||"page").top+(n?i.height:0)},defaultTextHeight:function(){return Lt(this.display)},defaultCharWidth:function(){return At(this.display)},setGutterMarker:Dt(null,function(e,t,n){return Gn(this,e,function(e){var r=e.gutterMarkers||(e.gutterMarkers={});return r[t]=n,!n&&bs(r)&&(e.gutterMarkers=null),!0})}),clearGutter:Dt(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,Bt(t,r,r+1),bs(n.gutterMarkers)&&(n.gutterMarkers=null)),++r})}),addLineClass:Dt(null,function(e,t,n){return Gn(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:Dt(null,function(e,t,n){return Gn(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:Dt(null,function(e,t,n){return Kr(this,e,t,n)}),removeLineWidget:function(e){e.clear()},lineInfo:function(e){if(typeof e=="number"){if(!Fn(this.doc,e))return null;var t=e;e=Si(this.doc,e);if(!e)return null}else{var t=Ci(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=xt(this,Bn(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&&Vn(this,u,o,u+t.offsetWidth,o+t.offsetHeight)},triggerOnKeyDown:Dt(null,pn),execCommand:function(e){if(pr.hasOwnProperty(e))return pr[e](this)},findPosH:function(e,t,n,r){var i=1;t<0&&(i=-1,t=-t);for(var s=0,o=Bn(this.doc,e);s<t;++s){o=Yn(this.doc,o,i,n,r);if(o.hitSide)break}return o},moveH:Dt(null,function(e,t){var n=this.doc.sel,r;n.shift||n.extend||Mn(n.from,n.to)?r=Yn(this.doc,n.head,e,t,this.options.rtlMoveVisually):r=e<0?n.from:n.to,In(this.doc,r,r,e)}),deleteH:Dt(null,function(e,t){var n=this.doc.sel;Mn(n.from,n.to)?An(this.doc,"",n.from,Yn(this.doc,n.head,e,t,!1),"+delete"):An(this.doc,"",n.from,n.to,"+delete"),this.curOp.userSelChange=!0}),findPosV:function(e,t,n,r){var i=1,s=r;t<0&&(i=-1,t=-t);for(var o=0,u=Bn(this.doc,e);o<t;++o){var a=xt(this,u,"div");s==null?s=a.left:a.left=s,u=Zn(this,a,i,n);if(u.hitSide)break}return u},moveV:Dt(null,function(e,t){var n=this.doc.sel,r,i;if(n.shift||n.extend||Mn(n.from,n.to)){var s=xt(this,n.head,"div");n.goalColumn!=null&&(s.left=n.goalColumn),r=Zn(this,s,e,t),t=="page"&&Kn(this,0,St(this,r,"div").top-s.top),i=s.left}else r=e<0?n.from:n.to;In(this.doc,r,r,e),i!=null&&(n.goalColumn=i)}),toggleOverwrite:function(e){if(e!=null&&e==this.state.overwrite)return;(this.state.overwrite=!this.state.overwrite)?this.display.cursor.className+=" CodeMirror-overwrite":this.display.cursor.className=this.display.cursor.className.replace(" CodeMirror-overwrite","")},hasFocus:function(){return this.state.focused},scrollTo:Dt(null,function(e,t){Jn(this,e,t)}),getScrollInfo:function(){var e=this.display.scroller,t=is;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-t,width:e.scrollWidth-t,clientHeight:e.clientHeight-t,clientWidth:e.clientWidth-t}},scrollIntoView:Dt(null,function(e,t){e==null?e={from:this.doc.sel.head,to:null}:typeof e=="number"?e={from:On(e,0),to:null}:e.from==null&&(e={from:e,to:null}),e.to||(e.to=e.from),t||(t=0);var n=e;e.from.line!=null&&(this.curOp.scrollToPos={from:e.from,to:e.to,margin:t},n={from:xt(this,e.from),to:xt(this,e.to)});var r=$n(this,Math.min(n.from.left,n.to.left),Math.min(n.from.top,n.to.top)-t,Math.max(n.from.right,n.to.right),Math.max(n.from.bottom,n.to.bottom)+t);Jn(this,r.scrollLeft,r.scrollTop)}),setSize:Dt(null,function(e,t){function n(e){return typeof e=="number"||/^\d+$/.test(String(e))?e+"px":e}e!=null&&(this.display.wrapper.style.width=n(e)),t!=null&&(this.display.wrapper.style.height=n(t)),this.options.lineWrapping&&(this.display.measureLineCache.length=this.display.measureLineCachePos=0),this.curOp.forceUpdate=!0}),operation:function(e){return Ht(this,e)},refresh:Dt(null,function(){var e=this.display.cachedTextHeight==null;gt(this),Jn(this,this.doc.scrollLeft,this.doc.scrollTop),Bt(this),e&&O(this)}),swapDoc:Dt(null,function(e){var t=this.doc;return t.cm=null,Ei(this,e),gt(this),qt(this,!0),Jn(this,e.scrollLeft,e.scrollTop),Zi(this,"swapDoc",this,t),t}),getInputField:function(){return this.display.input},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},rs(T);var nr=T.optionHandlers={},rr=T.defaults={},sr=T.Init={toString:function(){return"CodeMirror.Init"}};ir("value","",function(e,t){e.setValue(t)},!0),ir("mode",null,function(e,t){e.doc.modeOption=t,C(e)},!0),ir("indentUnit",2,C,!0),ir("indentWithTabs",!1),ir("smartIndent",!0),ir("tabSize",4,function(e){k(e),gt(e),Bt(e)},!0),ir("specialChars",/[\t\u0000-\u0019\u00ad\u200b\u2028\u2029\ufeff]/g,function(e,t){e.options.specialChars=new RegExp(t.source+(t.test(" ")?"":"| "),"g"),e.refresh()},!0),ir("specialCharPlaceholder",ui,function(e){e.refresh()},!0),ir("electricChars",!0),ir("rtlMoveVisually",!y),ir("wholeLineUpdateBefore",!0),ir("theme","default",function(e){_(e),D(e)},!0),ir("keyMap","default",M),ir("extraKeys",null),ir("onKeyEvent",null),ir("onDragEvent",null),ir("lineWrapping",!1,L,!0),ir("gutters",[],function(e){j(e.options),D(e)},!0),ir("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?z(e.display)+"px":"0",e.refresh()},!0),ir("coverGutterNextToScrollbar",!1,F,!0),ir("lineNumbers",!1,function(e){j(e.options),D(e)},!0),ir("firstLineNumber",1,D,!0),ir("lineNumberFormatter",function(e){return e},D,!0),ir("showCursorWhenSelecting",!1,Z,!0),ir("resetSelectionOnContextMenu",!0),ir("readOnly",!1,function(e,t){t=="nocursor"?(mn(e),e.display.input.blur(),e.display.disabled=!0):(e.display.disabled=!1,t||qt(e,!0))}),ir("disableInput",!1,function(e,t){t||qt(e,!0)},!0),ir("dragDrop",!0),ir("cursorBlinkRate",530),ir("cursorScrollMargin",0),ir("cursorHeight",1),ir("workTime",100),ir("workDelay",100),ir("flattenSpans",!0,k,!0),ir("addModeClass",!1,k,!0),ir("pollInterval",100),ir("undoDepth",40,function(e,t){e.doc.history.undoDepth=t}),ir("historyEventDelay",500),ir("viewportMargin",10,function(e){e.refresh()},!0),ir("maxHighlightLength",1e4,k,!0),ir("crudeMeasuringFrom",1e4),ir("moveInputWithCursor",!0,function(e,t){t||(e.display.inputDiv.style.top=e.display.inputDiv.style.left=0)}),ir("tabindex",null,function(e,t){e.display.input.tabIndex=t||""}),ir("autofocus",null);var or=T.modes={},ur=T.mimeModes={};T.defineMode=function(e,t){!T.defaults.mode&&e!="null"&&(T.defaults.mode=e);if(arguments.length>2){t.dependencies=[];for(var n=2;n<arguments.length;++n)t.dependencies.push(arguments[n])}or[e]=t},T.defineMIME=function(e,t){ur[e]=t},T.resolveMode=function(e){if(typeof e=="string"&&ur.hasOwnProperty(e))e=ur[e];else if(e&&typeof e.name=="string"&&ur.hasOwnProperty(e.name)){var t=ur[e.name];e=ps(t,e),e.name=t.name}else if(typeof e=="string"&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return T.resolveMode("application/xml");return typeof e=="string"?{name:e}:e||{name:"null"}},T.getMode=function(e,t){var t=T.resolveMode(t),n=or[t.name];if(!n)return T.getMode(e,"text/plain");var r=n(e,t);if(ar.hasOwnProperty(t.name)){var i=ar[t.name];for(var s in i){if(!i.hasOwnProperty(s))continue;r.hasOwnProperty(s)&&(r["_"+s]=r[s]),r[s]=i[s]}}r.name=t.name,t.helperType&&(r.helperType=t.helperType);if(t.modeProps)for(var s in t.modeProps)r[s]=t.modeProps[s];return r},T.defineMode("null",function(){return{token:function(e){e.skipToEnd()}}}),T.defineMIME("text/plain","null");var ar=T.modeExtensions={};T.extendMode=function(e,t){var n=ar.hasOwnProperty(e)?ar[e]:ar[e]={};ds(t,n)},T.defineExtension=function(e,t){T.prototype[e]=t},T.defineDocExtension=function(e,t){gi.prototype[e]=t},T.defineOption=ir;var fr=[];T.defineInitHook=function(e){fr.push(e)};var lr=T.helpers={};T.registerHelper=function(e,t,n){lr.hasOwnProperty(e)||(lr[e]=T[e]={_global:[]}),lr[e][t]=n},T.registerGlobalHelper=function(e,t,n,r){T.registerHelper(e,t,r),lr[e]._global.push({pred:n,val:r})},T.isWordChar=ys,T.copyState=cr,T.startState=hr,T.innerMode=function(e,t){while(e.innerMode){var n=e.innerMode(t);if(!n||n.mode==e)break;t=n.state,e=n.mode}return n||{mode:e,state:t}};var pr=T.commands={selectAll:function(e){e.setSelection(On(e.firstLine(),0),On(e.lastLine()))},killLine:function(e){var t=e.getCursor(!0),n=e.getCursor(!1),r=!Mn(t,n);!r&&e.getLine(t.line).length==t.ch?e.replaceRange("",t,On(t.line+1,0),"+delete"):e.replaceRange("",t,r?n:On(t.line),"+delete")},deleteLine:function(e){var t=e.getCursor().line;e.replaceRange("",On(t,0),On(t),"+delete")},delLineLeft:function(e){var t=e.getCursor();e.replaceRange("",On(t.line,0),t,"+delete")},undo:function(e){e.undo()},redo:function(e){e.redo()},goDocStart:function(e){e.extendSelection(On(e.firstLine(),0))},goDocEnd:function(e){e.extendSelection(On(e.lastLine()))},goLineStart:function(e){e.extendSelection(Us(e,e.getCursor().line))},goLineStartSmart:function(e){var t=e.getCursor(),n=Us(e,t.line),r=e.getLineHandle(n.line),i=Ai(r);if(!i||i[0].level==0){var s=Math.max(0,r.text.search(/\S/)),o=t.line==n.line&&t.ch<=s&&t.ch;e.extendSelection(On(n.line,o?0:s))}else e.extendSelection(n)},goLineEnd:function(e){e.extendSelection(zs(e,e.getCursor().line))},goLineRight:function(e){var t=e.charCoords(e.getCursor(),"div").top+5;e.extendSelection(e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:t},"div"))},goLineLeft:function(e){var t=e.charCoords(e.getCursor(),"div").top+5;e.extendSelection(e.coordsChar({left:0,top:t},"div"))},goLineUp:function(e){e.moveV(-1,"line")},goLineDown:function(e){e.moveV(1,"line")},goPageUp:function(e){e.moveV(-1,"page")},goPageDown:function(e){e.moveV(1,"page")},goCharLeft:function(e){e.moveH(-1,"char")},goCharRight:function(e){e.moveH(1,"char")},goColumnLeft:function(e){e.moveH(-1,"column")},goColumnRight:function(e){e.moveH(1,"column")},goWordLeft:function(e){e.moveH(-1,"word")},goGroupRight:function(e){e.moveH(1,"group")},goGroupLeft:function(e){e.moveH(-1,"group")},goWordRight:function(e){e.moveH(1,"word")},delCharBefore:function(e){e.deleteH(-1,"char")},delCharAfter:function(e){e.deleteH(1,"char")},delWordBefore:function(e){e.deleteH(-1,"word")},delWordAfter:function(e){e.deleteH(1,"word")},delGroupBefore:function(e){e.deleteH(-1,"group")},delGroupAfter:function(e){e.deleteH(1,"group")},indentAuto:function(e){e.indentSelection("smart")},indentMore:function(e){e.indentSelection("add")},indentLess:function(e){e.indentSelection("subtract")},insertTab:function(e){e.replaceSelection(" ","end","+input")},defaultTab:function(e){e.somethingSelected()?e.indentSelection("add"):e.replaceSelection(" ","end","+input")},transposeChars:function(e){var t=e.getCursor(),n=e.getLine(t.line);t.ch>0&&t.ch<n.length-1&&e.replaceRange(n.charAt(t.ch)+n.charAt(t.ch-1),On(t.line,t.ch-1),On(t.line,t.ch+1))},newlineAndIndent:function(e){Dt(e,function(){e.replaceSelection("\n","end","+input"),e.indentLine(e.getCursor().line,null,!0)})()},toggleOverwrite:function(e){e.toggleOverwrite()}},dr=T.keyMap={};dr.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite"},dr.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":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","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"},dr.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":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineStart","Cmd-Right":"goLineEnd","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","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","Cmd-Backspace":"delLineLeft",fallthrough:["basic","emacsy"]},dr["default"]=g?dr.macDefault:dr.pcDefault,dr.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":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars"},T.lookupKey=mr,T.isModifierKey=gr,T.keyName=yr,T.fromTextArea=function(e,t){function i(){e.value=a.getValue()}t||(t={}),t.value=e.value,!t.tabindex&&e.tabindex&&(t.tabindex=e.tabindex),!t.placeholder&&e.placeholder&&(t.placeholder=e.placeholder);if(t.autofocus==null){var n=document.body;try{n=document.activeElement}catch(r){}t.autofocus=n==e||e.getAttribute("autofocus")!=null&&n==document.body}if(e.form){Ji(e.form,"submit",i);if(!t.leaveSubmitMethodAlone){var s=e.form,o=s.submit;try{var u=s.submit=function(){i(),s.submit=o,s.submit(),s.submit=u}}catch(r){}}}e.style.display="none";var a=T(function(t){e.parentNode.insertBefore(t,e.nextSibling)},t);return a.save=i,a.getTextArea=function(){return e},a.toTextArea=function(){i(),e.parentNode.removeChild(a.getWrapperElement()),e.style.display="",e.form&&(Ki(e.form,"submit",i),typeof e.form.submit=="function"&&(e.form.submit=o))},a},br.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return this.pos==this.lineStart},peek:function(){return this.string.charAt(this.pos)||undefined},next:function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},eat:function(e){var t=this.string.charAt(this.pos);if(typeof e=="string")var n=t==e;else var n=t&&(e.test?e.test(t):e(t));if(n)return++this.pos,t},eatWhile:function(e){var t=this.pos;while(this.eat(e));return this.pos>t},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.lastColumnPos<this.start&&(this.lastColumnValue=us(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?us(this.string,this.lineStart,this.tabSize):0)},indentation:function(){return us(this.string,null,this.tabSize)-(this.lineStart?us(this.string,this.lineStart,this.tabSize):0)},match:function(e,t,n){if(typeof e!="string"){var s=this.string.slice(this.pos).match(e);return s&&s.index>0?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)},hideFirstChars:function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}}},T.StringStream=br,T.TextMarker=wr,rs(wr),wr.prototype.clear=function(){if(this.explicitlyCleared)return;var e=this.doc.cm,t=e&&!e.curOp;t&&Mt(e);if(ns(this,"clear")){var n=this.find();n&&Zi(this,"clear",n.from,n.to)}var r=null,i=null;for(var s=0;s<this.lines.length;++s){var o=this.lines[s],u=Nr(o.markedSpans,this);u.to!=null&&(i=Ci(o)),o.markedSpans=Cr(o.markedSpans,u),u.from!=null?r=Ci(o):this.collapsed&&!Ur(this.doc,o)&&e&&Ni(o,Lt(e.display))}if(e&&this.collapsed&&!e.options.lineWrapping)for(var s=0;s<this.lines.length;++s){var a=Rr(e.doc,this.lines[s]),f=H(e.doc,a);f>e.display.maxLineLength&&(e.display.maxLine=a,e.display.maxLineLength=f,e.display.maxLineChanged=!0)}r!=null&&e&&Bt(e,r,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&Un(e)),t&&_t(e) 7 },wr.prototype.find=function(e){var t,n;for(var r=0;r<this.lines.length;++r){var i=this.lines[r],s=Nr(i.markedSpans,this);if(s.from!=null||s.to!=null){var o=Ci(i);s.from!=null&&(t=On(o,s.from)),s.to!=null&&(n=On(o,s.to))}}return this.type=="bookmark"&&!e?t:t&&{from:t,to:n}},wr.prototype.changed=function(){var e=this.find(),t=this.doc.cm;if(!e||!t)return;this.type!="bookmark"&&(e=e.from);var n=Si(this.doc,e.line);ht(t,n);if(e.line>=t.display.showingFrom&&e.line<t.display.showingTo){for(var r=t.display.lineDiv.firstChild;r;r=r.nextSibling)if(r.lineObj==n){r.offsetHeight!=n.height&&Ni(n,r.offsetHeight);break}Ht(t,function(){t.curOp.selectionChanged=t.curOp.forceUpdate=t.curOp.updateMaxLine=!0})}},wr.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(!t.maybeHiddenMarkers||hs(t.maybeHiddenMarkers,this)==-1)&&(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)},wr.prototype.detachLine=function(e){this.lines.splice(hs(this.lines,e),1);if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}};var Er=0;T.SharedTextMarker=xr,rs(xr),xr.prototype.clear=function(){if(this.explicitlyCleared)return;this.explicitlyCleared=!0;for(var e=0;e<this.markers.length;++e)this.markers[e].clear();Zi(this,"clear")},xr.prototype.find=function(){return this.primary.find()};var Vr=T.LineWidget=function(e,t,n){if(n)for(var r in n)n.hasOwnProperty(r)&&(this[r]=n[r]);this.cm=e,this.node=t};rs(Vr),Vr.prototype.clear=$r(function(){var e=this.line.widgets,t=Ci(this.line);if(t==null||!e)return;for(var n=0;n<e.length;++n)e[n]==this&&e.splice(n--,1);e.length||(this.line.widgets=null);var r=Li(this.cm,this.line)<this.cm.doc.scrollTop;Ni(this.line,Math.max(0,this.line.height-Jr(this))),r&&Kn(this.cm,0,-this.height),Bt(this.cm,t,t+1)}),Vr.prototype.changed=$r(function(){var e=this.height;this.height=null;var t=Jr(this)-e;if(!t)return;Ni(this.line,this.line.height+t);var n=Ci(this.line);Bt(this.cm,n,n+1)});var Qr=T.Line=function(e,t,n){this.text=e,Xr(this,t),this.height=n?n(this):1};rs(Qr),Qr.prototype.lineNo=function(){return Ci(this)};var ri={},ii={};di.prototype={chunkSize:function(){return this.lines.length},removeInner:function(e,t){for(var n=e,r=e+t;n<r;++n){var i=this.lines[n];this.height-=i.height,Yr(i),Zi(i,"delete")}this.lines.splice(e,t)},collapse:function(e){e.splice.apply(e,[e.length,0].concat(this.lines))},insertInner:function(e,t,n){this.height+=n,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var r=0,i=t.length;r<i;++r)t[r].parent=this},iterN:function(e,t,n){for(var r=e+t;e<r;++e)if(n(this.lines[e]))return!0}},vi.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var n=0;n<this.children.length;++n){var r=this.children[n],i=r.chunkSize();if(e<i){var s=Math.min(t,i-e),o=r.height;r.removeInner(e,s),this.height-=o-r.height,i==s&&(this.children.splice(n--,1),r.parent=null);if((t-=s)==0)break;e=0}else e-=i}if(this.size-t<25){var u=[];this.collapse(u),this.children=[new di(u)],this.children[0].parent=this}},collapse:function(e){for(var t=0,n=this.children.length;t<n;++t)this.children[t].collapse(e)},insertInner:function(e,t,n){this.size+=t.length,this.height+=n;for(var r=0,i=this.children.length;r<i;++r){var s=this.children[r],o=s.chunkSize();if(e<=o){s.insertInner(e,t,n);if(s.lines&&s.lines.length>50){while(s.lines.length>50){var u=s.lines.splice(s.lines.length-25,25),a=new di(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 vi(t);if(!e.parent){var r=new vi(e.children);r.parent=e,e.children=[r,n],e=r}else{e.size-=n.size,e.height-=n.height;var i=hs(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<i;++r){var s=this.children[r],o=s.chunkSize();if(e<o){var u=Math.min(t,o-e);if(s.iterN(e,u,n))return!0;if((t-=u)==0)break;e=0}else e-=o}}};var mi=0,gi=T.Doc=function(e,t,n){if(!(this instanceof gi))return new gi(e,t,n);n==null&&(n=0),vi.call(this,[new di([new Qr("",null)])]),this.first=n,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.history=Oi(),this.cleanGeneration=1,this.frontier=n;var r=On(n,0);this.sel={from:r,to:r,head:r,anchor:r,shift:!1,extend:!1,goalColumn:null},this.id=++mi,this.modeOption=t,typeof e=="string"&&(e=Ds(e)),pi(this,{from:r,to:r,text:e},null,{head:r,anchor:r})};gi.prototype=ps(vi.prototype,{constructor:gi,iter:function(e,t,n){n?this.iterN(e-this.first,t-e,n):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){var n=0;for(var r=0,i=t.length;r<i;++r)n+=t[r].height;this.insertInner(e-this.first,t,n)},remove:function(e,t){this.removeInner(e-this.first,t)},getValue:function(e){var t=Ti(this,this.first,this.first+this.size);return e===!1?t:t.join(e||"\n")},setValue:function(e){var t=On(this.first,0),n=this.first+this.size-1;xn(this,{from:t,to:On(n,Si(this,n).text.length),text:Ds(e),origin:"setValue"},{head:t,anchor:t},!0)},replaceRange:function(e,t,n,r){t=Bn(this,t),n=n?Bn(this,n):t,An(this,e,t,n,r)},getRange:function(e,t,n){var r=xi(this,Bn(this,e),Bn(this,t));return n===!1?r:r.join(n||"\n")},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},setLine:function(e,t){Fn(this,e)&&An(this,t,On(e,0),Bn(this,On(e)))},removeLine:function(e){e?An(this,"",Bn(this,On(e-1)),Bn(this,On(e))):An(this,"",On(0,0),Bn(this,On(1,0)))},getLineHandle:function(e){if(Fn(this,e))return Si(this,e)},getLineNumber:function(e){return Ci(e)},getLineHandleVisualStart:function(e){return typeof e=="number"&&(e=Si(this,e)),Rr(this,e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return Bn(this,e)},getCursor:function(e){var t=this.sel,n;return e==null||e=="head"?n=t.head:e=="anchor"?n=t.anchor:e=="end"||e===!1?n=t.to:n=t.from,Pn(n)},somethingSelected:function(){return!Mn(this.sel.head,this.sel.anchor)},setCursor:Pt(function(e,t,n){var r=Bn(this,typeof e=="number"?On(e,t||0):e);n?In(this,r):Rn(this,r,r)}),setSelection:Pt(function(e,t,n){Rn(this,Bn(this,e),Bn(this,t||e),n)}),extendSelection:Pt(function(e,t,n){In(this,Bn(this,e),t&&Bn(this,t),n)}),getSelection:function(e){return this.getRange(this.sel.from,this.sel.to,e)},replaceSelection:function(e,t,n){xn(this,{from:this.sel.from,to:this.sel.to,text:Ds(e),origin:n},t||"around")},undo:Pt(function(){Nn(this,"undo")}),redo:Pt(function(){Nn(this,"redo")}),setExtending:function(e){this.sel.extend=e},historySize:function(){var e=this.history;return{undo:e.done.length,redo:e.undone.length}},clearHistory:function(){this.history=Oi(this.history.maxGeneration)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(e){return e&&(this.history.lastOp=this.history.lastOrigin=null),this.history.generation},isClean:function(e){return this.history.generation==(e||this.cleanGeneration)},getHistory:function(){return{done:Bi(this.history.done),undone:Bi(this.history.undone)}},setHistory:function(e){var t=this.history=Oi(this.history.maxGeneration);t.done=e.done.slice(0),t.undone=e.undone.slice(0)},markText:function(e,t,n){return Sr(this,Bn(this,e),Bn(this,t),n,"range")},setBookmark:function(e,t){var n={replacedWith:t&&(t.nodeType==null?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1};return e=Bn(this,e),Sr(this,e,e,n,"bookmark")},findMarksAt:function(e){e=Bn(this,e);var t=[],n=Si(this,e.line).markedSpans;if(n)for(var r=0;r<n.length;++r){var i=n[r];(i.from==null||i.from<=e.ch)&&(i.to==null||i.to>=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;r<n.length;++r)n[r].from!=null&&e.push(n[r].marker)}),e},posFromIndex:function(e){var t,n=this.first;return this.iter(function(r){var i=r.text.length+1;if(i>e)return t=e,!0;e-=i,++n}),Bn(this,On(n,t))},indexFromPos:function(e){e=Bn(this,e);var t=e.ch;return e.line<this.first||e.ch<0?0:(this.iter(this.first,e.line,function(e){t+=e.text.length+1}),t)},copy:function(e){var t=new gi(Ti(this,this.first,this.first+this.size),this.modeOption,this.first);return t.scrollTop=this.scrollTop,t.scrollLeft=this.scrollLeft,t.sel={from:this.sel.from,to:this.sel.to,head:this.sel.head,anchor:this.sel.anchor,shift:this.sel.shift,extend:!1,goalColumn:this.sel.goalColumn},e&&(t.history.undoDepth=this.history.undoDepth,t.setHistory(this.getHistory())),t},linkedDoc:function(e){e||(e={});var t=this.first,n=this.first+this.size;e.from!=null&&e.from>t&&(t=e.from),e.to!=null&&e.to<n&&(n=e.to);var r=new gi(Ti(this,t,n),e.mode||this.modeOption,t);return e.sharedHist&&(r.history=this.history),(this.linked||(this.linked=[])).push({doc:r,sharedHist:e.sharedHist}),r.linked=[{doc:this,isParent:!0,sharedHist:e.sharedHist}],r},unlinkDoc:function(e){e instanceof T&&(e=e.doc);if(this.linked)for(var t=0;t<this.linked.length;++t){var n=this.linked[t];if(n.doc!=e)continue;this.linked.splice(t,1),e.unlinkDoc(this);break}if(e.history==this.history){var r=[e.id];wi(e,function(e){r.push(e.id)},!0),e.history=Oi(),e.history.done=Bi(this.history.done,r),e.history.undone=Bi(this.history.undone,r)}},iterLinkedDocs:function(e){wi(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm}}),gi.prototype.eachLine=gi.prototype.iter;var yi="iter insert remove copy getEditor".split(" ");for(var bi in gi.prototype)gi.prototype.hasOwnProperty(bi)&&hs(yi,bi)<0&&(T.prototype[bi]=function(e){return function(){return e.apply(this.doc,arguments)}}(gi.prototype[bi]));rs(gi),T.e_stop=Xi,T.e_preventDefault=Ui,T.e_stopPropagation=zi;var Gi,Yi=0;T.on=Ji,T.off=Ki,T.signal=Qi;var is=30,ss=T.Pass={toString:function(){return"CodeMirror.Pass"}};os.prototype={set:function(e,t){clearTimeout(this.id),this.id=setTimeout(t,e)}},T.countColumn=us;var as=[""],gs=/[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,ws=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;T.replaceGetRect=function(e){Cs=e};var ks=function(){if(r)return!1;var e=Ss("div");return"draggable"in e||"dragDrop"in e}();e?Ls=function(e,t){return e.charCodeAt(t-1)==36&&e.charCodeAt(t)==39}:l&&!/Version\/([6-9]|\d\d)\b/.test(navigator.userAgent)?Ls=function(e,t){return/\-[^ \-?]|\?[^ !\'\"\),.\-\/:;\?\]\}]/.test(e.slice(t-1,t+1))}:o&&/Chrome\/(?:29|[3-9]\d|\d\d\d)\./.test(navigator.userAgent)?Ls=function(e,t){var n=e.charCodeAt(t-1);return n>=8208&&n<=8212}:o&&(Ls=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~`@#$%\^&*(_=+{[|><]|\u2026[\w~`@#$%\^&*(_=+{[><]/.test(e.slice(t-1,t+1))});var As,Ms,Ds="\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/)};T.splitLines=Ds;var Ps=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},Hs=function(){var e=Ss("div");return"oncopy"in e?!0:(e.setAttribute("oncopy","return;"),typeof e.oncopy=="function")}(),Bs={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:";",61:"=",91:"Mod",92:"Mod",93:"Mod",107:"=",109:"-",127:"Delete",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"};T.keyNames=Bs,function(){for(var e=0;e<10;e++)Bs[e+48]=Bs[e+96]=String(e);for(var e=65;e<=90;e++)Bs[e]=String.fromCharCode(e);for(var e=1;e<=12;e++)Bs[e+111]=Bs[e+63235]="F"+e}();var Xs,Qs=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<t;++l)f.push(c=n(e.charCodeAt(l)));for(var l=0,h=a;l<t;++l){var c=f[l];c=="m"?f[l]=h:h=c}for(var l=0,p=a;l<t;++l){var c=f[l];c=="1"&&p=="r"?f[l]="n":s.test(c)&&(p=c,c=="r"&&(f[l]="R"))}for(var l=1,h=f[0];l<t-1;++l){var c=f[l];c=="+"&&h=="1"&&f[l+1]=="1"?f[l]="1":c==","&&h==f[l+1]&&(h=="1"||h=="n")&&(f[l]=h),h=c}for(var l=0;l<t;++l){var c=f[l];if(c==",")f[l]="N";else if(c=="%"){for(var d=l+1;d<t&&f[d]=="%";++d);var v=l&&f[l-1]=="!"||d<t&&f[d]=="1"?"1":"N";for(var m=l;m<d;++m)f[m]=v;l=d-1}}for(var l=0,p=a;l<t;++l){var c=f[l];p=="L"&&c=="1"?f[l]="L":s.test(c)&&(p=c)}for(var l=0;l<t;++l)if(i.test(f[l])){for(var d=l+1;d<t&&i.test(f[d]);++d);var g=(l?f[l-1]:a)=="L",y=(d<t?f[d]:a)=="L",v=g||y?"L":"R";for(var m=l;m<d;++m)f[m]=v;l=d-1}var b=[],w;for(var l=0;l<t;)if(o.test(f[l])){var E=l;for(++l;l<t&&o.test(f[l]);++l);b.push({from:E,to:l,level:0})}else{var S=l,x=b.length;for(++l;l<t&&f[l]!="L";++l);for(var m=S;m<l;)if(u.test(f[m])){S<m&&b.splice(x,0,{from:S,to:m,level:1});var T=m;for(++m;m<l&&u.test(f[m]);++m);b.splice(x,0,{from:T,to:m,level:2}),S=m}else++m;S<l&&b.splice(x,0,{from:S,to:l,level:1})}return b[0].level==1&&(w=e.match(/^\s+/))&&(b[0].from=w[0].length,b.unshift({from:0,to:w[0].length,level:0})),ls(b).level==1&&(w=e.match(/\s+$/))&&(ls(b).to-=w[0].length,b.push({from:t-w[0].length,to:t,level:0})),b[0].level!=ls(b).level&&b.push({from:t,to:t,level:b[0].level}),b}}();return T.version="3.21.0",T}();