blob: b89670a447af90f94cb89e41fbc1007888ce4278 [file] [log] [blame]
// This is CodeMirror (http://codemirror.net), a code editor
// implemented in JavaScript on top of the browser's DOM.
//
// You can find some technical background for some of the code below
// at http://marijnhaverbeke.nl/blog/#cm-internals .
(function(e){if(typeof exports=="object"&&typeof module=="object")module.exports=e();else{if(typeof define=="function"&&define.amd)return define([],e);this.CodeMirror=e()}})(function(){"use strict";function N(e,n){if(!(this instanceof N))return new N(e,n);this.options=n=n||{};for(var r in Qr)n.hasOwnProperty(r)||(n[r]=Qr[r]);F(n);var i=n.value;typeof i=="string"&&(i=new ms(i,n.mode)),this.doc=i;var s=this.display=new C(e,i);s.wrapper.CodeMirror=this,H(this),D(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),n.autofocus&&!g&&Un(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,draggingText:!1,highlight:new co},t&&setTimeout(xo(Rn,this,!0),20),Xn(this);var o=this;Nn(this,function(){o.curOp.forceUpdate=!0,ws(o,i),n.autofocus&&!g||Po()==s.input?setTimeout(xo(br,o),20):wr(o);for(var e in Gr)Gr.hasOwnProperty(e)&&Gr[e](o,n[e],Zr);for(var t=0;t<ri.length;++t)ri[t](o)})}function C(e,t){var r=this,i=r.input=Ao("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none");u?i.style.width="1000px":i.setAttribute("wrap","off"),m&&(i.style.border="1px solid black"),i.setAttribute("autocorrect","off"),i.setAttribute("autocapitalize","off"),i.setAttribute("spellcheck","false"),r.inputDiv=Ao("div",[i],null,"overflow: hidden; position: relative; width: 3px; height: 0px;"),r.scrollbarH=Ao("div",[Ao("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar"),r.scrollbarV=Ao("div",[Ao("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),r.scrollbarFiller=Ao("div",null,"CodeMirror-scrollbar-filler"),r.gutterFiller=Ao("div",null,"CodeMirror-gutter-filler"),r.lineDiv=Ao("div",null,"CodeMirror-code"),r.selectionDiv=Ao("div",null,null,"position: relative; z-index: 1"),r.cursorDiv=Ao("div",null,"CodeMirror-cursors"),r.measure=Ao("div",null,"CodeMirror-measure"),r.lineMeasure=Ao("div",null,"CodeMirror-measure"),r.lineSpace=Ao("div",[r.measure,r.lineMeasure,r.selectionDiv,r.cursorDiv,r.lineDiv],null,"position: relative; outline: none"),r.mover=Ao("div",[Ao("div",[r.lineSpace],"CodeMirror-lines")],null,"position: relative"),r.sizer=Ao("div",[r.mover],"CodeMirror-sizer"),r.heightForcer=Ao("div",null,null,"position: absolute; height: "+oo+"px; width: 1px;"),r.gutters=Ao("div",null,"CodeMirror-gutters"),r.lineGutter=null,r.scroller=Ao("div",[r.sizer,r.heightForcer,r.gutters],"CodeMirror-scroll"),r.scroller.setAttribute("tabIndex","-1"),r.wrapper=Ao("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),m&&(i.style.width="0px"),u||(r.scroller.draggable=!0),h&&(r.inputDiv.style.height="1px",r.inputDiv.style.position="absolute"),n&&(r.scrollbarH.style.minHeight=r.scrollbarV.style.minWidth="18px"),e.appendChild?e.appendChild(r.wrapper):e(r.wrapper),r.viewFrom=r.viewTo=t.first,r.view=[],r.externalMeasured=null,r.viewOffset=0,r.lastSizeC=0,r.updateLineNumbers=null,r.lineNumWidth=r.lineNumInnerWidth=r.lineNumChars=null,r.prevInput="",r.alignWidgets=!1,r.pollingFast=!1,r.poll=new co,r.cachedCharWidth=r.cachedTextHeight=r.cachedPaddingH=null,r.inaccurateSelection=!1,r.maxLine=null,r.maxLineLength=0,r.maxLineChanged=!1,r.wheelDX=r.wheelDY=r.wheelStartX=r.wheelStartY=null,r.shift=!1}function k(e){e.doc.mode=N.getMode(e.options,e.doc.modeOption),L(e)}function L(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,zt(e,100),e.state.modeGen++,e.curOp&&Mn(e)}function A(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",""),j(e)),M(e),Mn(e),an(e),setTimeout(function(){q(e)},100)}function O(e){var t=wn(e.display),n=e.options.lineWrapping,r=n&&Math.max(5,e.display.scroller.clientWidth/En(e.display)-3);return function(i){if(Ui(e.doc,i))return 0;var s=0;if(i.widgets)for(var o=0;o<i.widgets.length;o++)i.widgets[o].height&&(s+=i.widgets[o].height);return n?s+(Math.ceil(i.text.length/r)||1)*t:s+t}}function M(e){var t=e.doc,n=O(e);t.iter(function(e){var t=n(e);t!=e.height&&Ts(e,t)})}function _(e){var t=ai[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 D(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),an(e)}function P(e){H(e),Mn(e),setTimeout(function(){U(e)},20)}function H(e){var t=e.display.gutters,n=e.options.gutters;Mo(t);for(var r=0;r<n.length;++r){var i=n[r],s=t.appendChild(Ao("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";var o=t.offsetWidth;e.display.sizer.style.marginLeft=o+"px",r&&(e.display.scrollbarH.style.left=e.options.fixedGutter?o+"px":0)}function B(e){if(e.height==0)return 0;var t=e.text.length,n,r=e;while(n=Hi(r)){var i=n.find(0,!0);r=i.from.line,t+=i.from.ch-i.to.ch}r=e;while(n=Bi(r)){var i=n.find(0,!0);t-=r.text.length-i.from.ch,r=i.to.line,t+=r.text.length-i.to.ch}return t}function j(e){var t=e.display,n=e.doc;t.maxLine=Es(n,n.first),t.maxLineLength=B(t.maxLine),t.maxLineChanged=!0,n.iter(function(e){var n=B(e);n>t.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)})}function F(e){var t=bo(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 I(e){var t=e.display.scroller;return{clientHeight:t.clientHeight,barHeight:e.display.scrollbarV.clientHeight,scrollWidth:t.scrollWidth,clientWidth:t.clientWidth,barWidth:e.display.scrollbarH.clientWidth,docHeight:Math.round(e.doc.height+Jt(e.display))}}function q(e,t){t||(t=I(e));var n=e.display,r=t.docHeight+oo,i=t.scrollWidth>t.clientWidth,s=r>t.clientHeight;s?(n.scrollbarV.style.display="block",n.scrollbarV.style.bottom=i?jo(n.measure)+"px":"0",n.scrollbarV.firstChild.style.height=Math.max(0,r-t.clientHeight+(t.barHeight||n.scrollbarV.clientHeight))+"px"):(n.scrollbarV.style.display="",n.scrollbarV.firstChild.style.height="0"),i?(n.scrollbarH.style.display="block",n.scrollbarH.style.right=s?jo(n.measure)+"px":"0",n.scrollbarH.firstChild.style.width=t.scrollWidth-t.clientWidth+(t.barWidth||n.scrollbarH.clientWidth)+"px"):(n.scrollbarH.style.display="",n.scrollbarH.firstChild.style.width="0"),i&&s?(n.scrollbarFiller.style.display="block",n.scrollbarFiller.style.height=n.scrollbarFiller.style.width=jo(n.measure)+"px"):n.scrollbarFiller.style.display="",i&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(n.gutterFiller.style.display="block",n.gutterFiller.style.height=jo(n.measure)+"px",n.gutterFiller.style.width=n.gutters.offsetWidth+"px"):n.gutterFiller.style.display="";if(p&&jo(n.measure)===0){n.scrollbarV.style.minWidth=n.scrollbarH.style.minHeight=d?"18px":"12px";var o=function(t){Js(t)!=n.scrollbarV&&Js(t)!=n.scrollbarH&&Cn(e,Jn)(t)};Qs(n.scrollbarV,"mousedown",o),Qs(n.scrollbarH,"mousedown",o)}}function R(e,t,n){var r=n&&n.top!=null?n.top:e.scroller.scrollTop;r=Math.floor(r-$t(e));var i=n&&n.bottom!=null?n.bottom:r+e.wrapper.clientHeight,s=Cs(t,r),o=Cs(t,i);if(n&&n.ensure){var u=n.ensure.from.line,a=n.ensure.to.line;if(u<s)return{from:u,to:Cs(t,ks(Es(t,u))+e.wrapper.clientHeight)};if(Math.min(a,t.lastLine())>=o)return{from:Cs(t,ks(Es(t,a))-e.wrapper.clientHeight),to:a}}return{from:s,to:o}}function U(e){var t=e.display,n=t.view;if(!t.alignWidgets&&(!t.gutters.firstChild||!e.options.fixedGutter))return;var r=X(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,s=r+"px";for(var o=0;o<n.length;o++)if(!n[o].hidden){e.options.fixedGutter&&n[o].gutter&&(n[o].gutter.style.left=s);var u=n[o].alignable;if(u)for(var a=0;a<u.length;a++)u[a].style.left=s}e.options.fixedGutter&&(t.gutters.style.left=r+i+"px")}function z(e){if(!e.options.lineNumbers)return!1;var t=e.doc,n=W(e.options,t.first+t.size-1),r=e.display;if(n.length!=r.lineNumChars){var i=r.measure.appendChild(Ao("div",[Ao("div",n)],"CodeMirror-linenumber CodeMirror-gutter-elt")),s=i.firstChild.offsetWidth,o=i.offsetWidth-s;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";var u=r.gutters.offsetWidth;return r.scrollbarH.style.left=e.options.fixedGutter?u+"px":0,r.sizer.style.marginLeft=u+"px",!0}return!1}function W(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function X(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function V(e,t,n){var r=e.display.viewFrom,i=e.display.viewTo,s,o=R(e.display,e.doc,t);for(var u=!0;;u=!1){var a=e.display.scroller.clientWidth;if(!$(e,o,n))break;s=!0,e.display.maxLineChanged&&!e.options.lineWrapping&&J(e);var f=I(e);It(e),K(e,f),q(e,f);if(u&&e.options.lineWrapping&&a!=e.display.scroller.clientWidth){n=!0;continue}n=!1,t&&t.top!=null&&(t={top:Math.min(f.docHeight-oo-f.clientHeight,t.top)}),o=R(e.display,e.doc,t);if(o.from>=e.display.viewFrom&&o.to<=e.display.viewTo)break}return e.display.updateLineNumbers=null,s&&(to(e,"update",e),(e.display.viewFrom!=r||e.display.viewTo!=i)&&to(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo)),s}function $(e,t,n){var r=e.display,i=e.doc;if(!r.wrapper.offsetWidth){Dn(e);return}if(!n&&t.from>=r.viewFrom&&t.to<=r.viewTo&&jn(e)==0)return;z(e)&&Dn(e);var s=Y(e),o=i.first+i.size,u=Math.max(t.from-e.options.viewportMargin,i.first),a=Math.min(o,t.to+e.options.viewportMargin);r.viewFrom<u&&u-r.viewFrom<20&&(u=Math.max(i.first,r.viewFrom)),r.viewTo>a&&r.viewTo-a<20&&(a=Math.min(o,r.viewTo)),T&&(u=qi(e.doc,u),a=Ri(e.doc,a));var f=u!=r.viewFrom||a!=r.viewTo||r.lastSizeC!=r.wrapper.clientHeight;Bn(e,u,a),r.viewOffset=ks(Es(e.doc,r.viewFrom)),e.display.mover.style.top=r.viewOffset+"px";var l=jn(e);if(!f&&l==0&&!n)return;var c=Po();return l>4&&(r.lineDiv.style.display="none"),Z(e,r.updateLineNumbers,s),l>4&&(r.lineDiv.style.display=""),c&&Po()!=c&&c.offsetHeight&&c.focus(),Mo(r.cursorDiv),Mo(r.selectionDiv),f&&(r.lastSizeC=r.wrapper.clientHeight,zt(e,400)),Q(e),!0}function J(e){var t=e.display,n=Zt(e,t.maxLine,t.maxLine.text.length).left;t.maxLineChanged=!1;var r=Math.max(0,n+3),i=Math.max(0,t.sizer.offsetLeft+r+oo-t.scroller.clientWidth);t.sizer.style.minWidth=r+"px",i<e.doc.scrollLeft&&or(e,Math.min(t.scroller.scrollLeft,i),!0)}function K(e,t){e.display.sizer.style.minHeight=e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=Math.max(t.docHeight,t.clientHeight-oo)+"px"}function Q(e){var t=e.display,r=t.lineDiv.offsetTop;for(var i=0;i<t.view.length;i++){var s=t.view[i],o;if(s.hidden)continue;if(n){var u=s.node.offsetTop+s.node.offsetHeight;o=u-r,r=u}else{var a=s.node.getBoundingClientRect();o=a.bottom-a.top}var f=s.line.height-o;o<2&&(o=wn(t));if(f>.001||f<-0.001){Ts(s.line,o),G(s.line);if(s.rest)for(var l=0;l<s.rest.length;l++)G(s.rest[l])}}}function G(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t)e.widgets[t].height=e.widgets[t].node.offsetHeight}function Y(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:X(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:r,wrapperWidth:t.wrapper.clientWidth}}function Z(e,t,n){function a(t){var n=t.nextSibling;return u&&y&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}var r=e.display,i=e.options.lineNumbers,s=r.lineDiv,o=s.firstChild,f=r.view,l=r.viewFrom;for(var c=0;c<f.length;c++){var h=f[c];if(!h.hidden)if(!h.node){var p=at(e,h,l,n);s.insertBefore(p,o)}else{while(o!=h.node)o=a(o);var d=i&&t!=null&&t<=l&&h.lineNumber;h.changes&&(bo(h.changes,"gutter")>-1&&(d=!1),et(e,h,l,n)),d&&(Mo(h.lineNumber),h.lineNumber.appendChild(document.createTextNode(W(e.options,l)))),o=h.node.nextSibling}l+=h.size}while(o)o=a(o)}function et(e,t,n,r){for(var i=0;i<t.changes.length;i++){var s=t.changes[i];s=="text"?it(e,t):s=="gutter"?ot(e,t,n,r):s=="class"?st(t):s=="widget"&&ut(t,r)}t.changes=null}function tt(e){return e.node==e.text&&(e.node=Ao("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),n&&(e.node.style.zIndex=2)),e.node}function nt(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;t&&(t+=" CodeMirror-linebackground");if(e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var n=tt(e);e.background=n.insertBefore(Ao("div",null,t),n.firstChild)}}function rt(e,t){var n=e.display.externalMeasured;return n&&n.line==t.line?(e.display.externalMeasured=null,t.measure=n.measure,n.built):is(e,t)}function it(e,t){var n=t.text.className,r=rt(e,t);t.text==t.node&&(t.node=r.pre),t.text.parentNode.replaceChild(r.pre,t.text),t.text=r.pre,r.bgClass!=t.bgClass||r.textClass!=t.textClass?(t.bgClass=r.bgClass,t.textClass=r.textClass,st(t)):n&&(t.text.className=n)}function st(e){nt(e),e.line.wrapClass?tt(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function ot(e,t,n,r){t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null);var i=t.line.gutterMarkers;if(e.options.lineNumbers||i){var s=tt(t),o=t.gutter=s.insertBefore(Ao("div",null,"CodeMirror-gutter-wrapper","position: absolute; left: "+(e.options.fixedGutter?r.fixedPos:-r.gutterTotalWidth)+"px"),t.text);e.options.lineNumbers&&(!i||!i["CodeMirror-linenumbers"])&&(t.lineNumber=o.appendChild(Ao("div",W(e.options,n),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+r.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px")));if(i)for(var u=0;u<e.options.gutters.length;++u){var a=e.options.gutters[u],f=i.hasOwnProperty(a)&&i[a];f&&o.appendChild(Ao("div",[f],"CodeMirror-gutter-elt","left: "+r.gutterLeft[a]+"px; width: "+r.gutterWidth[a]+"px"))}}}function ut(e,t){e.alignable&&(e.alignable=null);for(var n=e.node.firstChild,r;n;n=r){var r=n.nextSibling;n.className=="CodeMirror-linewidget"&&e.node.removeChild(n)}ft(e,t)}function at(e,t,n,r){var i=rt(e,t);return t.text=t.node=i.pre,i.bgClass&&(t.bgClass=i.bgClass),i.textClass&&(t.textClass=i.textClass),st(t),ot(e,t,n,r),ft(t,r),t.node}function ft(e,t){lt(e.line,e,t,!0);if(e.rest)for(var n=0;n<e.rest.length;n++)lt(e.rest[n],e,t,!1)}function lt(e,t,n,r){if(!e.widgets)return;var i=tt(t);for(var s=0,o=e.widgets;s<o.length;++s){var u=o[s],a=Ao("div",[u.node],"CodeMirror-linewidget");u.handleMouseEvents||(a.ignoreEvents=!0),ct(u,a,t,n),r&&u.above?i.insertBefore(a,t.gutter||t.text):i.appendChild(a),to(u,"redraw")}}function ct(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 dt(e){return ht(e.line,e.ch)}function vt(e,t){return pt(e,t)<0?t:e}function mt(e,t){return pt(e,t)<0?e:t}function gt(e,t){this.ranges=e,this.primIndex=t}function yt(e,t){this.anchor=e,this.head=t}function bt(e,t){var n=e[t];e.sort(function(e,t){return pt(e.from(),t.from())}),t=bo(e,n);for(var r=1;r<e.length;r++){var i=e[r],s=e[r-1];if(pt(s.to(),i.from())>=0){var o=mt(s.from(),i.from()),u=vt(s.to(),i.to()),a=s.empty()?i.from()==i.head:s.from()==s.head;r<=t&&--t,e.splice(--r,2,new yt(a?u:o,a?o:u))}}return new gt(e,t)}function wt(e,t){return new gt([new yt(e,t||e)],0)}function Et(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function St(e,t){if(t.line<e.first)return ht(e.first,0);var n=e.first+e.size-1;return t.line>n?ht(n,Es(e,n).text.length):xt(t,Es(e,t.line).text.length)}function xt(e,t){var n=e.ch;return n==null||n>t?ht(e.line,t):n<0?ht(e.line,0):e}function Tt(e,t){return t>=e.first&&t<e.first+e.size}function Nt(e,t){for(var n=[],r=0;r<t.length;r++)n[r]=St(e,t[r]);return n}function Ct(e,t,n,r){if(e.cm&&e.cm.display.shift||e.extend){var i=t.anchor;if(r){var s=pt(n,i)<0;s!=pt(r,i)<0?(i=n,n=r):s!=pt(n,r)<0&&(n=r)}return new yt(i,n)}return new yt(r||n,n)}function kt(e,t,n,r){Dt(e,new gt([Ct(e,e.sel.primary(),t,n)],0),r)}function Lt(e,t,n){for(var r=[],i=0;i<e.sel.ranges.length;i++)r[i]=Ct(e,e.sel.ranges[i],t[i],null);var s=bt(r,e.sel.primIndex);Dt(e,s,n)}function At(e,t,n,r){var i=e.sel.ranges.slice(0);i[t]=n,Dt(e,bt(i,e.sel.primIndex),r)}function Ot(e,t,n,r){Dt(e,wt(t,n),r)}function Mt(e,t){var n={ranges:t.ranges,update:function(t){this.ranges=[];for(var n=0;n<t.length;n++)this.ranges[n]=new yt(St(e,t[n].anchor),St(e,t[n].head))}};return Ys(e,"beforeSelectionChange",e,n),e.cm&&Ys(e.cm,"beforeSelectionChange",e.cm,n),n.ranges!=t.ranges?bt(n.ranges,n.ranges.length-1):t}function _t(e,t,n){var r=e.history.done,i=go(r);i&&i.ranges?(r[r.length-1]=t,Pt(e,t,n)):Dt(e,t,n)}function Dt(e,t,n){Pt(e,t,n),Hs(e,e.sel,e.cm?e.cm.curOp.id:NaN,n)}function Pt(e,t,n){if(io(e,"beforeSelectionChange")||e.cm&&io(e.cm,"beforeSelectionChange"))t=Mt(e,t);var r=pt(t.primary().head,e.sel.primary().head)<0?-1:1;Ht(e,jt(e,t,r,!0)),(!n||n.scroll!==!1)&&e.cm&&Ur(e.cm)}function Ht(e,t){if(t.equals(e.sel))return;e.sel=t,e.cm&&(e.cm.curOp.updateInput=e.cm.curOp.selectionChanged=e.cm.curOp.cursorActivity=!0),to(e,"cursorActivity",e)}function Bt(e){Ht(e,jt(e,e.sel,null,!1),ao)}function jt(e,t,n,r){var i;for(var s=0;s<t.ranges.length;s++){var o=t.ranges[s],u=Ft(e,o.anchor,n,r),a=Ft(e,o.head,n,r);if(i||u!=o.anchor||a!=o.head)i||(i=t.ranges.slice(0,s)),i[s]=new yt(u,a)}return i?bt(i,t.primIndex):t}function Ft(e,t,n,r){var i=!1,s=t,o=n||1;e.cantEdit=!1;e:for(;;){var u=Es(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){Ys(l,"beforeCursorEnter");if(l.explicitlyCleared){if(!u.markedSpans)break;--a;continue}}if(!l.atomic)continue;var c=l.find(o<0?-1:1);if(pt(c,s)==0){c.ch+=o,c.ch<0?c.line>e.first?c=St(e,ht(c.line-1)):c=null:c.ch>u.text.length&&(c.line<e.first+e.size-1?c=ht(c.line+1,0):c=null);if(!c){if(i)return r?(e.cantEdit=!0,ht(e.first,0)):Ft(e,t,n,!0);i=!0,c=t,o=-o}}s=c;continue e}}return s}}function It(e){var t=e.display,n=e.doc,r=document.createDocumentFragment(),i=document.createDocumentFragment();for(var s=0;s<n.sel.ranges.length;s++){var o=n.sel.ranges[s],u=o.empty();(u||e.options.showCursorWhenSelecting)&&qt(e,o,r),u||Rt(e,o,i)}if(e.options.moveInputWithCursor){var a=dn(e,n.sel.primary().head,"div"),f=t.wrapper.getBoundingClientRect(),l=t.lineDiv.getBoundingClientRect(),c=Math.max(0,Math.min(t.wrapper.clientHeight-10,a.top+l.top-f.top)),h=Math.max(0,Math.min(t.wrapper.clientWidth-10,a.left+l.left-f.left));t.inputDiv.style.top=c+"px",t.inputDiv.style.left=h+"px"}_o(t.cursorDiv,r),_o(t.selectionDiv,i)}function qt(e,t,n){var r=dn(e,t.head,"div"),i=n.appendChild(Ao("div"," ","CodeMirror-cursor"));i.style.left=r.left+"px",i.style.top=r.top+"px",i.style.height=Math.max(0,r.bottom-r.top)*e.options.cursorHeight+"px";if(r.other){var s=n.appendChild(Ao("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));s.style.display="",s.style.left=r.other.left+"px",s.style.top=r.other.top+"px",s.style.height=(r.other.bottom-r.other.top)*.85+"px"}}function Rt(e,t,n){function f(e,t,n,r){t<0&&(t=0),s.appendChild(Ao("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(n==null?a-e:n)+"px; height: "+(r-t)+"px"))}function l(t,n,r){function h(n,r){return pn(e,ht(t,n),"div",s,r)}var s=Es(i,t),o=s.text.length,l,c;return Vo(Ls(s),n||0,r==null?o:r,function(e,t,i){var s=h(e,"left"),p,d,v;if(e==t)p=s,d=v=s.left;else{p=h(t-1,"right");if(i=="rtl"){var m=s;s=p,p=m}d=s.left,v=p.right}n==null&&e==0&&(d=u),p.top-s.top>3&&(f(d,s.top,null,s.bottom),d=u,s.bottom<p.top&&f(d,s.bottom,null,p.top)),r==null&&t==o&&(v=a);if(!l||s.top<l.top||s.top==l.top&&s.left<l.left)l=s;if(!c||p.bottom>c.bottom||p.bottom==c.bottom&&p.right>c.right)c=p;d<u+1&&(d=u),f(d,p.top,v-d,p.bottom)}),{start:l,end:c}}var r=e.display,i=e.doc,s=document.createDocumentFragment(),o=Kt(e.display),u=o.left,a=r.lineSpace.offsetWidth-o.right,c=t.from(),h=t.to();if(c.line==h.line)l(c.line,c.ch,h.ch);else{var p=Es(i,c.line),d=Es(i,h.line),v=Fi(p)==Fi(d),m=l(c.line,c.ch,v?p.text.length+1:null).end,g=l(h.line,v?0:null,h.ch).start;v&&(m.top<g.top-2?(f(m.right,m.top,null,m.bottom),f(u,g.top,g.left,g.bottom)):f(m.right,m.top,g.left-m.right,m.bottom)),m.bottom<g.top&&f(u,m.bottom,null,g.top)}n.appendChild(s)}function Ut(e){if(!e.state.focused)return;var t=e.display;clearInterval(t.blinker);var n=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0&&(t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(n=!n)?"":"hidden"},e.options.cursorBlinkRate))}function zt(e,t){e.doc.mode.startState&&e.doc.frontier<e.display.viewTo&&e.state.highlight.set(t,xo(Wt,e))}function Wt(e){var t=e.doc;t.frontier<t.first&&(t.frontier=t.first);if(t.frontier>=e.display.viewTo)return;var n=+(new Date)+e.options.workTime,r=si(t.mode,Vt(e,t.frontier));Nn(e,function(){t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(i){if(t.frontier>=e.display.viewFrom){var s=i.styles;i.styles=Yi(e,i,r,!0);var o=!s||s.length!=i.styles.length;for(var u=0;!o&&u<s.length;++u)o=s[u]!=i.styles[u];o&&_n(e,t.frontier,"text"),i.stateAfter=si(t.mode,r)}else es(e,i.text,r),i.stateAfter=t.frontier%5==0?si(t.mode,r):null;++t.frontier;if(+(new Date)>n)return zt(e,e.options.workDelay),!0})})}function Xt(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=Es(s,u-1);if(a.stateAfter&&(!n||u<=s.frontier))return u;var f=ho(a.text,null,e.options.tabSize);if(i==null||r>f)i=u-1,r=f}return i}function Vt(e,t,n){var r=e.doc,i=e.display;if(!r.mode.startState)return!0;var s=Xt(e,t,n),o=s>r.first&&Es(r,s-1).stateAfter;return o?o=si(r.mode,o):o=oi(r.mode),r.iter(s,t,function(n){es(e,n.text,o);var u=s==t-1||s%5==0||s>=i.viewFrom&&s<i.viewTo;n.stateAfter=u?si(r.mode,o):null,++s}),n&&(r.frontier=s),o}function $t(e){return e.lineSpace.offsetTop}function Jt(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function Kt(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=_o(e.measure,Ao("pre","x")),n=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle;return e.cachedPaddingH={left:parseInt(n.paddingLeft),right:parseInt(n.paddingRight)}}function Qt(e,t,n){var r=e.options.lineWrapping,i=r&&e.display.scroller.clientWidth;if(!t.measure.heights||r&&t.measure.width!=i){var s=t.measure.heights=[];if(r){t.measure.width=i;var o=t.text.firstChild.getClientRects();for(var u=0;u<o.length-1;u++){var a=o[u],f=o[u+1];Math.abs(a.bottom-f.bottom)>2&&s.push((a.bottom+f.top)/2-n.top)}}s.push(n.bottom-n.top)}}function Gt(e,t,n){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var r=0;r<e.rest.length;r++)if(e.rest[r]==t)return{map:e.measure.maps[r],cache:e.measure.caches[r]};for(var r=0;r<e.rest.length;r++)if(Ns(e.rest[r])>n)return{map:e.measure.maps[r],cache:e.measure.caches[r],before:!0}}function Yt(e,t){t=Fi(t);var n=Ns(t),r=e.display.externalMeasured=new An(e.doc,t,n);r.lineN=n;var i=r.built=is(e,r);return r.text=i.pre,_o(e.display.lineMeasure,i.pre),r}function Zt(e,t,n,r){return nn(e,tn(e,t),n,r)}function en(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[Pn(e,t)];var n=e.display.externalMeasured;if(n&&t>=n.lineN&&t<n.lineN+n.size)return n}function tn(e,t){var n=Ns(t),r=en(e,n);r&&!r.text?r=null:r&&r.changes&&et(e,r,n,Y(e)),r||(r=Yt(e,t));var i=Gt(r,t,n);return{line:t,view:r,rect:null,map:i.map,cache:i.cache,before:i.before,hasHeights:!1}}function nn(e,t,n,r){t.before&&(n=-1);var i=n+(r||""),s;return t.cache.hasOwnProperty(i)?s=t.cache[i]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(Qt(e,t.view,t.rect),t.hasHeights=!0),s=sn(e,t,n,r),s.bogus||(t.cache[i]=s)),{left:s.left,right:s.right,top:s.top,bottom:s.bottom}}function sn(e,t,n,i){var s=t.map,u,a,f,l;for(var c=0;c<s.length;c+=3){var h=s[c],p=s[c+1];if(n<h)a=0,f=1,l="left";else if(n<p)a=n-h,f=a+1;else if(c==s.length-3||n==p&&s[c+3]>n)f=p-h,a=f-1,n>=p&&(l="right");if(a!=null){u=s[c+2],h==p&&i==(u.insertLeft?"left":"right")&&(l=i);if(i=="left"&&a==0)while(c&&s[c-2]==s[c-3]&&s[c-1].insertLeft)u=s[(c-=3)+2],l="left";if(i=="right"&&a==p-h)while(c<s.length-3&&s[c+3]==s[c+4]&&!s[c+5].insertLeft)u=s[(c+=3)+2],l="right";break}}var d;if(u.nodeType==3){while(a&&Lo(t.line.text.charAt(h+a)))--a;while(h+f<p&&Lo(t.line.text.charAt(h+f)))++f;if(r&&a==0&&f==p-h)d=u.parentNode.getBoundingClientRect();else if(o&&e.options.lineWrapping){var v=Oo(u,a,f).getClientRects();v.length?d=v[i=="right"?v.length-1:0]:d=rn}else d=Oo(u,a,f).getBoundingClientRect()}else{a>0&&(l=i="right");var v;e.options.lineWrapping&&(v=u.getClientRects()).length>1?d=v[i=="right"?v.length-1:0]:d=u.getBoundingClientRect()}if(r&&!a&&(!d||!d.left&&!d.right)){var m=u.parentNode.getClientRects()[0];m?d={left:m.left,right:m.left+En(e.display),top:m.top,bottom:m.bottom}:d=rn}var g,y=(d.bottom+d.top)/2-t.rect.top,b=t.view.measure.heights;for(var c=0;c<b.length-1;c++)if(y<b[c])break;g=c?b[c-1]:0,y=b[c];var w={left:(l=="right"?d.right:d.left)-t.rect.left,right:(l=="left"?d.left:d.right)-t.rect.left,top:g,bottom:y};return!d.left&&!d.right&&(w.bogus=!0),w}function on(e){if(e.measure){e.measure.cache={},e.measure.heights=null;if(e.rest)for(var t=0;t<e.rest.length;t++)e.measure.caches[t]={}}}function un(e){e.display.externalMeasure=null,Mo(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++)on(e.display.view[t])}function an(e){un(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function fn(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function ln(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function cn(e,t,n,r){if(t.widgets)for(var i=0;i<t.widgets.length;++i)if(t.widgets[i].above){var s=Vi(t.widgets[i]);n.top+=s,n.bottom+=s}if(r=="line")return n;r||(r="local");var o=ks(t);r=="local"?o+=$t(e.display):o-=e.display.viewOffset;if(r=="page"||r=="window"){var u=e.display.lineSpace.getBoundingClientRect();o+=u.top+(r=="window"?0:ln());var a=u.left+(r=="window"?0:fn());n.left+=a,n.right+=a}return n.top+=o,n.bottom+=o,n}function hn(e,t,n){if(n=="div")return t;var r=t.left,i=t.top;if(n=="page")r-=fn(),i-=ln();else if(n=="local"||!n){var s=e.display.sizer.getBoundingClientRect();r+=s.left,i+=s.top}var o=e.display.lineSpace.getBoundingClientRect();return{left:r-o.left,top:i-o.top}}function pn(e,t,n,r,i){return r||(r=Es(e.doc,t.line)),cn(e,r,Zt(e,r,t.ch,i),n)}function dn(e,t,n,r,i){function s(t,s){var o=nn(e,i,t,s?"right":"left");return s?o.left=o.right:o.right=o.left,cn(e,r,o,n)}function o(e,t){var n=u[t],r=n.level%2;return e==$o(n)&&t&&n.level<u[t-1].level?(n=u[--t],e=Jo(n)-(n.level%2?0:1),r=!0):e==Jo(n)&&t<u.length-1&&n.level<u[t+1].level&&(n=u[++t],e=$o(n)-n.level%2,r=!1),r&&e==n.to&&e>n.from?s(e-1):s(e,r)}r=r||Es(e.doc,t.line),i||(i=tn(e,r));var u=Ls(r),a=t.ch;if(!u)return s(a);var f=tu(u,a),l=o(a,f);return eu!=null&&(l.other=o(a,eu)),l}function vn(e,t){var n=0,t=St(e.doc,t);e.options.lineWrapping||(n=En(e.display)*t.ch);var r=Es(e.doc,t.line),i=ks(r)+$t(e.display);return{left:n,right:n,top:i,bottom:i+r.height}}function mn(e,t,n,r){var i=ht(e,t);return i.xRel=r,n&&(i.outside=!0),i}function gn(e,t,n){var r=e.doc;n+=e.display.viewOffset;if(n<0)return mn(r.first,0,!0,-1);var i=Cs(r,n),s=r.first+r.size-1;if(i>s)return mn(r.first+r.size-1,Es(r,s).text.length,!0,1);t<0&&(t=0);var o=Es(r,i);for(;;){var u=yn(e,o,i,t,n),a=Bi(o),f=a&&a.find(0,!0);if(!a||!(u.ch>f.from.ch||u.ch==f.from.ch&&u.xRel>0))return u;i=Ns(o=f.to.line)}}function yn(e,t,n,r,i){function f(r){var i=dn(e,ht(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-ks(t),o=!1,u=2*e.display.wrapper.clientWidth,a=tn(e,t),l=Ls(t),c=t.text.length,h=Ko(t),p=Qo(t),d=f(h),v=o,m=f(p),g=o;if(r>m)return mn(n,p,g,1);for(;;){if(l?p==h||p==ru(t,h,1):p-h<=1){var y=r<d||r-d<=m-r?h:p,b=r-(y==h?d:m);while(Lo(t.text.charAt(y)))++y;var w=mn(n,y,y==h?v:g,b<-1?-1:b>1?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=ru(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 wn(e){if(e.cachedTextHeight!=null)return e.cachedTextHeight;if(bn==null){bn=Ao("pre");for(var t=0;t<49;++t)bn.appendChild(document.createTextNode("x")),bn.appendChild(Ao("br"));bn.appendChild(document.createTextNode("x"))}_o(e.measure,bn);var n=bn.offsetHeight/50;return n>3&&(e.cachedTextHeight=n),Mo(e.measure),n||1}function En(e){if(e.cachedCharWidth!=null)return e.cachedCharWidth;var t=Ao("span","xxxxxxxxxx"),n=Ao("pre",[t]);_o(e.measure,n);var r=t.getBoundingClientRect(),i=(r.right-r.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function xn(e){e.curOp={viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivity:!1,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,id:++Sn},eo++||(Zs=[])}function Tn(e){var t=e.curOp,n=e.doc,r=e.display;e.curOp=null,t.updateMaxLine&&j(e);if(t.viewChanged||t.forceUpdate||t.scrollTop!=null||t.scrollToPos&&(t.scrollToPos.from.line<r.viewFrom||t.scrollToPos.to.line>=r.viewTo)||r.maxLineChanged&&e.options.lineWrapping){var i=V(e,{top:t.scrollTop,ensure:t.scrollToPos},t.forceUpdate);e.display.scroller.offsetHeight&&(e.doc.scrollTop=e.display.scroller.scrollTop)}!i&&t.selectionChanged&&It(e),!i&&t.startHeight!=e.doc.height&&q(e);if(t.scrollTop!=null&&r.scroller.scrollTop!=t.scrollTop){var s=Math.max(0,Math.min(r.scroller.scrollHeight-r.scroller.clientHeight,t.scrollTop));r.scroller.scrollTop=r.scrollbarV.scrollTop=n.scrollTop=s}if(t.scrollLeft!=null&&r.scroller.scrollLeft!=t.scrollLeft){var o=Math.max(0,Math.min(r.scroller.scrollWidth-r.scroller.clientWidth,t.scrollLeft));r.scroller.scrollLeft=r.scrollbarH.scrollLeft=n.scrollLeft=o,U(e)}if(t.scrollToPos){var u=Fr(e,St(e.doc,t.scrollToPos.from),St(e.doc,t.scrollToPos.to),t.scrollToPos.margin);t.scrollToPos.isCursor&&e.state.focused&&jr(e,u)}t.selectionChanged&&Ut(e),e.state.focused&&t.updateInput&&Rn(e,t.typing);var a=t.maybeHiddenMarkers,f=t.maybeUnhiddenMarkers;if(a)for(var l=0;l<a.length;++l)a[l].lines.length||Ys(a[l],"hide");if(f)for(var l=0;l<f.length;++l)f[l].lines.length&&Ys(f[l],"unhide");var c;--eo||(c=Zs,Zs=null);if(t.changeObjs){for(var l=0;l<t.changeObjs.length;l++)Ys(e,"change",e,t.changeObjs[l]);Ys(e,"changes",e,t.changeObjs)}t.cursorActivity&&Ys(e,"cursorActivity",e);if(c)for(var l=0;l<c.length;++l)c[l]()}function Nn(e,t){if(e.curOp)return t();xn(e);try{return t()}finally{Tn(e)}}function Cn(e,t){return function(){if(e.curOp)return t.apply(e,arguments);xn(e);try{return t.apply(e,arguments)}finally{Tn(e)}}}function kn(e){return function(){if(this.curOp)return e.apply(this,arguments);xn(this);try{return e.apply(this,arguments)}finally{Tn(this)}}}function Ln(e){return function(){var t=this.cm;if(!t||t.curOp)return e.apply(this,arguments);xn(t);try{return e.apply(this,arguments)}finally{Tn(t)}}}function An(e,t,n){this.line=t,this.rest=Ii(t),this.size=this.rest?Ns(go(this.rest))-n+1:1,this.node=this.text=null,this.hidden=Ui(e,t)}function On(e,t,n){var r=[],i;for(var s=t;s<n;s=i){var o=new An(e.doc,Es(e.doc,s),s);i=s+o.size,r.push(o)}return r}function Mn(e,t,n,r){t==null&&(t=e.doc.first),n==null&&(n=e.doc.first+e.doc.size),r||(r=0);var i=e.display;r&&n<i.viewTo&&(i.updateLineNumbers==null||i.updateLineNumbers>t)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0;if(t>=i.viewTo)T&&qi(e.doc,t)<i.viewTo&&Dn(e);else if(n<=i.viewFrom)T&&Ri(e.doc,n+r)>i.viewFrom?Dn(e):(i.viewFrom+=r,i.viewTo+=r);else if(t<=i.viewFrom&&n>=i.viewTo)Dn(e);else if(t<=i.viewFrom){var s=Hn(e,n,n+r,1);s?(i.view=i.view.slice(s.index),i.viewFrom=s.lineN,i.viewTo+=r):Dn
(e)}else if(n>=i.viewTo){var s=Hn(e,t,t,-1);s?(i.view=i.view.slice(0,s.index),i.viewTo=s.lineN):Dn(e)}else{var o=Hn(e,t,t,-1),u=Hn(e,n,n+r,1);o&&u?(i.view=i.view.slice(0,o.index).concat(On(e,o.lineN,u.lineN)).concat(i.view.slice(u.index)),i.viewTo+=r):Dn(e)}var a=i.externalMeasured;a&&(n<a.lineN?a.lineN+=r:t<a.lineN+a.size&&(i.externalMeasured=null))}function _n(e,t,n){e.curOp.viewChanged=!0;var r=e.display,i=e.display.externalMeasured;i&&t>=i.lineN&&t<i.lineN+i.size&&(r.externalMeasured=null);if(t<r.viewFrom||t>=r.viewTo)return;var s=r.view[Pn(e,t)];if(s.node==null)return;var o=s.changes||(s.changes=[]);bo(o,n)==-1&&o.push(n)}function Dn(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function Pn(e,t){if(t>=e.display.viewTo)return null;t-=e.display.viewFrom;if(t<0)return null;var n=e.display.view;for(var r=0;r<n.length;r++){t-=n[r].size;if(t<0)return r}}function Hn(e,t,n,r){var i=Pn(e,t),s,o=e.display.view;if(!T)return{index:i,lineN:n};for(var u=0,a=e.display.viewFrom;u<i;u++)a+=o[u].size;if(a!=t){if(r>0){if(i==o.length-1)return null;s=a+o[i].size-t,i++}else s=a-t;t+=s,n+=s}while(qi(e.doc,n)!=n){if(i==(r<0?0:o.length-1))return null;n+=r*o[i-(r<0?1:0)].size,i+=r}return{index:i,lineN:n}}function Bn(e,t,n){var r=e.display,i=r.view;i.length==0||t>=r.viewTo||n<=r.viewFrom?(r.view=On(e,t,n),r.viewFrom=t):(r.viewFrom>t?r.view=On(e,t,r.viewFrom).concat(r.view):r.viewFrom<t&&(r.view=r.view.slice(Pn(e,t))),r.viewFrom=t,r.viewTo<n?r.view=r.view.concat(On(e,r.viewTo,n)):r.viewTo>n&&(r.view=r.view.slice(0,Pn(e,n)))),r.viewTo=n}function jn(e){var t=e.display.view,n=0;for(var r=0;r<t.length;r++){var i=t[r];!i.hidden&&(!i.node||i.changes)&&++n}return n}function Fn(e){if(e.display.pollingFast)return;e.display.poll.set(e.options.pollInterval,function(){qn(e),e.state.focused&&Fn(e)})}function In(e){function n(){var r=qn(e);!r&&!t?(t=!0,e.display.poll.set(60,n)):(e.display.pollingFast=!1,Fn(e))}var t=!1;e.display.pollingFast=!0,e.display.poll.set(20,n)}function qn(e){var t=e.display.input,n=e.display.prevInput,i=e.doc;if(!e.state.focused||zo(t)||Wn(e)||e.options.disableInput)return!1;var s=t.value;if(s==n&&!e.somethingSelected())return!1;if(o&&!r&&e.display.inputHasSelection===s)return Rn(e),!1;var u=!e.curOp;u&&xn(e),e.display.shift=!1;var a=0,f=Math.min(n.length,s.length);while(a<f&&n.charCodeAt(a)==s.charCodeAt(a))++a;var l=s.slice(a),c=Uo(l),h=e.state.pasteIncoming&&c.length>1&&i.sel.ranges.length==c.length;for(var p=i.sel.ranges.length-1;p>=0;p--){var d=i.sel.ranges[p],v=d.from(),m=d.to();a<n.length?v=ht(v.line,v.ch-(n.length-a)):e.state.overwrite&&d.empty()&&!e.state.pasteIncoming&&(m=ht(m.line,Math.min(Es(i,m.line).text.length,m.ch+go(c).length)));var g=e.curOp.updateInput,y={from:v,to:m,text:h?[c[p]]:c,origin:e.state.pasteIncoming?"paste":e.state.cutIncoming?"cut":"+input"};Or(e.doc,y),to(e,"inputRead",e,y);if(l&&!e.state.pasteIncoming&&e.options.electricChars&&e.options.smartIndent&&d.head.ch<100&&(!p||i.sel.ranges[p-1].head.line!=d.head.line)){var b=e.getModeAt(d.head).electricChars;if(b)for(var w=0;w<b.length;w++)if(l.indexOf(b.charAt(w))>-1){Wr(e,d.head.line,"smart");break}}}return Ur(e),e.curOp.updateInput=g,e.curOp.typing=!0,s.length>1e3||s.indexOf("\n")>-1?t.value=e.display.prevInput="":e.display.prevInput=s,u&&Tn(e),e.state.pasteIncoming=e.state.cutIncoming=!1,!0}function Rn(e,t){var n,i,s=e.doc;if(e.somethingSelected()){e.display.prevInput="";var u=s.sel.primary();n=Wo&&(u.to().line-u.from().line>100||(i=e.getSelection()).length>1e3);var a=n?"-":i||e.getSelection();e.display.input.value=a,e.state.focused&&yo(e.display.input),o&&!r&&(e.display.inputHasSelection=a)}else t||(e.display.prevInput=e.display.input.value="",o&&!r&&(e.display.inputHasSelection=null));e.display.inaccurateSelection=n}function Un(e){e.options.readOnly!="nocursor"&&(!g||Po()!=e.display.input)&&e.display.input.focus()}function zn(e){e.state.focused||(Un(e),br(e))}function Wn(e){return e.options.readOnly||e.doc.cantEdit}function Xn(e){function i(){e.state.focused&&setTimeout(xo(Un,e),0)}function u(){s==null&&(s=setTimeout(function(){s=null,n.cachedCharWidth=n.cachedTextHeight=n.cachedPaddingH=Bo=null,e.setSize()},100))}function a(){Do(document.body,n.wrapper)?setTimeout(a,5e3):Gs(window,"resize",u)}function f(t){ro(e,t)||$s(t)}function l(t){n.inaccurateSelection&&(n.prevInput="",n.inaccurateSelection=!1,n.input.value=e.getSelection(),yo(n.input)),t.type=="cut"&&(e.state.cutIncoming=!0)}var n=e.display;Qs(n.scroller,"mousedown",Cn(e,Jn)),t?Qs(n.scroller,"dblclick",Cn(e,function(t){if(ro(e,t))return;var n=$n(e,t);if(!n||tr(e,t)||Vn(e.display,t))return;Ws(t);var r=Kr(e.doc,n);kt(e.doc,r.anchor,r.head)})):Qs(n.scroller,"dblclick",function(t){ro(e,t)||Ws(t)}),Qs(n.lineSpace,"selectstart",function(e){Vn(n,e)||Ws(e)}),S||Qs(n.scroller,"contextmenu",function(t){Sr(e,t)}),Qs(n.scroller,"scroll",function(){n.scroller.clientHeight&&(sr(e,n.scroller.scrollTop),or(e,n.scroller.scrollLeft,!0),Ys(e,"scroll",e))}),Qs(n.scrollbarV,"scroll",function(){n.scroller.clientHeight&&sr(e,n.scrollbarV.scrollTop)}),Qs(n.scrollbarH,"scroll",function(){n.scroller.clientHeight&&or(e,n.scrollbarH.scrollLeft)}),Qs(n.scroller,"mousewheel",function(t){fr(e,t)}),Qs(n.scroller,"DOMMouseScroll",function(t){fr(e,t)}),Qs(n.scrollbarH,"mousedown",i),Qs(n.scrollbarV,"mousedown",i),Qs(n.wrapper,"scroll",function(){n.wrapper.scrollTop=n.wrapper.scrollLeft=0});var s;Qs(window,"resize",u),setTimeout(a,5e3),Qs(n.input,"keyup",Cn(e,gr)),Qs(n.input,"input",function(){o&&!r&&e.display.inputHasSelection&&(e.display.inputHasSelection=null),In(e)}),Qs(n.input,"keydown",Cn(e,mr)),Qs(n.input,"keypress",Cn(e,yr)),Qs(n.input,"focus",xo(br,e)),Qs(n.input,"blur",xo(wr,e)),e.options.dragDrop&&(Qs(n.scroller,"dragstart",function(t){ir(e,t)}),Qs(n.scroller,"dragenter",f),Qs(n.scroller,"dragover",f),Qs(n.scroller,"drop",Cn(e,rr))),Qs(n.scroller,"paste",function(t){if(Vn(n,t))return;e.state.pasteIncoming=!0,Un(e),In(e)}),Qs(n.input,"paste",function(){e.state.pasteIncoming=!0,In(e)}),Qs(n.input,"cut",l),Qs(n.input,"copy",l),h&&Qs(n.sizer,"mouseup",function(){Po()==n.input&&n.input.blur(),Un(e)})}function Vn(e,t){for(var n=Js(t);n!=e.wrapper;n=n.parentNode)if(!n||n.ignoreEvents||n.parentNode==e.sizer&&n!=e.mover)return!0}function $n(e,t,n,r){var i=e.display;if(!n){var s=Js(t);if(s==i.scrollbarH||s==i.scrollbarV||s==i.scrollbarFiller||s==i.gutterFiller)return null}var o,u,a=i.lineSpace.getBoundingClientRect();try{o=t.clientX-a.left,u=t.clientY-a.top}catch(t){return null}var f=gn(e,o,u),l;if(r&&f.xRel==1&&(l=Es(e.doc,f.line).text).length==f.ch){var c=ho(l,l.length,e.options.tabSize)-l.length;f=ht(f.line,Math.round((o-Kt(e.display).left)/En(e.display))-c)}return f}function Jn(e){if(ro(this,e))return;var t=this,n=t.display;n.shift=e.shiftKey;if(Vn(n,e)){u||(n.scroller.draggable=!1,setTimeout(function(){n.scroller.draggable=!0},100));return}if(tr(t,e))return;var r=$n(t,e);window.focus();switch(Ks(e)){case 1:r?Gn(t,e,r):Js(e)==n.scroller&&Ws(e);break;case 2:u&&(t.state.lastMiddleDown=+(new Date)),r&&kt(t.doc,r),setTimeout(xo(Un,t),20),Ws(e);break;case 3:S&&Sr(t,e)}}function Gn(e,t,n){setTimeout(xo(zn,e),0);var r=+(new Date),i;Qn&&Qn.time>r-400&&pt(Qn.pos,n)==0?i="triple":Kn&&Kn.time>r-400&&pt(Kn.pos,n)==0?(i="double",Qn={time:r,pos:n}):(i="single",Kn={time:r,pos:n});var s=e.doc.sel,o=y?t.metaKey:t.ctrlKey;e.options.dragDrop&&Ho&&!o&&!Wn(e)&&i=="single"&&s.contains(n)>-1&&s.somethingSelected()?Yn(e,t,n):Zn(e,t,n,i,o)}function Yn(e,n,i){var s=e.display,o=Cn(e,function(a){u&&(s.scroller.draggable=!1),e.state.draggingText=!1,Gs(document,"mouseup",o),Gs(s.scroller,"drop",o),Math.abs(n.clientX-a.clientX)+Math.abs(n.clientY-a.clientY)<10&&(Ws(a),kt(e.doc,i),Un(e),t&&!r&&setTimeout(function(){document.body.focus(),Un(e)},20))});u&&(s.scroller.draggable=!0),e.state.draggingText=o,s.scroller.dragDrop&&s.scroller.dragDrop(),Qs(document,"mouseup",o),Qs(s.scroller,"drop",o)}function Zn(e,t,n,r,s){function v(t){if(pt(d,t)==0)return;d=t;if(r=="rect"){var i=[],s=e.options.tabSize,o=ho(Es(a,n.line).text,n.ch,s),u=ho(Es(a,t.line).text,t.ch,s),h=Math.min(o,u),p=Math.max(o,u);for(var v=Math.min(n.line,t.line),m=Math.min(e.lastLine(),Math.max(n.line,t.line));v<=m;v++){var g=Es(a,v).text,y=po(g,h,s);h==p?i.push(new yt(ht(v,y),ht(v,y))):g.length>y&&i.push(new yt(ht(v,y),ht(v,po(g,p,s))))}i.length||i.push(new yt(n,n)),Dt(a,bt(c.ranges.slice(0,l).concat(i),l),fo)}else{var b=f,w=b.anchor,E=t;if(r!="single"){if(r=="double")var S=Kr(a,t);else var S=new yt(ht(t.line,0),St(a,ht(t.line+1,0)));pt(S.anchor,w)>0?(E=S.head,w=mt(b.from(),S.anchor)):(E=S.anchor,w=vt(b.to(),S.head))}var i=c.ranges.slice(0);i[l]=new yt(St(a,w),E),Dt(a,bt(i,l),fo)}}function y(t){var n=++g,i=$n(e,t,!0,r=="rect");if(!i)return;if(pt(i,d)!=0){zn(e),v(i);var s=R(u,a);(i.line>=s.to||i.line<s.from)&&setTimeout(Cn(e,function(){g==n&&y(t)}),150)}else{var o=t.clientY<m.top?-20:t.clientY>m.bottom?20:0;o&&setTimeout(Cn(e,function(){if(g!=n)return;u.scroller.scrollTop+=o,y(t)}),50)}}function b(t){g=Infinity,Ws(t),Un(e),Gs(document,"mousemove",w),Gs(document,"mouseup",E),a.history.lastSelOrigin=null}var u=e.display,a=e.doc;Ws(t);var f,l,c=a.sel;s?(l=a.sel.contains(n),l>-1?f=a.sel.ranges[l]:f=new yt(n,n)):f=a.sel.primary();if(t.altKey)r="rect",s||(f=new yt(n,n)),n=$n(e,t,!0,!0),l=-1;else if(r=="double"){var h=Kr(a,n);e.display.shift||a.extend?f=Ct(a,f,h.anchor,h.head):f=h}else if(r=="triple"){var p=new yt(ht(n.line,0),St(a,ht(n.line+1,0)));e.display.shift||a.extend?f=Ct(a,f,p.anchor,p.head):f=p}else f=Ct(a,f,n);s?l>-1?At(a,l,f,fo):(l=a.sel.ranges.length,Dt(a,bt(a.sel.ranges.concat([f]),l),{scroll:!1,origin:"*mouse"})):(l=0,Dt(a,new gt([f],0),fo));var d=n,m=u.wrapper.getBoundingClientRect(),g=0,w=Cn(e,function(e){(o&&!i?!e.buttons:!Ks(e))?b(e):y(e)}),E=Cn(e,b);Qs(document,"mousemove",w),Qs(document,"mouseup",E)}function er(e,t,n,r,i){try{var s=t.clientX,o=t.clientY}catch(t){return!1}if(s>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;r&&Ws(t);var u=e.display,a=u.lineDiv.getBoundingClientRect();if(o>a.bottom||!io(e,n))return Vs(t);o-=a.top-u.viewOffset;for(var f=0;f<e.options.gutters.length;++f){var l=u.gutters.childNodes[f];if(l&&l.getBoundingClientRect().right>=s){var c=Cs(e.doc,o),h=e.options.gutters[f];return i(e,n,e,c,h,t),Vs(t)}}}function tr(e,t){return er(e,t,"gutterClick",!0,to)}function rr(e){var n=this;if(ro(n,e)||Vn(n.display,e))return;Ws(e),t&&(nr=+(new Date));var r=$n(n,e,!0),i=e.dataTransfer.files;if(!r||Wn(n))return;if(i&&i.length&&window.FileReader&&window.File){var s=i.length,o=Array(s),u=0,a=function(e,t){var i=new FileReader;i.onload=function(){o[t]=i.result;if(++u==s){r=St(n.doc,r);var e={from:r,to:r,text:Uo(o.join("\n")),origin:"paste"};Or(n.doc,e),_t(n.doc,wt(r,Tr(e)))}},i.readAsText(e)};for(var f=0;f<s;++f)a(i[f],f)}else{if(n.state.draggingText&&n.doc.sel.contains(r)>-1){n.state.draggingText(e),setTimeout(xo(Un,n),20);return}try{var o=e.dataTransfer.getData("Text");if(o){var l=n.state.draggingText&&n.listSelections();Pt(n.doc,wt(r,r));if(l)for(var f=0;f<l.length;++f)Br(n.doc,"",l[f].anchor,l[f].head,"drag");n.replaceSelection(o,"around","paste"),Un(n)}}catch(e){}}}function ir(e,n){if(t&&(!e.state.draggingText||+(new Date)-nr<100)){$s(n);return}if(ro(e,n)||Vn(e.display,n))return;n.dataTransfer.setData("Text",e.getSelection());if(n.dataTransfer.setDragImage&&!c){var r=Ao("img",null,null,"position: fixed; left: 0; top: 0;");r.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",l&&(r.width=r.height=1,e.display.wrapper.appendChild(r),r._top=r.offsetTop),n.dataTransfer.setDragImage(r,0,0),l&&r.parentNode.removeChild(r)}}function sr(t,n){if(Math.abs(t.doc.scrollTop-n)<2)return;t.doc.scrollTop=n,e||V(t,{top:n}),t.display.scroller.scrollTop!=n&&(t.display.scroller.scrollTop=n),t.display.scrollbarV.scrollTop!=n&&(t.display.scrollbarV.scrollTop=n),e&&V(t),zt(t,100)}function or(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,U(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbarH.scrollLeft!=t&&(e.display.scrollbarH.scrollLeft=t)}function fr(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,o=s.scroller;if(!(r&&o.scrollWidth>o.clientWidth||i&&o.scrollHeight>o.clientHeight))return;if(i&&y&&u)e:for(var a=n.target,f=s.view;a!=o;a=a.parentNode)for(var c=0;c<f.length;c++)if(f[c].node==a){t.display.currentWheelTarget=a;break e}if(r&&!e&&!l&&ar!=null){i&&sr(t,Math.max(0,Math.min(o.scrollTop+i*ar,o.scrollHeight-o.clientHeight))),or(t,Math.max(0,Math.min(o.scrollLeft+r*ar,o.scrollWidth-o.clientWidth))),Ws(n),s.wheelStartX=null;return}if(i&&ar!=null){var h=i*ar,p=t.doc.scrollTop,d=p+s.wrapper.clientHeight;h<0?p=Math.max(0,p+h-50):d=Math.min(t.doc.height,d+h+50),V(t,{top:p,bottom:d})}ur<20&&(s.wheelStartX==null?(s.wheelStartX=o.scrollLeft,s.wheelStartY=o.scrollTop,s.wheelDX=r,s.wheelDY=i,setTimeout(function(){if(s.wheelStartX==null)return;var e=o.scrollLeft-s.wheelStartX,t=o.scrollTop-s.wheelStartY,n=t&&s.wheelDY&&t/s.wheelDY||e&&s.wheelDX&&e/s.wheelDX;s.wheelStartX=s.wheelStartY=null;if(!n)return;ar=(ar*ur+n)/(ur+1),++ur},200)):(s.wheelDX+=r,s.wheelDY+=i))}function lr(e,t,n){if(typeof t=="string"){t=ui[t];if(!t)return!1}e.display.pollingFast&&qn(e)&&(e.display.pollingFast=!1);var r=e.display.shift,i=!1;try{Wn(e)&&(e.state.suppressEdits=!0),n&&(e.display.shift=!1),i=t(e)!=uo}finally{e.display.shift=r,e.state.suppressEdits=!1}return i}function cr(e){var t=e.state.keyMaps.slice(0);return e.options.extraKeys&&t.push(e.options.extraKeys),t.push(e.options.keyMap),t}function pr(e,t){var n=fi(e.options.keyMap),r=n.auto;clearTimeout(hr),r&&!ci(t)&&(hr=setTimeout(function(){fi(e.options.keyMap)==n&&(e.options.keyMap=r.call?r.call(null,e):r,_(e))},50));var i=hi(t,!0),s=!1;if(!i)return!1;var o=cr(e);return t.shiftKey?s=li("Shift-"+i,o,function(t){return lr(e,t,!0)})||li(i,o,function(t){if(typeof t=="string"?/^go[A-Z]/.test(t):t.motion)return lr(e,t)}):s=li(i,o,function(t){return lr(e,t)}),s&&(Ws(t),Ut(e),to(e,"keyHandled",e,i,t)),s}function dr(e,t,n){var r=li("'"+n+"'",cr(e),function(t){return lr(e,t,!0)});return r&&(Ws(t),Ut(e),to(e,"keyHandled",e,"'"+n+"'",t)),r}function mr(e){var n=this;zn(n);if(ro(n,e))return;t&&e.keyCode==27&&(e.returnValue=!1);var r=e.keyCode;n.display.shift=r==16||e.shiftKey;var i=pr(n,e);l&&(vr=i?r:null,!i&&r==88&&!Wo&&(y?e.metaKey:e.ctrlKey)&&n.replaceSelection("",null,"cut"))}function gr(e){if(ro(this,e))return;e.keyCode==16&&(this.doc.sel.shift=!1)}function yr(e){var t=this;if(ro(t,e))return;var n=e.keyCode,i=e.charCode;if(l&&n==vr){vr=null,Ws(e);return}if((l&&(!e.which||e.which<10)||h)&&pr(t,e))return;var s=String.fromCharCode(i==null?n:i);if(dr(t,e,s))return;o&&!r&&(t.display.inputHasSelection=null),In(t)}function br(e){if(e.options.readOnly=="nocursor")return;e.state.focused||(Ys(e,"focus",e),e.state.focused=!0,e.display.wrapper.className.search(/\bCodeMirror-focused\b/)==-1&&(e.display.wrapper.className+=" CodeMirror-focused"),e.curOp||(Rn(e),u&&setTimeout(xo(Rn,e,!0),0))),Fn(e),Ut(e)}function wr(e){e.state.focused&&(Ys(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.display.shift=!1)},150)}function Sr(e,t){function f(){if(n.input.selectionStart!=null){var t=n.input.value="​"+(e.somethingSelected()?n.input.value:"");n.prevInput="​",n.input.selectionStart=1,n.input.selectionEnd=t.length}}function c(){n.inputDiv.style.position="relative",n.input.style.cssText=a,r&&(n.scrollbarV.scrollTop=n.scroller.scrollTop=s),Fn(e);if(n.input.selectionStart!=null){(!o||r)&&f(),clearTimeout(Er);var t=0,i=function(){n.prevInput=="​"&&n.input.selectionStart==0?Cn(e,ui.selectAll)(e):t++<10?Er=setTimeout(i,500):Rn(e)};Er=setTimeout(i,200)}}if(ro(e,t,"contextmenu"))return;var n=e.display;if(Vn(n,t)||xr(e,t))return;var i=$n(e,t),s=n.scroller.scrollTop;if(!i||l)return;var u=e.options.resetSelectionOnContextMenu;u&&e.doc.sel.contains(i)==-1&&Cn(e,Dt)(e.doc,wt(i),ao);var a=n.input.style.cssText;n.inputDiv.style.position="absolute",n.input.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(t.clientY-5)+"px; left: "+(t.clientX-5)+"px; z-index: 1000; background: "+(o?"rgba(255, 255, 255, .05)":"transparent")+"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",Un(e),Rn(e),e.somethingSelected()||(n.input.value=n.prevInput=" "),o&&!r&&f();if(S){$s(t);var h=function(){Gs(window,"mouseup",h),setTimeout(c,20)};Qs(window,"mouseup",h)}else setTimeout(c,50)}function xr(e,t){return io(e,"gutterContextMenu")?er(e,t,"gutterContextMenu",!1,Ys):!1}function Nr(e,t){if(pt(e,t.from)<0)return e;if(pt(e,t.to)<=0)return Tr(t);var n=e.line+t.text.length-(t.to.line-t.from.line)-1,r=e.ch;return e.line==t.to.line&&(r+=Tr(t).ch-t.to.ch),ht(n,r)}function Cr(e,t){var n=[];for(var r=0;r<e.sel.ranges.length;r++){var i=e.sel.ranges[r];n.push(new yt(Nr(i.anchor,t),Nr(i.head,t)))}return bt(n,e.sel.primIndex)}function kr(e,t,n){return e.line==t.line?ht(n.line,e.ch-t.ch+n.ch):ht(n.line+(e.line-t.line),e.ch)}function Lr(e,t,n){var r=[],i=ht(e.first,0),s=i;for(var o=0;o<t.length;o++){var u=t[o],a=kr(u.from,i,s),f=kr(Tr(u),i,s);i=u.to,s=f;if(n=="around"){var l=e.sel.ranges[o],c=pt(l.head,l.anchor)<0;r[o]=new yt(c?f:a,c?a:f)}else r[o]=new yt(a,a)}return new gt(r,e.sel.primIndex)}function Ar(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=St(e,t)),n&&(this.to=St(e,n)),r&&(this.text=r),i!==undefined&&(this.origin=i)}),Ys(e,"beforeChange",e,r),e.cm&&Ys(e.cm,"beforeChange",e.cm,r),r.canceled?null:{from:r.from,to:r.to,text:r.text,origin:r.origin}}function Or(e,t,n){if(e.cm){if(!e.cm.curOp)return Cn(e.cm,Or)(e,t,n);if(e.cm.state.suppressEdits)return}if(io(e,"beforeChange")||e.cm&&io(e.cm,"beforeChange")){t=Ar(e,t,!0);if(!t)return}var r=x&&!n&&Li(e,t.from,t.to);if(r)for(var i=r.length-1;i>=0;--i)Mr(e,{from:r[i].from,to:r[i].to,text:i?[""]:t.text});else Mr(e,t)}function Mr(e,t){if(t.text.length==1&&t.text[0]==""&&pt(t.from,t.to)==0)return;var n=Cr(e,t);Ds(e,t,n,e.cm?e.cm.curOp.id:NaN),Pr(e,t,n,Ni(e,t));var r=[];bs(e,function(e,n){!n&&bo(r,e.history)==-1&&(zs(e.history,t),r.push(e.history)),Pr(e,t,null,Ni(e,t))})}function _r(e,t,n){if(e.cm&&e.cm.state.suppressEdits)return;var r=e.history,i,s=e.sel,o=t=="undo"?r.done:r.undone,u=t=="undo"?r.undone:r.done;for(var a=0;a<o.length;a++){i=o[a];if(n?i.ranges&&!i.equals(e.sel):!i.ranges)break}if(a==o.length)return;r.lastOrigin=r.lastSelOrigin=null;for(;;){i=o.pop();if(!i.ranges)break;Bs(i,u);if(n&&!i.equals(e.sel)){Dt(e,i,{clearRedo:!1});return}s=i}var f=[];Bs(s,u),u.push({changes:f,generation:r.generation}),r.generation=i.generation||++r.maxGeneration;var l=io(e,"beforeChange")||e.cm&&io(e.cm,"beforeChange");for(var a=i.changes.length-1;a>=0;--a){var c=i.changes[a];c.origin=t;if(l&&!Ar(e,c,!1)){o.length=0;return}f.push(Os(e,c));var h=a?Cr(e,c,null):go(o);Pr(e,c,h,ki(e,c)),e.cm&&Ur(e.cm);var p=[];bs(e,function(e,t){!t&&bo(p,e.history)==-1&&(zs(e.history,c),p.push(e.history)),Pr(e,c,null,ki(e,c))})}}function Dr(e,t){e.first+=t,e.sel=new gt(wo(e.sel.ranges,function(e){return new yt(ht(e.anchor.line+t,e.anchor.ch),ht(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm&&Mn(e.cm,e.first,e.first-t,t)}function Pr(e,t,n,r){if(e.cm&&!e.cm.curOp)return Cn(e.cm,Pr)(e,t,n,r);if(t.to.line<e.first){Dr(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);Dr(e,i),t={from:ht(e.first,0),to:ht(t.to.line+i,t.to.ch),text:[go(t.text)],origin:t.origin}}var s=e.lastLine();t.to.line>s&&(t={from:t.from,to:ht(s,Es(e,s).text.length),text:[t.text[0]],origin:t.origin}),t.removed=Ss(e,t.from,t.to),n||(n=Cr(e,t,null)),e.cm?Hr(e.cm,t,r):hs(e,t,r),Pt(e,n,ao)}function Hr(e,t,n){var r=e.doc,i=e.display,s=t.from,o=t.to,u=!1,a=s.line;e.options.lineWrapping||(a=Ns(Fi(Es(r,s.line))),r.iter(a,o.line+1,function(e){if(e==i.maxLine)return u=!0,!0})),r.sel.contains(t.from,t.to)>-1&&(e.curOp.cursorActivity=!0),hs(r,t,n,O(e)),e.options.lineWrapping||(r.iter(a,s.line+t.text.length,function(e){var t=B(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,u=!1)}),u&&(e.curOp.updateMaxLine=!0)),r.frontier=Math.min(r.frontier,s.line),zt(e,400);var f=t.text.length-(o.line-s.line)-1;s.line==o.line&&t.text.length==1&&!cs(e.doc,t)?_n(e,s.line,"text"):Mn(e,s.line,o.line+1,f),(io(e,"change")||io(e,"changes"))&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push({from:s,to:o,text:t.text,removed:t.removed,origin:t.origin})}function Br(e,t,n,r,i){r||(r=n);if(pt(r,n)<0){var s=r;r=n,n=s}typeof t=="string"&&(t=Uo(t)),Or(e,{from:n,to:r,text:t,origin:i})}function jr(e,t){var n=e.display,r=n.sizer.getBoundingClientRect(),i=null;t.top+r.top<0?i=!0:t.bottom+r.top>(window.innerHeight||document.documentElement.clientHeight)&&(i=!1);if(i!=null&&!v){var s=Ao("div","​",null,"position: absolute; top: "+(t.top-n.viewOffset-$t(e.display))+"px; height: "+(t.bottom-t.top+oo)+"px; left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(s),s.scrollIntoView(i),e.display.lineSpace.removeChild(s)}}function Fr(e,t,n,r){r==null&&(r=0);for(;;){var i=!1,s=dn(e,t),o=!n||n==t?s:dn(e,n),u=qr(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&&(sr(e,u.scrollTop),Math.abs(e.doc.scrollTop-a)>1&&(i=!0)),u.scrollLeft!=null&&(or(e,u.scrollLeft),Math.abs(e.doc.scrollLeft-f)>1&&(i=!0));if(!i)return s}}function Ir(e,t,n,r,i){var s=qr(e,t,n,r,i);s.scrollTop!=null&&sr(e,s.scrollTop),s.scrollLeft!=null&&or(e,s.scrollLeft)}function qr(e,t,n,r,i){var s=e.display,o=wn(e.display);n<0&&(n=0);var u=e.curOp&&e.curOp.scrollTop!=null?e.curOp.scrollTop:s.scroller.scrollTop,a=s.scroller.clientHeight-oo,f={},l=e.doc.height+Jt(s),c=n<o,h=i>l-o;if(n<u)f.scrollTop=c?0:n;else if(i>u+a){var p=Math.min(n,(h?l:i)-a);p!=u&&(f.scrollTop=p)}var d=e.curOp&&e.curOp.scrollLeft!=null?e.curOp.scrollLeft:s.scroller.scrollLeft,v=s.scroller.clientWidth-oo;t+=s.gutters.offsetWidth,r+=s.gutters.offsetWidth;var m=s.gutters.offsetWidth,g=t<m+10;return t<d+m||g?(g&&(t=0),f.scrollLeft=Math.max(0,t-10-m)):r>v+d-3&&(f.scrollLeft=r+10-v),f}function Rr(e,t,n){(t!=null||n!=null)&&zr(e),t!=null&&(e.curOp.scrollLeft=(e.curOp.scrollLeft==null?e.doc.scrollLeft:e.curOp.scrollLeft)+t),n!=null&&(e.curOp.scrollTop=(e.curOp.scrollTop==null?e.doc.scrollTop:e.curOp.scrollTop)+n)}function Ur(e){zr(e);var t=e.getCursor(),n=t,r=t;e.options.lineWrapping||(n=t.ch?ht(t.line,t.ch-1):t,r=ht(t.line,t.ch+1)),e.curOp.scrollToPos={from:n,to:r,margin:e.options.cursorScrollMargin,isCursor:!0}}function zr(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var n=vn(e,t.from),r=vn(e,t.to),i=qr(e,Math.min(n.left,r.left),Math.min(n.top,r.top)-t.margin,Math.max(n.right,r.right),Math.max(n.bottom,r.bottom)+t.margin);e.scrollTo(i.scrollLeft,i.scrollTop)}}function Wr(e,t,n,r){var i=e.doc,s;n==null&&(n="add"),n=="smart"&&(e.doc.mode.indent?s=Vt(e,t):n="prev");var o=e.options.tabSize,u=Es(i,t),a=ho(u.text,null,o);u.stateAfter&&(u.stateAfter=null);var 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==uo){if(!r)return;n="prev"}}n=="prev"?t>i.first?l=ho(Es(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+=mo(l-h));if(c!=f)Br(e.doc,c,ht(t,0),ht(t,f.length),"+input");else for(var p=0;p<i.sel.ranges.length;p++){var d=i.sel.ranges[p];if(d.head.line==t&&d.head.ch<f.length){var h=ht(t,f.length);At(i,p,new yt(h,h));break}}u.stateAfter=null}function Xr(e,t,n,r){var i=t,s=t,o=e.doc;return typeof t=="number"?s=Es(o,Et(o,t)):i=Ns(t),i==null?null:r(s,i)?(_n(e,i,n),s):null}function Vr(e,t){var n=e.doc.sel.ranges,r=[];for(var i=0;i<n.length;i++){var s=t(n[i]);while(r.length&&pt(s.from,go(r).to)<=0){var o=r.pop();if(pt(o.from,s.from)<0){s.from=o.from;break}}r.push(s)}Nn(e,function(){for(var t=r.length-1;t>=0;t--)Br(e.doc,"",r[t].from,r[t].to,"+delete");Ur(e)})}function $r(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=Es(e,t))}function c(e){var t=(i?ru:iu)(a,o,n,!0);if(t==null){if(!!e||!l())return f=!1;i?o=(n<0?Qo:Ko)(a):o=n<0?a.text.length:0}else o=t;return!0}var s=t.line,o=t.ch,u=n,a=Es(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=No(v)?"w":p&&v=="\n"?"n":!p||/\s/.test(v)?null:"p";p&&!d&&!m&&(m="s");if(h&&h!=m){n<0&&(n=1,c());break}m&&(h=m);if(n>0&&!c(!d))break}}var g=Ft(e,ht(s,o),u,!0);return f||(g.hitSide=!0),g}function Jr(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)*wn(e.display))}else r=="line"&&(o=n>0?t.bottom+3:t.top-3);for(;;){var a=gn(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 Kr(e,t){var n=Es(e,t.line).text,r=t.ch,i=t.ch;if(n){(t.xRel<0||i==n.length)&&r?--r:++i;var s=n.charAt(r),o=No(s)?No:/\s/.test(s)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!No(e)};while(r>0&&o(n.charAt(r-1)))--r;while(i<n.length&&o(n.charAt(i)))++i}return new yt(ht(t.line,r),ht(t.line,i))}function Yr(e,t,n,r){N.defaults[e]=t,n&&(Gr[e]=r?function(e,t,r){r!=Zr&&n(e,t,r)}:n)}function fi(e){return typeof e=="string"?ai[e]:e}function mi(e,t,n,r,i){if(r&&r.shared)return yi(e,t,n,r,i);if(e.cm&&!e.cm.curOp)return Cn(e.cm,mi)(e,t,n,r,i);var s=new di(e,i),o=pt(t,n);r&&So(r,s);if(o>0||o==0&&s.clearWhenEmpty!==!1)return s;s.replacedWith&&(s.collapsed=!0,s.widgetNode=Ao("span",[s.replacedWith],"CodeMirror-widget"),r.handleMouseEvents||(s.widgetNode.ignoreEvents=!0),r.insertLeft&&(s.widgetNode.insertLeft=!0));if(s.collapsed){if(ji(e,t.line,t,n,s)||t.line!=n.line&&ji(e,n.line,t,n,s))throw new Error("Inserting collapsed marker partially overlapping an existing one");T=!0}s.addToHistory&&Ds(e,{from:t,to:n,origin:"markText"},e.sel,NaN);var u=t.line,a=e.cm,f;e.iter(u,n.line+1,function(e){a&&s.collapsed&&!a.options.lineWrapping&&Fi(e)==a.display.maxLine&&(f=!0),s.collapsed&&u!=t.line&&Ts(e,0),Si(e,new bi(s,u==t.line?t.ch:null,u==n.line?n.ch:null)),++u}),s.collapsed&&e.iter(t.line,n.line+1,function(t){Ui(e,t)&&Ts(t,0)}),s.clearOnEnter&&Qs(s,"beforeCursorEnter",function(){s.clear()}),s.readOnly&&(x=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),s.collapsed&&(s.id=++vi,s.atomic=!0);if(a){f&&(a.curOp.updateMaxLine=!0);if(s.collapsed)Mn(a,t.line,n.line+1);else if(s.className||s.title||s.startStyle||s.endStyle)for(var l=t.line;l<=n.line;l++)_n(a,l,"text");s.atomic&&Bt(a.doc),to(a,"markerAdded",a,s)}return s}function yi(e,t,n,r,i){r=So(r),r.shared=!1;var s=[mi(e,t,n,r,i)],o=s[0],u=r.widgetNode;return bs(e,function(e){u&&(r.widgetNode=u.cloneNode(!0)),s.push(mi(e,St(e,t),St(e,n),r,i));for(var a=0;a<e.linked.length;++a)if(e.linked[a].isParent)return;o=go(s)}),new gi(s,o)}function bi(e,t,n){this.marker=e,this.from=t,this.to=n}function wi(e,t){if(e)for(var n=0;n<e.length;++n){var r=e[n];if(r.marker==t)return r}}function Ei(e,t){for(var n,r=0;r<e.length;++r)e[r]!=t&&(n||(n=[])).push(e[r]);return n}function Si(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}function xi(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(new bi(o,s.from,a?null:s.to))}}return i}function Ti(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(new bi(o,a?null:s.from-t,s.to==null?null:s.to-t))}}return i}function Ni(e,t){var n=Tt(e,t.from.line)&&Es(e,t.from.line).markedSpans,r=Tt(e,t.to.line)&&Es(e,t.to.line).markedSpans;if(!n&&!r)return null;var i=t.from.ch,s=t.to.ch,o=pt(t.from,t.to)==0,u=xi(n,i,o),a=Ti(r,s,o),f=t.text.length==1,l=go(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=wi(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=wi(u,h.marker);p||(h.from=l,f&&(u||(u=[])).push(h))}else h.from+=l,f&&(u||(u=[])).push(h)}u&&(u=Ci(u)),a&&a!=u&&(a=Ci(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(new bi(u[c].marker,null,null));for(var c=0;c<v;++c)d.push(m);d.push(a)}return d}function Ci(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 ki(e,t){var n=Is(e,t),r=Ni(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 Li(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||bo(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(0);for(var a=0;a<i.length;++a){var f=i[a];if(pt(f.to,u.from)<0||pt(f.from,u.to)>0)continue;var l=[a,1],c=pt(f.from,u.from),h=pt(f.to,u.to);(c<0||!o.inclusiveLeft&&!c)&&l.push({from:f.from,to:u.from}),(h>0||!o.inclusiveRight&&!h)&&l.push({from:u.to,to:f.to}),i.splice.apply(i,l),a+=l.length-1}}return i}function Ai(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 Oi(e,t){if(!t)return;for(var n=0;n<t.length;++n)t[n].marker.attachLine(e);e.markedSpans=t}function Mi(e){return e.inclusiveLeft?-1:0}function _i(e){return e.inclusiveRight?1:0}function Di(e,t){var n=e.lines.length-t.lines.length;if(n!=0)return n;var r=e.find(),i=t.find(),s=pt(r.from,i.from)||Mi(e)-Mi(t);if(s)return-s;var o=pt(r.to,i.to)||_i(e)-_i(t);return o?o:t.id-e.id}function Pi(e,t){var n=T&&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||Di(r,i.marker)<0)&&(r=i.marker);return r}function Hi(e){return Pi(e,!0)}function Bi(e){return Pi(e,!1)}function ji(e,t,n,r,i){var s=Es(e,t),o=T&&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=pt(f.from,n)||Mi(a.marker)-Mi(i),c=pt(f.to,r)||_i(a.marker)-_i(i);if(l>=0&&c<=0||l<=0&&c>=0)continue;if(l<=0&&(pt(f.to,n)||_i(a.marker)-Mi(i))>0||l>=0&&(pt(f.from,r)||Mi(a.marker)-_i(i))<0)return!0}}function Fi(e){var t;while(t=Hi(e))e=t.find(-1,!0).line;return e}function Ii(e){var t,n;while(t=Bi(e))e=t.find(1,!0).line,(n||(n=[])).push(e);return n}function qi(e,t){var n=Es(e,t),r=Fi(n);return n==r?t:Ns(r)}function Ri(e,t){if(t>e.lastLine())return t;var n=Es(e,t),r;if(!Ui(e,n))return t;while(r=Bi(n))n=r.find(1,!0).line;return Ns(n)+1}function Ui(e,t){var n=T&&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.widgetNode)continue;if(r.from==0&&r.marker.inclusiveLeft&&zi(e,t,r))return!0}}function zi(e,t,n){if(n.to==null){var r=n.marker.find(1,!0);return zi(e,r.line,wi(r.line.markedSpans,n.marker))}if(n.marker.inclusiveRight&&n.to==t.text.length)return!0;for(var i,s=0;s<t.markedSpans.length;++s){i=t.markedSpans[s];if(i.marker.collapsed&&!i.marker.widgetNode&&i.from==n.to&&(i.to==null||i.to!=n.from)&&(i.marker.inclusiveLeft||n.marker.inclusiveRight)&&zi(e,t,i))return!0}}function Xi(e,t,n){ks(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Rr(e,null,n)}function Vi(e){return e.height!=null?e.height:(Do(document.body,e.node)||_o(e.cm.display.measure,Ao("div",[e.node],null,"position: relative")),e.height=e.node.offsetHeight)}function $i
(e,t,n,r){var i=new Wi(e,n,r);return i.noHScroll&&(e.display.alignWidgets=!0),Xr(e,t,"widget",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(!Ui(e.doc,t)){var r=ks(t)<e.doc.scrollTop;Ts(t,t.height+Vi(i)),r&&Rr(e,null,i.height),e.curOp.forceUpdate=!0}return!0}),i}function Ki(e,t,n,r){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),e.order!=null&&(e.order=null),Ai(e),Oi(e,n);var i=r?r(e):1;i!=e.height&&Ts(e,i)}function Qi(e){e.parent=null,Ai(e)}function Gi(e,t,n,r,i,s){var o=n.flattenSpans;o==null&&(o=e.options.flattenSpans);var u=0,a=null,f=new pi(t,e.options.tabSize),l;t==""&&n.blankLine&&n.blankLine(r);while(!f.eol()){f.pos>e.options.maxHighlightLength?(o=!1,s&&es(e,t,r,f.pos),f.pos=t.length,l=null):l=n.token(f,r);if(e.options.addModeClass){var c=N.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 Yi(e,t,n,r){var i=[e.state.modeGen];Gi(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;Gi(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 Zi(e,t){if(!t.styles||t.styles[0]!=e.state.modeGen)t.styles=Yi(e,t,t.stateAfter=Vt(e,Ns(t)));return t.styles}function es(e,t,n,r){var i=e.doc.mode,s=new pi(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 rs(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])}if(/^\s*$/.test(e))return null;var i=t.cm.options.addModeClass?ns:ts;return i[e]||(i[e]=e.replace(/\S+/g,"cm-$&"))}function is(e,t){var n=Ao("span",null,null,u?"padding-right: .1px":null),r={pre:Ao("pre",[n]),content:n,col:0,pos:0,cm:e};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var s=i?t.rest[i-1]:t.line,a;r.pos=0,r.addToken=os,(o||u)&&e.getOption("lineWrapping")&&(r.addToken=us(r.addToken)),Ro(e.display.measure)&&(a=Ls(s))&&(r.addToken=as(r.addToken,a)),r.map=[],ls(s,r,Zi(e,s)),r.map.length==0&&r.map.push(0,0,r.content.appendChild(Io(e.display.measure))),i==0?(t.measure.map=r.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(r.map),(t.measure.caches||(t.measure.caches=[])).push({}))}return Ys(e,"renderLine",e,t.line,r.pre),r}function ss(e){var t=Ao("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t}function os(e,t,n,i,s,o){if(!t)return;var u=e.cm.options.specialChars,a=!1;if(!u.test(t)){e.col+=t.length;var f=document.createTextNode(t);e.map.push(e.pos,e.pos+t.length,f),r&&(a=!0),e.pos+=t.length}else{var f=document.createDocumentFragment(),l=0;for(;;){u.lastIndex=l;var c=u.exec(t),h=c?c.index-l:t.length-l;if(h){var p=document.createTextNode(t.slice(l,l+h));r?f.appendChild(Ao("span",[p])):f.appendChild(p),e.map.push(e.pos,e.pos+h,p),e.col+=h,e.pos+=h}if(!c)break;l+=h+1;if(c[0]==" "){var d=e.cm.options.tabSize,v=d-e.col%d,p=f.appendChild(Ao("span",mo(v),"cm-tab"));e.col+=v}else{var p=e.cm.options.specialCharPlaceholder(c[0]);r?f.appendChild(Ao("span",[p])):f.appendChild(p),e.col+=1}e.map.push(e.pos,e.pos+1,p),e.pos++}}if(n||i||s||a){var m=n||"";i&&(m+=i),s&&(m+=s);var g=Ao("span",[f],m);return o&&(g.title=o),e.content.appendChild(g)}e.content.appendChild(f)}function us(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){e(n,r.replace(/ {3,}/g,t),i,s,o,u)}}function as(e,t){return function(n,r,i,s,o,u){i=i?i+" cm-force-border":"cm-force-border";var a=n.pos,f=a+r.length;for(;;){for(var l=0;l<t.length;l++){var c=t[l];if(c.to>a&&c.from<=a)break}if(c.to>=f)return e(n,r,i,s,o,u);e(n,r.slice(0,c.to-a),i,s,null,u),s=null,r=r.slice(c.to-a),a=c.to}}}function fs(e,t,n,r){var i=!r&&n.widgetNode;i&&(e.map.push(e.pos,e.pos+t,i),e.content.appendChild(i)),e.pos+=t}function ls(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]),rs(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.from==a&&(d+=" "+w.startStyle),w.endStyle&&b.to==c&&(p+=" "+w.endStyle),w.title&&!v&&(v=w.title),w.collapsed&&(!m||Di(m.marker,w)<0)&&(m=b)):b.from>a&&c>b.from&&(c=b.from),w.type=="bookmark"&&b.from==a&&w.widgetNode&&g.push(w)}if(m&&(m.from||0)==a){fs(t,(m.to==null?u+1:m.to)-a,m.marker,m.from==null);if(m.to==null)return}if(!m&&g.length)for(var y=0;y<g.length;++y)fs(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=rs(n[o++],t)}}}function cs(e,t){return t.from.ch==0&&t.to.ch==0&&go(t.text)==""&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function hs(e,t,n,r){function i(e){return n?n[e]:null}function s(e,n,i){Ki(e,n,i,r),to(e,"change",e,t)}var o=t.from,u=t.to,a=t.text,f=Es(e,o.line),l=Es(e,u.line),c=go(a),h=i(a.length-1),p=u.line-o.line;if(cs(e,t)){for(var d=0,v=[];d<a.length-1;++d)v.push(new Ji(a[d],i(d),r));s(l,l.text,h),p&&e.remove(o.line,p),v.length&&e.insert(o.line,v)}else if(f==l)if(a.length==1)s(f,f.text.slice(0,o.ch)+c+f.text.slice(u.ch),h);else{for(var v=[],d=1;d<a.length-1;++d)v.push(new Ji(a[d],i(d),r));v.push(new Ji(c+f.text.slice(u.ch),h,r)),s(f,f.text.slice(0,o.ch)+a[0],i(0)),e.insert(o.line+1,v)}else if(a.length==1)s(f,f.text.slice(0,o.ch)+a[0]+l.text.slice(u.ch),i(0)),e.remove(o.line+1,p);else{s(f,f.text.slice(0,o.ch)+a[0],i(0)),s(l,c+l.text.slice(u.ch),h);for(var d=1,v=[];d<a.length-1;++d)v.push(new Ji(a[d],i(d),r));p>1&&e.remove(o.line+1,p-1),e.insert(o.line+1,v)}to(e,"change",e,t)}function ps(e){this.lines=e,this.parent=null;for(var t=0,n=0;t<e.length;++t)e[t].parent=this,n+=e[t].height;this.height=n}function ds(e){this.children=e;var t=0,n=0;for(var r=0;r<e.length;++r){var i=e[r];t+=i.chunkSize(),n+=i.height,i.parent=this}this.size=t,this.height=n,this.parent=null}function bs(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 ws(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,M(e),k(e),e.options.lineWrapping||j(e),e.options.mode=t.modeOption,Mn(e)}function Es(e,t){t-=e.first;if(t<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var n=e;!n.lines;)for(var r=0;;++r){var i=n.children[r],s=i.chunkSize();if(t<s){n=i;break}t-=s}return n.lines[t]}function Ss(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 xs(e,t,n){var r=[];return e.iter(t,n,function(e){r.push(e.text)}),r}function Ts(e,t){var n=t-e.height;if(n)for(var r=e;r;r=r.parent)r.height+=n}function Ns(e){if(e.parent==null)return null;var t=e.parent,n=bo(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 Cs(e,t){var n=e.first;e:do{for(var r=0;r<e.children.length;++r){var i=e.children[r],s=i.height;if(t<s){e=i;continue e}t-=s,n+=i.chunkSize()}return n}while(!e.lines);for(var r=0;r<e.lines.length;++r){var o=e.lines[r],u=o.height;if(t<u)break;t-=u}return n+r}function ks(e){e=Fi(e);var t=0,n=e.parent;for(var r=0;r<n.lines.length;++r){var i=n.lines[r];if(i==e)break;t+=i.height}for(var s=n.parent;s;n=s,s=n.parent)for(var r=0;r<s.children.length;++r){var o=s.children[r];if(o==n)break;t+=o.height}return t}function Ls(e){var t=e.order;return t==null&&(t=e.order=su(e.text)),t}function As(e){this.done=[],this.undone=[],this.undoDepth=Infinity,this.lastModTime=this.lastSelTime=0,this.lastOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=e||1}function Os(e,t){var n={from:dt(t.from),to:Tr(t),text:Ss(e,t.from,t.to)};return js(e,n,t.from.line,t.to.line+1),bs(e,function(e){js(e,n,t.from.line,t.to.line+1)},!0),n}function Ms(e){while(e.length){var t=go(e);if(!t.ranges)break;e.pop()}}function _s(e,t){if(t)return Ms(e.done),go(e.done);if(e.done.length&&!go(e.done).ranges)return go(e.done);if(e.done.length>1&&!e.done[e.done.length-2].ranges)return e.done.pop(),go(e.done)}function Ds(e,t,n,r){var i=e.history;i.undone.length=0;var s=+(new Date),o;if((i.lastOp==r||i.lastOrigin==t.origin&&t.origin&&(t.origin.charAt(0)=="+"&&e.cm&&i.lastModTime>s-e.cm.options.historyEventDelay||t.origin.charAt(0)=="*"))&&(o=_s(i,i.lastOp==r))){var u=go(o.changes);pt(t.from,t.to)==0&&pt(t.from,u.to)==0?u.to=Tr(t):o.changes.push(Os(e,t))}else{var a=go(i.done);(!a||!a.ranges)&&Bs(e.sel,i.done),o={changes:[Os(e,t)],generation:i.generation},i.done.push(o);while(i.done.length>i.undoDepth)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(n),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=s,i.lastOp=r,i.lastOrigin=i.lastSelOrigin=t.origin,u||Ys(e,"historyAdded")}function Ps(e,t,n,r){var i=t.charAt(0);return i=="*"||i=="+"&&n.ranges.length==r.ranges.length&&n.somethingSelected()==r.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}function Hs(e,t,n,r){var i=e.history,s=r&&r.origin;n==i.lastOp||s&&i.lastSelOrigin==s&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==s||Ps(e,s,go(i.done),t))?i.done[i.done.length-1]=t:Bs(t,i.done),i.lastSelTime=+(new Date),i.lastSelOrigin=s,i.lastOp=n,r&&r.clearRedo!==!1&&Ms(i.undone)}function Bs(e,t){var n=go(t);n&&n.ranges&&n.equals(e)||t.push(e)}function js(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 Fs(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 Is(e,t){var n=t["spans_"+e.id];if(!n)return null;for(var r=0,i=[];r<t.text.length;++r)i.push(Fs(n[r]));return i}function qs(e,t,n){for(var r=0,i=[];r<e.length;++r){var s=e[r];if(s.ranges){i.push(n?gt.prototype.deepCopy.call(s):s);continue}var o=s.changes,u=[];i.push({changes:u});for(var a=0;a<o.length;++a){var f=o[a],l;u.push({from:f.from,to:f.to,text:f.text});if(t)for(var c in f)(l=c.match(/^spans_(\d+)$/))&&bo(t,Number(l[1]))>-1&&(go(u)[c]=f[c],delete f[c])}}return i}function Rs(e,t,n,r){n<e.line?e.line+=r:t<e.line&&(e.line=t,e.ch=0)}function Us(e,t,n,r){for(var i=0;i<e.length;++i){var s=e[i],o=!0;if(s.ranges){s.copied||(s=e[i]=s.deepCopy(),s.copied=!0);for(var u=0;u<s.ranges.length;u++)Rs(s.ranges[u].anchor,t,n,r),Rs(s.ranges[u].head,t,n,r);continue}for(var u=0;u<s.changes.length;++u){var a=s.changes[u];if(n<a.from.line)a.from=ht(a.from.line+r,a.from.ch),a.to=ht(a.to.line+r,a.to.ch);else if(t<=a.to.line){o=!1;break}}o||(e.splice(0,i+1),i=0)}}function zs(e,t){var n=t.from.line,r=t.to.line,i=t.text.length-(r-n)-1;Us(e.done,n,r,i),Us(e.undone,n,r,i)}function Vs(e){return e.defaultPrevented!=null?e.defaultPrevented:e.returnValue==0}function Js(e){return e.target||e.srcElement}function Ks(e){var t=e.which;return t==null&&(e.button&1?t=1:e.button&2?t=3:e.button&4&&(t=2)),y&&e.ctrlKey&&t==1&&(t=3),t}function to(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);Zs||(++eo,Zs=[],setTimeout(no,0));for(var s=0;s<n.length;++s)Zs.push(i(n[s]))}function no(){--eo;var e=Zs;Zs=null;for(var t=0;t<e.length;++t)e[t]()}function ro(e,t,n){return Ys(e,n||t.type,e,t),Vs(t)||t.codemirrorIgnore}function io(e,t){var n=e._handlers&&e._handlers[t];return n&&n.length>0}function so(e){e.prototype.on=function(e,t){Qs(this,e,t)},e.prototype.off=function(e,t){Gs(this,e,t)}}function co(){this.id=null}function po(e,t,n){for(var r=0,i=0;;){var s=e.indexOf(" ",r);s==-1&&(s=e.length);var o=s-r;if(s==e.length||i+o>=t)return r+Math.min(o,t-i);i+=s-r,i+=n-i%n,r=s+1;if(i>=t)return r}}function mo(e){while(vo.length<=e)vo.push(go(vo)+" ");return vo[e]}function go(e){return e[e.length-1]}function bo(e,t){for(var n=0;n<e.length;++n)if(e[n]==t)return n;return-1}function wo(e,t){var n=[];for(var r=0;r<e.length;r++)n[r]=t(e[r],r);return n}function Eo(e,t){var n;if(Object.create)n=Object.create(e);else{var r=function(){};r.prototype=e,n=new r}return t&&So(t,n),n}function So(e,t){t||(t={});for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function xo(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function Co(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function Lo(e){return e.charCodeAt(0)>=768&&ko.test(e)}function Ao(e,t,n,r){var i=document.createElement(e);n&&(i.className=n),r&&(i.style.cssText=r);if(typeof t=="string")i.appendChild(document.createTextNode(t));else if(t)for(var s=0;s<t.length;++s)i.appendChild(t[s]);return i}function Mo(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function _o(e,t){return Mo(e).appendChild(t)}function Do(e,t){if(e.contains)return e.contains(t);while(t=t.parentNode)if(t==e)return!0}function Po(){return document.activeElement}function jo(e){if(Bo!=null)return Bo;var t=Ao("div",null,null,"width: 50px; height: 50px; overflow-x: scroll");return _o(e,t),t.offsetWidth&&(Bo=t.offsetHeight-t.clientHeight),Bo||0}function Io(e){if(Fo==null){var t=Ao("span","​");_o(e,Ao("span",[t,document.createTextNode("x")])),e.firstChild.offsetHeight!=0&&(Fo=t.offsetWidth<=1&&t.offsetHeight>2&&!n)}return Fo?Ao("span","​"):Ao("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px")}function Ro(e){if(qo!=null)return qo;var t=_o(e,document.createTextNode("AخA")),n=Oo(t,0,1).getBoundingClientRect();if(n.left==n.right)return!1;var r=Oo(t,1,2).getBoundingClientRect();return qo=r.right-n.right<3}function Vo(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 $o(e){return e.level%2?e.to:e.from}function Jo(e){return e.level%2?e.from:e.to}function Ko(e){var t=Ls(e);return t?$o(t[0]):0}function Qo(e){var t=Ls(e);return t?Jo(go(t)):e.text.length}function Go(e,t){var n=Es(e.doc,t),r=Fi(n);r!=n&&(t=Ns(r));var i=Ls(r),s=i?i[0].level%2?Qo(r):Ko(r):0;return ht(t,s)}function Yo(e,t){var n,r=Es(e.doc,t);while(n=Bi(r))r=n.find(1,!0).line,t=null;var i=Ls(r),s=i?i[0].level%2?Ko(r):Qo(r):r.text.length;return ht(t==null?Ns(r):t,s)}function Zo(e,t,n){var r=e[0].level;return t==r?!0:n==r?!1:t<n}function tu(e,t){eu=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 Zo(e,i.level,e[r].level)?(i.from!=i.to&&(eu=r),n):(i.from!=i.to&&(eu=n),r);r=n}}return r}function nu(e,t,n,r){if(!r)return t+n;do t+=n;while(t>0&&Lo(e.text.charAt(t)));return t}function ru(e,t,n,r){var i=Ls(e);if(!i)return iu(e,t,n,r);var s=tu(i,t),o=i[s],u=nu(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 tu(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=nu(e,o.to,-1,r):u=nu(e,o.from,1,r)}}function iu(e,t,n,r){var i=t+n;if(r)while(i>0&&Lo(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=t&&(document.documentMode==null||document.documentMode<10),s=/Trident\/([7-9]|\d{2,})\./.test(navigator.userAgent),o=t||s,u=/WebKit\//.test(navigator.userAgent),a=u&&/Qt\/\d+\.\d+/.test(navigator.userAgent),f=/Chrome\//.test(navigator.userAgent),l=/Opera\//.test(navigator.userAgent),c=/Apple Computer/.test(navigator.vendor),h=/KHTML\//.test(navigator.userAgent),p=/Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent),d=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),v=/PhantomJS/.test(navigator.userAgent),m=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),g=m||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),y=m||/Mac/.test(navigator.platform),b=/win/i.test(navigator.platform),w=l&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);w&&(w=Number(w[1])),w&&w>=15&&(l=!1,u=!0);var E=y&&(a||l&&(w==null||w<12.11)),S=e||o&&!r,x=!1,T=!1,ht=N.Pos=function(e,t){if(!(this instanceof ht))return new ht(e,t);this.line=e,this.ch=t},pt=N.cmpPos=function(e,t){return e.line-t.line||e.ch-t.ch};gt.prototype={primary:function(){return this.ranges[this.primIndex]},equals:function(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(var t=0;t<this.ranges.length;t++){var n=this.ranges[t],r=e.ranges[t];if(pt(n.anchor,r.anchor)!=0||pt(n.head,r.head)!=0)return!1}return!0},deepCopy:function(){for(var e=[],t=0;t<this.ranges.length;t++)e[t]=new yt(dt(this.ranges[t].anchor),dt(this.ranges[t].head));return new gt(e,this.primIndex)},somethingSelected:function(){for(var e=0;e<this.ranges.length;e++)if(!this.ranges[e].empty())return!0;return!1},contains:function(e,t){t||(t=e);for(var n=0;n<this.ranges.length;n++){var r=this.ranges[n];if(pt(t,r.from())>=0&&pt(e,r.to())<=0)return n}return-1}},yt.prototype={from:function(){return mt(this.anchor,this.head)},to:function(){return vt(this.anchor,this.head)},empty:function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch}};var rn={left:0,right:0,top:0,bottom:0},bn,Sn=0,Kn,Qn,nr=0,ur=0,ar=null;o?ar=-0.53:e?ar=15:f?ar=-0.7:c&&(ar=-1/3);var hr,vr=null,Er,Tr=N.changeEnd=function(e){return e.text?ht(e.from.line+e.text.length-1,go(e.text).length+(e.text.length==1?e.from.ch:0)):e.to};N.prototype={constructor:N,focus:function(){window.focus(),Un(this),In(this)},setOption:function(e,t){var n=this.options,r=n[e];if(n[e]==t&&e!="mode")return;n[e]=t,Gr.hasOwnProperty(e)&&Cn(this,Gr[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:kn(function(e,t){var n=e.token?e:N.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++,Mn(this)}),removeOverlay:kn(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++,Mn(this);return}}}),indentLine:kn(function(e,t,n){typeof t!="string"&&typeof t!="number"&&(t==null?t=this.options.smartIndent?"smart":"prev":t=t?"add":"subtract"),Tt(this.doc,e)&&Wr(this,e,t,n)}),indentSelection:kn(function(e){var t=this.doc.sel.ranges,n=-1;for(var r=0;r<t.length;r++){var i=t[r];if(!i.empty()){var s=Math.max(n,i.from().line),o=i.to();n=Math.min(this.lastLine(),o.line-(o.ch?0:1))+1;for(var u=s;u<n;++u)Wr(this,u,e)}else i.head.line>n&&(Wr(this,i.head.line,e,!0),n=i.head.line,r==this.doc.sel.primIndex&&Ur(this))}}),getTokenAt:function(e,t){var n=this.doc;e=St(n,e);var r=Vt(this,e.line,t),i=this.doc.mode,s=Es(n,e.line),o=new pi(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(),type:u||null,state:r}},getTokenTypeAt:function(e){e=St(this.doc,e);var t=Zi(this,Es(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?N.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(!ii.hasOwnProperty(t))return ii;var r=ii[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)&&bo(n,u.val)==-1&&n.push(u.val)}return n},getStateAfter:function(e,t){var n=this.doc;return e=Et(n,e==null?n.first+n.size-1:e),Vt(this,e+1,t)},cursorCoords:function(e,t){var n,r=this.doc.sel.primary();return e==null?n=r.head:typeof e=="object"?n=St(this.doc,e):n=e?r.from():r.to(),dn(this,n,t||"page")},charCoords:function(e,t){return pn(this,St(this.doc,e),t||"page")},coordsChar:function(e,t){return e=hn(this,e,t||"page"),gn(this,e.left,e.top)},lineAtHeight:function(e,t){return e=hn(this,{top:e,left:0},t||"page").top,Cs(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=Es(this.doc,e);return cn(this,i,{top:0,left:0},t||"page").top+(n?this.doc.height-ks(i):0)},defaultTextHeight:function(){return wn(this.display)},defaultCharWidth:function(){return En(this.display)},setGutterMarker:kn(function(e,t,n){return Xr(this,e,"gutter",function(e){var r=e.gutterMarkers||(e.gutterMarkers={});return r[t]=n,!n&&Co(r)&&(e.gutterMarkers=null),!0})}),clearGutter:kn(function(e){var t=this,n=t.doc,r=n.first;n.iter(function(n){n.gutterMarkers&&n.gutterMarkers[e]&&(n.gutterMarkers[e]=null,_n(t,r,"gutter"),Co(n.gutterMarkers)&&(n.gutterMarkers=null)),++r})}),addLineClass:kn(function(e,t,n){return Xr(this,e,"class",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:kn(function(e,t,n){return Xr(this,e,"class",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:kn(function(e,t,n){return $i(this,e,t,n)}),removeLineWidget:function(e){e.clear()},lineInfo:function(e){if(typeof e=="number"){if(!Tt(this.doc,e))return null;var t=e;e=Es(this.doc,e);if(!e)return null}else{var t=Ns(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.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,n,r,i){var s=this.display;e=dn(this,St(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&&Ir(this,u,o,u+t.offsetWidth,o+t.offsetHeight)},triggerOnKeyDown:kn(mr),triggerOnKeyPress:kn(yr),triggerOnKeyUp:kn(gr),execCommand:function(e){if(ui.hasOwnProperty(e))return ui[e](this)},findPosH:function(e,t,n,r){var i=1;t<0&&(i=-1,t=-t);for(var s=0,o=St(this.doc,e);s<t;++s){o=$r(this.doc,o,i,n,r);if(o.hitSide)break}return o},moveH:kn(function(e,t){var n=this;n.extendSelectionsBy(function(r){return n.display.shift||n.doc.extend||r.empty()?$r(n.doc,r.head,e,t,n.options.rtlMoveVisually):e<0?r.from():r.to()},lo)}),deleteH:kn(function(e,t){var n=this.doc.sel,r=this.doc;n.somethingSelected()?r.replaceSelection("",null,"+delete"):Vr(this,function(n){var i=$r(r,n.head,e,t,!1);return e<0?{from:i,to:n.head}:{from:n.head,to:i}})}),findPosV:function(e,t,n,r){var i=1,s=r;t<0&&(i=-1,t=-t);for(var o=0,u=St(this.doc,e);o<t;++o){var a=dn(this,u,"div");s==null?s=a.left:a.left=s,u=Jr(this,a,i,n);if(u.hitSide)break}return u},moveV:kn(function(e,t){var n=this,r=this.doc,i=[],s=!n.display.shift&&!r.extend&&r.sel.somethingSelected();r.extendSelectionsBy(function(o){if(s)return e<0?o.from():o.to();var u=dn(n,o.head,"div");o.goalColumn!=null&&(u.left=o.goalColumn),i.push(u.left);var a=Jr(n,u,e,t);return t=="page"&&o==r.sel.primary()&&Rr(n,null,pn(n,a,"div").top-u.top),a},lo);if(i.length)for(var o=0;o<r.sel.ranges.length;o++)r.sel.ranges[o].goalColumn=i[o]}),toggleOverwrite:function(e){if(e!=null&&e==this.state.overwrite)return;(this.state.overwrite=!this.state.overwrite)?this.display.cursorDiv.className+=" CodeMirror-overwrite":this.display.cursorDiv.className=this.display.cursorDiv.className.replace(" CodeMirror-overwrite",""),Ys(this,"overwriteToggle",this,this.state.overwrite)},hasFocus:function(){return Po()==this.display.input},scrollTo:kn(function(e,t){(e!=null||t!=null)&&zr(this),e!=null&&(this.curOp.scrollLeft=e),t!=null&&(this.curOp.scrollTop=t)}),getScrollInfo:function(){var e=this.display.scroller,t=oo;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-t,width:e.scrollWidth-t,clientHeight:e.clientHeight-t,clientWidth:e.clientWidth-t}},scrollIntoView:kn(function(e,t){e==null?(e={from:this.doc.sel.primary().head,to:null},t==null&&(t=this.options.cursorScrollMargin)):typeof e=="number"?e={from:ht(e,0),to:null}:e.from==null&&(e={from:e,to:null}),e.to||(e.to=e.from),e.margin=t||0;if(e.from.line!=null)zr(this),this.curOp.scrollToPos=e;else{var n=qr(this,Math.min(e.from.left,e.to.left),Math.min(e.from.top,e.to.top)-e.margin,Math.max(e.from.right,e.to.right),Math.max(e.from.bottom,e.to.bottom)+e.margin);this.scrollTo(n.scrollLeft,n.scrollTop)}}),setSize:kn(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&&un(this),this.curOp.forceUpdate=!0,Ys(this,"refresh",this)}),operation:function(e){return Nn(this,e)},refresh:kn(function(){var e=this.display.cachedTextHeight;Mn(this),an(this),this.scrollTo(this.doc.scrollLeft,this.doc.scrollTop),(e==null||Math.abs(e-wn(this.display))>.5)&&M(this),Ys(this,"refresh",this)}),swapDoc:kn(function(e){var t=this.doc;return t.cm=null,ws(this,e),an(this),Rn(this),this.scrollTo(e.scrollLeft,e.scrollTop),to(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}},so(N);var Qr=N.defaults={},Gr=N.optionHandlers={},Zr=N.Init={toString:function(){return"CodeMirror.Init"}};Yr("value","",function(e,t){e.setValue(t)},!0),Yr("mode",null,function(e,t){e.doc.modeOption=t,k(e)},!0),Yr("indentUnit",2,k,!0),Yr("indentWithTabs",!1),Yr("smartIndent",!0),Yr("tabSize",4,function(e){L(e),an(e),Mn(e)},!0),Yr("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),Yr("specialCharPlaceholder",ss,function(e){e.refresh()},!0),Yr("electricChars",!0),Yr("rtlMoveVisually",!b),Yr("wholeLineUpdateBefore",!0),Yr("theme","default",function(e){D(e),P(e)},!0),Yr("keyMap","default",_),Yr("extraKeys",null),Yr("lineWrapping",!1,A,!0),Yr("gutters",[],function(e){F(e.options),P(e)},!0),Yr("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?X(e.display)+"px":"0",e.refresh()},!0),Yr("coverGutterNextToScrollbar",!1,q,!0),Yr("lineNumbers",!1,function(e){F(e.options),P(e)},!0),Yr("firstLineNumber",1,P,!0),Yr("lineNumberFormatter",function(e){return e},P,!0),Yr("showCursorWhenSelecting",!1,It,!0),Yr("resetSelectionOnContextMenu",!0),Yr("readOnly",!1,function(e,t){t=="nocursor"?(wr(e),e.display.input.blur(),e.display.disabled=!0):(e.display.disabled=!1,t||Rn(e))}),Yr("disableInput",!1,function(e,t){t||Rn(e)},!0),Yr("dragDrop",!0),Yr("cursorBlinkRate",530),Yr("cursorScrollMargin",0),Yr("cursorHeight",1),Yr("workTime",100),Yr("workDelay",100),Yr("flattenSpans",!0,L,!0),Yr("addModeClass",!1,L,!0),Yr("pollInterval",100),Yr("undoDepth",200,function(e,t){e.doc.history.undoDepth=t}),Yr("historyEventDelay",1250),Yr("viewportMargin",10,function(e){e.refresh()},!0),Yr("maxHighlightLength",1e4,L,!0),Yr("moveInputWithCursor",!0,function(e,t){t||(e.display.inputDiv.style.top=e.display.inputDiv.style.left=0)}),Yr("tabindex",null,function(e,t){e.display.input.tabIndex=t||""}),Yr("autofocus",null);var ei=N.modes={},ti=N.mimeModes={};N.defineMode=function(e,t){!N.defaults.mode&&e!="null"&&(N.defaults.mode=e);if(arguments.length>2){t.dependencies=[];for(var n=2;n<arguments.length;++n)t.dependencies.push(arguments[n])}ei[e]=t},N.defineMIME=function(e,t){ti[e]=t},N.resolveMode=function(e){if(typeof e=="string"&&ti.hasOwnProperty(e))e=ti[e];else if(e&&typeof e.name=="string"&&ti.hasOwnProperty(e.name)){var t=ti[e.name];typeof t=="string"&&(t={name:t}),e=Eo(t,e),e.name=t.name}else if(typeof e=="string"&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return N.resolveMode("application/xml");return typeof e=="string"?{name:e}:e||{name:"null"}},N.getMode=function(e,t){var t=N.resolveMode(t),n=ei[t.name];if(!n)return N.getMode(e,"text/plain");var r=n(e,t);if(ni.hasOwnProperty(t.name)){var i=ni[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},N.defineMode("null",function(){return{token:function(e){e.skipToEnd()}}}),N.defineMIME("text/plain","null");var ni=N.modeExtensions={};N.extendMode=function(e,t){var n=ni.hasOwnProperty(e)?ni[e]:ni[e]={};So(t,n)},N.defineExtension=function(e,t){N.prototype[e]=t},N.defineDocExtension=function(e,t){ms.prototype[e]=t},N.defineOption=Yr;var ri=[];N.defineInitHook=function(e){ri.push(e)};var ii=N.helpers={};N.registerHelper=function(e,t,n){ii.hasOwnProperty(e)||(ii[e]=N[e]={_global:[]}),ii[e][t]=n},N.registerGlobalHelper=function(e,t,n,r){N.registerHelper(e,t,r),ii[e]._global.push({pred:n,val:r})};var si=N.copyState=function(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},oi=N.startState=function(e,t,n){return e.startState?e.startState(t,n):!0};N.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 ui=N.commands={selectAll:function(e){e.setSelection(ht(e.firstLine(),0),ht(e.lastLine()),ao)},singleSelection:function(e){e.setSelection(e.getCursor("anchor"),e.getCursor("head"),ao)},killLine:function(e){Vr(e,function(t){if(t.empty()){var n=Es(e.doc,t.head.line).text.length;return t.head.ch==n&&t.head.line<e.lastLine()?{from:t.head,to:ht(t.head.line+1,0)}:{from:t.head,to:ht(t.head.line,n)}}return{from:t.from(),to:t.to()}})},deleteLine:function(e){Vr(e,function(t){return{from:ht(t.from().line,0),to:St(e.doc,ht(t.to().line+1,0))}})},delLineLeft:function(e){Vr(e,function(e){return{from:ht(e.from().line,0),to:e.from()}})},undo:function(e){e.undo()},redo:function(e){e.redo()},undoSelection:function(e){e.undoSelection()},redoSelection:function(e){e.redoSelection()},goDocStart:function(e){e.extendSelection(ht(e.firstLine(),0))},goDocEnd:function(e){e.extendSelection(ht(e.lastLine()))},goLineStart:function(e){e.extendSelectionsBy(function(t){return Go(e,t.head.line)},lo)},goLineStartSmart:function(e){e.extendSelectionsBy(function(t){var n=Go(e,t.head.line),r=e.getLineHandle(n.line),i=Ls(r);if(!i||i[0].level==0){var s=Math.max(0,r.text.search(/\S/)),o=t.head.line==n.line&&t.head.ch<=s&&t.head.ch;return ht(n.line,o?0:s)}return n},lo)},goLineEnd:function(e){e.extendSelectionsBy(function(
t){return Yo(e,t.head.line)},lo)},goLineRight:function(e){e.extendSelectionsBy(function(t){var n=e.charCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div")},lo)},goLineLeft:function(e){e.extendSelectionsBy(function(t){var n=e.charCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:n},"div")},lo)},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(" ")},defaultTab:function(e){e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:function(e){Nn(e,function(){var t=e.listSelections();for(var n=0;n<t.length;n++){var r=t[n].head,i=Es(e.doc,r.line).text;r.ch>0&&r.ch<i.length-1&&e.replaceRange(i.charAt(r.ch)+i.charAt(r.ch-1),ht(r.line,r.ch-1),ht(r.line,r.ch+1))}})},newlineAndIndent:function(e){Nn(e,function(){var t=e.listSelections().length;for(var n=0;n<t;n++){var r=e.listSelections()[n];e.replaceRange("\n",r.anchor,r.head,"+input"),e.indentLine(r.from().line+1,null,!0),Ur(e)}})},toggleOverwrite:function(e){e.toggleOverwrite()}},ai=N.keyMap={};ai.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",Esc:"singleSelection"},ai.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-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","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},ai.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","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection",fallthrough:["basic","emacsy"]},ai.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"},ai["default"]=y?ai.macDefault:ai.pcDefault;var li=N.lookupKey=function(e,t,n){function r(t){t=fi(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;o<s.length;++o){var u=r(s[o]);if(u)return u}return!1}for(var i=0;i<t.length;++i){var s=r(t[i]);if(s)return s!="stop"}},ci=N.isModifierKey=function(e){var t=Xo[e.keyCode];return t=="Ctrl"||t=="Alt"||t=="Shift"||t=="Mod"},hi=N.keyName=function(e,t){if(l&&e.keyCode==34&&e["char"])return!1;var n=Xo[e.keyCode];if(n==null||e.altGraphKey)return!1;e.altKey&&(n="Alt-"+n);if(E?e.metaKey:e.ctrlKey)n="Ctrl-"+n;if(E?e.ctrlKey:e.metaKey)n="Cmd-"+n;return!t&&e.shiftKey&&(n="Shift-"+n),n};N.fromTextArea=function(e,t){function r(){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=Po();t.autofocus=n==e||e.getAttribute("autofocus")!=null&&n==document.body}if(e.form){Qs(e.form,"submit",r);if(!t.leaveSubmitMethodAlone){var i=e.form,s=i.submit;try{var o=i.submit=function(){r(),i.submit=s,i.submit(),i.submit=o}}catch(u){}}}e.style.display="none";var a=N(function(t){e.parentNode.insertBefore(t,e.nextSibling)},t);return a.save=r,a.getTextArea=function(){return e},a.toTextArea=function(){r(),e.parentNode.removeChild(a.getWrapperElement()),e.style.display="",e.form&&(Gs(e.form,"submit",r),typeof e.form.submit=="function"&&(e.form.submit=s))},a};var pi=N.StringStream=function(e,t){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0};pi.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=ho(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?ho(this.string,this.lineStart,this.tabSize):0)},indentation:function(){return ho(this.string,null,this.tabSize)-(this.lineStart?ho(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}}};var di=N.TextMarker=function(e,t){this.lines=[],this.type=t,this.doc=e};so(di),di.prototype.clear=function(){if(this.explicitlyCleared)return;var e=this.doc.cm,t=e&&!e.curOp;t&&xn(e);if(io(this,"clear")){var n=this.find();n&&to(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=wi(o.markedSpans,this);e&&!this.collapsed?_n(e,Ns(o),"text"):e&&(u.to!=null&&(i=Ns(o)),u.from!=null&&(r=Ns(o))),o.markedSpans=Ei(o.markedSpans,u),u.from==null&&this.collapsed&&!Ui(this.doc,o)&&e&&Ts(o,wn(e.display))}if(e&&this.collapsed&&!e.options.lineWrapping)for(var s=0;s<this.lines.length;++s){var a=Fi(this.lines[s]),f=B(a);f>e.display.maxLineLength&&(e.display.maxLine=a,e.display.maxLineLength=f,e.display.maxLineChanged=!0)}r!=null&&e&&this.collapsed&&Mn(e,r,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&Bt(e.doc)),e&&to(e,"markerCleared",e,this),t&&Tn(e)},di.prototype.find=function(e,t){e==null&&this.type=="bookmark"&&(e=1);var n,r;for(var i=0;i<this.lines.length;++i){var s=this.lines[i],o=wi(s.markedSpans,this);if(o.from!=null){n=ht(t?s:Ns(s),o.from);if(e==-1)return n}if(o.to!=null){r=ht(t?s:Ns(s),o.to);if(e==1)return r}}return n&&{from:n,to:r}},di.prototype.changed=function(){var e=this.find(-1,!0),t=this,n=this.doc.cm;if(!e||!n)return;Nn(n,function(){var r=e.line,i=Ns(e.line),s=en(n,i);s&&(on(s),n.curOp.selectionChanged=n.curOp.forceUpdate=!0),n.curOp.updateMaxLine=!0;if(!Ui(t.doc,r)&&t.height!=null){var o=t.height;t.height=null;var u=Vi(t)-o;u&&Ts(r,r.height+u)}})},di.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(!t.maybeHiddenMarkers||bo(t.maybeHiddenMarkers,this)==-1)&&(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)},di.prototype.detachLine=function(e){this.lines.splice(bo(this.lines,e),1);if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}};var vi=0,gi=N.SharedTextMarker=function(e,t){this.markers=e,this.primary=t;for(var n=0,r=this;n<e.length;++n)e[n].parent=this,Qs(e[n],"clear",function(){r.clear()})};so(gi),gi.prototype.clear=function(){if(this.explicitlyCleared)return;this.explicitlyCleared=!0;for(var e=0;e<this.markers.length;++e)this.markers[e].clear();to(this,"clear")},gi.prototype.find=function(e,t){return this.primary.find(e,t)};var Wi=N.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};so(Wi),Wi.prototype.clear=function(){var e=this.cm,t=this.line.widgets,n=this.line,r=Ns(n);if(r==null||!t)return;for(var i=0;i<t.length;++i)t[i]==this&&t.splice(i--,1);t.length||(n.widgets=null);var s=Vi(this);Nn(e,function(){Xi(e,n,-s),_n(e,r,"widget"),Ts(n,Math.max(0,n.height-s))})},Wi.prototype.changed=function(){var e=this.height,t=this.cm,n=this.line;this.height=null;var r=Vi(this)-e;if(!r)return;Nn(t,function(){t.curOp.forceUpdate=!0,Xi(t,n,r),Ts(n,n.height+r)})};var Ji=N.Line=function(e,t,n){this.text=e,Oi(this,t),this.height=n?n(this):1};so(Ji),Ji.prototype.lineNo=function(){return Ns(this)};var ts={},ns={};ps.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,Qi(i),to(i,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,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;r<t.length;++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}},ds.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&&(this.children.length>1||!(this.children[0]instanceof ps))){var u=[];this.collapse(u),this.children=[new ps(u)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t<this.children.length;++t)this.children[t].collapse(e)},insertInner:function(e,t,n){this.size+=t.length,this.height+=n;for(var r=0;r<this.children.length;++r){var i=this.children[r],s=i.chunkSize();if(e<=s){i.insertInner(e,t,n);if(i.lines&&i.lines.length>50){while(i.lines.length>50){var o=i.lines.splice(i.lines.length-25,25),u=new ps(o);i.height-=u.height,this.children.splice(r+1,0,u),u.parent=this}this.maybeSpill()}break}e-=s}},maybeSpill:function(){if(this.children.length<=10)return;var e=this;do{var t=e.children.splice(e.children.length-5,5),n=new ds(t);if(!e.parent){var r=new ds(e.children);r.parent=e,e.children=[r,n],e=r}else{e.size-=n.size,e.height-=n.height;var i=bo(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;r<this.children.length;++r){var i=this.children[r],s=i.chunkSize();if(e<s){var o=Math.min(t,s-e);if(i.iterN(e,o,n))return!0;if((t-=o)==0)break;e=0}else e-=s}}};var vs=0,ms=N.Doc=function(e,t,n){if(!(this instanceof ms))return new ms(e,t,n);n==null&&(n=0),ds.call(this,[new ps([new Ji("",null)])]),this.first=n,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.frontier=n;var r=ht(n,0);this.sel=wt(r),this.history=new As(null),this.id=++vs,this.modeOption=t,typeof e=="string"&&(e=Uo(e)),hs(this,{from:r,to:r,text:e}),Dt(this,wt(r),ao)};ms.prototype=Eo(ds.prototype,{constructor:ms,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;r<t.length;++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=xs(this,this.first,this.first+this.size);return e===!1?t:t.join(e||"\n")},setValue:Ln(function(e){var t=ht(this.first,0),n=this.first+this.size-1;Or(this,{from:t,to:ht(n,Es(this,n).text.length),text:Uo(e),origin:"setValue"},!0),Dt(this,wt(t))}),replaceRange:function(e,t,n,r){t=St(this,t),n=n?St(this,n):t,Br(this,e,t,n,r)},getRange:function(e,t,n){var r=Ss(this,St(this,e),St(this,t));return n===!1?r:r.join(n||"\n")},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},getLineHandle:function(e){if(Tt(this,e))return Es(this,e)},getLineNumber:function(e){return Ns(e)},getLineHandleVisualStart:function(e){return typeof e=="number"&&(e=Es(this,e)),Fi(e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return St(this,e)},getCursor:function(e){var t=this.sel.primary(),n;return e==null||e=="head"?n=t.head:e=="anchor"?n=t.anchor:e=="end"||e=="to"||e===!1?n=t.to():n=t.from(),n},listSelections:function(){return this.sel.ranges},somethingSelected:function(){return this.sel.somethingSelected()},setCursor:Ln(function(e,t,n){Ot(this,St(this,typeof e=="number"?ht(e,t||0):e),null,n)}),setSelection:Ln(function(e,t,n){Ot(this,St(this,e),St(this,t||e),n)}),extendSelection:Ln(function(e,t,n){kt(this,St(this,e),t&&St(this,t),n)}),extendSelections:Ln(function(e,t){Lt(this,Nt(this,e,t))}),extendSelectionsBy:Ln(function(e,t){Lt(this,wo(this.sel.ranges,e),t)}),setSelections:Ln(function(e,t,n){if(!e.length)return;for(var r=0,i=[];r<e.length;r++)i[r]=new yt(St(this,e[r].anchor),St(this,e[r].head));t==null&&(t=Math.min(e.length-1,this.sel.primIndex)),Dt(this,bt(i,t),n)}),addSelection:Ln(function(e,t,n){var r=this.sel.ranges.slice(0);r.push(new yt(St(this,e),St(this,t||e))),Dt(this,bt(r,r.length-1),n)}),getSelection:function(e){var t=this.sel.ranges,n;for(var r=0;r<t.length;r++){var i=Ss(this,t[r].from(),t[r].to());n=n?n.concat(i):i}return e===!1?n:n.join(e||"\n")},getSelections:function(e){var t=[],n=this.sel.ranges;for(var r=0;r<n.length;r++){var i=Ss(this,n[r].from(),n[r].to());e!==!1&&(i=i.join(e||"\n")),t[r]=i}return t},replaceSelection:Ln(function(e,t,n){var r=[];for(var i=0;i<this.sel.ranges.length;i++)r[i]=e;this.replaceSelections(r,t,n||"+input")}),replaceSelections:function(e,t,n){var r=[],i=this.sel;for(var s=0;s<i.ranges.length;s++){var o=i.ranges[s];r[s]={from:o.from(),to:o.to(),text:Uo(e[s]),origin:n}}var u=t&&t!="end"&&Lr(this,r,t);for(var s=r.length-1;s>=0;s--)Or(this,r[s]);u?_t(this,u):this.cm&&Ur(this.cm)},undo:Ln(function(){_r(this,"undo")}),redo:Ln(function(){_r(this,"redo")}),undoSelection:Ln(function(){_r(this,"undo",!0)}),redoSelection:Ln(function(){_r(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){var e=this.history,t=0,n=0;for(var r=0;r<e.done.length;r++)e.done[r].ranges||++t;for(var r=0;r<e.undone.length;r++)e.undone[r].ranges||++n;return{undo:t,redo:n}},clearHistory:function(){this.history=new As(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:qs(this.history.done),undone:qs(this.history.undone)}},setHistory:function(e){var t=this.history=new As(this.history.maxGeneration);t.done=qs(e.done.slice(0),null,!0),t.undone=qs(e.undone.slice(0),null,!0)},markText:function(e,t,n){return mi(this,St(this,e),St(this,t),n,"range")},setBookmark:function(e,t){var n={replacedWith:t&&(t.nodeType==null?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1,shared:t&&t.shared};return e=St(this,e),mi(this,e,e,n,"bookmark")},findMarksAt:function(e){e=St(this,e);var t=[],n=Es(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},findMarks:function(e,t){e=St(this,e),t=St(this,t);var n=[],r=e.line;return this.iter(e.line,t.line+1,function(i){var s=i.markedSpans;if(s)for(var o=0;o<s.length;o++){var u=s[o];r==e.line&&e.ch>u.to||u.from==null&&r!=e.line||r==t.line&&u.from>t.ch||n.push(u.marker.parent||u.marker)}++r}),n},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}),St(this,ht(n,t))},indexFromPos:function(e){e=St(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 ms(xs(this,this.first,this.first+this.size),this.modeOption,this.first);return t.scrollTop=this.scrollTop,t.scrollLeft=this.scrollLeft,t.sel=this.sel,t.extend=!1,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 ms(xs(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 N&&(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];bs(e,function(e){r.push(e.id)},!0),e.history=new As(null),e.history.done=qs(this.history.done,r),e.history.undone=qs(this.history.undone,r)}},iterLinkedDocs:function(e){bs(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm}}),ms.prototype.eachLine=ms.prototype.iter;var gs="iter insert remove copy getEditor".split(" ");for(var ys in ms.prototype)ms.prototype.hasOwnProperty(ys)&&bo(gs,ys)<0&&(N.prototype[ys]=function(e){return function(){return e.apply(this.doc,arguments)}}(ms.prototype[ys]));so(ms);var Ws=N.e_preventDefault=function(e){e.preventDefault?e.preventDefault():e.returnValue=!1},Xs=N.e_stopPropagation=function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},$s=N.e_stop=function(e){Ws(e),Xs(e)},Qs=N.on=function(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)}},Gs=N.off=function(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}}},Ys=N.signal=function(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)},Zs,eo=0,oo=30,uo=N.Pass={toString:function(){return"CodeMirror.Pass"}},ao={scroll:!1},fo={origin:"*mouse"},lo={origin:"+move"};co.prototype.set=function(e,t){clearTimeout(this.id),this.id=setTimeout(t,e)};var ho=N.countColumn=function(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;;){var u=e.indexOf(" ",s);if(u<0||u>=t)return o+(t-s);o+=u-s,o+=n-o%n,s=u+1}},vo=[""],yo=function(e){e.select()};m?yo=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:o&&(yo=function(e){try{e.select()}catch(t){}}),[].indexOf&&(bo=function(e,t){return e.indexOf(t)}),[].map&&(wo=function(e,t){return e.map(t)});var To=/[\u00df\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,No=N.isWordChar=function(e){return/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||To.test(e))},ko=/[\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]/,Oo;document.createRange?Oo=function(e,t,n){var r=document.createRange();return r.setEnd(e,n),r.setStart(e,t),r}:Oo=function(e,t,n){var r=document.body.createTextRange();return r.moveToElementText(e.parentNode),r.collapse(!0),r.moveEnd("character",n),r.moveStart("character",t),r},t&&(Po=function(){try{return document.activeElement}catch(e){return document.body}});var Ho=function(){if(r)return!1;var e=Ao("div");return"draggable"in e||"dragDrop"in e}(),Bo,Fo,qo,Uo=N.splitLines="\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/)},zo=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},Wo=function(){var e=Ao("div");return"oncopy"in e?!0:(e.setAttribute("oncopy","return;"),typeof e.oncopy=="function")}(),Xo={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"};N.keyNames=Xo,function(){for(var e=0;e<10;e++)Xo[e+48]=Xo[e+96]=String(e);for(var e=65;e<=90;e++)Xo[e]=String.fromCharCode(e);for(var e=1;e<=12;e++)Xo[e+111]=Xo[e+63235]="F"+e}();var eu,su=function(){function n(n){return n<=247?e.charAt(n):1424<=n&&n<=1524?"R":1536<=n&&n<=1773?t.charAt(n-1536):1774<=n&&n<=2220?"r":8192<=n&&n<=8203?"w":n==8204?"b":"L"}function f(e,t,n){this.level=e,this.from=t,this.to=n}var e="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",t="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm",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,l=[];for(var c=0,h;c<t;++c)l.push(h=n(e.charCodeAt(c)));for(var c=0,p=a;c<t;++c){var h=l[c];h=="m"?l[c]=p:p=h}for(var c=0,d=a;c<t;++c){var h=l[c];h=="1"&&d=="r"?l[c]="n":s.test(h)&&(d=h,h=="r"&&(l[c]="R"))}for(var c=1,p=l[0];c<t-1;++c){var h=l[c];h=="+"&&p=="1"&&l[c+1]=="1"?l[c]="1":h==","&&p==l[c+1]&&(p=="1"||p=="n")&&(l[c]=p),p=h}for(var c=0;c<t;++c){var h=l[c];if(h==",")l[c]="N";else if(h=="%"){for(var v=c+1;v<t&&l[v]=="%";++v);var m=c&&l[c-1]=="!"||v<t&&l[v]=="1"?"1":"N";for(var g=c;g<v;++g)l[g]=m;c=v-1}}for(var c=0,d=a;c<t;++c){var h=l[c];d=="L"&&h=="1"?l[c]="L":s.test(h)&&(d=h)}for(var c=0;c<t;++c)if(i.test(l[c])){for(var v=c+1;v<t&&i.test(l[v]);++v);var y=(c?l[c-1]:a)=="L",b=(v<t?l[v]:a)=="L",m=y||b?"L":"R";for(var g=c;g<v;++g)l[g]=m;c=v-1}var w=[],E;for(var c=0;c<t;)if(o.test(l[c])){var S=c;for(++c;c<t&&o.test(l[c]);++c);w.push(new f(0,S,c))}else{var x=c,T=w.length;for(++c;c<t&&l[c]!="L";++c);for(var g=x;g<c;)if(u.test(l[g])){x<g&&w.splice(T,0,new f(1,x,g));var N=g;for(++g;g<c&&u.test(l[g]);++g);w.splice(T,0,new f(2,N,g)),x=g}else++g;x<c&&w.splice(T,0,new f(1,x,c))}return w[0].level==1&&(E=e.match(/^\s+/))&&(w[0].from=E[0].length,w.unshift(new f(0,0,E[0].length))),go(w).level==1&&(E=e.match(/\s+$/))&&(go(w).to-=E[0].length,w.push(new f(0,t-E[0].length,t))),w[0].level!=go(w).level&&w.push(new f(w[0].level,t,t)),w}}();return N.version="4.0.3",N});