s-r;if(t.topi+o){var c=Math.min(t.top,(u?s:t.bottom)-o);c!=i&&(a.scrollTop=c)}var d=e.options.fixedGutter?0:n.gutters.offsetWidth,p=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:n.scroller.scrollLeft-d,f=Wn(e)-n.gutters.offsetWidth,h=t.right-t.left>f;return h&&(t.right=t.left+f),t.left<10?a.scrollLeft=0:t.leftf+p-3&&(a.scrollLeft=t.right+(h?0:10)-f),a}function oi(e,t){null!=t&&(ui(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+t)}function ai(e){ui(e);var t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function si(e,t,n){null==t&&null==n||ui(e),null!=t&&(e.curOp.scrollLeft=t),null!=n&&(e.curOp.scrollTop=n)}function li(e,t){ui(e),e.curOp.scrollToPos=t}function ui(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var n=vr(e,t.from),r=vr(e,t.to);ci(e,n,r,t.margin)}}function ci(e,t,n,r){var i=ii(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});si(e,i.scrollLeft,i.scrollTop)}function di(e,t){Math.abs(e.doc.scrollTop-t)<2||(n||Hi(e,{top:t}),pi(e,t,!0),n&&Hi(e),Mi(e,100))}function pi(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 fi(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,Vi(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function hi(e){var t=e.display,n=t.gutters.offsetWidth,r=Math.round(e.doc.height+zn(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+Yn(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}var mi=function(e,t,n){this.cm=n;var r=this.vert=O("div",[O("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=O("div",[O("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");r.tabIndex=i.tabIndex=-1,e(r),e(i),he(r,"scroll",(function(){r.clientHeight&&t(r.scrollTop,"vertical")})),he(i,"scroll",(function(){i.clientWidth&&t(i.scrollLeft,"horizontal")})),this.checkedZeroWidth=!1,a&&s<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};mi.prototype.update=function(e){var t=e.scrollWidth>e.clientWidth+1,n=e.scrollHeight>e.clientHeight+1,r=e.nativeBarWidth;if(n){this.vert.style.display="block",this.vert.style.bottom=t?r+"px":"0";var i=e.viewHeight-(t?r:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+i)+"px"}else this.vert.scrollTop=0,this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=n?r+"px":"0",this.horiz.style.left=e.barLeft+"px";var o=e.viewWidth-e.barLeft-(n?r:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+o)+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedZeroWidth&&e.clientHeight>0&&(0==r&&this.zeroWidthHack(),this.checkedZeroWidth=!0),{right:n?r:0,bottom:t?r:0}},mi.prototype.setScrollLeft=function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")},mi.prototype.setScrollTop=function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")},mi.prototype.zeroWidthHack=function(){var e=b&&!f?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new j,this.disableVert=new j},mi.prototype.enableZeroWidthBar=function(e,t,n){function r(){var i=e.getBoundingClientRect(),o="vert"==n?document.elementFromPoint(i.right-1,(i.top+i.bottom)/2):document.elementFromPoint((i.right+i.left)/2,i.bottom-1);o!=e?e.style.pointerEvents="none":t.set(1e3,r)}e.style.pointerEvents="auto",t.set(1e3,r)},mi.prototype.clear=function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)};var gi=function(){};function _i(e,t){t||(t=hi(e));var n=e.display.barWidth,r=e.display.barHeight;bi(e,t);for(var i=0;i<4&&n!=e.display.barWidth||r!=e.display.barHeight;i++)n!=e.display.barWidth&&e.options.lineWrapping&&Zr(e),bi(e,hi(e)),n=e.display.barWidth,r=e.display.barHeight}function bi(e,t){var n=e.display,r=n.scrollbars.update(t);n.sizer.style.paddingRight=(n.barWidth=r.right)+"px",n.sizer.style.paddingBottom=(n.barHeight=r.bottom)+"px",n.heightForcer.style.borderBottom=r.bottom+"px solid transparent",r.right&&r.bottom?(n.scrollbarFiller.style.display="block",n.scrollbarFiller.style.height=r.bottom+"px",n.scrollbarFiller.style.width=r.right+"px"):n.scrollbarFiller.style.display="",r.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(n.gutterFiller.style.display="block",n.gutterFiller.style.height=r.bottom+"px",n.gutterFiller.style.width=t.gutterWidth+"px"):n.gutterFiller.style.display=""}gi.prototype.update=function(){return{bottom:0,right:0}},gi.prototype.setScrollLeft=function(){},gi.prototype.setScrollTop=function(){},gi.prototype.clear=function(){};var vi={native:mi,null:gi};function yi(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&w(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new vi[e.options.scrollbarStyle]((function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),he(t,"mousedown",(function(){e.state.focused&&setTimeout((function(){return e.display.input.focus()}),0)})),t.setAttribute("cm-not-content","true")}),(function(t,n){"horizontal"==n?fi(e,t):di(e,t)}),e),e.display.scrollbars.addClass&&I(e.display.wrapper,e.display.scrollbars.addClass)}var Ei=0;function Si(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:0,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Ei,markArrays:null},Dn(e.curOp)}function Ci(e){var t=e.curOp;t&&wn(t,(function(e){for(var t=0;t=n.viewTo)||n.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new Pi(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function wi(e){e.updatedDisplay=e.mustUpdate&&Ui(e.cm,e.update)}function xi(e){var t=e.cm,n=t.display;e.updatedDisplay&&Zr(t),e.barMeasure=hi(t),n.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Jn(t,n.maxLine,n.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(n.scroller.clientWidth,n.sizer.offsetLeft+e.adjustWidthTo+Yn(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-Wn(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function Ai(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft=e.display.viewTo)){var n=+new Date+e.options.workTime,r=bt(e,t.highlightFrontier),i=[];t.iter(r.line,Math.min(t.first+t.size,e.display.viewTo+500),(function(o){if(r.line>=e.display.viewFrom){var a=o.styles,s=o.text.length>e.options.maxHighlightLength?Ve(t.mode,r.state):null,l=gt(e,o,r,!0);s&&(r.state=s),o.styles=l.styles;var u=o.styleClasses,c=l.classes;c?o.styleClasses=c:u&&(o.styleClasses=null);for(var d=!a||a.length!=o.styles.length||u!=c&&(!u||!c||u.bgClass!=c.bgClass||u.textClass!=c.textClass),p=0;!d&&pn)return Mi(e,e.options.workDelay),!0})),t.highlightFrontier=r.line,t.modeFrontier=Math.max(t.modeFrontier,r.line),i.length&&Ni(e,(function(){for(var t=0;t=n.viewFrom&&t.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==Gr(e))return!1;Yi(e)&&(Br(e),t.dims=Nr(e));var i=r.first+r.size,o=Math.max(t.visible.from-e.options.viewportMargin,r.first),a=Math.min(i,t.visible.to+e.options.viewportMargin);n.viewFroma&&n.viewTo-a<20&&(a=Math.min(i,n.viewTo)),Ot&&(o=en(e.doc,o),a=tn(e.doc,a));var s=o!=n.viewFrom||a!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth;Ur(e,o,a),n.viewOffset=on(Qe(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";var l=Gr(e);if(!s&&0==l&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;var u=Bi(e);return l>4&&(n.lineDiv.style.display="none"),$i(e,n.updateLineNumbers,t.dims),l>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,ji(u),x(n.cursorDiv),x(n.selectionDiv),n.gutters.style.height=n.sizer.style.minHeight=0,s&&(n.lastWrapHeight=t.wrapperHeight,n.lastWrapWidth=t.wrapperWidth,Mi(e,400)),n.updateLineNumbers=null,!0}function Gi(e,t){for(var n=t.viewport,r=!0;;r=!1){if(r&&e.options.lineWrapping&&t.oldDisplayWidth!=Wn(e))r&&(t.visible=ei(e.display,e.doc,n));else if(n&&null!=n.top&&(n={top:Math.min(e.doc.height+zn(e.display)-Kn(e),n.top)}),t.visible=ei(e.display,e.doc,n),t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)break;if(!Ui(e,t))break;Zr(e);var i=hi(e);Hr(e),_i(e,i),zi(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 Hi(e,t){var n=new Pi(e,t);if(Ui(e,n)){Zr(e),Gi(e,n);var r=hi(e);Hr(e),_i(e,r),zi(e,r),n.finish()}}function $i(e,t,n){var r=e.display,i=e.options.lineNumbers,o=r.lineDiv,a=o.firstChild;function s(t){var n=t.nextSibling;return l&&b&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}for(var u=r.view,c=r.viewFrom,d=0;d-1&&(f=!1),Nn(e,p,c,n)),f&&(x(p.lineNumber),p.lineNumber.appendChild(document.createTextNode(rt(e.options,c)))),a=p.node.nextSibling}else{var h=Bn(e,p,c,n);o.insertBefore(h,a)}c+=p.size}while(a)a=s(a)}function qi(e){var t=e.gutters.offsetWidth;e.sizer.style.marginLeft=t+"px",An(e,"gutterChanged",e)}function zi(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+Yn(e)+"px"}function Vi(e){var t=e.display,n=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var r=kr(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=r+"px",a=0;au.clientWidth,p=u.scrollHeight>u.clientHeight;if(i&&c||o&&p){if(o&&b&&l)e:for(var f=t.target,h=s.view;f!=u;f=f.parentNode)for(var m=0;m=0&&ot(e,r.to())<=0)return n}return-1};var io=function(e,t){this.anchor=e,this.head=t};function oo(e,t,n){var r=e&&e.options.selectionsMayTouch,i=t[n];t.sort((function(e,t){return ot(e.from(),t.from())})),n=U(t,i);for(var o=1;o0:l>=0){var u=ut(s.from(),a.from()),c=lt(s.to(),a.to()),d=s.empty()?a.from()==a.head:s.from()==s.head;o<=n&&--n,t.splice(--o,2,new io(d?c:u,d?u:c))}}return new ro(t,n)}function ao(e,t){return new ro([new io(e,t||e)],0)}function so(e){return e.text?it(e.from.line+e.text.length-1,K(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function lo(e,t){if(ot(e,t.from)<0)return e;if(ot(e,t.to)<=0)return so(t);var n=e.line+t.text.length-(t.to.line-t.from.line)-1,r=e.ch;return e.line==t.to.line&&(r+=so(t).ch-t.to.ch),it(n,r)}function uo(e,t){for(var n=[],r=0;r1&&e.remove(s.line+1,h-1),e.insert(s.line+1,_)}An(e,"change",e,t)}function _o(e,t,n){function r(e,i,o){if(e.linked)for(var a=0;a1&&!e.done[e.done.length-2].ranges?(e.done.pop(),K(e.done)):void 0}function To(e,t,n,r){var i=e.history;i.undone.length=0;var o,a,s=+new Date;if((i.lastOp==r||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&i.lastModTime>s-(e.cm?e.cm.options.historyEventDelay:500)||"*"==t.origin.charAt(0)))&&(o=Do(i,i.lastOp==r)))a=K(o.changes),0==ot(t.from,t.to)&&0==ot(t.from,a.to)?a.to=so(t):o.changes.push(So(e,t));else{var l=K(i.done);l&&l.ranges||Ao(e.sel,i.done),o={changes:[So(e,t)],generation:i.generation},i.done.push(o);while(i.done.length>i.undoDepth)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(n),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=s,i.lastOp=i.lastSelOp=r,i.lastOrigin=i.lastSelOrigin=t.origin,a||_e(e,"historyAdded")}function wo(e,t,n,r){var i=t.charAt(0);return"*"==i||"+"==i&&n.ranges.length==r.ranges.length&&n.somethingSelected()==r.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}function xo(e,t,n,r){var i=e.history,o=r&&r.origin;n==i.lastSelOp||o&&i.lastSelOrigin==o&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==o||wo(e,o,K(i.done),t))?i.done[i.done.length-1]=t:Ao(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=n,r&&!1!==r.clearRedo&&Co(i.undone)}function Ao(e,t){var n=K(t);n&&n.ranges&&n.equals(e)||t.push(e)}function Oo(e,t,n,r){var i=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,n),Math.min(e.first+e.size,r),(function(n){n.markedSpans&&((i||(i=t["spans_"+e.id]={}))[o]=n.markedSpans),++o}))}function No(e){if(!e)return null;for(var t,n=0;n-1&&(K(s)[d]=u[d],delete u[d])}}}return r}function Mo(e,t,n,r){if(r){var i=e.anchor;if(n){var o=ot(t,i)<0;o!=ot(n,i)<0?(i=t,t=n):o!=ot(t,n)<0&&(t=n)}return new io(i,t)}return new io(n||t,t)}function Lo(e,t,n,r,i){null==i&&(i=e.cm&&(e.cm.display.shift||e.extend)),Go(e,new ro([Mo(e.sel.primary(),t,n,i)],0),r)}function Po(e,t,n){for(var r=[],i=e.cm&&(e.cm.display.shift||e.extend),o=0;o=t.ch:s.to>t.ch))){if(i&&(_e(l,"beforeCursorEnter"),l.explicitlyCleared)){if(o.markedSpans){--a;continue}break}if(!l.atomic)continue;if(n){var d=l.find(r<0?1:-1),p=void 0;if((r<0?c:u)&&(d=Wo(e,d,-r,d&&d.line==t.line?o:null)),d&&d.line==t.line&&(p=ot(d,n))&&(r<0?p<0:p>0))return Vo(e,d,t,r,i)}var f=l.find(r<0?-1:1);return(r<0?u:c)&&(f=Wo(e,f,r,f.line==t.line?o:null)),f?Vo(e,f,t,r,i):null}}return t}function Yo(e,t,n,r,i){var o=r||1,a=Vo(e,t,n,o,i)||!i&&Vo(e,t,n,o,!0)||Vo(e,t,n,-o,i)||!i&&Vo(e,t,n,-o,!0);return a||(e.cantEdit=!0,it(e.first,0))}function Wo(e,t,n,r){return n<0&&0==t.ch?t.line>e.first?dt(e,it(t.line-1)):null:n>0&&t.ch==(r||Qe(e,t.line)).text.length?t.line=0;--i)Zo(e,{from:r[i].from,to:r[i].to,text:i?[""]:t.text,origin:t.origin});else Zo(e,t)}}function Zo(e,t){if(1!=t.text.length||""!=t.text[0]||0!=ot(t.from,t.to)){var n=uo(e,t);To(e,t,n,e.cm?e.cm.curOp.id:NaN),ta(e,t,n,Bt(e,t));var r=[];_o(e,(function(e,n){n||-1!=U(r,e.history)||(aa(e.history,t),r.push(e.history)),ta(e,t,null,Bt(e,t))}))}}function Jo(e,t,n){var r=e.cm&&e.cm.state.suppressEdits;if(!r||n){for(var i,o=e.history,a=e.sel,s="undo"==t?o.done:o.undone,l="undo"==t?o.undone:o.done,u=0;u=0;--f){var h=p(f);if(h)return h.v}}}}function ea(e,t){if(0!=t&&(e.first+=t,e.sel=new ro(Q(e.sel.ranges,(function(e){return new io(it(e.anchor.line+t,e.anchor.ch),it(e.head.line+t,e.head.ch))})),e.sel.primIndex),e.cm)){Pr(e.cm,e.first,e.first-t,t);for(var n=e.cm.display,r=n.viewFrom;re.lastLine())){if(t.from.lineo&&(t={from:t.from,to:it(o,Qe(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=Xe(e,t.from,t.to),n||(n=uo(e,t)),e.cm?na(e.cm,t,r):go(e,t,r),Ho(e,n,$),e.cantEdit&&Yo(e,it(e.firstLine(),0))&&(e.cantEdit=!1)}}function na(e,t,n){var r=e.doc,i=e.display,o=t.from,a=t.to,s=!1,l=o.line;e.options.lineWrapping||(l=et(Xt(Qe(r,o.line))),r.iter(l,a.line+1,(function(e){if(e==i.maxLine)return s=!0,!0}))),r.sel.contains(t.from,t.to)>-1&&ve(e),go(r,t,n,Rr(e)),e.options.lineWrapping||(r.iter(l,o.line+t.text.length,(function(e){var t=an(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,s=!1)})),s&&(e.curOp.updateMaxLine=!0)),xt(r,o.line),Mi(e,400);var u=t.text.length-(a.line-o.line)-1;t.full?Pr(e):o.line!=a.line||1!=t.text.length||mo(e.doc,t)?Pr(e,o.line,a.line+1,u):Fr(e,o.line,"text");var c=ye(e,"changes"),d=ye(e,"change");if(d||c){var p={from:o,to:a,text:t.text,removed:t.removed,origin:t.origin};d&&An(e,"change",e,p),c&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(p)}e.display.selForContextMenu=null}function ra(e,t,n,r,i){var o;r||(r=n),ot(r,n)<0&&(o=[r,n],n=o[0],r=o[1]),"string"==typeof t&&(t=e.splitLines(t)),Xo(e,{from:n,to:r,text:t,origin:i})}function ia(e,t,n,r){n1||!(this.children[0]instanceof la))){var s=[];this.collapse(s),this.children=[new la(s)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t50){for(var a=i.lines.length%25+25,s=a;s10);e.parent.maybeSpill()}},iterN:function(e,t,n){for(var r=0;r0||0==a&&!1!==o.clearWhenEmpty)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=N("span",[o.replacedWith],"CodeMirror-widget"),r.handleMouseEvents||o.widgetNode.setAttribute("cm-ignore-events","true"),r.insertLeft&&(o.widgetNode.insertLeft=!0)),o.collapsed){if(Qt(e,t.line,t,n,o)||t.line!=n.line&&Qt(e,n.line,t,n,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");kt()}o.addToHistory&&To(e,{from:t,to:n,origin:"markText"},e.sel,NaN);var s,l=t.line,u=e.cm;if(e.iter(l,n.line+1,(function(r){u&&o.collapsed&&!u.options.lineWrapping&&Xt(r)==u.display.maxLine&&(s=!0),o.collapsed&&l!=t.line&&Je(r,0),Lt(r,new Rt(o,l==t.line?t.ch:null,l==n.line?n.ch:null),e.cm&&e.cm.curOp),++l})),o.collapsed&&e.iter(t.line,n.line+1,(function(t){nn(e,t)&&Je(t,0)})),o.clearOnEnter&&he(o,"beforeCursorEnter",(function(){return o.clear()})),o.readOnly&&(Nt(),(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++fa,o.atomic=!0),u){if(s&&(u.curOp.updateMaxLine=!0),o.collapsed)Pr(u,t.line,n.line+1);else if(o.className||o.startStyle||o.endStyle||o.css||o.attributes||o.title)for(var c=t.line;c<=n.line;c++)Fr(u,c,"text");o.atomic&&qo(u.doc),An(u,"markerAdded",u,o)}return o}ha.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&Si(e),ye(this,"clear")){var n=this.find();n&&An(this,"clear",n.from,n.to)}for(var r=null,i=null,o=0;oe.display.maxLineLength&&(e.display.maxLine=u,e.display.maxLineLength=c,e.display.maxLineChanged=!0)}null!=r&&e&&this.collapsed&&Pr(e,r,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&qo(e.doc)),e&&An(e,"markerCleared",e,this,r,i),t&&Ci(e),this.parent&&this.parent.clear()}},ha.prototype.find=function(e,t){var n,r;null==e&&"bookmark"==this.type&&(e=1);for(var i=0;i=0;l--)Xo(this,r[l]);s?Uo(this,s):this.cm&&ai(this.cm)})),undo:Ii((function(){Jo(this,"undo")})),redo:Ii((function(){Jo(this,"redo")})),undoSelection:Ii((function(){Jo(this,"undo",!0)})),redoSelection:Ii((function(){Jo(this,"redo",!0)})),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,n=0,r=0;r=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t,n){e=dt(this,e),t=dt(this,t);var r=[],i=e.line;return this.iter(e.line,t.line+1,(function(o){var a=o.markedSpans;if(a)for(var s=0;s=l.to||null==l.from&&i!=e.line||null!=l.from&&i==t.line&&l.from>=t.ch||n&&!n(l.marker)||r.push(l.marker.parent||l.marker)}++i})),r},getAllMarks:function(){var e=[];return this.iter((function(t){var n=t.markedSpans;if(n)for(var r=0;re)return t=e,!0;e-=o,++n})),dt(this,it(n,t))},indexFromPos:function(e){e=dt(this,e);var t=e.ch;if(e.linet&&(t=e.from),null!=e.to&&e.to-1)return t.state.draggingText(e),void setTimeout((function(){return t.display.input.focus()}),20);try{var d=e.dataTransfer.getData("Text");if(d){var p;if(t.state.draggingText&&!t.state.draggingText.copy&&(p=t.listSelections()),Ho(t.doc,ao(n,n)),p)for(var f=0;f=0;t--)ra(e.doc,"",r[t].from,r[t].to,"+delete");ai(e)}))}function Va(e,t,n){var r=ae(e.text,t+n,n);return r<0||r>e.text.length?null:r}function Ya(e,t,n){var r=Va(e,t.ch,n);return null==r?null:new it(t.line,r,n<0?"after":"before")}function Wa(e,t,n,r,i){if(e){"rtl"==t.doc.direction&&(i=-i);var o=pe(n,t.doc.direction);if(o){var a,s=i<0?K(o):o[0],l=i<0==(1==s.level),u=l?"after":"before";if(s.level>0||"rtl"==t.doc.direction){var c=tr(t,n);a=i<0?n.text.length-1:0;var d=nr(t,c,a).top;a=se((function(e){return nr(t,c,e).top==d}),i<0==(1==s.level)?s.from:s.to-1,a),"before"==u&&(a=Va(n,a,1))}else a=i<0?s.to:s.from;return new it(r,a,u)}}return new it(r,i<0?n.text.length:0,i<0?"before":"after")}function Ka(e,t,n,r){var i=pe(t,e.doc.direction);if(!i)return Ya(t,n,r);n.ch>=t.text.length?(n.ch=t.text.length,n.sticky="before"):n.ch<=0&&(n.ch=0,n.sticky="after");var o=ce(i,n.ch,n.sticky),a=i[o];if("ltr"==e.doc.direction&&a.level%2==0&&(r>0?a.to>n.ch:a.from=a.from&&p>=c.begin)){var f=d?"before":"after";return new it(n.line,p,f)}}var h=function(e,t,r){for(var o=function(e,t){return t?new it(n.line,l(e,1),"before"):new it(n.line,e,"after")};e>=0&&e0==(1!=a.level),u=s?r.begin:l(r.end,-1);if(a.from<=u&&u0?c.end:l(c.begin,-1);return null==g||r>0&&g==t.text.length||(m=h(r>0?0:i.length-1,r,u(g)),!m)?null:m}Fa.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"},Fa.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"},Fa.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Fa.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"]},Fa["default"]=b?Fa.macDefault:Fa.pcDefault;var Qa={selectAll:Ko,singleSelection:function(e){return e.setSelection(e.getCursor("anchor"),e.getCursor("head"),$)},killLine:function(e){return za(e,(function(t){if(t.empty()){var n=Qe(e.doc,t.head.line).text.length;return t.head.ch==n&&t.head.line0)i=new it(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),it(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var a=Qe(e.doc,i.line-1).text;a&&(i=new it(i.line,1),e.replaceRange(o.charAt(0)+e.doc.lineSeparator()+a.charAt(a.length-1),it(i.line-1,a.length-1),i,"+transpose"))}n.push(new io(i,i))}e.setSelections(n)}))},newlineAndIndent:function(e){return Ni(e,(function(){for(var t=e.listSelections(),n=t.length-1;n>=0;n--)e.replaceRange(e.doc.lineSeparator(),t[n].anchor,t[n].head,"+input");t=e.listSelections();for(var r=0;r-1&&(ot((i=s.ranges[i]).from(),t)<0||t.xRel>0)&&(ot(i.to(),t)>0||t.xRel<0)?Es(e,r,t,o):Cs(e,r,t,o)}function Es(e,t,n,r){var i=e.display,o=!1,u=ki(e,(function(t){l&&(i.scroller.draggable=!1),e.state.draggingText=!1,e.state.delayingBlurEvent&&(e.hasFocus()?e.state.delayingBlurEvent=!1:Kr(e)),ge(i.wrapper.ownerDocument,"mouseup",u),ge(i.wrapper.ownerDocument,"mousemove",c),ge(i.scroller,"dragstart",d),ge(i.scroller,"drop",u),o||(Se(t),r.addNew||Lo(e.doc,n,null,null,r.extend),l&&!p||a&&9==s?setTimeout((function(){i.wrapper.ownerDocument.body.focus({preventScroll:!0}),i.input.focus()}),20):i.input.focus())})),c=function(e){o=o||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},d=function(){return o=!0};l&&(i.scroller.draggable=!0),e.state.draggingText=u,u.copy=!r.moveOnDrag,he(i.wrapper.ownerDocument,"mouseup",u),he(i.wrapper.ownerDocument,"mousemove",c),he(i.scroller,"dragstart",d),he(i.scroller,"drop",u),e.state.delayingBlurEvent=!0,setTimeout((function(){return i.input.focus()}),20),i.scroller.dragDrop&&i.scroller.dragDrop()}function Ss(e,t,n){if("char"==n)return new io(t,t);if("word"==n)return e.findWordAt(t);if("line"==n)return new io(it(t.line,0),dt(e.doc,it(t.line+1,0)));var r=n(e,t);return new io(r.from,r.to)}function Cs(e,t,n,r){a&&Kr(e);var i=e.display,o=e.doc;Se(t);var s,l,u=o.sel,c=u.ranges;if(r.addNew&&!r.extend?(l=o.sel.contains(n),s=l>-1?c[l]:new io(n,n)):(s=o.sel.primary(),l=o.sel.primIndex),"rectangle"==r.unit)r.addNew||(s=new io(n,n)),n=Mr(e,t,!0,!0),l=-1;else{var d=Ss(e,n,r.unit);s=r.extend?Mo(s,d.anchor,d.head,r.extend):d}r.addNew?-1==l?(l=c.length,Go(o,oo(e,c.concat([s]),l),{scroll:!1,origin:"*mouse"})):c.length>1&&c[l].empty()&&"char"==r.unit&&!r.extend?(Go(o,oo(e,c.slice(0,l).concat(c.slice(l+1)),0),{scroll:!1,origin:"*mouse"}),u=o.sel):Fo(o,l,s,q):(l=0,Go(o,new ro([s],0),q),u=o.sel);var p=n;function f(t){if(0!=ot(p,t))if(p=t,"rectangle"==r.unit){for(var i=[],a=e.options.tabSize,c=B(Qe(o,n.line).text,n.ch,a),d=B(Qe(o,t.line).text,t.ch,a),f=Math.min(c,d),h=Math.max(c,d),m=Math.min(n.line,t.line),g=Math.min(e.lastLine(),Math.max(n.line,t.line));m<=g;m++){var _=Qe(o,m).text,b=V(_,f,a);f==h?i.push(new io(it(m,b),it(m,b))):_.length>b&&i.push(new io(it(m,b),it(m,V(_,h,a))))}i.length||i.push(new io(n,n)),Go(o,oo(e,u.ranges.slice(0,l).concat(i),l),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var v,y=s,E=Ss(e,t,r.unit),S=y.anchor;ot(E.anchor,S)>0?(v=E.head,S=ut(y.from(),E.anchor)):(v=E.anchor,S=lt(y.to(),E.head));var C=u.ranges.slice(0);C[l]=Ds(e,new io(dt(o,S),v)),Go(o,oo(e,C,l),q)}}var h=i.wrapper.getBoundingClientRect(),m=0;function g(t){var n=++m,a=Mr(e,t,!0,"rectangle"==r.unit);if(a)if(0!=ot(a,p)){e.curOp.focus=R(),f(a);var s=ei(i,o);(a.line>=s.to||a.lineh.bottom?20:0;l&&setTimeout(ki(e,(function(){m==n&&(i.scroller.scrollTop+=l,g(t))})),50)}}function _(t){e.state.selectingText=!1,m=1/0,t&&(Se(t),i.input.focus()),ge(i.wrapper.ownerDocument,"mousemove",b),ge(i.wrapper.ownerDocument,"mouseup",v),o.history.lastSelOrigin=null}var b=ki(e,(function(e){0!==e.buttons&&xe(e)?g(e):_(e)})),v=ki(e,_);e.state.selectingText=v,he(i.wrapper.ownerDocument,"mousemove",b),he(i.wrapper.ownerDocument,"mouseup",v)}function Ds(e,t){var n=t.anchor,r=t.head,i=Qe(e.doc,n.line);if(0==ot(n,r)&&n.sticky==r.sticky)return t;var o=pe(i);if(!o)return t;var a=ce(o,n.ch,n.sticky),s=o[a];if(s.from!=n.ch&&s.to!=n.ch)return t;var l,u=a+(s.from==n.ch==(1!=s.level)?0:1);if(0==u||u==o.length)return t;if(r.line!=n.line)l=(r.line-n.line)*("ltr"==e.doc.direction?1:-1)>0;else{var c=ce(o,r.ch,r.sticky),d=c-a||(r.ch-n.ch)*(1==s.level?-1:1);l=c==u-1||c==u?d<0:d>0}var p=o[u+(l?-1:0)],f=l==(1==p.level),h=f?p.from:p.to,m=f?"after":"before";return n.ch==h&&n.sticky==m?t:new io(new it(n.line,h,m),r)}function Ts(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(p){return!1}if(i>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;r&&Se(t);var a=e.display,s=a.lineDiv.getBoundingClientRect();if(o>s.bottom||!ye(e,n))return De(t);o-=s.top-a.viewOffset;for(var l=0;l=i){var c=tt(e.doc,o),d=e.display.gutterSpecs[l];return _e(e,n,e,c,d.className,t),De(t)}}}function ws(e,t){return Ts(e,t,"gutterClick",!0)}function xs(e,t){$n(e.display,t)||As(e,t)||be(e,t,"contextmenu")||C||e.display.input.onContextMenu(t)}function As(e,t){return!!ye(e,"gutterContextMenu")&&Ts(e,t,"gutterContextMenu",!1)}function Os(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),dr(e)}ms.prototype.compare=function(e,t,n){return this.time+hs>e&&0==ot(t,this.pos)&&n==this.button};var Ns={toString:function(){return"CodeMirror.Init"}},ks={},Rs={};function Is(e){var t=e.optionHandlers;function n(n,r,i,o){e.defaults[n]=r,i&&(t[n]=o?function(e,t,n){n!=Ns&&i(e,t,n)}:i)}e.defineOption=n,e.Init=Ns,n("value","",(function(e,t){return e.setValue(t)}),!0),n("mode",null,(function(e,t){e.doc.modeOption=t,fo(e)}),!0),n("indentUnit",2,fo,!0),n("indentWithTabs",!1),n("smartIndent",!0),n("tabSize",4,(function(e){ho(e),dr(e),Pr(e)}),!0),n("lineSeparator",null,(function(e,t){if(e.doc.lineSep=t,t){var n=[],r=e.doc.first;e.doc.iter((function(e){for(var i=0;;){var o=e.text.indexOf(t,i);if(-1==o)break;i=o+t.length,n.push(it(r,o))}r++}));for(var i=n.length-1;i>=0;i--)ra(e.doc,t,n[i],it(n[i].line,n[i].ch+t.length))}})),n("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g,(function(e,t,n){e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),n!=Ns&&e.refresh()})),n("specialCharPlaceholder",mn,(function(e){return e.refresh()}),!0),n("electricChars",!0),n("inputStyle",_?"contenteditable":"textarea",(function(){throw new Error("inputStyle can not (yet) be changed in a running editor")}),!0),n("spellcheck",!1,(function(e,t){return e.getInputField().spellcheck=t}),!0),n("autocorrect",!1,(function(e,t){return e.getInputField().autocorrect=t}),!0),n("autocapitalize",!1,(function(e,t){return e.getInputField().autocapitalize=t}),!0),n("rtlMoveVisually",!y),n("wholeLineUpdateBefore",!0),n("theme","default",(function(e){Os(e),Qi(e)}),!0),n("keyMap","default",(function(e,t,n){var r=qa(t),i=n!=Ns&&qa(n);i&&i.detach&&i.detach(e,r),r.attach&&r.attach(e,i||null)})),n("extraKeys",null),n("configureMouse",null),n("lineWrapping",!1,Ls,!0),n("gutters",[],(function(e,t){e.display.gutterSpecs=Wi(t,e.options.lineNumbers),Qi(e)}),!0),n("fixedGutter",!0,(function(e,t){e.display.gutters.style.left=t?kr(e.display)+"px":"0",e.refresh()}),!0),n("coverGutterNextToScrollbar",!1,(function(e){return _i(e)}),!0),n("scrollbarStyle","native",(function(e){yi(e),_i(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)}),!0),n("lineNumbers",!1,(function(e,t){e.display.gutterSpecs=Wi(e.options.gutters,t),Qi(e)}),!0),n("firstLineNumber",1,Qi,!0),n("lineNumberFormatter",(function(e){return e}),Qi,!0),n("showCursorWhenSelecting",!1,Hr,!0),n("resetSelectionOnContextMenu",!0),n("lineWiseCopyCut",!0),n("pasteLinesPerSelection",!0),n("selectionsMayTouch",!1),n("readOnly",!1,(function(e,t){"nocursor"==t&&(Xr(e),e.display.input.blur()),e.display.input.readOnlyChanged(t)})),n("screenReaderLabel",null,(function(e,t){t=""===t?null:t,e.display.input.screenReaderLabelChanged(t)})),n("disableInput",!1,(function(e,t){t||e.display.input.reset()}),!0),n("dragDrop",!0,Ms),n("allowDropFileTypes",null),n("cursorBlinkRate",530),n("cursorScrollMargin",0),n("cursorHeight",1,Hr,!0),n("singleCursorHeightPerLine",!0,Hr,!0),n("workTime",100),n("workDelay",100),n("flattenSpans",!0,ho,!0),n("addModeClass",!1,ho,!0),n("pollInterval",100),n("undoDepth",200,(function(e,t){return e.doc.history.undoDepth=t})),n("historyEventDelay",1250),n("viewportMargin",10,(function(e){return e.refresh()}),!0),n("maxHighlightLength",1e4,ho,!0),n("moveInputWithCursor",!0,(function(e,t){t||e.display.input.resetPosition()})),n("tabindex",null,(function(e,t){return e.display.input.getField().tabIndex=t||""})),n("autofocus",null),n("direction","ltr",(function(e,t){return e.doc.setDirection(t)}),!0),n("phrases",null)}function Ms(e,t,n){var r=n&&n!=Ns;if(!t!=!r){var i=e.display.dragFunctions,o=t?he:ge;o(e.display.scroller,"dragstart",i.start),o(e.display.scroller,"dragenter",i.enter),o(e.display.scroller,"dragover",i.over),o(e.display.scroller,"dragleave",i.leave),o(e.display.scroller,"drop",i.drop)}}function Ls(e){e.options.lineWrapping?(I(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(w(e.display.wrapper,"CodeMirror-wrap"),sn(e)),Ir(e),Pr(e),dr(e),setTimeout((function(){return _i(e)}),100)}function Ps(e,t){var n=this;if(!(this instanceof Ps))return new Ps(e,t);this.options=t=t?F(t):{},F(ks,t,!1);var r=t.value;"string"==typeof r?r=new Sa(r,t.mode,null,t.lineSeparator,t.direction):t.mode&&(r.modeOption=t.mode),this.doc=r;var i=new Ps.inputStyles[t.inputStyle](this),o=this.display=new Xi(e,r,i,t);for(var u in o.wrapper.CodeMirror=this,Os(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),yi(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 j,keySeq:null,specialChars:null},t.autofocus&&!_&&o.input.focus(),a&&s<11&&setTimeout((function(){return n.display.input.reset(!0)}),20),Fs(this),Na(),Si(this),this.curOp.forceUpdate=!0,bo(this,r),t.autofocus&&!_||this.hasFocus()?setTimeout((function(){n.hasFocus()&&!n.state.focused&&Qr(n)}),20):Xr(this),Rs)Rs.hasOwnProperty(u)&&Rs[u](this,t[u],Ns);Yi(this),t.finishInit&&t.finishInit(this);for(var c=0;c400}he(t.scroller,"touchstart",(function(i){if(!be(e,i)&&!o(i)&&!ws(e,i)){t.input.ensurePolled(),clearTimeout(n);var a=+new Date;t.activeTouch={start:a,moved:!1,prev:a-r.end<=300?r:null},1==i.touches.length&&(t.activeTouch.left=i.touches[0].pageX,t.activeTouch.top=i.touches[0].pageY)}})),he(t.scroller,"touchmove",(function(){t.activeTouch&&(t.activeTouch.moved=!0)})),he(t.scroller,"touchend",(function(n){var r=t.activeTouch;if(r&&!$n(t,n)&&null!=r.left&&!r.moved&&new Date-r.start<300){var o,a=e.coordsChar(t.activeTouch,"page");o=!r.prev||l(r,r.prev)?new io(a,a):!r.prev.prev||l(r,r.prev.prev)?e.findWordAt(a):new io(it(a.line,0),dt(e.doc,it(a.line+1,0))),e.setSelection(o.anchor,o.head),e.focus(),Se(n)}i()})),he(t.scroller,"touchcancel",i),he(t.scroller,"scroll",(function(){t.scroller.clientHeight&&(di(e,t.scroller.scrollTop),fi(e,t.scroller.scrollLeft,!0),_e(e,"scroll",e))})),he(t.scroller,"mousewheel",(function(t){return no(e,t)})),he(t.scroller,"DOMMouseScroll",(function(t){return no(e,t)})),he(t.wrapper,"scroll",(function(){return t.wrapper.scrollTop=t.wrapper.scrollLeft=0})),t.dragFunctions={enter:function(t){be(e,t)||Te(t)},over:function(t){be(e,t)||(wa(e,t),Te(t))},start:function(t){return Ta(e,t)},drop:ki(e,Da),leave:function(t){be(e,t)||xa(e)}};var u=t.input.getField();he(u,"keyup",(function(t){return cs.call(e,t)})),he(u,"keydown",ki(e,ls)),he(u,"keypress",ki(e,ds)),he(u,"focus",(function(t){return Qr(e,t)})),he(u,"blur",(function(t){return Xr(e,t)}))}Ps.defaults=ks,Ps.optionHandlers=Rs;var Bs=[];function js(e,t,n,r){var i,o=e.doc;null==n&&(n="add"),"smart"==n&&(o.mode.indent?i=bt(e,t).state:n="prev");var a=e.options.tabSize,s=Qe(o,t),l=B(s.text,null,a);s.stateAfter&&(s.stateAfter=null);var u,c=s.text.match(/^\s*/)[0];if(r||/\S/.test(s.text)){if("smart"==n&&(u=o.mode.indent(i,s.text.slice(c.length),s.text),u==H||u>150)){if(!r)return;n="prev"}}else u=0,n="not";"prev"==n?u=t>o.first?B(Qe(o,t-1).text,null,a):0:"add"==n?u=l+e.options.indentUnit:"subtract"==n?u=l-e.options.indentUnit:"number"==typeof n&&(u=l+n),u=Math.max(0,u);var d="",p=0;if(e.options.indentWithTabs)for(var f=Math.floor(u/a);f;--f)p+=a,d+="\t";if(pa,l=Ie(t),u=null;if(s&&r.ranges.length>1)if(Us&&Us.text.join("\n")==t){if(r.ranges.length%Us.text.length==0){u=[];for(var c=0;c=0;p--){var f=r.ranges[p],h=f.from(),m=f.to();f.empty()&&(n&&n>0?h=it(h.line,h.ch-n):e.state.overwrite&&!s?m=it(m.line,Math.min(Qe(o,m.line).text.length,m.ch+K(l).length)):s&&Us&&Us.lineWise&&Us.text.join("\n")==l.join("\n")&&(h=m=it(h.line,0)));var g={from:h,to:m,text:u?u[p%u.length]:l,origin:i||(s?"paste":e.state.cutIncoming>a?"cut":"+input")};Xo(e.doc,g),An(e,"inputRead",e,g)}t&&!s&&qs(e,t),ai(e),e.curOp.updateInput<2&&(e.curOp.updateInput=d),e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=-1}function $s(e,t){var n=e.clipboardData&&e.clipboardData.getData("Text");if(n)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||Ni(t,(function(){return Hs(t,n,0,null,"paste")})),!0}function qs(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var n=e.doc.sel,r=n.ranges.length-1;r>=0;r--){var i=n.ranges[r];if(!(i.head.ch>100||r&&n.ranges[r-1].head.line==i.head.line)){var o=e.getModeAt(i.head),a=!1;if(o.electricChars){for(var s=0;s-1){a=js(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Qe(e.doc,i.head.line).text.slice(0,i.head.ch))&&(a=js(e,i.head.line,"smart"));a&&An(e,"electricInput",e,i.head.line)}}}function zs(e){for(var t=[],n=[],r=0;rn&&(js(this,i.head.line,e,!0),n=i.head.line,r==this.doc.sel.primIndex&&ai(this));else{var o=i.from(),a=i.to(),s=Math.max(n,o.line);n=Math.min(this.lastLine(),a.line-(a.ch?0:1))+1;for(var l=s;l0&&Fo(this.doc,r,new io(o,u[r].to()),$)}}})),getTokenAt:function(e,t){return Ct(this,e,t)},getLineTokens:function(e,t){return Ct(this,it(e),t,!0)},getTokenTypeAt:function(e){e=dt(this.doc,e);var t,n=_t(this,Qe(this.doc,e.line)),r=0,i=(n.length-1)/2,o=e.ch;if(0==o)t=n[2];else for(;;){var a=r+i>>1;if((a?n[2*a-1]:0)>=o)i=a;else{if(!(n[2*a+1]o&&(e=o,i=!0),r=Qe(this.doc,e)}else r=e;return mr(this,r,{top:0,left:0},t||"page",n||i).top+(i?this.doc.height-on(r):0)},defaultTextHeight:function(){return Ar(this.display)},defaultCharWidth:function(){return Or(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,n,r,i){var o=this.display;e=br(this,dt(this.doc,e));var a=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"==r)a=e.top;else if("above"==r||"near"==r){var l=Math.max(o.wrapper.clientHeight,this.doc.height),u=Math.max(o.sizer.clientWidth,o.lineSpace.clientWidth);("above"==r||e.bottom+t.offsetHeight>l)&&e.top>t.offsetHeight?a=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=l&&(a=e.bottom),s+t.offsetWidth>u&&(s=u-t.offsetWidth)}t.style.top=a+"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"),n&&ri(this,{left:s,top:a,right:s+t.offsetWidth,bottom:a+t.offsetHeight})},triggerOnKeyDown:Ri(ls),triggerOnKeyPress:Ri(ds),triggerOnKeyUp:cs,triggerOnMouseDown:Ri(_s),execCommand:function(e){if(Qa.hasOwnProperty(e))return Qa[e].call(null,this)},triggerElectric:Ri((function(e){qs(this,e)})),findPosH:function(e,t,n,r){var i=1;t<0&&(i=-1,t=-t);for(var o=dt(this.doc,e),a=0;a0&&s(n.charAt(r-1)))--r;while(i.5||this.options.lineWrapping)&&Ir(this),_e(this,"refresh",this)})),swapDoc:Ri((function(e){var t=this.doc;return t.cm=null,this.state.selectingText&&this.state.selectingText(),bo(this,e),dr(this),this.display.input.reset(),si(this,e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,An(this,"swapDoc",this,t),t})),phrase:function(e){var t=this.options.phrases;return t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:e},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}},Ee(e),e.registerHelper=function(t,r,i){n.hasOwnProperty(t)||(n[t]=e[t]={_global:[]}),n[t][r]=i},e.registerGlobalHelper=function(t,r,i,o){e.registerHelper(t,r,o),n[t]._global.push({pred:i,val:o})}}function Ks(e,t,n,r,i){var o=t,a=n,s=Qe(e,t.line),l=i&&"rtl"==e.direction?-n:n;function u(){var n=t.line+l;return!(n=e.first+e.size)&&(t=new it(n,t.ch,t.sticky),s=Qe(e,n))}function c(o){var a;if("codepoint"==r){var c=s.text.charCodeAt(t.ch+(n>0?0:-1));if(isNaN(c))a=null;else{var d=n>0?c>=55296&&c<56320:c>=56320&&c<57343;a=new it(t.line,Math.max(0,Math.min(s.text.length,t.ch+n*(d?2:1))),-n)}}else a=i?Ka(e.cm,s,t,n):Ya(s,t,n);if(null==a){if(o||!u())return!1;t=Wa(i,e.cm,s,t.line,l)}else t=a;return!0}if("char"==r||"codepoint"==r)c();else if("column"==r)c(!0);else if("word"==r||"group"==r)for(var d=null,p="group"==r,f=e.cm&&e.cm.getHelper(t,"wordChars"),h=!0;;h=!1){if(n<0&&!c(!h))break;var m=s.text.charAt(t.ch)||"\n",g=ne(m,f)?"w":p&&"\n"==m?"n":!p||/\s/.test(m)?null:"p";if(!p||h||g||(g="s"),d&&d!=g){n<0&&(n=1,c(),t.sticky="after");break}if(g&&(d=g),n>0&&!c(!h))break}var _=Yo(e,t,o,a,!0);return at(o,_)&&(_.hitSide=!0),_}function Qs(e,t,n,r){var i,o,a=e.doc,s=t.left;if("page"==r){var l=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),u=Math.max(l-.5*Ar(e.display),3);i=(n>0?t.bottom:t.top)+n*u}else"line"==r&&(i=n>0?t.bottom+3:t.top-3);for(;;){if(o=Er(e,s,i),!o.outside)break;if(n<0?i<=0:i>=a.height){o.hitSide=!0;break}i+=5*n}return o}var Xs=function(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new j,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};function Zs(e,t){var n=er(e,t.line);if(!n||n.hidden)return null;var r=Qe(e.doc,t.line),i=Xn(n,r,t.line),o=pe(r,e.doc.direction),a="left";if(o){var s=ce(o,t.ch);a=s%2?"right":"left"}var l=or(i.map,t.ch,a);return l.offset="right"==l.collapse?l.end:l.start,l}function Js(e){for(var t=e;t;t=t.parentNode)if(/CodeMirror-gutter-wrapper/.test(t.className))return!0;return!1}function el(e,t){return t&&(e.bad=!0),e}function tl(e,t,n,r,i){var o="",a=!1,s=e.doc.lineSeparator(),l=!1;function u(e){return function(t){return t.id==e}}function c(){a&&(o+=s,l&&(o+=s),a=l=!1)}function d(e){e&&(c(),o+=e)}function p(t){if(1==t.nodeType){var n=t.getAttribute("cm-text");if(n)return void d(n);var o,f=t.getAttribute("cm-marker");if(f){var h=e.findMarks(it(r,0),it(i+1,0),u(+f));return void(h.length&&(o=h[0].find(0))&&d(Xe(e.doc,o.from,o.to).join(s)))}if("false"==t.getAttribute("contenteditable"))return;var m=/^(pre|div|p|li|table|br)$/i.test(t.nodeName);if(!/^br$/i.test(t.nodeName)&&0==t.textContent.length)return;m&&c();for(var g=0;g=t.display.viewTo||o.line