!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).CodeMirror=t()}(this,function(){"use strict";var e=navigator.userAgent,s=navigator.platform,m=/gecko\/\d/i.test(e),t=/MSIE \d/.test(e),a=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(e),u=/Edge\/(\d+)/.exec(e),w=t||a||u,v=w&&(t?document.documentMode||6:+(u||a)[1]),x=!u&&/WebKit\//.test(e),t=x&&/Qt\/\d+\.\d+/.test(e),U=!u&&/Chrome\/(\d+)/.exec(e),V=U&&+U[1],K=/Opera\//.test(e),j=/Apple Computer/.test(navigator.vendor),c=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(e),X=/PhantomJS/.test(e),d=j&&(/Mobile\/\w+/.test(e)||2t)return i;o.to==t&&(o.from!=o.to&&"before"==n?r=i:We=i),o.from==t&&(o.from!=o.to&&"before"!=n?r=i:We=i)}return null!=r?r:We}Fe=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,Pe=/[stwN]/,Ee=/[LRr]/,ze=/[Lb1n]/,Ie=/[1n]/;var Fe,Pe,Ee,ze,Ie,Re=function(e,t){var n="ltr"==t?"L":"R";if(0==e.length||"ltr"==t&&!Fe.test(e))return!1;for(var r,i=e.length,o=[],l=0;l=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],o=i.chunkSize();if(t=e.first&&tn?H(n,D(e,n).text.length):(e=D(e,(n=t).line).text.length,null==(t=n.ch)||e=this.string.length},g.prototype.sol=function(){return this.pos==this.lineStart},g.prototype.peek=function(){return this.string.charAt(this.pos)||void 0},g.prototype.next=function(){if(this.post},g.prototype.eatSpace=function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},g.prototype.skipToEnd=function(){this.pos=this.string.length},g.prototype.skipTo=function(e){e=this.string.indexOf(e,this.pos);if(-1e.options.maxHighlightLength&&ht(e.doc.mode,r.state),o=Nt(e,t,r),i&&(r.state=i),t.stateAfter=r.save(!i),t.styles=o.styles,o.classes?t.styleClasses=o.classes:t.styleClasses&&(t.styleClasses=null),n===e.doc.highlightFrontier&&(e.doc.modeFrontier=Math.max(e.doc.modeFrontier,++e.doc.highlightFrontier))),t.styles}function At(n,r,e){var t,i,o,l=n.doc,s=n.display;return l.mode.startState?(i=(t=function(e,t,n){for(var r,i,o=e.doc,l=n?-1:t-(e.doc.mode.innerMode?1e3:100),s=t;ll.first&&D(l,t-1).stateAfter,o=i?Mt.fromSaved(l,i,t):new Mt(l,ft(l.mode),t),l.iter(t,r,function(e){Dt(n,e.text,o);var t=o.line;e.stateAfter=t==r-1||t%5==0||t>=s.viewFrom&&tt.start)return o}throw new Error("Mode "+e.name+" failed to advance stream.")}Mt.prototype.lookAhead=function(e){var t=this.doc.getLine(this.line+e);return null!=t&&e>this.maxLookAhead&&(this.maxLookAhead=e),t},Mt.prototype.baseToken=function(e){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=e;)this.baseTokenPos+=2;var t=this.baseTokens[this.baseTokenPos+1];return{type:t&&t.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}},Mt.prototype.nextLine=function(){this.line++,0e.options.maxHighlightLength?(s=!1,l&&Dt(e,t,r,c.pos),c.pos=t.length,null):Et(Ht(n,c,r.state,h),o);if(h&&(d=h[0].name)&&(f="m-"+(f?d+" "+f:d)),!s||u!=f){for(;a=t:l.to>t),(r=r||[]).push(new Bt(s,l.from,o?null:l.to)))}return r}(n,r,o),s=function(e,t,n){var r;if(e)for(var i=0;i=t:l.to>t))&&(l.from!=t||"bookmark"!=s.type||n&&!l.marker.insertLeft)||(o=null==l.from||(s.inclusiveLeft?l.from<=t:l.frome.lastLine())return t;var n,r=D(e,t);if(!nn(e,r))return t;for(;n=Zt(r);)r=n.find(1,!0).line;return W(r)+1}function nn(e,t){var n=Rt&&t.markedSpans;if(n)for(var r,i=0;in.maxLineLength&&(n.maxLineLength=t,n.maxLine=e)})}var sn=function(e,t,n){this.text=e,jt(this,t),this.height=n?n(this):1};sn.prototype.lineNo=function(){return W(this)},Xe(sn);var an={},un={};function cn(e,t){return!e||/^\s*$/.test(e)?null:(t=t.addModeClass?un:an)[e]||(t[e]=e.replace(/\S+/g,"cm-$&"))}function hn(e,t){var n=te("span",null,null,x?"padding-right: .1px":null),r={pre:te("pre",[n],"CodeMirror-line"),content:n,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:e.getOption("lineWrapping")};t.measure={};for(var i,o,l=0;l<=(t.rest?t.rest.length:0);l++){var s=l?t.rest[l-1]:t.line,a=void 0,u=(r.pos=0,r.addToken=fn,u=e.display.measure,o=i=void 0,(null!=Je?Je:(o=y(u,document.createTextNode("AخA")),i=oe(o,0,1).getBoundingClientRect(),o=oe(o,1,2).getBoundingClientRect(),ee(u),i&&i.left!=i.right&&(Je=o.right-i.right<3)))&&(a=Ge(s,e.doc.direction))&&(r.addToken=function(h,d){return function(e,t,n,r,i,o,l){n=n?n+" cm-force-border":"cm-force-border";for(var s=e.pos,a=s+t.length;;){for(var u=void 0,c=0;cs&&u.from<=s);c++);if(u.to>=a)return h(e,t,n,r,i,o,l);h(e,t.slice(0,u.to-s),n,r,null,o,l),r=null,t=t.slice(u.to-s),s=u.to}}}(r.addToken,a)),r.map=[],t!=e.display.externalMeasured&&W(s));!function(e,t,n){var r=e.markedSpans,i=e.text,o=0;if(r)for(var l,s,a,u,c,h,d,f=i.length,p=0,g=1,m="",v=0;;){if(v==p){a=u=c=s="",h=d=null,v=1/0;for(var y=[],b=void 0,w=0;wp||C.collapsed&&x.to==p&&x.from==p)){if(null!=x.to&&x.to!=p&&v>x.to&&(v=x.to,u=""),C.className&&(a+=" "+C.className),C.css&&(s=(s?s+";":"")+C.css),C.startStyle&&x.from==p&&(c+=" "+C.startStyle),C.endStyle&&x.to==v&&(b=b||[]).push(C.endStyle,x.to),C.title&&((d=d||{}).title=C.title),C.attributes)for(var S in C.attributes)(d=d||{})[S]=C.attributes[S];C.collapsed&&(!h||$t(h.marker,C)<0)&&(h=x)}else x.from>p&&v>x.from&&(v=x.from)}if(b)for(var L=0;Ln)return{map:e.measure.maps[i],cache:e.measure.caches[i],before:!0}}}function En(e,t,n,r){return Rn(e,In(e,t),n,r)}function zn(e,t){return t>=e.display.viewFrom&&t=e.lineN&&tt)&&(i=(o=a-s)-1,a<=t)&&(l="right"),null!=i){if(r=e[u+2],s==a&&n==(r.insertLeft?"left":"right")&&(l=n),"left"==n&&0==i)for(;u&&e[u-2]==e[u-3]&&e[u-1].insertLeft;)r=e[2+(u-=3)],l="left";if("right"==n&&i==a-s)for(;u=i.text.length?(c=i.text.length,e="before"):c<=0&&(c=0,e="after"),u?(a=He(u,c,e),t=We,a=h(c,a,"before"==e),null!=t&&(a.other=h(c,t,"before"!=e)),a):s("before"==e?c-1:c,"before"==e);function h(e,t,n){return s(n?e-1:e,1==u[t].level!=n)}}function Jn(e,t){var n=0,t=(t=P(e.doc,t),e.options.lineWrapping||(n=ar(e.display)*t.ch),D(e.doc,t.line)),e=rn(t)+On(e.display);return{left:n,right:n,top:e,bottom:e+t.height}}function er(e,t,n,r,i){e=H(e,t,n);return e.xRel=i,r&&(e.outside=r),e}function tr(e,t,n){var r=e.doc;if((n+=e.display.viewOffset)<0)return er(r.first,0,null,-1,-1);var i=vt(r,n),o=r.first+r.size-1;if(o=a.bottom?1:0)}return c=Ae(e.text,c,1),er(t,c,g,f,r-p)}(e,l,i,t,n),a=function(e,t){var n,r=Rt&&e.markedSpans;if(r)for(var i=0;it)&&(!n||$t(n,o.marker)<0)&&(n=o.marker)}return n}(l,s.ch+(0r},i,e)}}function rr(e,t,n,r){return nr(e,t,n=n||In(e,t),_n(e,t,Rn(e,n,r),"line").top)}function ir(e,t,n,r){return!(e.bottom<=n)&&(e.top>n||(r?e.left:e.right)>t)}function or(n,r,i,o,l,s,a){var e,t=De(function(e){var e=l[e],t=1!=e.level;return ir(Qn(n,H(i,t?e.to:e.from,t?"before":"after"),"line",r,o),s,a,!0)},0,l.length-1),u=l[t];return u=0a?l[t-1]:u}function lr(e,t,n,r,i,o,l){for(var l=nr(e,t,r,l),s=l.begin,a=l.end,u=(/\s/.test(t.text.charAt(a-1))&&a--,null),c=null,h=0;h=a||f.to<=s||(d=(d=Rn(e,r,1!=f.level?Math.min(a,f.to)-1:Math.max(s,f.from)).right)a?{from:u.from,to:a,level:u.level}:u}function sr(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Bn){Bn=M("pre",null,"CodeMirror-line-like");for(var t=0;t<49;++t)Bn.appendChild(document.createTextNode("x")),Bn.appendChild(M("br"));Bn.appendChild(document.createTextNode("x"))}y(e.measure,Bn);var n=Bn.offsetHeight/50;return 3=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;for(var n=e.display.view,r=0;rt)&&(o.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=o.viewTo?Rt&&en(e.doc,t)o.viewFrom?mr(e):(o.viewFrom+=r,o.viewTo+=r):t<=o.viewFrom&&n>=o.viewTo?mr(e):t<=o.viewFrom?(l=vr(e,n,n+r,1))?(o.view=o.view.slice(l.index),o.viewFrom=l.lineN,o.viewTo+=r):mr(e):n>=o.viewTo?(l=vr(e,t,t,-1))?(o.view=o.view.slice(0,l.index),o.viewTo=l.lineN):mr(e):(l=vr(e,t,t,-1),i=vr(e,n,n+r,1),l&&i?(o.view=o.view.slice(0,l.index).concat(mn(e,l.lineN,i.lineN)).concat(o.view.slice(i.index)),o.viewTo+=r):mr(e)),o.externalMeasured);l&&(n=i.lineN&&t=r.viewTo||null!=(i=r.view[pr(e,t)]).node&&-1==S(r=i.changes||(i.changes=[]),n)&&r.push(n)}function mr(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function vr(e,t,n,r){var i,o=pr(e,t),l=e.display.view;if(Rt&&n!=e.doc.first+e.doc.size){for(var s=e.display.viewFrom,a=0;a=e.display.viewTo||s.to().linet||t==n&&l.to==t)&&(r(Math.max(l.from,t),Math.min(l.to,n),1==l.level?"rtl":"ltr",o),i=!0)}i||r(t,n,"ltr")}(C,g||0,null==m?b:m,function(e,t,n,r){var i,o,l,s,a,u="ltr"==n,c=w(e,u?"left":"right"),h=w(t-1,u?"right":"left"),d=null==g&&0==e,f=null==m&&t==b,p=0==r,r=!C||r==C.length-1;h.top-c.top<=3?(i=(k?d:f)&&p?S:(u?c:h).left,a=(k?f:d)&&r?L:(u?h:c).right,T(i,c.top,a-i,c.bottom)):(a=u?(o=k&&d&&p?S:c.left,l=k?L:x(e,n,"before"),s=k?S:x(t,n,"after"),k&&f&&r?L:h.right):(o=k?x(e,n,"before"):S,l=!k&&d&&p?L:c.right,s=!k&&f&&r?S:h.left,k?x(t,n,"after"):L),T(o,c.top,l-o,c.bottom),c.bottome.display.sizerWidth&&(a=Math.ceil(c/ar(e.display)))>e.display.maxLineLength&&(e.display.maxLineLength=a,e.display.maxLine=s.line,e.display.maxLineChanged=!0)}}2=o&&(i=vt(t,rn(D(t,n))-e.wrapper.clientHeight),o=n)),{from:i,to:Math.max(o,i+1)}}function Dr(e,t){var n=e.display,r=sr(e.display),i=(t.top<0&&(t.top=0),(e.curOp&&null!=e.curOp.scrollTop?e.curOp:n.scroller).scrollTop),o=Fn(e),l={},s=(t.bottom-t.top>o&&(t.bottom=t.top+o),e.doc.height+An(n)),a=t.tops-r,r=(t.topi+o&&(a=Math.min(t.top,(r?s:t.bottom)-o))!=i&&(l.scrollTop=a),e.options.fixedGutter?0:n.gutters.offsetWidth),s=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:n.scroller.scrollLeft-r,o=Hn(e)-n.gutters.offsetWidth,i=t.right-t.left>o;return i&&(t.right=t.left+o),t.left<10?l.scrollLeft=0:t.lefto+s-3&&(l.scrollLeft=t.right+(i?0:10)-o),l}function Wr(e,t){null!=t&&(Pr(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc:e.curOp).scrollTop+t)}function Hr(e){Pr(e);var t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function Fr(e,t,n){null==t&&null==n||Pr(e),null!=t&&(e.curOp.scrollLeft=t),null!=n&&(e.curOp.scrollTop=n)}function Pr(e){var t=e.curOp.scrollToPos;t&&(e.curOp.scrollToPos=null,Er(e,Jn(e,t.from),Jn(e,t.to),t.margin))}function Er(e,t,n,r){t=Dr(e,{left:Math.min(t.left,n.left),top:Math.min(t.top,n.top)-r,right:Math.max(t.right,n.right),bottom:Math.max(t.bottom,n.bottom)+r});Fr(e,t.scrollLeft,t.scrollTop)}function zr(e,t){Math.abs(e.doc.scrollTop-t)<2||(m||ti(e,{top:t}),Ir(e,t,!0),m&&ti(e),qr(e,100))}function Ir(e,t,n){t=Math.max(0,Math.min(e.display.scroller.scrollHeight-e.display.scroller.clientHeight,t)),e.display.scroller.scrollTop==t&&!n||(e.doc.scrollTop=t,e.display.scrollbars.setScrollTop(t),e.display.scroller.scrollTop==t)||(e.display.scroller.scrollTop=t)}function Rr(e,t,n,r){t=Math.max(0,Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth)),(n?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)&&!r||(e.doc.scrollLeft=t,ii(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function Br(e){var t=e.display,n=t.gutters.offsetWidth,r=Math.round(e.doc.height+An(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?n:0,docHeight:r,scrollHeight:r+Wn(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}function Gr(e,t,n){this.cm=n;var r=this.vert=M("div",[M("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=M("div",[M("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");r.tabIndex=i.tabIndex=-1,e(r),e(i),L(r,"scroll",function(){r.clientHeight&&t(r.scrollTop,"vertical")}),L(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,w&&v<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}function Ur(){}Gr.prototype.update=function(e){var t,n=e.scrollWidth>e.clientWidth+1,r=e.scrollHeight>e.clientHeight+1,i=e.nativeBarWidth;return r?(this.vert.style.display="block",this.vert.style.bottom=n?i+"px":"0",t=e.viewHeight-(n?i:0),this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+t)+"px"):(this.vert.scrollTop=0,this.vert.style.display="",this.vert.firstChild.style.height="0"),n?(this.horiz.style.display="block",this.horiz.style.right=r?i+"px":"0",this.horiz.style.left=e.barLeft+"px",t=e.viewWidth-e.barLeft-(r?i:0),this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+t)+"px"):(this.horiz.style.display="",this.horiz.firstChild.style.width="0"),!this.checkedZeroWidth&&0=l.viewTo)||l.maxLineChanged&&o.options.lineWrapping,i.update=i.mustUpdate&&new Qr(o,i.mustUpdate&&{top:i.scrollTop,ensure:i.scrollToPos},i.forceUpdate)}for(var s=0;s(i.defaultView.innerHeight||i.documentElement.clientHeight)&&(r=!1),null==r)||X||(o=M("div","​",null,"position: absolute;\n top: "+(t.top-n.viewOffset-On(e.display))+"px;\n height: "+(t.bottom-t.top+Wn(e)+n.barHeight)+"px;\n left: "+t.left+"px; width: "+Math.max(2,t.right-t.left)+"px;"),e.display.lineSpace.appendChild(o),o.scrollIntoView(r),e.display.lineSpace.removeChild(o))}(w,v));var S=b.maybeHiddenMarkers,L=b.maybeUnhiddenMarkers;if(S)for(var k=0;k=l.display.viewTo||(s=+new Date+l.options.workTime,a=At(l,c.highlightFrontier),u=[],c.iter(a.line,Math.min(c.first+c.size,l.display.viewTo+500),function(e){if(a.line>=l.display.viewFrom){for(var t=e.styles,n=e.text.length>l.options.maxHighlightLength?ht(c.mode,a.state):null,r=Nt(l,e,a,!0),n=(n&&(a.state=n),e.styles=r.styles,e.styleClasses),r=r.classes,i=(r?e.styleClasses=r:n&&(e.styleClasses=null),!t||t.length!=e.styles.length||n!=r&&(!n||!r||n.bgClass!=r.bgClass||n.textClass!=r.textClass)),o=0;!i&&os)return qr(l,l.options.workDelay),!0}),c.highlightFrontier=a.line,c.modeFrontier=Math.max(c.modeFrontier,a.line),u.length&&h(l,function(){for(var e=0;e=n.viewFrom&&t.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==yr(e))return!1;oi(e)&&(mr(e),t.dims=ur(e));var i=r.first+r.size,o=Math.max(t.visible.from-e.options.viewportMargin,r.first),l=Math.min(i,t.visible.to+e.options.viewportMargin),r=(n.viewFroml&&n.viewTo-l<20&&(l=Math.min(i,n.viewTo)),Rt&&(o=en(e.doc,o),l=tn(e.doc,l)),o!=n.viewFrom||l!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth),i=(i=o,o=l,0==(s=(l=e).display).view.length||i>=s.viewTo||o<=s.viewFrom?(s.view=mn(l,i,o),s.viewFrom=i):(s.viewFrom>i?s.view=mn(l,i,s.viewFrom).concat(s.view):s.viewFromo&&(s.view=s.view.slice(0,pr(l,o)))),s.viewTo=o,n.viewOffset=rn(D(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px",yr(e));if(!r&&0==i&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;var s,l=!(l=e).hasFocus()&&(s=N(se(l)))&&ne(l.display.lineDiv,s)?(s={activeElt:s},window.getSelection&&(o=ae(l).getSelection()).anchorNode&&o.extend&&ne(l.display.lineDiv,o.anchorNode)&&(s.anchorNode=o.anchorNode,s.anchorOffset=o.anchorOffset,s.focusNode=o.focusNode,s.focusOffset=o.focusOffset),s):null,a=(4=e.display.viewFrom&&t.visible.to<=e.display.viewTo)break;if(!Jr(e,t))break;Nr(e);var i=Br(e);br(e),Vr(e,i),ri(e,i),t.force=!1}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 ti(e,t){var n,t=new Qr(e,t);Jr(e,t)&&(Nr(e),ei(e,t),n=Br(e),br(e),Vr(e,n),ri(e,n),t.finish())}function ni(e){var t=e.gutters.offsetWidth;e.sizer.style.marginLeft=t+"px",b(e,"gutterChanged",e)}function ri(e,t){e.display.sizer.style.minHeight=t.docHeight+"px",e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=t.docHeight+e.display.barHeight+Wn(e)+"px"}function ii(e){var t=e.display,n=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var r=cr(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=r+"px",l=0;la.clientWidth,c=a.scrollHeight>a.clientHeight;if(o&&u||i&&c){if(i&&C&&x)e:for(var h=t.target,d=s.view;h!=a;h=h.parentNode)for(var f=0;fs-(e.cm?e.cm.options.historyEventDelay:500)||"*"==t.origin.charAt(0)))&&(o=(o=l).lastOp==r?(Ai(o.done),I(o.done)):o.done.length&&!I(o.done).ranges?I(o.done):1l.undoDepth;)l.done.shift(),l.done[0].ranges||l.done.shift()}l.done.push(n),l.generation=++l.maxGeneration,l.lastModTime=l.lastSelTime=s,l.lastOp=l.lastSelOp=r,l.lastOrigin=l.lastSelOrigin=t.origin,i||O(e,"historyAdded")}function Wi(e,t,n,r){var i,o,l,s=e.history,a=r&&r.origin;n==s.lastSelOp||a&&s.lastSelOrigin==a&&(s.lastModTime==s.lastSelTime&&s.lastOrigin==a||(e=e,i=a,o=I(s.done),l=t,"*"==(i=i.charAt(0)))||"+"==i&&o.ranges.length==l.ranges.length&&o.somethingSelected()==l.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500))?s.done[s.done.length-1]=t:Hi(t,s.done),s.lastSelTime=+new Date,s.lastSelOrigin=a,s.lastSelOp=n,r&&!1!==r.clearRedo&&Ai(s.undone)}function Hi(e,t){var n=I(t);n&&n.ranges&&n.equals(e)||t.push(e)}function Fi(t,n,e,r){var i=n["spans_"+t.id],o=0;t.iter(Math.max(t.first,e),Math.min(t.first+t.size,r),function(e){e.markedSpans&&((i=i||(n["spans_"+t.id]={}))[o]=e.markedSpans),++o})}function Pi(e,t){var n=t["spans_"+e.id];if(!n)return null;for(var r=[],i=0;i=t.ch:s.to>t.ch))){if(i&&(O(a,"beforeCursorEnter"),a.explicitlyCleared)){if(o.markedSpans){--l;continue}break}if(a.atomic){if(n){var s=a.find(r<0?1:-1),h=void 0;if((s=(r<0?c:u)?qi(e,s,-r,s&&s.line==t.line?o:null):s)&&s.line==t.line&&(h=F(s,n))&&(r<0?h<0:0e.first?P(e,H(t.line-1)):null:0e.lastLine())){t.from.linei?{from:t.from,to:H(i,D(e,i).text.length),text:[t.text[0]],origin:t.origin}:t).removed=pt(e,t.from,t.to),n=n||bi(e,t),e.cm){var i=e.cm,o=t,l=r,s=i.doc,a=i.display,u=o.from,c=o.to,h=!1,d=u.line,f=(i.options.lineWrapping||(d=W(Jt(D(s,u.line))),s.iter(d,c.line+1,function(e){if(e==a.maxLine)return h=!0})),-1a.maxLineLength&&(a.maxLine=e,a.maxLineLength=t,a.maxLineChanged=!0,h=!1)}),h&&(i.curOp.updateMaxLine=!0)),s),p=u.line;if(f.modeFrontier=Math.min(f.modeFrontier,p),!(f.highlightFrontiert.display.maxLineLength&&(t.display.maxLine=u,t.display.maxLineLength=c,t.display.maxLineChanged=!0)}null!=r&&t&&this.collapsed&&E(t,r,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,t)&&Xi(t.doc),t&&b(t,"markerCleared",t,this,r,i),n&&_r(t),this.parent&&this.parent.clear()}},po.prototype.find=function(e,t){var n,r;null==e&&"bookmark"==this.type&&(e=1);for(var i=0;i=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(i,o,l){i=P(this,i),o=P(this,o);var s=[],a=i.line;return this.iter(i.line,o.line+1,function(e){var t=e.markedSpans;if(t)for(var n=0;n=r.to||null==r.from&&a!=i.line||null!=r.from&&a==o.line&&r.from>=o.ch||l&&!l(r.marker)||s.push(r.marker.parent||r.marker)}++a}),s},getAllMarks:function(){var r=[];return this.iter(function(e){var t=e.markedSpans;if(t)for(var n=0;nt&&(t=e.from),null!=e.to&&e.toe.text.length?null:t}function Uo(e,t,n){e=Go(e,t.ch,n);return null==e?null:new H(t.line,e,n<0?"after":"before")}function Vo(e,t,n,r,i){if(e){"rtl"==t.doc.direction&&(i=-i);var o,l,s,a,e=Ge(n,t.doc.direction);if(e)return o=i<0==(1==(e=i<0?I(e):e[0]).level)?"after":"before",0=n.text.length?(s.ch=n.text.length,s.sticky="before"):s.ch<=0&&(s.ch=0,s.sticky="after");var r=He(a,s.ch,s.sticky),i=a[r];if("ltr"==t.doc.direction&&i.level%2==0&&(0s.ch:i.from=i.from&&d>=c.begin))return new H(s.line,d,h?"before":"after")}function f(e,t,n){for(var r=function(e,t){return t?new H(s.line,u(e,1),"before"):new H(s.line,e,"after")};0<=e&&el.doc.first&&(n=D(l.doc,e.line-1).text)&&(e=new H(e.line,1),l.replaceRange(t.charAt(0)+l.doc.lineSeparator()+n.charAt(n.length-1),H(e.line-1,n.length-1),e,"+transpose"))),i.push(new B(e,e)));l.setSelections(i)})},newlineAndIndent:function(r){return h(r,function(){for(var e=(t=r.listSelections()).length-1;0<=e;e--)r.replaceRange(r.doc.lineSeparator(),t[e].anchor,t[e].head,"+input");for(var t=r.listSelections(),n=0;nc&&t.push(new B(H(s,c),H(s,ye(u,l,n))))}t.length||t.push(new B(f,f)),G(g,gi(d,y.ranges.slice(0,v).concat(t),v),{origin:"*mouse",scroll:!1}),d.scrollIntoView(e)}else{var h,r=m,i=sl(d,e,p.unit),e=r.anchor,e=0=n.to||o.linea.bottom?20:0)&&setTimeout(z(d,function(){u==i&&(l.scroller.scrollTop+=r,e(t))}),50))}:n)(e)}),i=z(d,n);d.state.selectingText=i,L(l.wrapper.ownerDocument,"mousemove",r),L(l.wrapper.ownerDocument,"mouseup",i)})(i,s,o,a)):qe(e)==h.scroller&&T(e):2==n?(t&&Ri(c.doc,t),setTimeout(function(){return h.input.focus()},20)):3==n&&(Z?c.display.input.onContextMenu(e):kr(c))))}function sl(e,t,n){return"char"==n?new B(t,t):"word"==n?e.findWordAt(t):"line"==n?new B(H(t.line,0),P(e.doc,H(t.line+1,0))):(n=n(e,t),new B(n.from,n.to))}function al(e,t,n,r){var i,o;if(t.touches)i=t.touches[0].clientX,o=t.touches[0].clientY;else try{i=t.clientX,o=t.clientY}catch(e){return!1}if(i>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;r&&T(t);var l=e.display,r=l.lineDiv.getBoundingClientRect();if(o>r.bottom||!je(e,n))return $e(t);o-=r.top-l.viewOffset;for(var s=0;s=i)return O(e,n,e,vt(e.doc,o),e.display.gutterSpecs[s].className,t),$e(t)}}function ul(e,t){return al(e,t,"gutterClick",!0)}function cl(e,t){var n,r;Nn(e.display,t)||(r=t,je(n=e,"gutterContextMenu")&&al(n,r,"gutterContextMenu",!1))||(A(e,t,"contextmenu")||Z||e.display.input.onContextMenu(t))}function hl(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),jn(e)}rl.prototype.compare=function(e,t,n){return this.time+400>e&&0==F(t,this.pos)&&n==this.button};var dl={toString:function(){return"CodeMirror.Init"}},fl={},pl={};function gl(e,t,n){!t!=!(n&&n!=dl)&&(n=e.display.dragFunctions,(t=t?L:k)(e.display.scroller,"dragstart",n.start),t(e.display.scroller,"dragenter",n.enter),t(e.display.scroller,"dragover",n.over),t(e.display.scroller,"dragleave",n.leave),t(e.display.scroller,"drop",n.drop))}function ml(e){e.options.lineWrapping?(re(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(J(e.display.wrapper,"CodeMirror-wrap"),ln(e)),dr(e),E(e),jn(e),setTimeout(function(){return Vr(e)},100)}function p(e,t){var n=this;if(!(this instanceof p))return new p(e,t);this.options=t=t?ce(t):{},ce(fl,t,!1);var r,i=t.value,o=("string"==typeof i?i=new f(i,t.mode,null,t.lineSeparator,t.direction):t.mode&&(i.modeOption=t.mode),this.doc=i,new p.inputStyles[t.inputStyle](this)),e=this.display=new ui(e,i,o,t),l=(hl(e.wrapper.CodeMirror=this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),Xr(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:-1,cutIncoming:-1,selectingText:!1,draggingText:!1,highlight:new de,keySeq:null,specialChars:null},t.autofocus&&!$&&e.input.focus(),w&&v<11&&setTimeout(function(){return n.display.input.reset(!0)},20),this),s=l.display;L(s.scroller,"mousedown",z(l,ll)),L(s.scroller,"dblclick",w&&v<11?z(l,function(e){var t;A(l,e)||!(t=fr(l,e))||ul(l,e)||Nn(l.display,e)||(T(e),e=l.findWordAt(t),Ri(l.doc,e.anchor,e.head))}):function(e){return A(l,e)||T(e)}),L(s.scroller,"contextmenu",function(e){return cl(l,e)}),L(s.input.getField(),"contextmenu",function(e){s.scroller.contains(e.target)||cl(l,e)});var a,u={end:0};function c(){s.activeTouch&&(a=setTimeout(function(){return s.activeTouch=null},1e3),(u=s.activeTouch).end=+new Date)}function h(e,t){var n;return null==t.left||400<(n=t.left-e.left)*n+(n=t.top-e.top)*n}L(s.scroller,"touchstart",function(e){var t;A(l,e)||function(e){if(1==e.touches.length)return(e=e.touches[0]).radiusX<=1&&e.radiusY<=1}(e)||ul(l,e)||(s.input.ensurePolled(),clearTimeout(a),t=+new Date,s.activeTouch={start:t,moved:!1,prev:t-u.end<=300?u:null},1==e.touches.length&&(s.activeTouch.left=e.touches[0].pageX,s.activeTouch.top=e.touches[0].pageY))}),L(s.scroller,"touchmove",function(){s.activeTouch&&(s.activeTouch.moved=!0)}),L(s.scroller,"touchend",function(e){var t,n=s.activeTouch;n&&!Nn(s,e)&&null!=n.left&&!n.moved&&new Date-n.start<300&&(t=l.coordsChar(s.activeTouch,"page"),n=!n.prev||h(n,n.prev)?new B(t,t):!n.prev.prev||h(n,n.prev.prev)?l.findWordAt(t):new B(H(t.line,0),P(l.doc,H(t.line+1,0))),l.setSelection(n.anchor,n.head),l.focus(),T(e)),c()}),L(s.scroller,"touchcancel",c),L(s.scroller,"scroll",function(){s.scroller.clientHeight&&(zr(l,s.scroller.scrollTop),Rr(l,s.scroller.scrollLeft,!0),O(l,"scroll",l))}),L(s.scroller,"mousewheel",function(e){return pi(l,e)}),L(s.scroller,"DOMMouseScroll",function(e){return pi(l,e)}),L(s.wrapper,"scroll",function(){return s.wrapper.scrollTop=s.wrapper.scrollLeft=0}),s.dragFunctions={enter:function(e){A(l,e)||_e(e)},over:function(e){var t,n;A(l,e)||((n=fr(t=l,n=e))&&(xr(t,n,n=document.createDocumentFragment()),t.display.dragCursor||(t.display.dragCursor=M("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),t.display.lineSpace.insertBefore(t.display.dragCursor,t.display.cursorDiv)),y(t.display.dragCursor,n)),_e(e))},start:function(e){var t,n;t=l,e=e,w&&(!t.state.draggingText||+new Date-xo<100)?_e(e):A(t,e)||Nn(t.display,e)||(e.dataTransfer.setData("Text",t.getSelection()),e.dataTransfer.effectAllowed="copyMove",e.dataTransfer.setDragImage&&!j&&((n=M("img",null,null,"position: fixed; left: 0; top: 0;")).src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",K&&(n.width=n.height=1,t.display.wrapper.appendChild(n),n._top=n.offsetTop),e.dataTransfer.setDragImage(n,0,0),K)&&n.parentNode.removeChild(n))},drop:z(l,Co),leave:function(e){A(l,e)||So(l)}};o=s.input.getField();for(r in L(o,"keyup",function(e){return tl.call(l,e)}),L(o,"keydown",z(l,el)),L(o,"keypress",z(l,nl)),L(o,"focus",function(e){return Tr(l,e)}),L(o,"blur",function(e){return Mr(l,e)}),To(),$r(this),this.curOp.forceUpdate=!0,Ti(this,i),t.autofocus&&!$||this.hasFocus()?setTimeout(function(){n.hasFocus()&&!n.state.focused&&Tr(n)},20):Mr(this),pl)pl.hasOwnProperty(r)&&pl[r](this,t[r],dl);oi(this),t.finishInit&&t.finishInit(this);for(var d=0;do.first?he(D(o,t-1).text,null,l):0:"add"==n?c=a+e.options.indentUnit:"subtract"==n?c=a-e.options.indentUnit:"number"==typeof n&&(c=a+n);var c=Math.max(0,c),h="",d=0;if(e.options.indentWithTabs)for(var f=Math.floor(c/l);f;--f)d+=l,h+="\t";if(dl,a=tt(t),u=null;if(s&&1l?"cut":"+input")});Ji(e.doc,f),b(e,"inputRead",e,f)}t&&!s&&Sl(e,t),Hr(e),e.curOp.updateInput<2&&(e.curOp.updateInput=h),e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=-1}function Cl(e,t){var n=e.clipboardData&&e.clipboardData.getData("Text");return n&&(e.preventDefault(),t.isReadOnly()||t.options.disableInput||!t.hasFocus()||h(t,function(){return xl(t,n,0,null,"paste")}),1)}function Sl(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var n=e.doc.sel,r=n.ranges.length-1;0<=r;r--){var i=n.ranges[r];if(!(100=n.first+n.size||(r=new H(e,r.ch,r.sticky),!(s=D(n,e))))return;r=Vo(l,n.cm,s,r.line,a)}else r=t;return 1}if("char"==o||"codepoint"==o)u();else if("column"==o)u(!0);else if("word"==o||"group"==o)for(var c=null,h="group"==o,d=n.cm&&n.cm.getHelper(r,"wordChars"),f=!0;!(i<0)||u(!f);f=!1){var p=s.text.charAt(r.ch)||"\n",p=Te(p,d)?"w":h&&"\n"==p?"n":!h||/\s/.test(p)?null:"p";if(h&&!f&&(p=p||"s"),c&&c!=p){i<0&&(i=1,u(),r.sticky="after");break}if(p&&(c=p),0=s.height){l.hitSide=!0;break}o+=5*n}return l}function i(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new de,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null}function Ol(e,t){var n,r,i=zn(e,t.line);return!i||i.hidden?null:(n=Pn(i,i=D(e.doc,t.line),t.line),r="left",(i=Ge(i,e.doc.direction))&&(r=He(i,t.ch)%2?"right":"left"),(e=Un(n.map,t.ch,r)).offset="right"==e.collapse?e.end:e.start,e)}function Al(e,t){return t&&(e.bad=!0),e}function Dl(e,t,n){var r;if(t==e.display.lineDiv){if(!(r=e.display.lineDiv.childNodes[n]))return Al(e.clipPos(H(e.display.viewTo-1)),!0);t=null,n=0}else for(r=t;;r=r.parentNode){if(!r||r==e.display.lineDiv)return null;if(r.parentNode&&r.parentNode==e.display.lineDiv)break}for(var i=0;i=t.display.viewTo||n.line=t.display.viewFrom&&Ol(t,r)||{node:i[0].measure.map[2],offset:0},r=n.linet.firstLine()&&(i=H(i.line-1,D(t.doc,i.line-1).length)),r.ch==D(t.doc,r.line).text.length&&r.linen.viewTo-1)return!1;var o,l=i.line==n.viewFrom||0==(l=pr(t,i.line))?(e=W(n.view[0].line),n.view[0].node):(e=W(n.view[l].line),n.view[l-1].node.nextSibling),r=pr(t,r.line),n=r==n.view.length-1?(o=n.viewTo-1,n.lineDiv.lastChild):(o=W(n.view[r+1].line)-1,n.view[r+1].node.previousSibling);if(!l)return!1;for(var s=t.doc.splitLines(function(o,e,t,l,s){var n="",a=!1,u=o.doc.lineSeparator(),c=!1;function h(){a&&(n+=u,c&&(n+=u),a=c=!1)}function d(e){e&&(h(),n+=e)}for(;!function e(t){if(1==t.nodeType){var n=t.getAttribute("cm-text");if(n)d(n);else if(n=t.getAttribute("cm-marker"))(n=o.findMarks(H(l,0),H(s+1,0),(i=+n,function(e){return e.id==i}))).length&&(n=n[0].find(0))&&d(pt(o.doc,n.from,n.to).join(u));else if("false"!=t.getAttribute("contenteditable")&&(n=/^(pre|div|p|li|table|br)$/i.test(t.nodeName),/^br$/i.test(t.nodeName)||0!=t.textContent.length)){n&&h();for(var r=0;ri.ch&&p.charCodeAt(p.length-c-1)==g.charCodeAt(g.length-c-1);)u--,c++;s[s.length-1]=p.slice(0,p.length-c).replace(/^\u200b+/,""),s[0]=s[0].slice(u).replace(/\u200b+$/,"");r=H(e,u),l=H(o,a.length?I(a).length-c:0);return 1n&&(yl(this,i.head.line,e,!0),n=i.head.line,r==this.doc.sel.primIndex)&&Hr(this);else{for(var o=i.from(),i=i.to(),l=Math.max(n,o.line),n=Math.min(this.lastLine(),i.line-(i.ch?0:1))+1,s=l;s>1;if((l?n[2*l-1]:0)>=o)i=l;else{if(!(n[2*l+1]l)&&e.top>t.offsetHeight?a=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=l&&(a=e.bottom),u+t.offsetWidth>o&&(u=o-t.offsetWidth)),t.style.top=a+"px",t.style.left=t.style.right="","right"==i?(u=s.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?u=0:"middle"==i&&(u=(s.sizer.clientWidth-t.offsetWidth)/2),t.style.left=u+"px"),n&&(r=this,l={left:u,top:a,right:u+t.offsetWidth,bottom:a+t.offsetHeight},null!=(l=Dr(r,l)).scrollTop&&zr(r,l.scrollTop),null!=l.scrollLeft)&&Rr(r,l.scrollLeft)},triggerOnKeyDown:n(el),triggerOnKeyPress:n(nl),triggerOnKeyUp:tl,triggerOnMouseDown:n(ll),execCommand:function(e){if(jo.hasOwnProperty(e))return jo[e].call(null,this)},triggerElectric:n(function(e){Sl(this,e)}),findPosH:function(e,t,n,r){for(var i=1,o=(t<0&&(i=-1,t=-t),P(this.doc,e)),l=0;l