!function(e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else{if("function"==typeof define&&define.amd)return define([],e);this.CodeMirror=e()}}(function(){"use strict";function e(r,n){if(!(this instanceof e))return new e(r,n);this.options=n=n?Io(n):{},Io(Yl,n,!1),d(n);var i=n.value;"string"==typeof i&&(i=new ys(i,n.mode)),this.doc=i;var o=new e.inputStyles[n.inputStyle](this),l=this.display=new t(r,i,o);l.wrapper.CodeMirror=this,u(this),s(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),n.autofocus&&!Ll&&l.input.focus(),m(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,draggingText:!1,highlight:new ko,keySeq:null,specialChars:null};var a=this;pl&&11>gl&&setTimeout(function(){a.display.input.reset(!0)},20),Gr(this),_o(),br(this),this.curOp.forceUpdate=!0,_i(this,i),n.autofocus&&!Ll||a.hasFocus()?setTimeout(Eo(pn,this),20):gn(this);for(var c in $l)$l.hasOwnProperty(c)&&$l[c](this,n[c],ql);C(this),n.finishInit&&n.finishInit(this);for(var f=0;fgl&&(n.gutters.style.zIndex=-1,n.scroller.style.paddingRight=0),vl||fl&&Ll||(n.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(n.wrapper):e(n.wrapper)),n.viewFrom=n.viewTo=t.first,n.reportedViewFrom=n.reportedViewTo=t.first,n.view=[],n.renderedView=null,n.externalMeasured=null,n.viewOffset=0,n.lastWrapHeight=n.lastWrapWidth=0,n.updateLineNumbers=null,n.nativeBarWidth=n.barHeight=n.barWidth=0,n.scrollbarsClipped=!1,n.lineNumWidth=n.lineNumInnerWidth=n.lineNumChars=null,n.alignWidgets=!1,n.cachedCharWidth=n.cachedTextHeight=n.cachedPaddingH=null,n.maxLine=null,n.maxLineLength=0,n.maxLineChanged=!1,n.wheelDX=n.wheelDY=n.wheelStartX=n.wheelStartY=null,n.shift=!1,n.selForContextMenu=null,n.activeTouch=null,r.init(n)}function r(t){t.doc.mode=e.getMode(t.options,t.doc.modeOption),n(t)}function n(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,Ft(e,100),e.state.modeGen++,e.curOp&&Pr(e)}function i(e){e.options.lineWrapping?(Ks(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(Vs(e.display.wrapper,"CodeMirror-wrap"),h(e)),l(e),Pr(e),lr(e),setTimeout(function(){y(e)},100)}function o(e){var t=mr(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/yr(e.display)-3);return function(i){if(bi(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;lt.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function d(e){var t=Oo(e.gutters,"CodeMirror-linenumbers");-1==t&&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 p(e){var t=e.display,r=t.gutters.offsetWidth,n=Math.round(e.doc.height+Vt(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?r:0,docHeight:n,scrollHeight:n+jt(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:r}}function g(e,t,r){this.cm=r;var n=this.vert=Bo("div",[Bo("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=Bo("div",[Bo("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(n),e(i),Ls(n,"scroll",function(){n.clientHeight&&t(n.scrollTop,"vertical")}),Ls(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedOverlay=!1,pl&&8>gl&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}function v(){}function m(t){t.display.scrollbars&&(t.display.scrollbars.clear(),t.display.scrollbars.addClass&&Vs(t.display.wrapper,t.display.scrollbars.addClass)),t.display.scrollbars=new e.scrollbarModel[t.options.scrollbarStyle](function(e){t.display.wrapper.insertBefore(e,t.display.scrollbarFiller),Ls(e,"mousedown",function(){t.state.focused&&setTimeout(function(){t.display.input.focus()},0)}),e.setAttribute("cm-not-content","true")},function(e,r){"horizontal"==r?tn(t,e):en(t,e)},t),t.display.scrollbars.addClass&&Ks(t.display.wrapper,t.display.scrollbars.addClass)}function y(e,t){t||(t=p(e));var r=e.display.barWidth,n=e.display.barHeight;b(e,t);for(var i=0;4>i&&r!=e.display.barWidth||n!=e.display.barHeight;i++)r!=e.display.barWidth&&e.options.lineWrapping&&O(e),b(e,p(e)),r=e.display.barWidth,n=e.display.barHeight}function b(e,t){var r=e.display,n=r.scrollbars.update(t);r.sizer.style.paddingRight=(r.barWidth=n.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=n.bottom)+"px",n.right&&n.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=n.bottom+"px",r.scrollbarFiller.style.width=n.right+"px"):r.scrollbarFiller.style.display="",n.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=n.bottom+"px",r.gutterFiller.style.width=t.gutterWidth+"px"):r.gutterFiller.style.display=""}function w(e,t,r){var n=r&&null!=r.top?Math.max(0,r.top):e.scroller.scrollTop;n=Math.floor(n-Ut(e));var i=r&&null!=r.bottom?r.bottom:n+e.wrapper.clientHeight,o=Ji(t,n),l=Ji(t,i);if(r&&r.ensure){var s=r.ensure.from.line,a=r.ensure.to.line;o>s?(o=s,l=Ji(t,eo(Yi(t,s))+e.wrapper.clientHeight)):Math.min(a,t.lastLine())>=l&&(o=Ji(t,eo(Yi(t,a))-e.wrapper.clientHeight),l=a)}return{from:o,to:Math.max(l,o+1)}}function x(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=L(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",l=0;l=r.viewFrom&&t.visible.to<=r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&0==Br(e))return!1;C(e)&&(Er(e),t.dims=H(e));var i=n.first+n.size,o=Math.max(t.visible.from-e.options.viewportMargin,n.first),l=Math.min(i,t.visible.to+e.options.viewportMargin);r.viewFroml&&r.viewTo-l<20&&(l=Math.min(i,r.viewTo)),Ol&&(o=mi(e.doc,o),l=yi(e.doc,l));var s=o!=r.viewFrom||l!=r.viewTo||r.lastWrapHeight!=t.wrapperHeight||r.lastWrapWidth!=t.wrapperWidth;Rr(e,o,l),r.viewOffset=eo(Yi(e.doc,r.viewFrom)),e.display.mover.style.top=r.viewOffset+"px";var a=Br(e);if(!s&&0==a&&!t.force&&r.renderedView==r.view&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo))return!1;var u=Vo();return a>4&&(r.lineDiv.style.display="none"),P(e,r.updateLineNumbers,t.dims),a>4&&(r.lineDiv.style.display=""),r.renderedView=r.view,u&&Vo()!=u&&u.offsetHeight&&u.focus(),Go(r.cursorDiv),Go(r.selectionDiv),r.gutters.style.height=0,s&&(r.lastWrapHeight=t.wrapperHeight,r.lastWrapWidth=t.wrapperWidth,Ft(e,400)),r.updateLineNumbers=null,!0}function A(e,t){for(var r=t.viewport,n=!0;(n&&e.options.lineWrapping&&t.oldDisplayWidth!=Xt(e)||(r&&null!=r.top&&(r={top:Math.min(e.doc.height+Vt(e.display)-_t(e),r.top)}),t.visible=w(e.display,e.doc,r),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&k(e,t);n=!1){O(e);var i=p(e);Ht(e),W(e,i),y(e,i)}t.signal(e,"update",e),(e.display.viewFrom!=e.display.reportedViewFrom||e.display.viewTo!=e.display.reportedViewTo)&&(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function N(e,t){var r=new T(e,t);if(k(e,r)){O(e),A(e,r);var n=p(e);Ht(e),W(e,n),y(e,n),r.finish()}}function W(e,t){e.display.sizer.style.minHeight=t.docHeight+"px";var r=t.docHeight+e.display.barHeight;e.display.heightForcer.style.top=r+"px",e.display.gutters.style.height=Math.max(r+jt(e),t.clientHeight)+"px"}function O(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;ngl){var l=o.node.offsetTop+o.node.offsetHeight;i=l-r,r=l}else{var s=o.node.getBoundingClientRect();i=s.bottom-s.top}var a=o.line.height-i;if(2>i&&(i=mr(t)),(a>.001||-.001>a)&&(Zi(o.line,i),D(o.line),o.rest))for(var u=0;u=t&&f.lineNumber;f.changes&&(Oo(f.changes,"gutter")>-1&&(h=!1),I(e,f,u,r)),h&&(Go(f.lineNumber),f.lineNumber.appendChild(document.createTextNode(S(e.options,u)))),s=f.node.nextSibling}else{var d=V(e,f,u,r);l.insertBefore(d,s)}u+=f.size}for(;s;)s=n(s)}function I(e,t,r,n){for(var i=0;igl&&(e.node.style.zIndex=2)),e.node}function z(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var r=E(e);e.background=r.insertBefore(Bo("div",null,t),r.firstChild)}}function F(e,t){var r=e.display.externalMeasured;return r&&r.line==t.line?(e.display.externalMeasured=null,t.measure=r.measure,r.built):Ii(e,t)}function R(e,t){var r=t.text.className,n=F(e,t);t.text==t.node&&(t.node=n.pre),t.text.parentNode.replaceChild(n.pre,t.text),t.text=n.pre,n.bgClass!=t.bgClass||n.textClass!=t.textClass?(t.bgClass=n.bgClass,t.textClass=n.textClass,B(t)):r&&(t.text.className=r)}function B(e){z(e),e.line.wrapClass?E(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 G(e,t,r,n){t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null);var i=t.line.gutterMarkers;if(e.options.lineNumbers||i){var o=E(t),l=t.gutter=Bo("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px; width: "+n.gutterTotalWidth+"px");if(e.display.input.setUneditable(l),o.insertBefore(l,t.text),t.line.gutterClass&&(l.className+=" "+t.line.gutterClass),!e.options.lineNumbers||i&&i["CodeMirror-linenumbers"]||(t.lineNumber=l.appendChild(Bo("div",S(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+n.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),i)for(var s=0;s1&&(Pl&&Pl.join("\n")==t?a=n.ranges.length%Pl.length==0&&Do(Pl,_s):s.length==n.ranges.length&&(a=Do(s,function(e){return[e]})));for(var u=n.ranges.length-1;u>=0;u--){var c=n.ranges[u],f=c.from(),h=c.to();c.empty()&&(r&&r>0?f=Dl(f.line,f.ch-r):e.state.overwrite&&!l&&(h=Dl(h.line,Math.min(Yi(o,h.line).text.length,h.ch+Wo(s).length))));var d=e.curOp.updateInput,p={from:f,to:h,text:a?a[u%a.length]:s,origin:i||(l?"paste":e.state.cutIncoming?"cut":"+input")};Sn(e.doc,p),xo(e,"inputRead",e,p)}t&&!l&&et(e,t),In(e),e.curOp.updateInput=d,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function J(e,t){var r=e.clipboardData&&e.clipboardData.getData("text/plain");return r?(e.preventDefault(),Ar(t,function(){Q(t,r,0,null,"paste")}),!0):void 0}function et(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var r=e.doc.sel,n=r.ranges.length-1;n>=0;n--){var i=r.ranges[n];if(!(i.head.ch>100||n&&r.ranges[n-1].head.line==i.head.line)){var o=e.getModeAt(i.head),l=!1;if(o.electricChars){for(var s=0;s-1){l=zn(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Yi(e.doc,i.head.line).text.slice(0,i.head.ch))&&(l=zn(e,i.head.line,"smart"));l&&xo(e,"electricInput",e,i.head.line)}}}function tt(e){for(var t=[],r=[],n=0;ni?u.map:c[i],l=0;li?e.line:e.rest[i]),f=o[l]+n;return(0>n||s!=t)&&(f=o[l+(n?1:0)]),Dl(a,f)}}}var i=e.text.firstChild,o=!1;if(!t||!Bs(i,t))return st(Dl(Qi(e.line),0),!0);if(t==i&&(o=!0,t=i.childNodes[r],r=0,!t)){var l=e.rest?Wo(e.rest):e.line;return st(Dl(Qi(l),l.text.length),o)}var s=3==t.nodeType?t:null,a=t;for(s||1!=t.childNodes.length||3!=t.firstChild.nodeType||(s=t.firstChild,r&&(r=s.nodeValue.length));a.parentNode!=i;)a=a.parentNode;var u=e.measure,c=u.maps,f=n(s,a,r);if(f)return st(f,o);for(var h=a.nextSibling,d=s?s.nodeValue.length-r:0;h;h=h.nextSibling){if(f=n(h,h.firstChild,0))return st(Dl(f.line,f.ch-d),o);d+=h.textContent.length}for(var p=a.previousSibling,d=r;p;p=p.previousSibling){if(f=n(p,p.firstChild,-1))return st(Dl(f.line,f.ch+d),o);d+=h.textContent.length}}function ct(e,t,r,n,i){function o(e){return function(t){return t.id==e}}function l(t){if(1==t.nodeType){var r=t.getAttribute("cm-text");if(null!=r)return""==r&&(r=t.textContent.replace(/\u200b/g,"")),void(s+=r);var u,c=t.getAttribute("cm-marker");if(c){var f=e.findMarks(Dl(n,0),Dl(i+1,0),o(+c));return void(f.length&&(u=f[0].find())&&(s+=$i(e.doc,u.from,u.to).join("\n")))}if("false"==t.getAttribute("contenteditable"))return;for(var h=0;h=0){var l=$(o.from(),i.from()),s=Y(o.to(),i.to()),a=o.empty()?i.from()==i.head:o.from()==o.head;t>=n&&--t,e.splice(--n,2,new ht(a?s:l,a?l:s))}}return new ft(e,t)}function pt(e,t){return new ft([new ht(e,t||e)],0)}function gt(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function vt(e,t){if(t.liner?Dl(r,Yi(e,r).text.length):mt(t,Yi(e,t.line).text.length)}function mt(e,t){var r=e.ch;return null==r||r>t?Dl(e.line,t):0>r?Dl(e.line,0):e}function yt(e,t){return t>=e.first&&t=o.ch:u.to>o.ch))){if(n&&(Ms(c,"beforeCursorEnter"),c.explicitlyCleared)){if(s.markedSpans){--a;continue}break}if(!c.atomic)continue;var f=c.find(0>l?-1:1);if(0==Hl(f,o)&&(f.ch+=l,f.ch<0?f=f.line>e.first?vt(e,Dl(f.line-1)):null:f.ch>s.text.length&&(f=f.linet&&(t=0),t=Math.round(t),n=Math.round(n),s.appendChild(Bo("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(null==r?c-e:r)+"px; height: "+(n-t)+"px"))}function i(t,r,i){function o(r,n){return fr(e,Dl(t,r),"div",f,n)}var s,a,f=Yi(l,t),h=f.text.length;return Qo(to(f),r||0,null==i?h:i,function(e,t,l){var f,d,p,g=o(e,"left");if(e==t)f=g,d=p=g.left;else{if(f=o(t-1,"right"),"rtl"==l){var v=g;g=f,f=v}d=g.left,p=f.right}null==r&&0==e&&(d=u),f.top-g.top>3&&(n(d,g.top,null,g.bottom),d=u,g.bottoma.bottom||f.bottom==a.bottom&&f.right>a.right)&&(a=f),u+1>d&&(d=u),n(d,f.top,p-d,f.bottom)}),{start:s,end:a}}var o=e.display,l=e.doc,s=document.createDocumentFragment(),a=Kt(e.display),u=a.left,c=Math.max(o.sizerWidth,Xt(e)-o.sizer.offsetLeft)-a.right,f=t.from(),h=t.to();if(f.line==h.line)i(f.line,f.ch,h.ch);else{var d=Yi(l,f.line),p=Yi(l,h.line),g=gi(d)==gi(p),v=i(f.line,f.ch,g?d.text.length+1:null).end,m=i(h.line,g?0:null,h.ch).start;g&&(v.top0?t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(r=!r)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function Ft(e,t){e.doc.mode.startState&&e.doc.frontier=e.display.viewTo)){var r=+new Date+e.options.workTime,n=rs(t.mode,Gt(e,t.frontier)),i=[];t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(t.frontier>=e.display.viewFrom){var l=o.styles,s=Oi(e,o,n,!0);o.styles=s.styles;var a=o.styleClasses,u=s.classes;u?o.styleClasses=u:a&&(o.styleClasses=null);for(var c=!l||l.length!=o.styles.length||a!=u&&(!a||!u||a.bgClass!=u.bgClass||a.textClass!=u.textClass),f=0;!c&&fr?(Ft(e,e.options.workDelay),!0):void 0}),i.length&&Ar(e,function(){for(var t=0;tl;--s){if(s<=o.first)return o.first;var a=Yi(o,s-1);if(a.stateAfter&&(!r||s<=o.frontier))return s;var u=Hs(a.text,null,e.options.tabSize);(null==i||n>u)&&(i=s-1,n=u)}return i}function Gt(e,t,r){var n=e.doc,i=e.display;if(!n.mode.startState)return!0;var o=Bt(e,t,r),l=o>n.first&&Yi(n,o-1).stateAfter;return l=l?rs(n.mode,l):ns(n.mode),n.iter(o,t,function(r){Hi(e,r.text,l);var s=o==t-1||o%5==0||o>=i.viewFrom&&o2&&o.push((a.bottom+u.top)/2-r.top)}}o.push(r.bottom-r.top)}}function $t(e,t,r){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var n=0;nr)return{map:e.measure.maps[n],cache:e.measure.caches[n],before:!0}}function qt(e,t){t=gi(t);var r=Qi(t),n=e.display.externalMeasured=new Dr(e.doc,t,r);n.lineN=r;var i=n.built=Ii(e,n);return n.text=i.pre,Uo(e.display.lineMeasure,i.pre),n}function Zt(e,t,r,n){return er(e,Jt(e,t),r,n)}function Qt(e,t){if(t>=e.display.viewFrom&&t=r.lineN&&tt?(i=0,o=1,l="left"):u>t?(i=t-a,o=i+1):(s==e.length-3||t==u&&e[s+3]>t)&&(o=u-a,i=o-1,t>=u&&(l="right")),null!=i){if(n=e[s+2],a==u&&r==(n.insertLeft?"left":"right")&&(l=r),"left"==r&&0==i)for(;s&&e[s-2]==e[s-3]&&e[s-1].insertLeft;)n=e[(s-=3)+2],l="left";if("right"==r&&i==u-a)for(;sc;c++){for(;s&&Ro(t.line.text.charAt(o.coverStart+s));)--s;for(;o.coverStart+agl&&0==s&&a==o.coverEnd-o.coverStart)i=l.parentNode.getBoundingClientRect();else if(pl&&e.options.lineWrapping){var f=Es(l,s,a).getClientRects();i=f.length?f["right"==n?f.length-1:0]:Fl}else i=Es(l,s,a).getBoundingClientRect()||Fl;if(i.left||i.right||0==s)break;a=s,s-=1,u="right"}pl&&11>gl&&(i=nr(e.display.measure,i))}else{s>0&&(u=n="right");var f;i=e.options.lineWrapping&&(f=l.getClientRects()).length>1?f["right"==n?f.length-1:0]:l.getBoundingClientRect()}if(pl&&9>gl&&!s&&(!i||!i.left&&!i.right)){var h=l.parentNode.getClientRects()[0];i=h?{left:h.left,right:h.left+yr(e.display),top:h.top,bottom:h.bottom}:Fl }for(var d=i.top-t.rect.top,p=i.bottom-t.rect.top,g=(d+p)/2,v=t.view.measure.heights,c=0;cr.from?l(e-1):l(e,n)}n=n||Yi(e.doc,t.line),i||(i=Jt(e,n));var a=to(n),u=t.ch;if(!a)return l(u);var c=sl(a,u),f=s(u,c);return null!=Qs&&(f.other=s(u,Qs)),f}function dr(e,t){var r=0,t=vt(e.doc,t);e.options.lineWrapping||(r=yr(e.display)*t.ch);var n=Yi(e.doc,t.line),i=eo(n)+Ut(e.display);return{left:r,right:r,top:i,bottom:i+n.height}}function pr(e,t,r,n){var i=Dl(e,t);return i.xRel=n,r&&(i.outside=!0),i}function gr(e,t,r){var n=e.doc;if(r+=e.display.viewOffset,0>r)return pr(n.first,0,!0,-1);var i=Ji(n,r),o=n.first+n.size-1;if(i>o)return pr(n.first+n.size-1,Yi(n,o).text.length,!0,1);0>t&&(t=0);for(var l=Yi(n,i);;){var s=vr(e,l,i,t,r),a=di(l),u=a&&a.find(0,!0);if(!a||!(s.ch>u.from.ch||s.ch==u.from.ch&&s.xRel>0))return s;i=Qi(l=u.to.line)}}function vr(e,t,r,n,i){function o(n){var i=hr(e,Dl(r,n),"line",t,u);return s=!0,l>i.bottom?i.left-a:lv)return pr(r,d,m,1);for(;;){if(c?d==h||d==ul(t,h,1):1>=d-h){for(var y=p>n||v-n>=n-p?h:d,b=n-(y==h?p:v);Ro(t.text.charAt(y));)++y;var w=pr(r,y,y==h?g:m,-1>b?-1:b>1?1:0);return w}var x=Math.ceil(f/2),C=h+x;if(c){C=h;for(var S=0;x>S;++S)C=ul(t,C,1)}var L=o(C);L>n?(d=C,v=L,(m=s)&&(v+=1e3),f=x):(h=C,p=L,g=s,f-=x)}}function mr(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Il){Il=Bo("pre");for(var t=0;49>t;++t)Il.appendChild(document.createTextNode("x")),Il.appendChild(Bo("br"));Il.appendChild(document.createTextNode("x"))}Uo(e.measure,Il);var r=Il.offsetHeight/50;return r>3&&(e.cachedTextHeight=r),Go(e.measure),r||1}function yr(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=Bo("span","xxxxxxxxxx"),r=Bo("pre",[t]);Uo(e.measure,r);var n=t.getBoundingClientRect(),i=(n.right-n.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function br(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Bl},Rl?Rl.ops.push(e.curOp):e.curOp.ownsGroup=Rl={ops:[e.curOp],delayedCallbacks:[]}}function wr(e){var t=e.delayedCallbacks,r=0;do{for(;r=r.viewTo)||r.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new T(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function Lr(e){e.updatedDisplay=e.mustUpdate&&k(e.cm,e.update)}function Tr(e){var t=e.cm,r=t.display;e.updatedDisplay&&O(t),e.barMeasure=p(t),r.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Zt(t,r.maxLine,r.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(r.scroller.clientWidth,r.sizer.offsetLeft+e.adjustWidthTo+jt(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,r.sizer.offsetLeft+e.adjustWidthTo-Xt(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=r.input.prepareSelection())}function Mr(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLefto;o=n){var l=new Dr(e.doc,Yi(e.doc,o),o);n=o+l.size,i.push(l)}return i}function Pr(e,t,r,n){null==t&&(t=e.doc.first),null==r&&(r=e.doc.first+e.doc.size),n||(n=0);var i=e.display;if(n&&rt)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Ol&&mi(e.doc,t)i.viewFrom?Er(e):(i.viewFrom+=n,i.viewTo+=n);else if(t<=i.viewFrom&&r>=i.viewTo)Er(e);else if(t<=i.viewFrom){var o=Fr(e,r,r+n,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=n):Er(e)}else if(r>=i.viewTo){var o=Fr(e,t,t,-1);o?(i.view=i.view.slice(0,o.index),i.viewTo=o.lineN):Er(e)}else{var l=Fr(e,t,t,-1),s=Fr(e,r,r+n,1);l&&s?(i.view=i.view.slice(0,l.index).concat(Hr(e,l.lineN,s.lineN)).concat(i.view.slice(s.index)),i.viewTo+=n):Er(e)}var a=i.externalMeasured;a&&(r=i.lineN&&t=n.viewTo)){var o=n.view[zr(e,t)];if(null!=o.node){var l=o.changes||(o.changes=[]);-1==Oo(l,r)&&l.push(r)}}}function Er(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function zr(e,t){if(t>=e.display.viewTo)return null;if(t-=e.display.viewFrom,0>t)return null;for(var r=e.display.view,n=0;nt)return n}function Fr(e,t,r,n){var i,o=zr(e,t),l=e.display.view;if(!Ol||r==e.doc.first+e.doc.size)return{index:o,lineN:r};for(var s=0,a=e.display.viewFrom;o>s;s++)a+=l[s].size;if(a!=t){if(n>0){if(o==l.length-1)return null;i=a+l[o].size-t,o++}else i=a-t;t+=i,r+=i}for(;mi(e.doc,r)!=r;){if(o==(0>n?0:l.length-1))return null;r+=n*l[o-(0>n?1:0)].size,o+=n}return{index:o,lineN:r}}function Rr(e,t,r){var n=e.display,i=n.view;0==i.length||t>=n.viewTo||r<=n.viewFrom?(n.view=Hr(e,t,r),n.viewFrom=t):(n.viewFrom>t?n.view=Hr(e,t,n.viewFrom).concat(n.view):n.viewFromr&&(n.view=n.view.slice(0,zr(e,r)))),n.viewTo=r}function Br(e){for(var t=e.display.view,r=0,n=0;n400}var i=e.display;Ls(i.scroller,"mousedown",Nr(e,Xr)),pl&&11>gl?Ls(i.scroller,"dblclick",Nr(e,function(t){if(!So(e,t)){var r=jr(e,t);if(r&&!Zr(e,t)&&!Kr(e.display,t)){xs(t);var n=e.findWordAt(r);xt(e.doc,n.anchor,n.head)}}})):Ls(i.scroller,"dblclick",function(t){So(e,t)||xs(t)}),Nl||Ls(i.scroller,"contextmenu",function(t){vn(e,t)});var o,l={end:0};Ls(i.scroller,"touchstart",function(e){if(!r(e)){clearTimeout(o);var t=+new Date;i.activeTouch={start:t,moved:!1,prev:t-l.end<=300?l:null},1==e.touches.length&&(i.activeTouch.left=e.touches[0].pageX,i.activeTouch.top=e.touches[0].pageY)}}),Ls(i.scroller,"touchmove",function(){i.activeTouch&&(i.activeTouch.moved=!0)}),Ls(i.scroller,"touchend",function(r){var o=i.activeTouch;if(o&&!Kr(i,r)&&null!=o.left&&!o.moved&&new Date-o.start<300){var l,s=e.coordsChar(i.activeTouch,"page");l=!o.prev||n(o,o.prev)?new ht(s,s):!o.prev.prev||n(o,o.prev.prev)?e.findWordAt(s):new ht(Dl(s.line,0),vt(e.doc,Dl(s.line+1,0))),e.setSelection(l.anchor,l.head),e.focus(),xs(r)}t()}),Ls(i.scroller,"touchcancel",t),Ls(i.scroller,"scroll",function(){i.scroller.clientHeight&&(en(e,i.scroller.scrollTop),tn(e,i.scroller.scrollLeft,!0),Ms(e,"scroll",e))}),Ls(i.scroller,"mousewheel",function(t){rn(e,t)}),Ls(i.scroller,"DOMMouseScroll",function(t){rn(e,t)}),Ls(i.wrapper,"scroll",function(){i.wrapper.scrollTop=i.wrapper.scrollLeft=0}),i.dragFunctions={simple:function(t){So(e,t)||Ss(t)},start:function(t){Jr(e,t)},drop:Nr(e,Qr)};var s=i.input.getField();Ls(s,"keyup",function(t){fn.call(e,t)}),Ls(s,"keydown",Nr(e,un)),Ls(s,"keypress",Nr(e,hn)),Ls(s,"focus",Eo(pn,e)),Ls(s,"blur",Eo(gn,e))}function Ur(t,r,n){var i=n&&n!=e.Init;if(!r!=!i){var o=t.display.dragFunctions,l=r?Ls:Ts;l(t.display.scroller,"dragstart",o.start),l(t.display.scroller,"dragenter",o.simple),l(t.display.scroller,"dragover",o.simple),l(t.display.scroller,"drop",o.drop)}}function Vr(e){var t=e.display;(t.lastWrapHeight!=t.wrapper.clientHeight||t.lastWrapWidth!=t.wrapper.clientWidth)&&(t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize())}function Kr(e,t){for(var r=bo(t);r!=e.wrapper;r=r.parentNode)if(!r||1==r.nodeType&&"true"==r.getAttribute("cm-ignore-events")||r.parentNode==e.sizer&&r!=e.mover)return!0}function jr(e,t,r,n){var i=e.display;if(!r&&"true"==bo(t).getAttribute("cm-not-content"))return null;var o,l,s=i.lineSpace.getBoundingClientRect();try{o=t.clientX-s.left,l=t.clientY-s.top}catch(t){return null}var a,u=gr(e,o,l);if(n&&1==u.xRel&&(a=Yi(e.doc,u.line).text).length==u.ch){var c=Hs(a,a.length,e.options.tabSize)-a.length;u=Dl(u.line,Math.max(0,Math.round((o-Kt(e.display).left)/yr(e.display))-c))}return u}function Xr(e){var t=this,r=t.display;if(!(r.activeTouch&&r.input.supportsTouch()||So(t,e))){if(r.shift=e.shiftKey,Kr(r,e))return void(vl||(r.scroller.draggable=!1,setTimeout(function(){r.scroller.draggable=!0},100)));if(!Zr(t,e)){var n=jr(t,e);switch(window.focus(),wo(e)){case 1:n?_r(t,e,n):bo(e)==r.scroller&&xs(e);break;case 2:vl&&(t.state.lastMiddleDown=+new Date),n&&xt(t.doc,n),setTimeout(function(){r.input.focus()},20),xs(e);break;case 3:Nl?vn(t,e):dn(t)}}}}function _r(e,t,r){pl?setTimeout(Eo(q,e),0):e.curOp.focus=Vo();var n,i=+new Date;zl&&zl.time>i-400&&0==Hl(zl.pos,r)?n="triple":El&&El.time>i-400&&0==Hl(El.pos,r)?(n="double",zl={time:i,pos:r}):(n="single",El={time:i,pos:r});var o,l=e.doc.sel,s=Tl?t.metaKey:t.ctrlKey;e.options.dragDrop&&Xs&&!Z(e)&&"single"==n&&(o=l.contains(r))>-1&&(Hl((o=l.ranges[o]).from(),r)<0||r.xRel>0)&&(Hl(o.to(),r)>0||r.xRel<0)?Yr(e,t,r,s):$r(e,t,r,n,s)}function Yr(e,t,r,n){var i=e.display,o=+new Date,l=Nr(e,function(s){vl&&(i.scroller.draggable=!1),e.state.draggingText=!1,Ts(document,"mouseup",l),Ts(i.scroller,"drop",l),Math.abs(t.clientX-s.clientX)+Math.abs(t.clientY-s.clientY)<10&&(xs(s),!n&&+new Date-200=p;p++){var m=Yi(u,p).text,y=Ao(m,a,o);a==d?i.push(new ht(Dl(p,y),Dl(p,y))):m.length>y&&i.push(new ht(Dl(p,y),Dl(p,Ao(m,d,o))))}i.length||i.push(new ht(r,r)),kt(u,dt(h.ranges.slice(0,f).concat(i),f),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var b=c,w=b.anchor,x=t;if("single"!=n){if("double"==n)var C=e.findWordAt(t);else var C=new ht(Dl(t.line,0),vt(u,Dl(t.line+1,0)));Hl(C.anchor,w)>0?(x=C.head,w=$(b.from(),C.anchor)):(x=C.anchor,w=Y(b.to(),C.head))}var i=h.ranges.slice(0);i[f]=new ht(vt(u,w),x),kt(u,dt(i,f),Os)}}function l(t){var r=++y,i=jr(e,t,!0,"rect"==n);if(i)if(0!=Hl(i,v)){e.curOp.focus=Vo(),o(i);var s=w(a,u);(i.line>=s.to||i.linem.bottom?20:0;c&&setTimeout(Nr(e,function(){y==r&&(a.scroller.scrollTop+=c,l(t))}),50)}}function s(e){y=1/0,xs(e),a.input.focus(),Ts(document,"mousemove",b),Ts(document,"mouseup",x),u.history.lastSelOrigin=null}var a=e.display,u=e.doc;xs(t);var c,f,h=u.sel,d=h.ranges;if(i&&!t.shiftKey?(f=u.sel.contains(r),c=f>-1?d[f]:new ht(r,r)):(c=u.sel.primary(),f=u.sel.primIndex),t.altKey)n="rect",i||(c=new ht(r,r)),r=jr(e,t,!0,!0),f=-1;else if("double"==n){var p=e.findWordAt(r);c=e.display.shift||u.extend?wt(u,c,p.anchor,p.head):p}else if("triple"==n){var g=new ht(Dl(r.line,0),vt(u,Dl(r.line+1,0)));c=e.display.shift||u.extend?wt(u,c,g.anchor,g.head):g}else c=wt(u,c,r);i?-1==f?(f=d.length,kt(u,dt(d.concat([c]),f),{scroll:!1,origin:"*mouse"})):d.length>1&&d[f].empty()&&"single"==n&&!t.shiftKey?(kt(u,dt(d.slice(0,f).concat(d.slice(f+1)),0)),h=u.sel):St(u,f,c,Os):(f=0,kt(u,new ft([c],0),Os),h=u.sel);var v=r,m=a.wrapper.getBoundingClientRect(),y=0,b=Nr(e,function(e){wo(e)?l(e):s(e)}),x=Nr(e,s);Ls(document,"mousemove",b),Ls(document,"mouseup",x)}function qr(e,t,r,n,i){try{var o=t.clientX,l=t.clientY}catch(t){return!1}if(o>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;n&&xs(t);var s=e.display,a=s.lineDiv.getBoundingClientRect();if(l>a.bottom||!To(e,r))return yo(t);l-=a.top-s.viewOffset;for(var u=0;u=o){var f=Ji(e.doc,l),h=e.options.gutters[u];return i(e,r,e,f,h,t),yo(t)}}}function Zr(e,t){return qr(e,t,"gutterClick",!0,xo)}function Qr(e){var t=this;if(!So(t,e)&&!Kr(t.display,e)){xs(e),pl&&(Gl=+new Date);var r=jr(t,e,!0),n=e.dataTransfer.files;if(r&&!Z(t))if(n&&n.length&&window.FileReader&&window.File)for(var i=n.length,o=Array(i),l=0,s=function(e,n){var s=new FileReader;s.onload=Nr(t,function(){if(o[n]=s.result,++l==i){r=vt(t.doc,r);var e={from:r,to:r,text:_s(o.join("\n")),origin:"paste"};Sn(t.doc,e),Mt(t.doc,pt(r,_l(e)))}}),s.readAsText(e)},a=0;i>a;++a)s(n[a],a);else{if(t.state.draggingText&&t.doc.sel.contains(r)>-1)return t.state.draggingText(e),void setTimeout(function(){t.display.input.focus()},20);try{var o=e.dataTransfer.getData("Text");if(o){if(t.state.draggingText&&!(Tl?e.altKey:e.ctrlKey))var u=t.listSelections();if(At(t.doc,pt(r,r)),u)for(var a=0;al.clientWidth||i&&l.scrollHeight>l.clientHeight){if(i&&Tl&&vl)e:for(var s=t.target,a=o.view;s!=l;s=s.parentNode)for(var u=0;uc?f=Math.max(0,f+c-50):h=Math.min(e.doc.height,h+c+50),N(e,{top:f,bottom:h})}20>Ul&&(null==o.wheelStartX?(o.wheelStartX=l.scrollLeft,o.wheelStartY=l.scrollTop,o.wheelDX=n,o.wheelDY=i,setTimeout(function(){if(null!=o.wheelStartX){var e=l.scrollLeft-o.wheelStartX,t=l.scrollTop-o.wheelStartY,r=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,r&&(Vl=(Vl*Ul+r)/(Ul+1),++Ul)}},200)):(o.wheelDX+=n,o.wheelDY+=i))}}function nn(e,t,r){if("string"==typeof t&&(t=is[t],!t))return!1;e.display.input.ensurePolled();var n=e.display.shift,i=!1;try{Z(e)&&(e.state.suppressEdits=!0),r&&(e.display.shift=!1),i=t(e)!=Ns}finally{e.display.shift=n,e.state.suppressEdits=!1}return i}function on(e,t,r){for(var n=0;ngl&&27==e.keyCode&&(e.returnValue=!1);var r=e.keyCode;t.display.shift=16==r||e.shiftKey;var n=sn(t,e);bl&&(Xl=n?r:null,!n&&88==r&&!$s&&(Tl?e.metaKey:e.ctrlKey)&&t.replaceSelection("",null,"cut")),18!=r||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||cn(t)}}function cn(e){function t(e){18!=e.keyCode&&e.altKey||(Vs(r,"CodeMirror-crosshair"),Ts(document,"keyup",t),Ts(document,"mouseover",t))}var r=e.display.lineDiv;Ks(r,"CodeMirror-crosshair"),Ls(document,"keyup",t),Ls(document,"mouseover",t)}function fn(e){16==e.keyCode&&(this.doc.sel.shift=!1),So(this,e)}function hn(e){var t=this;if(!(Kr(t.display,e)||So(t,e)||e.ctrlKey&&!e.altKey||Tl&&e.metaKey)){var r=e.keyCode,n=e.charCode;if(bl&&r==Xl)return Xl=null,void xs(e);if(!bl||e.which&&!(e.which<10)||!sn(t,e)){var i=String.fromCharCode(null==n?r:n);an(t,e,i)||t.display.input.onKeyPress(e)}}}function dn(e){e.state.delayingBlurEvent=!0,setTimeout(function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,gn(e))},100)}function pn(e){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(Ms(e,"focus",e),e.state.focused=!0,Ks(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),vl&&setTimeout(function(){e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),zt(e))}function gn(e){e.state.delayingBlurEvent||(e.state.focused&&(Ms(e,"blur",e),e.state.focused=!1,Vs(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150))}function vn(e,t){Kr(e.display,t)||mn(e,t)||e.display.input.onContextMenu(t)}function mn(e,t){return To(e,"gutterContextMenu")?qr(e,t,"gutterContextMenu",!1,Ms):!1}function yn(e,t){if(Hl(e,t.from)<0)return e;if(Hl(e,t.to)<=0)return _l(t);var r=e.line+t.text.length-(t.to.line-t.from.line)-1,n=e.ch;return e.line==t.to.line&&(n+=_l(t).ch-t.to.ch),Dl(r,n)}function bn(e,t){for(var r=[],n=0;n=0;--i)Ln(e,{from:n[i].from,to:n[i].to,text:i?[""]:t.text});else Ln(e,t)}}function Ln(e,t){if(1!=t.text.length||""!=t.text[0]||0!=Hl(t.from,t.to)){var r=bn(e,t);lo(e,t,r,e.cm?e.cm.curOp.id:0/0),kn(e,t,r,ri(e,t));var n=[];Xi(e,function(e,r){r||-1!=Oo(n,e.history)||(mo(e.history,t),n.push(e.history)),kn(e,t,null,ri(e,t))})}}function Tn(e,t,r){if(!e.cm||!e.cm.state.suppressEdits){for(var n,i=e.history,o=e.sel,l="undo"==t?i.done:i.undone,s="undo"==t?i.undone:i.done,a=0;a=0;--a){var f=n.changes[a];if(f.origin=t,c&&!Cn(e,f,!1))return void(l.length=0);u.push(no(e,f));var h=a?bn(e,f):Wo(l);kn(e,f,h,ii(e,f)),!a&&e.cm&&e.cm.scrollIntoView({from:f.from,to:_l(f)});var d=[];Xi(e,function(e,t){t||-1!=Oo(d,e.history)||(mo(e.history,f),d.push(e.history)),kn(e,f,null,ii(e,f))})}}}}function Mn(e,t){if(0!=t&&(e.first+=t,e.sel=new ft(Do(e.sel.ranges,function(e){return new ht(Dl(e.anchor.line+t,e.anchor.ch),Dl(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){Pr(e.cm,e.first,e.first-t,t);for(var r=e.cm.display,n=r.viewFrom;ne.lastLine())){if(t.from.lineo&&(t={from:t.from,to:Dl(o,Yi(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=$i(e,t.from,t.to),r||(r=bn(e,t)),e.cm?An(e.cm,t,n):Vi(e,t,n),At(e,r,Ws)}}function An(e,t,r){var n=e.doc,i=e.display,l=t.from,s=t.to,a=!1,u=l.line;e.options.lineWrapping||(u=Qi(gi(Yi(n,l.line))),n.iter(u,s.line+1,function(e){return e==i.maxLine?(a=!0,!0):void 0})),n.sel.contains(t.from,t.to)>-1&&Lo(e),Vi(n,t,r,o(e)),e.options.lineWrapping||(n.iter(u,l.line+t.text.length,function(e){var t=f(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,a=!1)}),a&&(e.curOp.updateMaxLine=!0)),n.frontier=Math.min(n.frontier,l.line),Ft(e,400);var c=t.text.length-(s.line-l.line)-1;t.full?Pr(e):l.line!=s.line||1!=t.text.length||Ui(e.doc,t)?Pr(e,l.line,s.line+1,c):Ir(e,l.line,"text");var h=To(e,"changes"),d=To(e,"change");if(d||h){var p={from:l,to:s,text:t.text,removed:t.removed,origin:t.origin};d&&xo(e,"change",e,p),h&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(p)}e.display.selForContextMenu=null}function Nn(e,t,r,n,i){if(n||(n=r),Hl(n,r)<0){var o=n;n=r,r=o}"string"==typeof t&&(t=_s(t)),Sn(e,{from:r,to:n,text:t,origin:i})}function Wn(e,t){if(!So(e,"scrollCursorIntoView")){var r=e.display,n=r.sizer.getBoundingClientRect(),i=null;if(t.top+n.top<0?i=!0:t.bottom+n.top>(window.innerHeight||document.documentElement.clientHeight)&&(i=!1),null!=i&&!Cl){var o=Bo("div","​",null,"position: absolute; top: "+(t.top-r.viewOffset-Ut(e.display))+"px; height: "+(t.bottom-t.top+jt(e)+r.barHeight)+"px; left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(o),o.scrollIntoView(i),e.display.lineSpace.removeChild(o)}}}function On(e,t,r,n){null==n&&(n=0);for(var i=0;5>i;i++){var o=!1,l=hr(e,t),s=r&&r!=t?hr(e,r):l,a=Hn(e,Math.min(l.left,s.left),Math.min(l.top,s.top)-n,Math.max(l.left,s.left),Math.max(l.bottom,s.bottom)+n),u=e.doc.scrollTop,c=e.doc.scrollLeft;if(null!=a.scrollTop&&(en(e,a.scrollTop),Math.abs(e.doc.scrollTop-u)>1&&(o=!0)),null!=a.scrollLeft&&(tn(e,a.scrollLeft),Math.abs(e.doc.scrollLeft-c)>1&&(o=!0)),!o)break}return l}function Dn(e,t,r,n,i){var o=Hn(e,t,r,n,i);null!=o.scrollTop&&en(e,o.scrollTop),null!=o.scrollLeft&&tn(e,o.scrollLeft)}function Hn(e,t,r,n,i){var o=e.display,l=mr(e.display);0>r&&(r=0);var s=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:o.scroller.scrollTop,a=_t(e),u={};i-r>a&&(i=r+a);var c=e.doc.height+Vt(o),f=l>r,h=i>c-l;if(s>r)u.scrollTop=f?0:r;else if(i>s+a){var d=Math.min(r,(h?c:i)-a);d!=s&&(u.scrollTop=d)}var p=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:o.scroller.scrollLeft,g=Xt(e)-(e.options.fixedGutter?o.gutters.offsetWidth:0),v=n-t>g;return v&&(n=t+g),10>t?u.scrollLeft=0:p>t?u.scrollLeft=Math.max(0,t-(v?0:10)):n>g+p-3&&(u.scrollLeft=n+(v?0:10)-g),u}function Pn(e,t,r){(null!=t||null!=r)&&En(e),null!=t&&(e.curOp.scrollLeft=(null==e.curOp.scrollLeft?e.doc.scrollLeft:e.curOp.scrollLeft)+t),null!=r&&(e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+r)}function In(e){En(e);var t=e.getCursor(),r=t,n=t;e.options.lineWrapping||(r=t.ch?Dl(t.line,t.ch-1):t,n=Dl(t.line,t.ch+1)),e.curOp.scrollToPos={from:r,to:n,margin:e.options.cursorScrollMargin,isCursor:!0}}function En(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var r=dr(e,t.from),n=dr(e,t.to),i=Hn(e,Math.min(r.left,n.left),Math.min(r.top,n.top)-t.margin,Math.max(r.right,n.right),Math.max(r.bottom,n.bottom)+t.margin);e.scrollTo(i.scrollLeft,i.scrollTop)}}function zn(e,t,r,n){var i,o=e.doc;null==r&&(r="add"),"smart"==r&&(o.mode.indent?i=Gt(e,t):r="prev");var l=e.options.tabSize,s=Yi(o,t),a=Hs(s.text,null,l);s.stateAfter&&(s.stateAfter=null);var u,c=s.text.match(/^\s*/)[0];if(n||/\S/.test(s.text)){if("smart"==r&&(u=o.mode.indent(i,s.text.slice(c.length),s.text),u==Ns||u>150)){if(!n)return;r="prev"}}else u=0,r="not";"prev"==r?u=t>o.first?Hs(Yi(o,t-1).text,null,l):0:"add"==r?u=a+e.options.indentUnit:"subtract"==r?u=a-e.options.indentUnit:"number"==typeof r&&(u=a+r),u=Math.max(0,u);var f="",h=0;if(e.options.indentWithTabs)for(var d=Math.floor(u/l);d;--d)h+=l,f+=" ";if(u>h&&(f+=No(u-h)),f!=c)return Nn(o,f,Dl(t,0),Dl(t,c.length),"+input"),s.stateAfter=null,!0;for(var d=0;d=0;t--)Nn(e.doc,"",n[t].from,n[t].to,"+delete");In(e)})}function Bn(e,t,r,n,i){function o(){var t=s+r;return t=e.first+e.size?f=!1:(s=t,c=Yi(e,t))}function l(e){var t=(i?ul:cl)(c,a,r,!0);if(null==t){if(e||!o())return f=!1;a=i?(0>r?rl:tl)(c):0>r?c.text.length:0}else a=t;return!0}var s=t.line,a=t.ch,u=r,c=Yi(e,s),f=!0;if("char"==n)l();else if("column"==n)l(!0);else if("word"==n||"group"==n)for(var h=null,d="group"==n,p=e.cm&&e.cm.getHelper(t,"wordChars"),g=!0;!(0>r)||l(!g);g=!1){var v=c.text.charAt(a)||"\n",m=zo(v,p)?"w":d&&"\n"==v?"n":!d||/\s/.test(v)?null:"p";if(!d||g||m||(m="s"),h&&h!=m){0>r&&(r=1,l()); break}if(m&&(h=m),r>0&&!l(!g))break}var y=Dt(e,Dl(s,a),u,!0);return f||(y.hitSide=!0),y}function Gn(e,t,r,n){var i,o=e.doc,l=t.left;if("page"==n){var s=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight);i=t.top+r*(s-(0>r?1.5:.5)*mr(e.display))}else"line"==n&&(i=r>0?t.bottom+3:t.top-3);for(;;){var a=gr(e,l,i);if(!a.outside)break;if(0>r?0>=i:i>=o.height){a.hitSide=!0;break}i+=5*r}return a}function Un(t,r,n,i){e.defaults[t]=r,n&&($l[t]=i?function(e,t,r){r!=ql&&n(e,t,r)}:n)}function Vn(e){for(var t,r,n,i,o=e.split(/-(?!$)/),e=o[o.length-1],l=0;l0||0==l&&o.clearWhenEmpty!==!1)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=Bo("span",[o.replacedWith],"CodeMirror-widget"),n.handleMouseEvents||o.widgetNode.setAttribute("cm-ignore-events","true"),n.insertLeft&&(o.widgetNode.insertLeft=!0)),o.collapsed){if(pi(e,t.line,t,r,o)||t.line!=r.line&&pi(e,r.line,t,r,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");Ol=!0}o.addToHistory&&lo(e,{from:t,to:r,origin:"markText"},e.sel,0/0);var s,a=t.line,u=e.cm;if(e.iter(a,r.line+1,function(e){u&&o.collapsed&&!u.options.lineWrapping&&gi(e)==u.display.maxLine&&(s=!0),o.collapsed&&a!=t.line&&Zi(e,0),Jn(e,new qn(o,a==t.line?t.ch:null,a==r.line?r.ch:null)),++a}),o.collapsed&&e.iter(t.line,r.line+1,function(t){bi(e,t)&&Zi(t,0)}),o.clearOnEnter&&Ls(o,"beforeCursorEnter",function(){o.clear()}),o.readOnly&&(Wl=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++cs,o.atomic=!0),u){if(s&&(u.curOp.updateMaxLine=!0),o.collapsed)Pr(u,t.line,r.line+1);else if(o.className||o.title||o.startStyle||o.endStyle||o.css)for(var c=t.line;c<=r.line;c++)Ir(u,c,"text");o.atomic&&Wt(u.doc),xo(u,"markerAdded",u,o)}return o}function Xn(e,t,r,n,i){n=Io(n),n.shared=!1;var o=[jn(e,t,r,n,i)],l=o[0],s=n.widgetNode;return Xi(e,function(e){s&&(n.widgetNode=s.cloneNode(!0)),o.push(jn(e,vt(e,t),vt(e,r),n,i));for(var a=0;a=t:o.to>t);(n||(n=[])).push(new qn(l,o.from,a?null:o.to))}}return n}function ti(e,t,r){if(e)for(var n,i=0;i=t:o.to>t);if(s||o.from==t&&"bookmark"==l.type&&(!r||o.marker.insertLeft)){var a=null==o.from||(l.inclusiveLeft?o.from<=t:o.from0&&s)for(var f=0;ff;++f)p.push(g);p.push(a)}return p}function ni(e){for(var t=0;t0)){var c=[a,1],f=Hl(u.from,s.from),h=Hl(u.to,s.to);(0>f||!l.inclusiveLeft&&!f)&&c.push({from:u.from,to:s.from}),(h>0||!l.inclusiveRight&&!h)&&c.push({from:s.to,to:u.to}),i.splice.apply(i,c),a+=c.length-1}}return i}function li(e){var t=e.markedSpans;if(t){for(var r=0;r=0&&0>=f||0>=c&&f>=0)&&(0>=c&&(Hl(u.to,r)>0||a.marker.inclusiveRight&&i.inclusiveLeft)||c>=0&&(Hl(u.from,n)<0||a.marker.inclusiveLeft&&i.inclusiveRight)))return!0}}}function gi(e){for(var t;t=hi(e);)e=t.find(-1,!0).line;return e}function vi(e){for(var t,r;t=di(e);)e=t.find(1,!0).line,(r||(r=[])).push(e);return r}function mi(e,t){var r=Yi(e,t),n=gi(r);return r==n?t:Qi(n)}function yi(e,t){if(t>e.lastLine())return t;var r,n=Yi(e,t);if(!bi(e,n))return t;for(;r=di(n);)n=r.find(1,!0).line;return Qi(n)+1}function bi(e,t){var r=Ol&&t.markedSpans;if(r)for(var n,i=0;io;o++){i&&(i[0]=e.innerMode(t,n).mode);var l=t.token(r,n);if(r.pos>r.start)return l}throw new Error("Mode "+t.name+" failed to advance stream.")}function Ni(e,t,r,n){function i(e){return{start:f.start,end:f.pos,string:f.current(),type:o||null,state:e?rs(l.mode,c):c}}var o,l=e.doc,s=l.mode;t=vt(l,t);var a,u=Yi(l,t.line),c=Gt(e,t.line,r),f=new us(u.text,e.options.tabSize);for(n&&(a=[]);(n||f.pose.options.maxHighlightLength?(s=!1,l&&Hi(e,t,n,f.pos),f.pos=t.length,a=null):a=Mi(Ai(r,f,n,h),o),h){var d=h[0].name;d&&(a="m-"+(a?d+" "+a:d))}if(!s||c!=a){for(;uu;){var n=i[a];n>e&&i.splice(a,1,e,i[a+1],n),a+=2,u=Math.min(e,n)}if(t)if(s.opaque)i.splice(r,a-r,e,"cm-overlay "+t),a=r+2;else for(;a>r;r+=2){var o=i[r+1];i[r+1]=(o?o+" ":"")+"cm-overlay "+t}},o)}return{styles:i,classes:o.bgClass||o.textClass?o:null}}function Di(e,t,r){if(!t.styles||t.styles[0]!=e.state.modeGen){var n=Oi(e,t,t.stateAfter=Gt(e,Qi(t)));t.styles=n.styles,n.classes?t.styleClasses=n.classes:t.styleClasses&&(t.styleClasses=null),r===e.doc.frontier&&e.doc.frontier++}return t.styles}function Hi(e,t,r,n){var i=e.doc.mode,o=new us(t,e.options.tabSize);for(o.start=o.pos=n||0,""==t&&ki(i,r);!o.eol()&&o.pos<=e.options.maxHighlightLength;)Ai(i,o,r),o.start=o.pos}function Pi(e,t){if(!e||/^\s*$/.test(e))return null;var r=t.addModeClass?vs:gs;return r[e]||(r[e]=e.replace(/\S+/g,"cm-$&"))}function Ii(e,t){var r=Bo("span",null,null,vl?"padding-right: .1px":null),n={pre:Bo("pre",[r]),content:r,col:0,pos:0,cm:e,splitSpaces:(pl||vl)&&e.getOption("lineWrapping")};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var o,l=i?t.rest[i-1]:t.line;n.pos=0,n.addToken=zi,qo(e.display.measure)&&(o=to(l))&&(n.addToken=Ri(n.addToken,o)),n.map=[];var s=t!=e.display.externalMeasured&&Qi(l);Gi(l,n,Di(e,l,s)),l.styleClasses&&(l.styleClasses.bgClass&&(n.bgClass=jo(l.styleClasses.bgClass,n.bgClass||"")),l.styleClasses.textClass&&(n.textClass=jo(l.styleClasses.textClass,n.textClass||""))),0==n.map.length&&n.map.push(0,0,n.content.appendChild($o(e.display.measure))),0==i?(t.measure.map=n.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(n.map),(t.measure.caches||(t.measure.caches=[])).push({}))}return vl&&/\bcm-tab\b/.test(n.content.lastChild.className)&&(n.content.className="cm-tab-wrap-hack"),Ms(e,"renderLine",e,t.line,n.pre),n.pre.className&&(n.textClass=jo(n.pre.className,n.textClass||"")),n}function Ei(e){var t=Bo("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function zi(e,t,r,n,i,o,l){if(t){var s=e.splitSpaces?t.replace(/ {3,}/g,Fi):t,a=e.cm.state.specialChars,u=!1;if(a.test(t))for(var c=document.createDocumentFragment(),f=0;;){a.lastIndex=f;var h=a.exec(t),d=h?h.index-f:t.length-f;if(d){var p=document.createTextNode(s.slice(f,f+d));c.appendChild(pl&&9>gl?Bo("span",[p]):p),e.map.push(e.pos,e.pos+d,p),e.col+=d,e.pos+=d}if(!h)break;if(f+=d+1," "==h[0]){var g=e.cm.options.tabSize,v=g-e.col%g,p=c.appendChild(Bo("span",No(v),"cm-tab"));p.setAttribute("role","presentation"),p.setAttribute("cm-text"," "),e.col+=v}else{var p=e.cm.options.specialCharPlaceholder(h[0]);p.setAttribute("cm-text",h[0]),c.appendChild(pl&&9>gl?Bo("span",[p]):p),e.col+=1}e.map.push(e.pos,e.pos+1,p),e.pos++}else{e.col+=t.length;var c=document.createTextNode(s);e.map.push(e.pos,e.pos+t.length,c),pl&&9>gl&&(u=!0),e.pos+=t.length}if(r||n||i||u||l){var m=r||"";n&&(m+=n),i&&(m+=i);var y=Bo("span",[c],m,l);return o&&(y.title=o),e.content.appendChild(y)}e.content.appendChild(c)}}function Fi(e){for(var t=" ",r=0;ru&&h.from<=u)break}if(h.to>=c)return e(r,n,i,o,l,s,a);e(r,n.slice(0,h.to-u),i,o,null,s,a),o=null,n=n.slice(h.to-u),u=h.to}}}function Bi(e,t,r,n){var i=!n&&r.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!n&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",r.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t}function Gi(e,t,r){var n=e.markedSpans,i=e.text,o=0;if(n)for(var l,s,a,u,c,f,h,d=i.length,p=0,g=1,v="",m=0;;){if(m==p){a=u=c=f=s="",h=null,m=1/0;for(var y=[],b=0;bp||x.collapsed&&w.to==p&&w.from==p)?(null!=w.to&&w.to!=p&&m>w.to&&(m=w.to,u=""),x.className&&(a+=" "+x.className),x.css&&(s=x.css),x.startStyle&&w.from==p&&(c+=" "+x.startStyle),x.endStyle&&w.to==m&&(u+=" "+x.endStyle),x.title&&!f&&(f=x.title),x.collapsed&&(!h||ci(h.marker,x)<0)&&(h=w)):w.from>p&&m>w.from&&(m=w.from)}if(h&&(h.from||0)==p){if(Bi(t,(null==h.to?d+1:h.to)-p,h.marker,null==h.from),null==h.to)return;h.to==p&&(h=!1)}if(!h&&y.length)for(var b=0;b=d)break;for(var C=Math.min(d,m);;){if(v){var S=p+v.length;if(!h){var L=S>C?v.slice(0,C-p):v;t.addToken(t,L,l?l+a:a,c,p+L.length==m?u:"",f,s)}if(S>=C){v=v.slice(C-p),p=C;break}p=S,c=""}v=i.slice(o,o=r[g++]),l=Pi(r[g++],t.cm.options)}}else for(var g=1;gr;++r)o.push(new ps(u[r],i(r),n));return o}var s=t.from,a=t.to,u=t.text,c=Yi(e,s.line),f=Yi(e,a.line),h=Wo(u),d=i(u.length-1),p=a.line-s.line;if(t.full)e.insert(0,l(0,u.length)),e.remove(u.length,e.size-u.length);else if(Ui(e,t)){var g=l(0,u.length-1);o(f,f.text,d),p&&e.remove(s.line,p),g.length&&e.insert(s.line,g)}else if(c==f)if(1==u.length)o(c,c.text.slice(0,s.ch)+h+c.text.slice(a.ch),d);else{var g=l(1,u.length-1);g.push(new ps(h+c.text.slice(a.ch),d,n)),o(c,c.text.slice(0,s.ch)+u[0],i(0)),e.insert(s.line+1,g)}else if(1==u.length)o(c,c.text.slice(0,s.ch)+u[0]+f.text.slice(a.ch),i(0)),e.remove(s.line+1,p);else{o(c,c.text.slice(0,s.ch)+u[0],i(0)),o(f,h+f.text.slice(a.ch),d);var g=l(1,u.length-1);p>1&&e.remove(s.line+1,p-1),e.insert(s.line+1,g)}xo(e,"change",e,t)}function Ki(e){this.lines=e,this.parent=null;for(var t=0,r=0;tt||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var r=e;!r.lines;)for(var n=0;;++n){var i=r.children[n],o=i.chunkSize();if(o>t){r=i;break}t-=o}return r.lines[t]}function $i(e,t,r){var n=[],i=t.line;return e.iter(t.line,r.line+1,function(e){var o=e.text;i==r.line&&(o=o.slice(0,r.ch)),i==t.line&&(o=o.slice(t.ch)),n.push(o),++i}),n}function qi(e,t,r){var n=[];return e.iter(t,r,function(e){n.push(e.text)}),n}function Zi(e,t){var r=t-e.height;if(r)for(var n=e;n;n=n.parent)n.height+=r}function Qi(e){if(null==e.parent)return null;for(var t=e.parent,r=Oo(t.lines,e),n=t.parent;n;t=n,n=n.parent)for(var i=0;n.children[i]!=t;++i)r+=n.children[i].chunkSize();return r+t.first}function Ji(e,t){var r=e.first;e:do{for(var n=0;nt){e=i;continue e}t-=o,r+=i.chunkSize()}return r}while(!e.lines);for(var n=0;nt)break;t-=s}return r+n}function eo(e){e=gi(e);for(var t=0,r=e.parent,n=0;n1&&!e.done[e.done.length-2].ranges?(e.done.pop(),Wo(e.done)):void 0}function lo(e,t,r,n){var i=e.history;i.undone.length=0;var o,l=+new Date;if((i.lastOp==n||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&e.cm&&i.lastModTime>l-e.cm.options.historyEventDelay||"*"==t.origin.charAt(0)))&&(o=oo(i,i.lastOp==n))){var s=Wo(o.changes);0==Hl(t.from,t.to)&&0==Hl(t.from,s.to)?s.to=_l(t):o.changes.push(no(e,t))}else{var a=Wo(i.done);for(a&&a.ranges||uo(e.sel,i.done),o={changes:[no(e,t)],generation:i.generation},i.done.push(o);i.done.length>i.undoDepth;)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(r),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=l,i.lastOp=i.lastSelOp=n,i.lastOrigin=i.lastSelOrigin=t.origin,s||Ms(e,"historyAdded")}function so(e,t,r,n){var i=t.charAt(0);return"*"==i||"+"==i&&r.ranges.length==n.ranges.length&&r.somethingSelected()==n.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}function ao(e,t,r,n){var i=e.history,o=n&&n.origin;r==i.lastSelOp||o&&i.lastSelOrigin==o&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==o||so(e,o,Wo(i.done),t))?i.done[i.done.length-1]=t:uo(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=r,n&&n.clearRedo!==!1&&io(i.undone)}function uo(e,t){var r=Wo(t);r&&r.ranges&&r.equals(e)||t.push(e)}function co(e,t,r,n){var i=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,r),Math.min(e.first+e.size,n),function(r){r.markedSpans&&((i||(i=t["spans_"+e.id]={}))[o]=r.markedSpans),++o})}function fo(e){if(!e)return null;for(var t,r=0;r-1&&(Wo(s)[f]=c[f],delete c[f])}}}return i}function go(e,t,r,n){r0}function Mo(e){e.prototype.on=function(e,t){Ls(this,e,t)},e.prototype.off=function(e,t){Ts(this,e,t)}}function ko(){this.id=null}function Ao(e,t,r){for(var n=0,i=0;;){var o=e.indexOf(" ",n);-1==o&&(o=e.length);var l=o-n;if(o==e.length||i+l>=t)return n+Math.min(l,t-i);if(i+=o-n,i+=r-i%r,n=o+1,i>=t)return n}}function No(e){for(;Ps.length<=e;)Ps.push(Wo(Ps)+" ");return Ps[e]}function Wo(e){return e[e.length-1]}function Oo(e,t){for(var r=0;r-1&&Fs(e)?!0:t.test(e):Fs(e)}function Fo(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function Ro(e){return e.charCodeAt(0)>=768&&Rs.test(e)}function Bo(e,t,r,n){var i=document.createElement(e);if(r&&(i.className=r),n&&(i.style.cssText=n),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o0;--t)e.removeChild(e.firstChild);return e}function Uo(e,t){return Go(e).appendChild(t)}function Vo(){return document.activeElement}function Ko(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function jo(e,t){for(var r=e.split(" "),n=0;n2&&!(pl&&8>gl))}var r=Gs?Bo("span","​"):Bo("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return r.setAttribute("cm-text",""),r}function qo(e){if(null!=Us)return Us;var t=Uo(e,document.createTextNode("AخA")),r=Es(t,0,1).getBoundingClientRect();if(!r||r.left==r.right)return!1;var n=Es(t,1,2).getBoundingClientRect();return Us=n.right-r.right<3}function Zo(e){if(null!=qs)return qs;var t=Uo(e,Bo("span","x")),r=t.getBoundingClientRect(),n=Es(t,0,1).getBoundingClientRect();return qs=Math.abs(r.left-n.left)>1}function Qo(e,t,r,n){if(!e)return n(t,r,"ltr");for(var i=!1,o=0;ot||t==r&&l.to==t)&&(n(Math.max(l.from,t),Math.min(l.to,r),1==l.level?"rtl":"ltr"),i=!0)}i||n(t,r,"ltr")}function Jo(e){return e.level%2?e.to:e.from}function el(e){return e.level%2?e.from:e.to}function tl(e){var t=to(e);return t?Jo(t[0]):0}function rl(e){var t=to(e);return t?el(Wo(t)):e.text.length}function nl(e,t){var r=Yi(e.doc,t),n=gi(r);n!=r&&(t=Qi(n));var i=to(n),o=i?i[0].level%2?rl(n):tl(n):0;return Dl(t,o)}function il(e,t){for(var r,n=Yi(e.doc,t);r=di(n);)n=r.find(1,!0).line,t=null;var i=to(n),o=i?i[0].level%2?tl(n):rl(n):n.text.length;return Dl(null==t?Qi(n):t,o)}function ol(e,t){var r=nl(e,t.line),n=Yi(e.doc,r.line),i=to(n);if(!i||0==i[0].level){var o=Math.max(0,n.text.search(/\S/)),l=t.line==r.line&&t.ch<=o&&t.ch;return Dl(r.line,l?0:o)}return r}function ll(e,t,r){var n=e[0].level;return t==n?!0:r==n?!1:r>t}function sl(e,t){Qs=null;for(var r,n=0;nt)return n;if(i.from==t||i.to==t){if(null!=r)return ll(e,i.level,e[r].level)?(i.from!=i.to&&(Qs=r),n):(i.from!=i.to&&(Qs=n),r);r=n}}return r}function al(e,t,r,n){if(!n)return t+r;do t+=r;while(t>0&&Ro(e.text.charAt(t)));return t}function ul(e,t,r,n){var i=to(e);if(!i)return cl(e,t,r,n);for(var o=sl(i,t),l=i[o],s=al(e,t,l.level%2?-r:r,n);;){if(s>l.from&&s0==l.level%2?l.to:l.from);if(l=i[o+=r],!l)return null;s=r>0==l.level%2?al(e,l.to,-1,n):al(e,l.from,1,n)}}function cl(e,t,r,n){var i=t+r;if(n)for(;i>0&&Ro(e.text.charAt(i));)i+=r;return 0>i||i>e.text.length?null:i}var fl=/gecko\/\d/i.test(navigator.userAgent),hl=/MSIE \d/.test(navigator.userAgent),dl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),pl=hl||dl,gl=pl&&(hl?document.documentMode||6:dl[1]),vl=/WebKit\//.test(navigator.userAgent),ml=vl&&/Qt\/\d+\.\d+/.test(navigator.userAgent),yl=/Chrome\//.test(navigator.userAgent),bl=/Opera\//.test(navigator.userAgent),wl=/Apple Computer/.test(navigator.vendor),xl=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),Cl=/PhantomJS/.test(navigator.userAgent),Sl=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),Ll=Sl||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),Tl=Sl||/Mac/.test(navigator.platform),Ml=/win/i.test(navigator.platform),kl=bl&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);kl&&(kl=Number(kl[1])),kl&&kl>=15&&(bl=!1,vl=!0);var Al=Tl&&(ml||bl&&(null==kl||12.11>kl)),Nl=fl||pl&&gl>=9,Wl=!1,Ol=!1;g.prototype=Io({update:function(e){var t=e.scrollWidth>e.clientWidth+1,r=e.scrollHeight>e.clientHeight+1,n=e.nativeBarWidth;if(r){this.vert.style.display="block",this.vert.style.bottom=t?n+"px":"0";var i=e.viewHeight-(t?n:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+i)+"px"}else this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=r?n+"px":"0",this.horiz.style.left=e.barLeft+"px";var o=e.viewWidth-e.barLeft-(r?n:0);this.horiz.firstChild.style.width=e.scrollWidth-e.clientWidth+o+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedOverlay&&e.clientHeight>0&&(0==n&&this.overlayHack(),this.checkedOverlay=!0),{right:r?n:0,bottom:t?n:0}},setScrollLeft:function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e)},setScrollTop:function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e)},overlayHack:function(){var e=Tl&&!xl?"12px":"18px";this.horiz.style.minHeight=this.vert.style.minWidth=e;var t=this,r=function(e){bo(e)!=t.vert&&bo(e)!=t.horiz&&Nr(t.cm,Xr)(e)};Ls(this.vert,"mousedown",r),Ls(this.horiz,"mousedown",r)},clear:function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)}},g.prototype),v.prototype=Io({update:function(){return{bottom:0,right:0}},setScrollLeft:function(){},setScrollTop:function(){},clear:function(){}},v.prototype),e.scrollbarModel={"native":g,"null":v},T.prototype.signal=function(e,t){To(e,t)&&this.events.push(arguments)},T.prototype.finish=function(){for(var e=0;e=9&&r.hasSelection&&(r.hasSelection=null),r.poll()}),Ls(o,"paste",function(e){return J(e,n)?!0:(n.state.pasteIncoming=!0,void r.fastPoll())}),Ls(o,"cut",t),Ls(o,"copy",t),Ls(e.scroller,"paste",function(t){Kr(e,t)||(n.state.pasteIncoming=!0,r.focus())}),Ls(e.lineSpace,"selectstart",function(t){Kr(e,t)||xs(t)}),Ls(o,"compositionstart",function(){var e=n.getCursor("from");r.composing={start:e,range:n.markText(e,n.getCursor("to"),{className:"CodeMirror-composing"})}}),Ls(o,"compositionend",function(){r.composing&&(r.poll(),r.composing.range.clear(),r.composing=null)})},prepareSelection:function(){var e=this.cm,t=e.display,r=e.doc,n=Pt(e);if(e.options.moveInputWithCursor){var i=hr(e,r.sel.primary().head,"div"),o=t.wrapper.getBoundingClientRect(),l=t.lineDiv.getBoundingClientRect();n.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,i.top+l.top-o.top)),n.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,i.left+l.left-o.left))}return n},showSelection:function(e){var t=this.cm,r=t.display;Uo(r.cursorDiv,e.cursors),Uo(r.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},reset:function(e){if(!this.contextMenuPending){var t,r,n=this.cm,i=n.doc;if(n.somethingSelected()){this.prevInput="";var o=i.sel.primary();t=$s&&(o.to().line-o.from().line>100||(r=n.getSelection()).length>1e3);var l=t?"-":r||n.getSelection();this.textarea.value=l,n.state.focused&&Is(this.textarea),pl&&gl>=9&&(this.hasSelection=l)}else e||(this.prevInput=this.textarea.value="",pl&&gl>=9&&(this.hasSelection=null));this.inaccurateSelection=t}},getField:function(){return this.textarea},supportsTouch:function(){return!1},focus:function(){if("nocursor"!=this.cm.options.readOnly&&(!Ll||Vo()!=this.textarea))try{this.textarea.focus() }catch(e){}},blur:function(){this.textarea.blur()},resetPosition:function(){this.wrapper.style.top=this.wrapper.style.left=0},receivedFocus:function(){this.slowPoll()},slowPoll:function(){var e=this;e.pollingFast||e.polling.set(this.cm.options.pollInterval,function(){e.poll(),e.cm.state.focused&&e.slowPoll()})},fastPoll:function(){function e(){var n=r.poll();n||t?(r.pollingFast=!1,r.slowPoll()):(t=!0,r.polling.set(60,e))}var t=!1,r=this;r.pollingFast=!0,r.polling.set(20,e)},poll:function(){var e=this.cm,t=this.textarea,r=this.prevInput;if(this.contextMenuPending||!e.state.focused||Ys(t)&&!r||Z(e)||e.options.disableInput||e.state.keySeq)return!1;var n=t.value;if(n==r&&!e.somethingSelected())return!1;if(pl&&gl>=9&&this.hasSelection===n||Tl&&/[\uf700-\uf7ff]/.test(n))return e.display.input.reset(),!1;if(e.doc.sel==e.display.selForContextMenu){var i=n.charCodeAt(0);if(8203!=i||r||(r="​"),8666==i)return this.reset(),this.cm.execCommand("undo")}for(var o=0,l=Math.min(r.length,n.length);l>o&&r.charCodeAt(o)==n.charCodeAt(o);)++o;var s=this;return Ar(e,function(){Q(e,n.slice(o),r.length-o,null,s.composing?"*compose":null),n.length>1e3||n.indexOf("\n")>-1?t.value=s.prevInput="":s.prevInput=n,s.composing&&(s.composing.range.clear(),s.composing.range=e.markText(s.composing.start,e.getCursor("to"),{className:"CodeMirror-composing"}))}),!0},ensurePolled:function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},onKeyPress:function(){pl&&gl>=9&&(this.hasSelection=null),this.fastPoll()},onContextMenu:function(e){function t(){if(null!=l.selectionStart){var e=i.somethingSelected(),t="​"+(e?l.value:"");l.value="⇚",l.value=t,n.prevInput=e?"":"​",l.selectionStart=1,l.selectionEnd=t.length,o.selForContextMenu=i.doc.sel}}function r(){if(n.contextMenuPending=!1,n.wrapper.style.position="relative",l.style.cssText=c,pl&&9>gl&&o.scrollbars.setScrollTop(o.scroller.scrollTop=a),null!=l.selectionStart){(!pl||pl&&9>gl)&&t();var e=0,r=function(){o.selForContextMenu==i.doc.sel&&0==l.selectionStart&&l.selectionEnd>0&&"​"==n.prevInput?Nr(i,is.selectAll)(i):e++<10?o.detectingSelectAll=setTimeout(r,500):o.input.reset()};o.detectingSelectAll=setTimeout(r,200)}}var n=this,i=n.cm,o=i.display,l=n.textarea,s=jr(i,e),a=o.scroller.scrollTop;if(s&&!bl){var u=i.options.resetSelectionOnContextMenu;u&&-1==i.doc.sel.contains(s)&&Nr(i,kt)(i.doc,pt(s),Ws);var c=l.style.cssText;if(n.wrapper.style.position="absolute",l.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(e.clientY-5)+"px; left: "+(e.clientX-5)+"px; z-index: 1000; background: "+(pl?"rgba(255, 255, 255, .05)":"transparent")+"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",vl)var f=window.scrollY;if(o.input.focus(),vl&&window.scrollTo(null,f),o.input.reset(),i.somethingSelected()||(l.value=n.prevInput=" "),n.contextMenuPending=!0,o.selForContextMenu=i.doc.sel,clearTimeout(o.detectingSelectAll),pl&&gl>=9&&t(),Nl){Ss(e);var h=function(){Ts(window,"mouseup",h),setTimeout(r,20)};Ls(window,"mouseup",h)}else setTimeout(r,50)}},setUneditable:Ho,needsContentAttribute:!1},nt.prototype),ot.prototype=Io({init:function(e){function t(e){if(n.somethingSelected())Pl=n.getSelections(),"cut"==e.type&&n.replaceSelection("",null,"cut");else{if(!n.options.lineWiseCopyCut)return;var t=tt(n);Pl=t.text,"cut"==e.type&&n.operation(function(){n.setSelections(t.ranges,0,Ws),n.replaceSelection("",null,"cut")})}if(e.clipboardData&&!Sl)e.preventDefault(),e.clipboardData.clearData(),e.clipboardData.setData("text/plain",Pl.join("\n"));else{var r=it(),i=r.firstChild;n.display.lineSpace.insertBefore(r,n.display.lineSpace.firstChild),i.value=Pl.join("\n");var o=document.activeElement;Is(i),setTimeout(function(){n.display.lineSpace.removeChild(r),o.focus()},50)}}var r=this,n=r.cm,i=r.div=e.lineDiv;i.contentEditable="true",rt(i),Ls(i,"paste",function(e){J(e,n)}),Ls(i,"compositionstart",function(e){var t=e.data;if(r.composing={sel:n.doc.sel,data:t,startData:t},t){var i=n.doc.sel.primary(),o=n.getLine(i.head.line),l=o.indexOf(t,Math.max(0,i.head.ch-t.length));l>-1&&l<=i.head.ch&&(r.composing.sel=pt(Dl(i.head.line,l),Dl(i.head.line,l+t.length)))}}),Ls(i,"compositionupdate",function(e){r.composing.data=e.data}),Ls(i,"compositionend",function(e){var t=r.composing;t&&(e.data==t.startData||/\u200b/.test(e.data)||(t.data=e.data),setTimeout(function(){t.handled||r.applyComposition(t),r.composing==t&&(r.composing=null)},50))}),Ls(i,"touchstart",function(){r.forceCompositionEnd()}),Ls(i,"input",function(){r.composing||r.pollContent()||Ar(r.cm,function(){Pr(n)})}),Ls(i,"copy",t),Ls(i,"cut",t)},prepareSelection:function(){var e=Pt(this.cm,!1);return e.focus=this.cm.state.focused,e},showSelection:function(e){e&&this.cm.display.view.length&&(e.focus&&this.showPrimarySelection(),this.showMultipleSelections(e))},showPrimarySelection:function(){var e=window.getSelection(),t=this.cm.doc.sel.primary(),r=at(this.cm,e.anchorNode,e.anchorOffset),n=at(this.cm,e.focusNode,e.focusOffset);if(!r||r.bad||!n||n.bad||0!=Hl($(r,n),t.from())||0!=Hl(Y(r,n),t.to())){var i=lt(this.cm,t.from()),o=lt(this.cm,t.to());if(i||o){var l=this.cm.display.view,s=e.rangeCount&&e.getRangeAt(0);if(i){if(!o){var a=l[l.length-1].measure,u=a.maps?a.maps[a.maps.length-1]:a.map;o={node:u[u.length-1],offset:u[u.length-2]-u[u.length-3]}}}else i={node:l[0].measure.map[2],offset:0};try{var c=Es(i.node,i.offset,o.offset,o.node)}catch(f){}c&&(e.removeAllRanges(),e.addRange(c),s&&null==e.anchorNode?e.addRange(s):fl&&this.startGracePeriod()),this.rememberSelection()}}},startGracePeriod:function(){var e=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout(function(){e.gracePeriod=!1,e.selectionChanged()&&e.cm.operation(function(){e.cm.curOp.selectionChanged=!0})},20)},showMultipleSelections:function(e){Uo(this.cm.display.cursorDiv,e.cursors),Uo(this.cm.display.selectionDiv,e.selection)},rememberSelection:function(){var e=window.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset},selectionInEditor:function(){var e=window.getSelection();if(!e.rangeCount)return!1;var t=e.getRangeAt(0).commonAncestorContainer;return Bs(this.div,t)},focus:function(){"nocursor"!=this.cm.options.readOnly&&this.div.focus()},blur:function(){this.div.blur()},getField:function(){return this.div},supportsTouch:function(){return!0},receivedFocus:function(){function e(){t.cm.state.focused&&(t.pollSelection(),t.polling.set(t.cm.options.pollInterval,e))}var t=this;this.selectionInEditor()?this.pollSelection():Ar(this.cm,function(){t.cm.curOp.selectionChanged=!0}),this.polling.set(this.cm.options.pollInterval,e)},selectionChanged:function(){var e=window.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset},pollSelection:function(){if(!this.composing&&!this.gracePeriod&&this.selectionChanged()){var e=window.getSelection(),t=this.cm;this.rememberSelection();var r=at(t,e.anchorNode,e.anchorOffset),n=at(t,e.focusNode,e.focusOffset);r&&n&&Ar(t,function(){kt(t.doc,pt(r,n),Ws),(r.bad||n.bad)&&(t.curOp.selectionChanged=!0)})}},pollContent:function(){var e=this.cm,t=e.display,r=e.doc.sel.primary(),n=r.from(),i=r.to();if(n.linet.viewTo-1)return!1;var o;if(n.line==t.viewFrom||0==(o=zr(e,n.line)))var l=Qi(t.view[0].line),s=t.view[0].node;else var l=Qi(t.view[o].line),s=t.view[o-1].node.nextSibling;var a=zr(e,i.line);if(a==t.view.length-1)var u=t.viewTo-1,c=t.lineDiv.lastChild;else var u=Qi(t.view[a+1].line)-1,c=t.view[a+1].node.previousSibling;for(var f=_s(ct(e,s,c,l,u)),h=$i(e.doc,Dl(l,0),Dl(u,Yi(e.doc,u).text.length));f.length>1&&h.length>1;)if(Wo(f)==Wo(h))f.pop(),h.pop(),u--;else{if(f[0]!=h[0])break;f.shift(),h.shift(),l++}for(var d=0,p=0,g=f[0],v=h[0],m=Math.min(g.length,v.length);m>d&&g.charCodeAt(d)==v.charCodeAt(d);)++d;for(var y=Wo(f),b=Wo(h),w=Math.min(y.length-(1==f.length?d:0),b.length-(1==h.length?d:0));w>p&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)++p;f[f.length-1]=y.slice(0,y.length-p),f[0]=f[0].slice(d);var x=Dl(l,d),C=Dl(u,h.length?Wo(h).length-p:0);return f.length>1||f[0]||Hl(x,C)?(Nn(e.doc,f,x,C,"+input"),!0):void 0},ensurePolled:function(){this.forceCompositionEnd()},reset:function(){this.forceCompositionEnd()},forceCompositionEnd:function(){this.composing&&!this.composing.handled&&(this.applyComposition(this.composing),this.composing.handled=!0,this.div.blur(),this.div.focus())},applyComposition:function(e){e.data&&e.data!=e.startData&&Nr(this.cm,Q)(this.cm,e.data,0,e.sel)},setUneditable:function(e){e.setAttribute("contenteditable","false")},onKeyPress:function(e){e.preventDefault(),Nr(this.cm,Q)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0)},onContextMenu:Ho,resetPosition:Ho,needsContentAttribute:!0},ot.prototype),e.inputStyles={textarea:nt,contenteditable:ot},ft.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=0&&Hl(e,n.to())<=0)return r}return-1}},ht.prototype={from:function(){return $(this.anchor,this.head)},to:function(){return Y(this.anchor,this.head)},empty:function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch}};var Il,El,zl,Fl={left:0,right:0,top:0,bottom:0},Rl=null,Bl=0,Gl=0,Ul=0,Vl=null;pl?Vl=-.53:fl?Vl=15:yl?Vl=-.7:wl&&(Vl=-1/3);var Kl=function(e){var t=e.wheelDeltaX,r=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==r&&e.detail&&e.axis==e.VERTICAL_AXIS?r=e.detail:null==r&&(r=e.wheelDelta),{x:t,y:r}};e.wheelEventPixels=function(e){var t=Kl(e);return t.x*=Vl,t.y*=Vl,t};var jl=new ko,Xl=null,_l=e.changeEnd=function(e){return e.text?Dl(e.from.line+e.text.length-1,Wo(e.text).length+(1==e.text.length?e.from.ch:0)):e.to};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,t){var r=this.options,n=r[e];(r[e]!=t||"mode"==e)&&(r[e]=t,$l.hasOwnProperty(e)&&Nr(this,$l[e])(this,t,n))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](Kn(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,r=0;rr&&(zn(this,i.head.line,e,!0),r=i.head.line,n==this.doc.sel.primIndex&&In(this));else{var o=i.from(),l=i.to(),s=Math.max(r,o.line);r=Math.min(this.lastLine(),l.line-(l.ch?0:1))+1;for(var a=s;r>a;++a)zn(this,a,e);var u=this.doc.sel.ranges;0==o.ch&&t.length==u.length&&u[n].from().ch>0&&St(this.doc,n,new ht(o,u[n].to()),Ws)}}}),getTokenAt:function(e,t){return Ni(this,e,t)},getLineTokens:function(e,t){return Ni(this,Dl(e),t,!0)},getTokenTypeAt:function(e){e=vt(this.doc,e);var t,r=Di(this,Yi(this.doc,e.line)),n=0,i=(r.length-1)/2,o=e.ch;if(0==o)t=r[2];else for(;;){var l=n+i>>1;if((l?r[2*l-1]:0)>=o)i=l;else{if(!(r[2*l+1]s?t:0==s?null:t.slice(0,s-1)},getModeAt:function(t){var r=this.doc.mode;return r.innerMode?e.innerMode(r,this.getTokenAt(t).state).mode:r},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var r=[];if(!ts.hasOwnProperty(t))return r;var n=ts[t],i=this.getModeAt(e);if("string"==typeof i[t])n[i[t]]&&r.push(n[i[t]]);else if(i[t])for(var o=0;oi&&(e=i,n=!0),r=Yi(this.doc,e)}else r=e;return ur(this,r,{top:0,left:0},t||"page").top+(n?this.doc.height-eo(r):0)},defaultTextHeight:function(){return mr(this.display)},defaultCharWidth:function(){return yr(this.display)},setGutterMarker:Wr(function(e,t,r){return Fn(this.doc,e,"gutter",function(e){var n=e.gutterMarkers||(e.gutterMarkers={});return n[t]=r,!r&&Fo(n)&&(e.gutterMarkers=null),!0})}),clearGutter:Wr(function(e){var t=this,r=t.doc,n=r.first;r.iter(function(r){r.gutterMarkers&&r.gutterMarkers[e]&&(r.gutterMarkers[e]=null,Ir(t,n,"gutter"),Fo(r.gutterMarkers)&&(r.gutterMarkers=null)),++n})}),lineInfo:function(e){if("number"==typeof e){if(!yt(this.doc,e))return null;var t=e;if(e=Yi(this.doc,e),!e)return null}else{var t=Qi(e);if(null==t)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,r,n,i){var o=this.display;e=hr(this,vt(this.doc,e));var l=e.bottom,s=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),o.sizer.appendChild(t),"over"==n)l=e.top;else if("above"==n||"near"==n){var a=Math.max(o.wrapper.clientHeight,this.doc.height),u=Math.max(o.sizer.clientWidth,o.lineSpace.clientWidth);("above"==n||e.bottom+t.offsetHeight>a)&&e.top>t.offsetHeight?l=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=a&&(l=e.bottom),s+t.offsetWidth>u&&(s=u-t.offsetWidth)}t.style.top=l+"px",t.style.left=t.style.right="","right"==i?(s=o.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?s=0:"middle"==i&&(s=(o.sizer.clientWidth-t.offsetWidth)/2),t.style.left=s+"px"),r&&Dn(this,s,l,s+t.offsetWidth,l+t.offsetHeight)},triggerOnKeyDown:Wr(un),triggerOnKeyPress:Wr(hn),triggerOnKeyUp:fn,execCommand:function(e){return is.hasOwnProperty(e)?is[e](this):void 0},triggerElectric:Wr(function(e){et(this,e)}),findPosH:function(e,t,r,n){var i=1;0>t&&(i=-1,t=-t);for(var o=0,l=vt(this.doc,e);t>o&&(l=Bn(this.doc,l,i,r,n),!l.hitSide);++o);return l},moveH:Wr(function(e,t){var r=this;r.extendSelectionsBy(function(n){return r.display.shift||r.doc.extend||n.empty()?Bn(r.doc,n.head,e,t,r.options.rtlMoveVisually):0>e?n.from():n.to()},Ds)}),deleteH:Wr(function(e,t){var r=this.doc.sel,n=this.doc;r.somethingSelected()?n.replaceSelection("",null,"+delete"):Rn(this,function(r){var i=Bn(n,r.head,e,t,!1);return 0>e?{from:i,to:r.head}:{from:r.head,to:i}})}),findPosV:function(e,t,r,n){var i=1,o=n;0>t&&(i=-1,t=-t);for(var l=0,s=vt(this.doc,e);t>l;++l){var a=hr(this,s,"div");if(null==o?o=a.left:a.left=o,s=Gn(this,a,i,r),s.hitSide)break}return s},moveV:Wr(function(e,t){var r=this,n=this.doc,i=[],o=!r.display.shift&&!n.extend&&n.sel.somethingSelected();if(n.extendSelectionsBy(function(l){if(o)return 0>e?l.from():l.to();var s=hr(r,l.head,"div");null!=l.goalColumn&&(s.left=l.goalColumn),i.push(s.left);var a=Gn(r,s,e,t);return"page"==t&&l==n.sel.primary()&&Pn(r,null,fr(r,a,"div").top-s.top),a},Ds),i.length)for(var l=0;l0&&s(r.charAt(n-1));)--n;for(;i.5)&&l(this),Ms(this,"refresh",this)}),swapDoc:Wr(function(e){var t=this.doc;return t.cm=null,_i(this,e),lr(this),this.display.input.reset(),this.scrollTo(e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,xo(this,"swapDoc",this,t),t}),getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},Mo(e);var Yl=e.defaults={},$l=e.optionHandlers={},ql=e.Init={toString:function(){return"CodeMirror.Init"}};Un("value","",function(e,t){e.setValue(t)},!0),Un("mode",null,function(e,t){e.doc.modeOption=t,r(e)},!0),Un("indentUnit",2,r,!0),Un("indentWithTabs",!1),Un("smartIndent",!0),Un("tabSize",4,function(e){n(e),lr(e),Pr(e)},!0),Un("specialChars",/[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g,function(t,r,n){t.state.specialChars=new RegExp(r.source+(r.test(" ")?"":"| "),"g"),n!=e.Init&&t.refresh()}),Un("specialCharPlaceholder",Ei,function(e){e.refresh()},!0),Un("electricChars",!0),Un("inputStyle",Ll?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),Un("rtlMoveVisually",!Ml),Un("wholeLineUpdateBefore",!0),Un("theme","default",function(e){s(e),a(e)},!0),Un("keyMap","default",function(t,r,n){var i=Kn(r),o=n!=e.Init&&Kn(n);o&&o.detach&&o.detach(t,i),i.attach&&i.attach(t,o||null)}),Un("extraKeys",null),Un("lineWrapping",!1,i,!0),Un("gutters",[],function(e){d(e.options),a(e)},!0),Un("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?L(e.display)+"px":"0",e.refresh()},!0),Un("coverGutterNextToScrollbar",!1,function(e){y(e)},!0),Un("scrollbarStyle","native",function(e){m(e),y(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),Un("lineNumbers",!1,function(e){d(e.options),a(e)},!0),Un("firstLineNumber",1,a,!0),Un("lineNumberFormatter",function(e){return e},a,!0),Un("showCursorWhenSelecting",!1,Ht,!0),Un("resetSelectionOnContextMenu",!0),Un("lineWiseCopyCut",!0),Un("readOnly",!1,function(e,t){"nocursor"==t?(gn(e),e.display.input.blur(),e.display.disabled=!0):(e.display.disabled=!1,t||e.display.input.reset())}),Un("disableInput",!1,function(e,t){t||e.display.input.reset()},!0),Un("dragDrop",!0,Ur),Un("cursorBlinkRate",530),Un("cursorScrollMargin",0),Un("cursorHeight",1,Ht,!0),Un("singleCursorHeightPerLine",!0,Ht,!0),Un("workTime",100),Un("workDelay",100),Un("flattenSpans",!0,n,!0),Un("addModeClass",!1,n,!0),Un("pollInterval",100),Un("undoDepth",200,function(e,t){e.doc.history.undoDepth=t}),Un("historyEventDelay",1250),Un("viewportMargin",10,function(e){e.refresh()},!0),Un("maxHighlightLength",1e4,n,!0),Un("moveInputWithCursor",!0,function(e,t){t||e.display.input.resetPosition()}),Un("tabindex",null,function(e,t){e.display.input.getField().tabIndex=t||""}),Un("autofocus",null);var Zl=e.modes={},Ql=e.mimeModes={};e.defineMode=function(t,r){e.defaults.mode||"null"==t||(e.defaults.mode=t),arguments.length>2&&(r.dependencies=Array.prototype.slice.call(arguments,2)),Zl[t]=r},e.defineMIME=function(e,t){Ql[e]=t},e.resolveMode=function(t){if("string"==typeof t&&Ql.hasOwnProperty(t))t=Ql[t];else if(t&&"string"==typeof t.name&&Ql.hasOwnProperty(t.name)){var r=Ql[t.name];"string"==typeof r&&(r={name:r}),t=Po(r,t),t.name=r.name}else if("string"==typeof t&&/^[\w\-]+\/[\w\-]+\+xml$/.test(t))return e.resolveMode("application/xml");return"string"==typeof t?{name:t}:t||{name:"null"}},e.getMode=function(t,r){var r=e.resolveMode(r),n=Zl[r.name];if(!n)return e.getMode(t,"text/plain");var i=n(t,r);if(Jl.hasOwnProperty(r.name)){var o=Jl[r.name];for(var l in o)o.hasOwnProperty(l)&&(i.hasOwnProperty(l)&&(i["_"+l]=i[l]),i[l]=o[l])}if(i.name=r.name,r.helperType&&(i.helperType=r.helperType),r.modeProps)for(var l in r.modeProps)i[l]=r.modeProps[l];return i},e.defineMode("null",function(){return{token:function(e){e.skipToEnd()}}}),e.defineMIME("text/plain","null");var Jl=e.modeExtensions={};e.extendMode=function(e,t){var r=Jl.hasOwnProperty(e)?Jl[e]:Jl[e]={};Io(t,r)},e.defineExtension=function(t,r){e.prototype[t]=r},e.defineDocExtension=function(e,t){ys.prototype[e]=t},e.defineOption=Un;var es=[];e.defineInitHook=function(e){es.push(e)};var ts=e.helpers={};e.registerHelper=function(t,r,n){ts.hasOwnProperty(t)||(ts[t]=e[t]={_global:[]}),ts[t][r]=n},e.registerGlobalHelper=function(t,r,n,i){e.registerHelper(t,r,i),ts[t]._global.push({pred:n,val:i})};var rs=e.copyState=function(e,t){if(t===!0)return t;if(e.copyState)return e.copyState(t);var r={};for(var n in t){var i=t[n];i instanceof Array&&(i=i.concat([])),r[n]=i}return r},ns=e.startState=function(e,t,r){return e.startState?e.startState(t,r):!0};e.innerMode=function(e,t){for(;e.innerMode;){var r=e.innerMode(t);if(!r||r.mode==e)break;t=r.state,e=r.mode}return r||{mode:e,state:t}};var is=e.commands={selectAll:function(e){e.setSelection(Dl(e.firstLine(),0),Dl(e.lastLine()),Ws)},singleSelection:function(e){e.setSelection(e.getCursor("anchor"),e.getCursor("head"),Ws)},killLine:function(e){Rn(e,function(t){if(t.empty()){var r=Yi(e.doc,t.head.line).text.length;return t.head.ch==r&&t.head.line0)i=new Dl(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),Dl(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var l=Yi(e.doc,i.line-1).text;l&&e.replaceRange(o.charAt(0)+"\n"+l.charAt(l.length-1),Dl(i.line-1,l.length-1),Dl(i.line,1),"+transpose")}r.push(new ht(i,i))}e.setSelections(r)})},newlineAndIndent:function(e){Ar(e,function(){for(var t=e.listSelections().length,r=0;t>r;r++){var n=e.listSelections()[r];e.replaceRange("\n",n.anchor,n.head,"+input"),e.indentLine(n.from().line+1,null,!0),In(e)}})},toggleOverwrite:function(e){e.toggleOverwrite()}},os=e.keyMap={};os.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"},os.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","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"},os.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"},os.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","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":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},os["default"]=Tl?os.macDefault:os.pcDefault,e.normalizeKeyMap=function(e){var t={};for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];if(/^(name|fallthrough|(de|at)tach)$/.test(r))continue;if("..."==n){delete e[r];continue}for(var i=Do(r.split(" "),Vn),o=0;o=this.string.length},sol:function(){return this.pos==this.lineStart},peek:function(){return this.string.charAt(this.pos)||void 0},next:function(){return this.post},eatSpace:function(){for(var e=this.pos;/[\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);return t>-1?(this.pos=t,!0):void 0},backUp:function(e){this.pos-=e},column:function(){return this.lastColumnPos0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}var i=function(e){return r?e.toLowerCase():e},o=this.string.substr(this.pos,e.length);return i(o)==i(e)?(t!==!1&&(this.pos+=e.length),!0):void 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 cs=0,fs=e.TextMarker=function(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++cs};Mo(fs),fs.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&br(e),To(this,"clear")){var r=this.find();r&&xo(this,"clear",r.from,r.to)}for(var n=null,i=null,o=0;oe.display.maxLineLength&&(e.display.maxLine=a,e.display.maxLineLength=u,e.display.maxLineChanged=!0)}null!=n&&e&&this.collapsed&&Pr(e,n,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&Wt(e.doc)),e&&xo(e,"markerCleared",e,this),t&&xr(e),this.parent&&this.parent.clear()}},fs.prototype.find=function(e,t){null==e&&"bookmark"==this.type&&(e=1);for(var r,n,i=0;ir;++r){var i=this.lines[r];this.height-=i.height,Ti(i),xo(i,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,r){this.height+=r,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var n=0;ne;++e)if(r(this.lines[e]))return!0}},ji.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var r=0;re){var o=Math.min(t,i-e),l=n.height;if(n.removeInner(e,o),this.height-=l-n.height,i==o&&(this.children.splice(r--,1),n.parent=null),0==(t-=o))break;e=0}else e-=i}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof Ki))){var s=[];this.collapse(s),this.children=[new Ki(s)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t=e){if(i.insertInner(e,t,r),i.lines&&i.lines.length>50){for(;i.lines.length>50;){var l=i.lines.splice(i.lines.length-25,25),s=new Ki(l);i.height-=s.height,this.children.splice(n+1,0,s),s.parent=this}this.maybeSpill()}break}e-=o}},maybeSpill:function(){if(!(this.children.length<=10)){var e=this;do{var t=e.children.splice(e.children.length-5,5),r=new ji(t);if(e.parent){e.size-=r.size,e.height-=r.height;var n=Oo(e.parent.children,e);e.parent.children.splice(n+1,0,r)}else{var i=new ji(e.children);i.parent=e,e.children=[i,r],e=i}r.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},iterN:function(e,t,r){for(var n=0;ne){var l=Math.min(t,o-e);if(i.iterN(e,l,r))return!0;if(0==(t-=l))break;e=0}else e-=o}}};var ms=0,ys=e.Doc=function(e,t,r){if(!(this instanceof ys))return new ys(e,t,r);null==r&&(r=0),ji.call(this,[new Ki([new ps("",null)])]),this.first=r,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.frontier=r;var n=Dl(r,0);this.sel=pt(n),this.history=new ro(null),this.id=++ms,this.modeOption=t,"string"==typeof e&&(e=_s(e)),Vi(this,{from:n,to:n,text:e}),kt(this,pt(n),Ws)};ys.prototype=Po(ji.prototype,{constructor:ys,iter:function(e,t,r){r?this.iterN(e-this.first,t-e,r):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var r=0,n=0;n=0;o--)Sn(this,n[o]);s?Mt(this,s):this.cm&&In(this.cm)}),undo:Or(function(){Tn(this,"undo")}),redo:Or(function(){Tn(this,"redo")}),undoSelection:Or(function(){Tn(this,"undo",!0)}),redoSelection:Or(function(){Tn(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,r=0,n=0;n=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t,r){e=vt(this,e),t=vt(this,t);var n=[],i=e.line;return this.iter(e.line,t.line+1,function(o){var l=o.markedSpans;if(l)for(var s=0;sa.to||null==a.from&&i!=e.line||i==t.line&&a.from>t.ch||r&&!r(a.marker)||n.push(a.marker.parent||a.marker)}++i}),n},getAllMarks:function(){var e=[];return this.iter(function(t){var r=t.markedSpans;if(r)for(var n=0;ne?(t=e,!0):(e-=i,void++r)}),vt(this,Dl(r,t))},indexFromPos:function(e){e=vt(this,e);var t=e.ch;return e.linet&&(t=e.from),null!=e.to&&e.tos||s>=t)return l+(t-o);l+=s-o,l+=r-l%r,o=s+1}},Ps=[""],Is=function(e){e.select()};Sl?Is=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:pl&&(Is=function(e){try{e.select()}catch(t){}});var Es,zs=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Fs=e.isWordChar=function(e){return/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||zs.test(e))},Rs=/[\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]/;Es=document.createRange?function(e,t,r,n){var i=document.createRange();return i.setEnd(n||e,r),i.setStart(e,t),i}:function(e,t,r){var n=document.body.createTextRange();try{n.moveToElementText(e.parentNode)}catch(i){return n}return n.collapse(!0),n.moveEnd("character",r),n.moveStart("character",t),n};var Bs=e.contains=function(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do if(11==t.nodeType&&(t=t.host),t==e)return!0;while(t=t.parentNode)};pl&&11>gl&&(Vo=function(){try{return document.activeElement}catch(e){return document.body}});var Gs,Us,Vs=e.rmClass=function(e,t){var r=e.className,n=Ko(t).exec(r);if(n){var i=r.slice(n.index+n[0].length);e.className=r.slice(0,n.index)+(i?n[1]+i:"")}},Ks=e.addClass=function(e,t){var r=e.className;Ko(t).test(r)||(e.className+=(r?" ":"")+t)},js=!1,Xs=function(){if(pl&&9>gl)return!1;var e=Bo("div");return"draggable"in e||"dragDrop"in e}(),_s=e.splitLines=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,r=[],n=e.length;n>=t;){var i=e.indexOf("\n",t);-1==i&&(i=e.length);var o=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),l=o.indexOf("\r");-1!=l?(r.push(o.slice(0,l)),t+=l+1):(r.push(o),t=i+1)}return r}:function(e){return e.split(/\r\n?|\n/)},Ys=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(t){return!1}}:function(e){try{var t=e.ownerDocument.selection.createRange()}catch(r){}return t&&t.parentElement()==e?0!=t.compareEndPoints("StartToEnd",t):!1},$s=function(){var e=Bo("div");return"oncopy"in e?!0:(e.setAttribute("oncopy","return;"),"function"==typeof e.oncopy)}(),qs=null,Zs={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"};e.keyNames=Zs,function(){for(var e=0;10>e;e++)Zs[e+48]=Zs[e+96]=String(e);for(var e=65;90>=e;e++)Zs[e]=String.fromCharCode(e);for(var e=1;12>=e;e++)Zs[e+111]=Zs[e+63235]="F"+e}();var Qs,Js=function(){function e(e){return 247>=e?r.charAt(e):e>=1424&&1524>=e?"R":e>=1536&&1773>=e?n.charAt(e-1536):e>=1774&&2220>=e?"r":e>=8192&&8203>=e?"w":8204==e?"b":"L"}function t(e,t,r){this.level=e,this.from=t,this.to=r}var r="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",n="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm",i=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,o=/[stwN]/,l=/[LRr]/,s=/[Lb1n]/,a=/[1n]/,u="L";return function(r){if(!i.test(r))return!1;for(var n,c=r.length,f=[],h=0;c>h;++h)f.push(n=e(r.charCodeAt(h)));for(var h=0,d=u;c>h;++h){var n=f[h];"m"==n?f[h]=d:d=n}for(var h=0,p=u;c>h;++h){var n=f[h];"1"==n&&"r"==p?f[h]="n":l.test(n)&&(p=n,"r"==n&&(f[h]="R"))}for(var h=1,d=f[0];c-1>h;++h){var n=f[h];"+"==n&&"1"==d&&"1"==f[h+1]?f[h]="1":","!=n||d!=f[h+1]||"1"!=d&&"n"!=d||(f[h]=d),d=n}for(var h=0;c>h;++h){var n=f[h];if(","==n)f[h]="N";else if("%"==n){for(var g=h+1;c>g&&"%"==f[g];++g);for(var v=h&&"!"==f[h-1]||c>g&&"1"==f[g]?"1":"N",m=h;g>m;++m)f[m]=v;h=g-1}}for(var h=0,p=u;c>h;++h){var n=f[h];"L"==p&&"1"==n?f[h]="L":l.test(n)&&(p=n)}for(var h=0;c>h;++h)if(o.test(f[h])){for(var g=h+1;c>g&&o.test(f[g]);++g);for(var y="L"==(h?f[h-1]:u),b="L"==(c>g?f[g]:u),v=y||b?"L":"R",m=h;g>m;++m)f[m]=v;h=g-1}for(var w,x=[],h=0;c>h;)if(s.test(f[h])){var C=h;for(++h;c>h&&s.test(f[h]);++h);x.push(new t(0,C,h))}else{var S=h,L=x.length;for(++h;c>h&&"L"!=f[h];++h);for(var m=S;h>m;)if(a.test(f[m])){m>S&&x.splice(L,0,new t(1,S,m));var T=m;for(++m;h>m&&a.test(f[m]);++m);x.splice(L,0,new t(2,T,m)),S=m}else++m;h>S&&x.splice(L,0,new t(1,S,h))}return 1==x[0].level&&(w=r.match(/^\s+/))&&(x[0].from=w[0].length,x.unshift(new t(0,0,w[0].length))),1==Wo(x).level&&(w=r.match(/\s+$/))&&(Wo(x).to-=w[0].length,x.push(new t(0,c-w[0].length,c))),2==x[0].level&&x.unshift(new t(1,x[0].to,x[0].to)),x[0].level!=Wo(x).level&&x.push(new t(x[0].level,c,c)),x}}();return e.version="5.3.1",e});