UNPKG

scriptbox

Version:

Script box is a full VAS application

2 lines 166 kB
!function(a){if("object"==typeof exports&&"object"==typeof module)module.exports=a();else{if("function"==typeof define&&define.amd)return define([],a);this.CodeMirror=a()}}(function(){"use strict";function z(a,c){if(!(this instanceof z))return new z(a,c);this.options=c=c||{},Fg($d,c,!1),N(c);var d=c.value;"string"==typeof d&&(d=new zf(d,c.mode)),this.doc=d;var e=this.display=new A(a,d);e.wrapper.CodeMirror=this,J(this),H(this),c.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),c.autofocus&&!r&&Rc(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,draggingText:!1,highlight:new vg},b&&setTimeout(Gg(Qc,this,!0),20),Uc(this);var f=this;Ac(this,function(){f.curOp.forceUpdate=!0,Df(f,d),c.autofocus&&!r||Rg()==e.input?setTimeout(Gg(vd,f),20):wd(f);for(var a in _d)_d.hasOwnProperty(a)&&_d[a](f,c[a],be);for(var b=0;b<fe.length;++b)fe[b](f)})}function A(a,b){var d=this,e=d.input=Mg("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none");h?e.style.width="1000px":e.setAttribute("wrap","off"),q&&(e.style.border="1px solid black"),e.setAttribute("autocorrect","off"),e.setAttribute("autocapitalize","off"),e.setAttribute("spellcheck","false"),d.inputDiv=Mg("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;"),d.scrollbarH=Mg("div",[Mg("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar"),d.scrollbarV=Mg("div",[Mg("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),d.scrollbarFiller=Mg("div",null,"CodeMirror-scrollbar-filler"),d.gutterFiller=Mg("div",null,"CodeMirror-gutter-filler"),d.lineDiv=Mg("div",null,"CodeMirror-code"),d.selectionDiv=Mg("div",null,null,"position: relative; z-index: 1"),d.cursorDiv=Mg("div",null,"CodeMirror-cursors"),d.measure=Mg("div",null,"CodeMirror-measure"),d.lineMeasure=Mg("div",null,"CodeMirror-measure"),d.lineSpace=Mg("div",[d.measure,d.lineMeasure,d.selectionDiv,d.cursorDiv,d.lineDiv],null,"position: relative; outline: none"),d.mover=Mg("div",[Mg("div",[d.lineSpace],"CodeMirror-lines")],null,"position: relative"),d.sizer=Mg("div",[d.mover],"CodeMirror-sizer"),d.heightForcer=Mg("div",null,null,"position: absolute; height: "+qg+"px; width: 1px;"),d.gutters=Mg("div",null,"CodeMirror-gutters"),d.lineGutter=null,d.scroller=Mg("div",[d.sizer,d.heightForcer,d.gutters],"CodeMirror-scroll"),d.scroller.setAttribute("tabIndex","-1"),d.wrapper=Mg("div",[d.inputDiv,d.scrollbarH,d.scrollbarV,d.scrollbarFiller,d.gutterFiller,d.scroller],"CodeMirror"),c&&(d.gutters.style.zIndex=-1,d.scroller.style.paddingRight=0),q&&(e.style.width="0px"),h||(d.scroller.draggable=!0),m&&(d.inputDiv.style.height="1px",d.inputDiv.style.position="absolute"),c&&(d.scrollbarH.style.minHeight=d.scrollbarV.style.minWidth="18px"),a.appendChild?a.appendChild(d.wrapper):a(d.wrapper),d.viewFrom=d.viewTo=b.first,d.view=[],d.externalMeasured=null,d.viewOffset=0,d.lastSizeC=0,d.updateLineNumbers=null,d.lineNumWidth=d.lineNumInnerWidth=d.lineNumChars=null,d.prevInput="",d.alignWidgets=!1,d.pollingFast=!1,d.poll=new vg,d.cachedCharWidth=d.cachedTextHeight=d.cachedPaddingH=null,d.inaccurateSelection=!1,d.maxLine=null,d.maxLineLength=0,d.maxLineChanged=!1,d.wheelDX=d.wheelDY=d.wheelStartX=d.wheelStartY=null,d.shift=!1}function B(a){a.doc.mode=z.getMode(a.options,a.doc.modeOption),C(a)}function C(a){a.doc.iter(function(a){a.stateAfter&&(a.stateAfter=null),a.styles&&(a.styles=null)}),a.doc.frontier=a.doc.first,Tb(a,100),a.state.modeGen++,a.curOp&&Gc(a)}function D(a){a.options.lineWrapping?(Ug(a.display.wrapper,"CodeMirror-wrap"),a.display.sizer.style.minWidth=""):(Tg(a.display.wrapper,"CodeMirror-wrap"),M(a)),F(a),Gc(a),jc(a),setTimeout(function(){P(a)},100)}function E(a){var b=vc(a.display),c=a.options.lineWrapping,d=c&&Math.max(5,a.display.scroller.clientWidth/wc(a.display)-3);return function(e){if(Ve(a.doc,e))return 0;var f=0;if(e.widgets)for(var g=0;g<e.widgets.length;g++)e.widgets[g].height&&(f+=e.widgets[g].height);return c?f+(Math.ceil(e.text.length/d)||1)*b:f+b}}function F(a){var b=a.doc,c=E(a);b.iter(function(a){var b=c(a);b!=a.height&&Hf(a,b)})}function G(a){var b=ke[a.options.keyMap],c=b.style;a.display.wrapper.className=a.display.wrapper.className.replace(/\s*cm-keymap-\S+/g,"")+(c?" cm-keymap-"+c:"")}function H(a){a.display.wrapper.className=a.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+a.options.theme.replace(/(^|\s)\s*/g," cm-s-"),jc(a)}function I(a){J(a),Gc(a),setTimeout(function(){R(a)},20)}function J(a){var b=a.display.gutters,c=a.options.gutters;Og(b);for(var d=0;d<c.length;++d){var e=c[d],f=b.appendChild(Mg("div",null,"CodeMirror-gutter "+e));"CodeMirror-linenumbers"==e&&(a.display.lineGutter=f,f.style.width=(a.display.lineNumWidth||1)+"px")}b.style.display=d?"":"none",K(a)}function K(a){var b=a.display.gutters.offsetWidth;a.display.sizer.style.marginLeft=b+"px",a.display.scrollbarH.style.left=a.options.fixedGutter?b+"px":0}function L(a){if(0==a.height)return 0;for(var c,b=a.text.length,d=a;c=Oe(d);){var e=c.find(0,!0);d=e.from.line,b+=e.from.ch-e.to.ch}for(d=a;c=Pe(d);){var e=c.find(0,!0);b-=d.text.length-e.from.ch,d=e.to.line,b+=d.text.length-e.to.ch}return b}function M(a){var b=a.display,c=a.doc;b.maxLine=Ef(c,c.first),b.maxLineLength=L(b.maxLine),b.maxLineChanged=!0,c.iter(function(a){var c=L(a);c>b.maxLineLength&&(b.maxLineLength=c,b.maxLine=a)})}function N(a){var b=Cg(a.gutters,"CodeMirror-linenumbers");-1==b&&a.lineNumbers?a.gutters=a.gutters.concat(["CodeMirror-linenumbers"]):b>-1&&!a.lineNumbers&&(a.gutters=a.gutters.slice(0),a.gutters.splice(b,1))}function O(a){var b=a.display.scroller;return{clientHeight:b.clientHeight,barHeight:a.display.scrollbarV.clientHeight,scrollWidth:b.scrollWidth,clientWidth:b.clientWidth,barWidth:a.display.scrollbarH.clientWidth,docHeight:Math.round(a.doc.height+Yb(a.display))}}function P(a,b){b||(b=O(a));var c=a.display,d=b.docHeight+qg,e=b.scrollWidth>b.clientWidth,f=d>b.clientHeight;if(f?(c.scrollbarV.style.display="block",c.scrollbarV.style.bottom=e?Yg(c.measure)+"px":"0",c.scrollbarV.firstChild.style.height=Math.max(0,d-b.clientHeight+(b.barHeight||c.scrollbarV.clientHeight))+"px"):(c.scrollbarV.style.display="",c.scrollbarV.firstChild.style.height="0"),e?(c.scrollbarH.style.display="block",c.scrollbarH.style.right=f?Yg(c.measure)+"px":"0",c.scrollbarH.firstChild.style.width=b.scrollWidth-b.clientWidth+(b.barWidth||c.scrollbarH.clientWidth)+"px"):(c.scrollbarH.style.display="",c.scrollbarH.firstChild.style.width="0"),e&&f?(c.scrollbarFiller.style.display="block",c.scrollbarFiller.style.height=c.scrollbarFiller.style.width=Yg(c.measure)+"px"):c.scrollbarFiller.style.display="",e&&a.options.coverGutterNextToScrollbar&&a.options.fixedGutter?(c.gutterFiller.style.display="block",c.gutterFiller.style.height=Yg(c.measure)+"px",c.gutterFiller.style.width=c.gutters.offsetWidth+"px"):c.gutterFiller.style.display="",n&&0===Yg(c.measure)){c.scrollbarV.style.minWidth=c.scrollbarH.style.minHeight=o?"18px":"12px";var g=function(b){dg(b)!=c.scrollbarV&&dg(b)!=c.scrollbarH&&Bc(a,Xc)(b)};fg(c.scrollbarV,"mousedown",g),fg(c.scrollbarH,"mousedown",g)}}function Q(a,b,c){var d=c&&null!=c.top?c.top:a.scroller.scrollTop;d=Math.floor(d-Xb(a));var e=c&&null!=c.bottom?c.bottom:d+a.wrapper.clientHeight,f=Jf(b,d),g=Jf(b,e);if(c&&c.ensure){var h=c.ensure.from.line,i=c.ensure.to.line;if(f>h)return{from:h,to:Jf(b,Kf(Ef(b,h))+a.wrapper.clientHeight)};if(Math.min(i,b.lastLine())>=g)return{from:Jf(b,Kf(Ef(b,i))-a.wrapper.clientHeight),to:i}}return{from:f,to:g}}function R(a){var b=a.display,c=b.view;if(b.alignWidgets||b.gutters.firstChild&&a.options.fixedGutter){for(var d=U(b)-b.scroller.scrollLeft+a.doc.scrollLeft,e=b.gutters.offsetWidth,f=d+"px",g=0;g<c.length;g++)if(!c[g].hidden){a.options.fixedGutter&&c[g].gutter&&(c[g].gutter.style.left=f);var h=c[g].alignable;if(h)for(var i=0;i<h.length;i++)h[i].style.left=f}a.options.fixedGutter&&(b.gutters.style.left=d+e+"px")}}function S(a){if(!a.options.lineNumbers)return!1;var b=a.doc,c=T(a.options,b.first+b.size-1),d=a.display;if(c.length!=d.lineNumChars){var e=d.measure.appendChild(Mg("div",[Mg("div",c)],"CodeMirror-linenumber CodeMirror-gutter-elt")),f=e.firstChild.offsetWidth,g=e.offsetWidth-f;return d.lineGutter.style.width="",d.lineNumInnerWidth=Math.max(f,d.lineGutter.offsetWidth-g),d.lineNumWidth=d.lineNumInnerWidth+g,d.lineNumChars=d.lineNumInnerWidth?c.length:-1,d.lineGutter.style.width=d.lineNumWidth+"px",K(a),!0}return!1}function T(a,b){return String(a.lineNumberFormatter(b+a.firstLineNumber))}function U(a){return a.scroller.getBoundingClientRect().left-a.sizer.getBoundingClientRect().left}function V(a,b,c){for(var f,d=a.display.viewFrom,e=a.display.viewTo,g=Q(a.display,a.doc,b),i=!0;;i=!1){var j=a.display.scroller.clientWidth;if(!W(a,g,c))break;f=!0,a.display.maxLineChanged&&!a.options.lineWrapping&&X(a);var k=O(a);if(Pb(a),Y(a,k),P(a,k),h&&a.options.lineWrapping&&Z(a,k),i&&a.options.lineWrapping&&j!=a.display.scroller.clientWidth)c=!0;else if(c=!1,b&&null!=b.top&&(b={top:Math.min(k.docHeight-qg-k.clientHeight,b.top)}),g=Q(a.display,a.doc,b),g.from>=a.display.viewFrom&&g.to<=a.display.viewTo)break}return a.display.updateLineNumbers=null,f&&(kg(a,"update",a),(a.display.viewFrom!=d||a.display.viewTo!=e)&&kg(a,"viewportChange",a,a.display.viewFrom,a.display.viewTo)),f}function W(a,b,c){var d=a.display,e=a.doc;if(!d.wrapper.offsetWidth)return Ic(a),void 0;if(!(!c&&b.from>=d.viewFrom&&b.to<=d.viewTo&&0==Mc(a))){S(a)&&Ic(a);var f=ab(a),g=e.first+e.size,h=Math.max(b.from-a.options.viewportMargin,e.first),i=Math.min(g,b.to+a.options.viewportMargin);d.viewFrom<h&&h-d.viewFrom<20&&(h=Math.max(e.first,d.viewFrom)),d.viewTo>i&&d.viewTo-i<20&&(i=Math.min(g,d.viewTo)),y&&(h=Te(a.doc,h),i=Ue(a.doc,i));var j=h!=d.viewFrom||i!=d.viewTo||d.lastSizeC!=d.wrapper.clientHeight;Lc(a,h,i),d.viewOffset=Kf(Ef(a.doc,d.viewFrom)),a.display.mover.style.top=d.viewOffset+"px";var k=Mc(a);if(j||0!=k||c){var l=Rg();return k>4&&(d.lineDiv.style.display="none"),bb(a,d.updateLineNumbers,f),k>4&&(d.lineDiv.style.display=""),l&&Rg()!=l&&l.offsetHeight&&l.focus(),Og(d.cursorDiv),Og(d.selectionDiv),j&&(d.lastSizeC=d.wrapper.clientHeight,Tb(a,400)),$(a),!0}}}function X(a){var b=a.display,c=bc(a,b.maxLine,b.maxLine.text.length).left;b.maxLineChanged=!1;var d=Math.max(0,c+3),e=Math.max(0,b.sizer.offsetLeft+d+qg-b.scroller.clientWidth);b.sizer.style.minWidth=d+"px",e<a.doc.scrollLeft&&hd(a,Math.min(b.scroller.scrollLeft,e),!0)}function Y(a,b){a.display.sizer.style.minHeight=a.display.heightForcer.style.top=b.docHeight+"px",a.display.gutters.style.height=Math.max(b.docHeight,b.clientHeight-qg)+"px"}function Z(a,b){a.display.sizer.offsetWidth+a.display.gutters.offsetWidth<a.display.scroller.clientWidth-1&&(a.display.sizer.style.minHeight=a.display.heightForcer.style.top="0px",a.display.gutters.style.height=b.docHeight+"px")}function $(a){for(var b=a.display,d=b.lineDiv.offsetTop,e=0;e<b.view.length;e++){var g,f=b.view[e];if(!f.hidden){if(c){var h=f.node.offsetTop+f.node.offsetHeight;g=h-d,d=h}else{var i=f.node.getBoundingClientRect();g=i.bottom-i.top}var j=f.line.height-g;if(2>g&&(g=vc(b)),(j>.001||-.001>j)&&(Hf(f.line,g),_(f.line),f.rest))for(var k=0;k<f.rest.length;k++)_(f.rest[k])}}}function _(a){if(a.widgets)for(var b=0;b<a.widgets.length;++b)a.widgets[b].height=a.widgets[b].node.offsetHeight}function ab(a){for(var b=a.display,c={},d={},e=b.gutters.firstChild,f=0;e;e=e.nextSibling,++f)c[a.options.gutters[f]]=e.offsetLeft,d[a.options.gutters[f]]=e.offsetWidth;return{fixedPos:U(b),gutterTotalWidth:b.gutters.offsetWidth,gutterLeft:c,gutterWidth:d,wrapperWidth:b.wrapper.clientWidth}}function bb(a,b,c){function i(b){var c=b.nextSibling;return h&&s&&a.display.currentWheelTarget==b?b.style.display="none":b.parentNode.removeChild(b),c}for(var d=a.display,e=a.options.lineNumbers,f=d.lineDiv,g=f.firstChild,j=d.view,k=d.viewFrom,l=0;l<j.length;l++){var m=j[l];if(m.hidden);else if(m.node){for(;g!=m.node;)g=i(g);var o=e&&null!=b&&k>=b&&m.lineNumber;m.changes&&(Cg(m.changes,"gutter")>-1&&(o=!1),cb(a,m,k,c)),o&&(Og(m.lineNumber),m.lineNumber.appendChild(document.createTextNode(T(a.options,k)))),g=m.node.nextSibling}else{var n=kb(a,m,k,c);f.insertBefore(n,g)}k+=m.size}for(;g;)g=i(g)}function cb(a,b,c,d){for(var e=0;e<b.changes.length;e++){var f=b.changes[e];"text"==f?gb(a,b):"gutter"==f?ib(a,b,c,d):"class"==f?hb(b):"widget"==f&&jb(b,d)}b.changes=null}function db(a){return a.node==a.text&&(a.node=Mg("div",null,null,"position: relative"),a.text.parentNode&&a.text.parentNode.replaceChild(a.node,a.text),a.node.appendChild(a.text),c&&(a.node.style.zIndex=2)),a.node}function eb(a){var b=a.bgClass?a.bgClass+" "+(a.line.bgClass||""):a.line.bgClass;if(b&&(b+=" CodeMirror-linebackground"),a.background)b?a.background.className=b:(a.background.parentNode.removeChild(a.background),a.background=null);else if(b){var c=db(a);a.background=c.insertBefore(Mg("div",null,b),c.firstChild)}}function fb(a,b){var c=a.display.externalMeasured;return c&&c.line==b.line?(a.display.externalMeasured=null,b.measure=c.measure,c.built):nf(a,b)}function gb(a,b){var c=b.text.className,d=fb(a,b);b.text==b.node&&(b.node=d.pre),b.text.parentNode.replaceChild(d.pre,b.text),b.text=d.pre,d.bgClass!=b.bgClass||d.textClass!=b.textClass?(b.bgClass=d.bgClass,b.textClass=d.textClass,hb(b)):c&&(b.text.className=c)}function hb(a){eb(a),a.line.wrapClass?db(a).className=a.line.wrapClass:a.node!=a.text&&(a.node.className="");var b=a.textClass?a.textClass+" "+(a.line.textClass||""):a.line.textClass;a.text.className=b||""}function ib(a,b,c,d){b.gutter&&(b.node.removeChild(b.gutter),b.gutter=null);var e=b.line.gutterMarkers;if(a.options.lineNumbers||e){var f=db(b),g=b.gutter=f.insertBefore(Mg("div",null,"CodeMirror-gutter-wrapper","position: absolute; left: "+(a.options.fixedGutter?d.fixedPos:-d.gutterTotalWidth)+"px"),b.text);if(!a.options.lineNumbers||e&&e["CodeMirror-linenumbers"]||(b.lineNumber=g.appendChild(Mg("div",T(a.options,c),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+d.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+a.display.lineNumInnerWidth+"px"))),e)for(var h=0;h<a.options.gutters.length;++h){var i=a.options.gutters[h],j=e.hasOwnProperty(i)&&e[i];j&&g.appendChild(Mg("div",[j],"CodeMirror-gutter-elt","left: "+d.gutterLeft[i]+"px; width: "+d.gutterWidth[i]+"px"))}}}function jb(a,b){a.alignable&&(a.alignable=null);for(var d,c=a.node.firstChild;c;c=d){var d=c.nextSibling;"CodeMirror-linewidget"==c.className&&a.node.removeChild(c)}lb(a,b)}function kb(a,b,c,d){var e=fb(a,b);return b.text=b.node=e.pre,e.bgClass&&(b.bgClass=e.bgClass),e.textClass&&(b.textClass=e.textClass),hb(b),ib(a,b,c,d),lb(b,d),b.node}function lb(a,b){if(mb(a.line,a,b,!0),a.rest)for(var c=0;c<a.rest.length;c++)mb(a.rest[c],a,b,!1)}function mb(a,b,c,d){if(a.widgets)for(var e=db(b),f=0,g=a.widgets;f<g.length;++f){var h=g[f],i=Mg("div",[h.node],"CodeMirror-linewidget");h.handleMouseEvents||(i.ignoreEvents=!0),nb(h,i,b,c),d&&h.above?e.insertBefore(i,b.gutter||b.text):e.appendChild(i),kg(h,"redraw")}}function nb(a,b,c,d){if(a.noHScroll){(c.alignable||(c.alignable=[])).push(b);var e=d.wrapperWidth;b.style.left=d.fixedPos+"px",a.coverGutter||(e-=d.gutterTotalWidth,b.style.paddingLeft=d.gutterTotalWidth+"px"),b.style.width=e+"px"}a.coverGutter&&(b.style.zIndex=5,b.style.position="relative",a.noHScroll||(b.style.marginLeft=-d.gutterTotalWidth+"px"))}function qb(a){return ob(a.line,a.ch)}function rb(a,b){return pb(a,b)<0?b:a}function sb(a,b){return pb(a,b)<0?a:b}function tb(a,b){this.ranges=a,this.primIndex=b}function ub(a,b){this.anchor=a,this.head=b}function vb(a,b){var c=a[b];a.sort(function(a,b){return pb(a.from(),b.from())}),b=Cg(a,c);for(var d=1;d<a.length;d++){var e=a[d],f=a[d-1];if(pb(f.to(),e.from())>=0){var g=sb(f.from(),e.from()),h=rb(f.to(),e.to()),i=f.empty()?e.from()==e.head:f.from()==f.head;b>=d&&--b,a.splice(--d,2,new ub(i?h:g,i?g:h))}}return new tb(a,b)}function wb(a,b){return new tb([new ub(a,b||a)],0)}function xb(a,b){return Math.max(a.first,Math.min(b,a.first+a.size-1))}function yb(a,b){if(b.line<a.first)return ob(a.first,0);var c=a.first+a.size-1;return b.line>c?ob(c,Ef(a,c).text.length):zb(b,Ef(a,b.line).text.length)}function zb(a,b){var c=a.ch;return null==c||c>b?ob(a.line,b):0>c?ob(a.line,0):a}function Ab(a,b){return b>=a.first&&b<a.first+a.size}function Bb(a,b){for(var c=[],d=0;d<b.length;d++)c[d]=yb(a,b[d]);return c}function Cb(a,b,c,d){if(a.cm&&a.cm.display.shift||a.extend){var e=b.anchor;if(d){var f=pb(c,e)<0;f!=pb(d,e)<0?(e=c,c=d):f!=pb(c,d)<0&&(c=d)}return new ub(e,c)}return new ub(d||c,c)}function Db(a,b,c,d){Jb(a,new tb([Cb(a,a.sel.primary(),b,c)],0),d)}function Eb(a,b,c){for(var d=[],e=0;e<a.sel.ranges.length;e++)d[e]=Cb(a,a.sel.ranges[e],b[e],null);var f=vb(d,a.sel.primIndex);Jb(a,f,c)}function Fb(a,b,c,d){var e=a.sel.ranges.slice(0);e[b]=c,Jb(a,vb(e,a.sel.primIndex),d)}function Gb(a,b,c,d){Jb(a,wb(b,c),d)}function Hb(a,b){var c={ranges:b.ranges,update:function(b){this.ranges=[];for(var c=0;c<b.length;c++)this.ranges[c]=new ub(yb(a,b[c].anchor),yb(a,b[c].head))}};return hg(a,"beforeSelectionChange",a,c),a.cm&&hg(a.cm,"beforeSelectionChange",a.cm,c),c.ranges!=b.ranges?vb(c.ranges,c.ranges.length-1):b}function Ib(a,b,c){var d=a.history.done,e=Ag(d);e&&e.ranges?(d[d.length-1]=b,Kb(a,b,c)):Jb(a,b,c)}function Jb(a,b,c){Kb(a,b,c),Sf(a,a.sel,a.cm?a.cm.curOp.id:0/0,c)}function Kb(a,b,c){(og(a,"beforeSelectionChange")||a.cm&&og(a.cm,"beforeSelectionChange"))&&(b=Hb(a,b));var d=pb(b.primary().head,a.sel.primary().head)<0?-1:1;Lb(a,Nb(a,b,d,!0)),c&&c.scroll===!1||!a.cm||Sd(a.cm)}function Lb(a,b){b.equals(a.sel)||(a.sel=b,a.cm&&(a.cm.curOp.updateInput=a.cm.curOp.selectionChanged=!0,ng(a.cm)),kg(a,"cursorActivity",a))}function Mb(a){Lb(a,Nb(a,a.sel,null,!1),sg)}function Nb(a,b,c,d){for(var e,f=0;f<b.ranges.length;f++){var g=b.ranges[f],h=Ob(a,g.anchor,c,d),i=Ob(a,g.head,c,d);(e||h!=g.anchor||i!=g.head)&&(e||(e=b.ranges.slice(0,f)),e[f]=new ub(h,i))}return e?vb(e,b.primIndex):b}function Ob(a,b,c,d){var e=!1,f=b,g=c||1;a.cantEdit=!1;a:for(;;){var h=Ef(a,f.line);if(h.markedSpans)for(var i=0;i<h.markedSpans.length;++i){var j=h.markedSpans[i],k=j.marker;if((null==j.from||(k.inclusiveLeft?j.from<=f.ch:j.from<f.ch))&&(null==j.to||(k.inclusiveRight?j.to>=f.ch:j.to>f.ch))){if(d&&(hg(k,"beforeCursorEnter"),k.explicitlyCleared)){if(h.markedSpans){--i;continue}break}if(!k.atomic)continue;var l=k.find(0>g?-1:1);if(0==pb(l,f)&&(l.ch+=g,l.ch<0?l=l.line>a.first?yb(a,ob(l.line-1)):null:l.ch>h.text.length&&(l=l.line<a.first+a.size-1?ob(l.line+1,0):null),!l)){if(e)return d?(a.cantEdit=!0,ob(a.first,0)):Ob(a,b,c,!0);e=!0,l=b,g=-g}f=l;continue a}}return f}}function Pb(a){for(var b=a.display,c=a.doc,d=document.createDocumentFragment(),e=document.createDocumentFragment(),f=0;f<c.sel.ranges.length;f++){var g=c.sel.ranges[f],h=g.empty();(h||a.options.showCursorWhenSelecting)&&Qb(a,g,d),h||Rb(a,g,e)}if(a.options.moveInputWithCursor){var i=pc(a,c.sel.primary().head,"div"),j=b.wrapper.getBoundingClientRect(),k=b.lineDiv.getBoundingClientRect(),l=Math.max(0,Math.min(b.wrapper.clientHeight-10,i.top+k.top-j.top)),m=Math.max(0,Math.min(b.wrapper.clientWidth-10,i.left+k.left-j.left));b.inputDiv.style.top=l+"px",b.inputDiv.style.left=m+"px"}Pg(b.cursorDiv,d),Pg(b.selectionDiv,e)}function Qb(a,b,c){var d=pc(a,b.head,"div"),e=c.appendChild(Mg("div","\xa0","CodeMirror-cursor"));if(e.style.left=d.left+"px",e.style.top=d.top+"px",e.style.height=Math.max(0,d.bottom-d.top)*a.options.cursorHeight+"px",d.other){var f=c.appendChild(Mg("div","\xa0","CodeMirror-cursor CodeMirror-secondarycursor"));f.style.display="",f.style.left=d.other.left+"px",f.style.top=d.other.top+"px",f.style.height=.85*(d.other.bottom-d.other.top)+"px"}}function Rb(a,b,c){function j(a,b,c,d){0>b&&(b=0),b=Math.round(b),d=Math.round(d),f.appendChild(Mg("div",null,"CodeMirror-selected","position: absolute; left: "+a+"px; top: "+b+"px; width: "+(null==c?i-a:c)+"px; height: "+(d-b)+"px"))}function k(b,c,d){function m(c,d){return oc(a,ob(b,c),"div",f,d)}var k,l,f=Ef(e,b),g=f.text.length;return fh(Lf(f),c||0,null==d?g:d,function(a,b,e){var n,o,p,f=m(a,"left");if(a==b)n=f,o=p=f.left;else{if(n=m(b-1,"right"),"rtl"==e){var q=f;f=n,n=q}o=f.left,p=n.right}null==c&&0==a&&(o=h),n.top-f.top>3&&(j(o,f.top,null,f.bottom),o=h,f.bottom<n.top&&j(o,f.bottom,null,n.top)),null==d&&b==g&&(p=i),(!k||f.top<k.top||f.top==k.top&&f.left<k.left)&&(k=f),(!l||n.bottom>l.bottom||n.bottom==l.bottom&&n.right>l.right)&&(l=n),h+1>o&&(o=h),j(o,n.top,p-o,n.bottom)}),{start:k,end:l}}var d=a.display,e=a.doc,f=document.createDocumentFragment(),g=Zb(a.display),h=g.left,i=d.lineSpace.offsetWidth-g.right,l=b.from(),m=b.to();if(l.line==m.line)k(l.line,l.ch,m.ch);else{var n=Ef(e,l.line),o=Ef(e,m.line),p=Re(n)==Re(o),q=k(l.line,l.ch,p?n.text.length+1:null).end,r=k(m.line,p?0:null,m.ch).start;p&&(q.top<r.top-2?(j(q.right,q.top,null,q.bottom),j(h,r.top,r.left,r.bottom)):j(q.right,q.top,r.left-q.right,q.bottom)),q.bottom<r.top&&j(h,q.bottom,null,r.top)}c.appendChild(f)}function Sb(a){if(a.state.focused){var b=a.display;clearInterval(b.blinker);var c=!0;b.cursorDiv.style.visibility="",a.options.cursorBlinkRate>0&&(b.blinker=setInterval(function(){b.cursorDiv.style.visibility=(c=!c)?"":"hidden"},a.options.cursorBlinkRate))}}function Tb(a,b){a.doc.mode.startState&&a.doc.frontier<a.display.viewTo&&a.state.highlight.set(b,Gg(Ub,a))}function Ub(a){var b=a.doc;if(b.frontier<b.first&&(b.frontier=b.first),!(b.frontier>=a.display.viewTo)){var c=+new Date+a.options.workTime,d=he(b.mode,Wb(a,b.frontier));Ac(a,function(){b.iter(b.frontier,Math.min(b.first+b.size,a.display.viewTo+500),function(e){if(b.frontier>=a.display.viewFrom){var f=e.styles,g=gf(a,e,d,!0);e.styles=g.styles,g.classes?e.styleClasses=g.classes:e.styleClasses&&(e.styleClasses=null);for(var h=!f||f.length!=e.styles.length,i=0;!h&&i<f.length;++i)h=f[i]!=e.styles[i];h&&Hc(a,b.frontier,"text"),e.stateAfter=he(b.mode,d)}else jf(a,e.text,d),e.stateAfter=0==b.frontier%5?he(b.mode,d):null;return++b.frontier,+new Date>c?(Tb(a,a.options.workDelay),!0):void 0})})}}function Vb(a,b,c){for(var d,e,f=a.doc,g=c?-1:b-(a.doc.mode.innerMode?1e3:100),h=b;h>g;--h){if(h<=f.first)return f.first;var i=Ef(f,h-1);if(i.stateAfter&&(!c||h<=f.frontier))return h;var j=wg(i.text,null,a.options.tabSize);(null==e||d>j)&&(e=h-1,d=j)}return e}function Wb(a,b,c){var d=a.doc,e=a.display;if(!d.mode.startState)return!0;var f=Vb(a,b,c),g=f>d.first&&Ef(d,f-1).stateAfter;return g=g?he(d.mode,g):ie(d.mode),d.iter(f,b,function(c){jf(a,c.text,g);var h=f==b-1||0==f%5||f>=e.viewFrom&&f<e.viewTo;c.stateAfter=h?he(d.mode,g):null,++f}),c&&(d.frontier=f),g}function Xb(a){return a.lineSpace.offsetTop}function Yb(a){return a.mover.offsetHeight-a.lineSpace.offsetHeight}function Zb(a){if(a.cachedPaddingH)return a.cachedPaddingH;var b=Pg(a.measure,Mg("pre","x")),c=window.getComputedStyle?window.getComputedStyle(b):b.currentStyle,d={left:parseInt(c.paddingLeft),right:parseInt(c.paddingRight)};return isNaN(d.left)||isNaN(d.right)||(a.cachedPaddingH=d),d}function $b(a,b,c){var d=a.options.lineWrapping,e=d&&a.display.scroller.clientWidth;if(!b.measure.heights||d&&b.measure.width!=e){var f=b.measure.heights=[];if(d){b.measure.width=e;for(var g=b.text.firstChild.getClientRects(),h=0;h<g.length-1;h++){var i=g[h],j=g[h+1];Math.abs(i.bottom-j.bottom)>2&&f.push((i.bottom+j.top)/2-c.top)}}f.push(c.bottom-c.top)}}function _b(a,b,c){if(a.line==b)return{map:a.measure.map,cache:a.measure.cache};for(var d=0;d<a.rest.length;d++)if(a.rest[d]==b)return{map:a.measure.maps[d],cache:a.measure.caches[d]};for(var d=0;d<a.rest.length;d++)if(If(a.rest[d])>c)return{map:a.measure.maps[d],cache:a.measure.caches[d],before:!0}}function ac(a,b){b=Re(b);var c=If(b),d=a.display.externalMeasured=new Ec(a.doc,b,c);d.lineN=c;var e=d.built=nf(a,d);return d.text=e.pre,Pg(a.display.lineMeasure,e.pre),d}function bc(a,b,c,d){return ec(a,dc(a,b),c,d)}function cc(a,b){if(b>=a.display.viewFrom&&b<a.display.viewTo)return a.display.view[Jc(a,b)];var c=a.display.externalMeasured;return c&&b>=c.lineN&&b<c.lineN+c.size?c:void 0}function dc(a,b){var c=If(b),d=cc(a,c);d&&!d.text?d=null:d&&d.changes&&cb(a,d,c,ab(a)),d||(d=ac(a,b));var e=_b(d,b,c);return{line:b,view:d,rect:null,map:e.map,cache:e.cache,before:e.before,hasHeights:!1}}function ec(a,b,c,d){b.before&&(c=-1);var f,e=c+(d||"");return b.cache.hasOwnProperty(e)?f=b.cache[e]:(b.rect||(b.rect=b.view.text.getBoundingClientRect()),b.hasHeights||($b(a,b.view,b.rect),b.hasHeights=!0),f=gc(a,b,c,d),f.bogus||(b.cache[e]=f)),{left:f.left,right:f.right,top:f.top,bottom:f.bottom}}function gc(a,b,c,e){for(var h,i,j,k,f=b.map,l=0;l<f.length;l+=3){var m=f[l],n=f[l+1];if(m>c?(i=0,j=1,k="left"):n>c?(i=c-m,j=i+1):(l==f.length-3||c==n&&f[l+3]>c)&&(j=n-m,i=j-1,c>=n&&(k="right")),null!=i){if(h=f[l+2],m==n&&e==(h.insertLeft?"left":"right")&&(k=e),"left"==e&&0==i)for(;l&&f[l-2]==f[l-3]&&f[l-1].insertLeft;)h=f[(l-=3)+2],k="left";if("right"==e&&i==n-m)for(;l<f.length-3&&f[l+3]==f[l+4]&&!f[l+5].insertLeft;)h=f[(l+=3)+2],k="right";break}}var o;if(3==h.nodeType){for(;i&&Lg(b.line.text.charAt(m+i));)--i;for(;n>m+j&&Lg(b.line.text.charAt(m+j));)++j;if(d&&0==i&&j==n-m)o=h.parentNode.getBoundingClientRect();else if(g&&a.options.lineWrapping){var p=Ng(h,i,j).getClientRects();o=p.length?p["right"==e?p.length-1:0]:fc}else o=Ng(h,i,j).getBoundingClientRect()}else{i>0&&(k=e="right");var p;o=a.options.lineWrapping&&(p=h.getClientRects()).length>1?p["right"==e?p.length-1:0]:h.getBoundingClientRect()}if(d&&!i&&(!o||!o.left&&!o.right)){var q=h.parentNode.getClientRects()[0];o=q?{left:q.left,right:q.left+wc(a.display),top:q.top,bottom:q.bottom}:fc}for(var r,s=(o.bottom+o.top)/2-b.rect.top,t=b.view.measure.heights,l=0;l<t.length-1&&!(s<t[l]);l++);r=l?t[l-1]:0,s=t[l];var u={left:("right"==k?o.right:o.left)-b.rect.left,right:("left"==k?o.left:o.right)-b.rect.left,top:r,bottom:s};return o.left||o.right||(u.bogus=!0),u}function hc(a){if(a.measure&&(a.measure.cache={},a.measure.heights=null,a.rest))for(var b=0;b<a.rest.length;b++)a.measure.caches[b]={}}function ic(a){a.display.externalMeasure=null,Og(a.display.lineMeasure);for(var b=0;b<a.display.view.length;b++)hc(a.display.view[b])}function jc(a){ic(a),a.display.cachedCharWidth=a.display.cachedTextHeight=a.display.cachedPaddingH=null,a.options.lineWrapping||(a.display.maxLineChanged=!0),a.display.lineNumChars=null}function kc(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function lc(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function mc(a,b,c,d){if(b.widgets)for(var e=0;e<b.widgets.length;++e)if(b.widgets[e].above){var f=Ze(b.widgets[e]);c.top+=f,c.bottom+=f}if("line"==d)return c;d||(d="local");var g=Kf(b);if("local"==d?g+=Xb(a.display):g-=a.display.viewOffset,"page"==d||"window"==d){var h=a.display.lineSpace.getBoundingClientRect();g+=h.top+("window"==d?0:lc());var i=h.left+("window"==d?0:kc());c.left+=i,c.right+=i}return c.top+=g,c.bottom+=g,c}function nc(a,b,c){if("div"==c)return b;var d=b.left,e=b.top;if("page"==c)d-=kc(),e-=lc();else if("local"==c||!c){var f=a.display.sizer.getBoundingClientRect();d+=f.left,e+=f.top}var g=a.display.lineSpace.getBoundingClientRect();return{left:d-g.left,top:e-g.top}}function oc(a,b,c,d,e){return d||(d=Ef(a.doc,b.line)),mc(a,d,bc(a,d,b.ch,e),c)}function pc(a,b,c,d,e){function f(b,f){var g=ec(a,e,b,f?"right":"left");return f?g.left=g.right:g.right=g.left,mc(a,d,g,c)}function g(a,b){var c=h[b],d=c.level%2;return a==gh(c)&&b&&c.level<h[b-1].level?(c=h[--b],a=hh(c)-(c.level%2?0:1),d=!0):a==hh(c)&&b<h.length-1&&c.level<h[b+1].level&&(c=h[++b],a=gh(c)-c.level%2,d=!1),d&&a==c.to&&a>c.from?f(a-1):f(a,d)}d=d||Ef(a.doc,b.line),e||(e=dc(a,d));var h=Lf(d),i=b.ch;if(!h)return f(i);var j=oh(h,i),k=g(i,j);return null!=nh&&(k.other=g(i,nh)),k}function qc(a,b){var c=0,b=yb(a.doc,b);a.options.lineWrapping||(c=wc(a.display)*b.ch);var d=Ef(a.doc,b.line),e=Kf(d)+Xb(a.display);return{left:c,right:c,top:e,bottom:e+d.height}}function rc(a,b,c,d){var e=ob(a,b);return e.xRel=d,c&&(e.outside=!0),e}function sc(a,b,c){var d=a.doc;if(c+=a.display.viewOffset,0>c)return rc(d.first,0,!0,-1);var e=Jf(d,c),f=d.first+d.size-1;if(e>f)return rc(d.first+d.size-1,Ef(d,f).text.length,!0,1);0>b&&(b=0);for(var g=Ef(d,e);;){var h=tc(a,g,e,b,c),i=Pe(g),j=i&&i.find(0,!0);if(!i||!(h.ch>j.from.ch||h.ch==j.from.ch&&h.xRel>0))return h;e=If(g=j.to.line)}}function tc(a,b,c,d,e){function j(d){var e=pc(a,ob(c,d),"line",b,i);return g=!0,f>e.bottom?e.left-h:f<e.top?e.left+h:(g=!1,e.left)}var f=e-Kf(b),g=!1,h=2*a.display.wrapper.clientWidth,i=dc(a,b),k=Lf(b),l=b.text.length,m=ih(b),n=jh(b),o=j(m),p=g,q=j(n),r=g;if(d>q)return rc(c,n,r,1);for(;;){if(k?n==m||n==qh(b,m,1):1>=n-m){for(var s=o>d||q-d>=d-o?m:n,t=d-(s==m?o:q);Lg(b.text.charAt(s));)++s;var u=rc(c,s,s==m?p:r,-1>t?-1:t>1?1:0);return u}var v=Math.ceil(l/2),w=m+v;if(k){w=m;for(var x=0;v>x;++x)w=qh(b,w,1)}var y=j(w);y>d?(n=w,q=y,(r=g)&&(q+=1e3),l=v):(m=w,o=y,p=g,l-=v)}}function vc(a){if(null!=a.cachedTextHeight)return a.cachedTextHeight;if(null==uc){uc=Mg("pre");for(var b=0;49>b;++b)uc.appendChild(document.createTextNode("x")),uc.appendChild(Mg("br"));uc.appendChild(document.createTextNode("x"))}Pg(a.measure,uc);var c=uc.offsetHeight/50;return c>3&&(a.cachedTextHeight=c),Og(a.measure),c||1}function wc(a){if(null!=a.cachedCharWidth)return a.cachedCharWidth;var b=Mg("span","xxxxxxxxxx"),c=Mg("pre",[b]);Pg(a.measure,c);var d=b.getBoundingClientRect(),e=(d.right-d.left)/10;return e>2&&(a.cachedCharWidth=e),e||10}function yc(a){a.curOp={viewChanged:!1,startHeight:a.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,id:++xc},jg++||(ig=[])}function zc(a){var b=a.curOp,c=a.doc,d=a.display;if(a.curOp=null,b.updateMaxLine&&M(a),b.viewChanged||b.forceUpdate||null!=b.scrollTop||b.scrollToPos&&(b.scrollToPos.from.line<d.viewFrom||b.scrollToPos.to.line>=d.viewTo)||d.maxLineChanged&&a.options.lineWrapping){var e=V(a,{top:b.scrollTop,ensure:b.scrollToPos},b.forceUpdate);a.display.scroller.offsetHeight&&(a.doc.scrollTop=a.display.scroller.scrollTop)}if(!e&&b.selectionChanged&&Pb(a),e||b.startHeight==a.doc.height||P(a),null!=b.scrollTop&&d.scroller.scrollTop!=b.scrollTop){var f=Math.max(0,Math.min(d.scroller.scrollHeight-d.scroller.clientHeight,b.scrollTop));d.scroller.scrollTop=d.scrollbarV.scrollTop=c.scrollTop=f}if(null!=b.scrollLeft&&d.scroller.scrollLeft!=b.scrollLeft){var g=Math.max(0,Math.min(d.scroller.scrollWidth-d.scroller.clientWidth,b.scrollLeft));d.scroller.scrollLeft=d.scrollbarH.scrollLeft=c.scrollLeft=g,R(a)}if(b.scrollToPos){var h=Od(a,yb(a.doc,b.scrollToPos.from),yb(a.doc,b.scrollToPos.to),b.scrollToPos.margin);b.scrollToPos.isCursor&&a.state.focused&&Nd(a,h)}b.selectionChanged&&Sb(a),a.state.focused&&b.updateInput&&Qc(a,b.typing);var i=b.maybeHiddenMarkers,j=b.maybeUnhiddenMarkers;if(i)for(var k=0;k<i.length;++k)i[k].lines.length||hg(i[k],"hide");if(j)for(var k=0;k<j.length;++k)j[k].lines.length&&hg(j[k],"unhide");var l;if(--jg||(l=ig,ig=null),b.changeObjs&&hg(a,"changes",a,b.changeObjs),l)for(var k=0;k<l.length;++k)l[k]();if(b.cursorActivityHandlers)for(var k=0;k<b.cursorActivityHandlers.length;k++)b.cursorActivityHandlers[k](a)}function Ac(a,b){if(a.curOp)return b();yc(a);try{return b()}finally{zc(a)}}function Bc(a,b){return function(){if(a.curOp)return b.apply(a,arguments);yc(a);try{return b.apply(a,arguments)}finally{zc(a)}}}function Cc(a){return function(){if(this.curOp)return a.apply(this,arguments);yc(this);try{return a.apply(this,arguments)}finally{zc(this)}}}function Dc(a){return function(){var b=this.cm;if(!b||b.curOp)return a.apply(this,arguments);yc(b);try{return a.apply(this,arguments)}finally{zc(b)}}}function Ec(a,b,c){this.line=b,this.rest=Se(b),this.size=this.rest?If(Ag(this.rest))-c+1:1,this.node=this.text=null,this.hidden=Ve(a,b) }function Fc(a,b,c){for(var e,d=[],f=b;c>f;f=e){var g=new Ec(a.doc,Ef(a.doc,f),f);e=f+g.size,d.push(g)}return d}function Gc(a,b,c,d){null==b&&(b=a.doc.first),null==c&&(c=a.doc.first+a.doc.size),d||(d=0);var e=a.display;if(d&&c<e.viewTo&&(null==e.updateLineNumbers||e.updateLineNumbers>b)&&(e.updateLineNumbers=b),a.curOp.viewChanged=!0,b>=e.viewTo)y&&Te(a.doc,b)<e.viewTo&&Ic(a);else if(c<=e.viewFrom)y&&Ue(a.doc,c+d)>e.viewFrom?Ic(a):(e.viewFrom+=d,e.viewTo+=d);else if(b<=e.viewFrom&&c>=e.viewTo)Ic(a);else if(b<=e.viewFrom){var f=Kc(a,c,c+d,1);f?(e.view=e.view.slice(f.index),e.viewFrom=f.lineN,e.viewTo+=d):Ic(a)}else if(c>=e.viewTo){var f=Kc(a,b,b,-1);f?(e.view=e.view.slice(0,f.index),e.viewTo=f.lineN):Ic(a)}else{var g=Kc(a,b,b,-1),h=Kc(a,c,c+d,1);g&&h?(e.view=e.view.slice(0,g.index).concat(Fc(a,g.lineN,h.lineN)).concat(e.view.slice(h.index)),e.viewTo+=d):Ic(a)}var i=e.externalMeasured;i&&(c<i.lineN?i.lineN+=d:b<i.lineN+i.size&&(e.externalMeasured=null))}function Hc(a,b,c){a.curOp.viewChanged=!0;var d=a.display,e=a.display.externalMeasured;if(e&&b>=e.lineN&&b<e.lineN+e.size&&(d.externalMeasured=null),!(b<d.viewFrom||b>=d.viewTo)){var f=d.view[Jc(a,b)];if(null!=f.node){var g=f.changes||(f.changes=[]);-1==Cg(g,c)&&g.push(c)}}}function Ic(a){a.display.viewFrom=a.display.viewTo=a.doc.first,a.display.view=[],a.display.viewOffset=0}function Jc(a,b){if(b>=a.display.viewTo)return null;if(b-=a.display.viewFrom,0>b)return null;for(var c=a.display.view,d=0;d<c.length;d++)if(b-=c[d].size,0>b)return d}function Kc(a,b,c,d){var f,e=Jc(a,b),g=a.display.view;if(!y)return{index:e,lineN:c};for(var h=0,i=a.display.viewFrom;e>h;h++)i+=g[h].size;if(i!=b){if(d>0){if(e==g.length-1)return null;f=i+g[e].size-b,e++}else f=i-b;b+=f,c+=f}for(;Te(a.doc,c)!=c;){if(e==(0>d?0:g.length-1))return null;c+=d*g[e-(0>d?1:0)].size,e+=d}return{index:e,lineN:c}}function Lc(a,b,c){var d=a.display,e=d.view;0==e.length||b>=d.viewTo||c<=d.viewFrom?(d.view=Fc(a,b,c),d.viewFrom=b):(d.viewFrom>b?d.view=Fc(a,b,d.viewFrom).concat(d.view):d.viewFrom<b&&(d.view=d.view.slice(Jc(a,b))),d.viewFrom=b,d.viewTo<c?d.view=d.view.concat(Fc(a,d.viewTo,c)):d.viewTo>c&&(d.view=d.view.slice(0,Jc(a,c)))),d.viewTo=c}function Mc(a){for(var b=a.display.view,c=0,d=0;d<b.length;d++){var e=b[d];e.hidden||e.node&&!e.changes||++c}return c}function Nc(a){a.display.pollingFast||a.display.poll.set(a.options.pollInterval,function(){Pc(a),a.state.focused&&Nc(a)})}function Oc(a){function c(){var d=Pc(a);d||b?(a.display.pollingFast=!1,Nc(a)):(b=!0,a.display.poll.set(60,c))}var b=!1;a.display.pollingFast=!0,a.display.poll.set(20,c)}function Pc(a){var b=a.display.input,c=a.display.prevInput,e=a.doc;if(!a.state.focused||ch(b)&&!c||Tc(a)||a.options.disableInput)return!1;a.state.pasteIncoming&&a.state.fakedLastChar&&(b.value=b.value.substring(0,b.value.length-1),a.state.fakedLastChar=!1);var f=b.value;if(f==c&&!a.somethingSelected())return!1;if(g&&!d&&a.display.inputHasSelection===f)return Qc(a),!1;var h=!a.curOp;h&&yc(a),a.display.shift=!1;for(var i=0,j=Math.min(c.length,f.length);j>i&&c.charCodeAt(i)==f.charCodeAt(i);)++i;for(var k=f.slice(i),l=bh(k),m=a.state.pasteIncoming&&l.length>1&&e.sel.ranges.length==l.length,n=e.sel.ranges.length-1;n>=0;n--){var o=e.sel.ranges[n],p=o.from(),q=o.to();i<c.length?p=ob(p.line,p.ch-(c.length-i)):a.state.overwrite&&o.empty()&&!a.state.pasteIncoming&&(q=ob(q.line,Math.min(Ef(e,q.line).text.length,q.ch+Ag(l).length)));var r=a.curOp.updateInput,s={from:p,to:q,text:m?[l[n]]:l,origin:a.state.pasteIncoming?"paste":a.state.cutIncoming?"cut":"+input"};if(Gd(a.doc,s),kg(a,"inputRead",a,s),k&&!a.state.pasteIncoming&&a.options.electricChars&&a.options.smartIndent&&o.head.ch<100&&(!n||e.sel.ranges[n-1].head.line!=o.head.line)){var t=a.getModeAt(o.head);if(t.electricChars){for(var u=0;u<t.electricChars.length;u++)if(k.indexOf(t.electricChars.charAt(u))>-1){Ud(a,o.head.line,"smart");break}}else if(t.electricInput){var v=Ad(s);t.electricInput.test(Ef(e,v.line).text.slice(0,v.ch))&&Ud(a,o.head.line,"smart")}}}return Sd(a),a.curOp.updateInput=r,a.curOp.typing=!0,f.length>1e3||f.indexOf("\n")>-1?b.value=a.display.prevInput="":a.display.prevInput=f,h&&zc(a),a.state.pasteIncoming=a.state.cutIncoming=!1,!0}function Qc(a,b){var c,e,f=a.doc;if(a.somethingSelected()){a.display.prevInput="";var h=f.sel.primary();c=dh&&(h.to().line-h.from().line>100||(e=a.getSelection()).length>1e3);var i=c?"-":e||a.getSelection();a.display.input.value=i,a.state.focused&&Bg(a.display.input),g&&!d&&(a.display.inputHasSelection=i)}else b||(a.display.prevInput=a.display.input.value="",g&&!d&&(a.display.inputHasSelection=null));a.display.inaccurateSelection=c}function Rc(a){"nocursor"==a.options.readOnly||r&&Rg()==a.display.input||a.display.input.focus()}function Sc(a){a.state.focused||(Rc(a),vd(a))}function Tc(a){return a.options.readOnly||a.doc.cantEdit}function Uc(a){function e(){a.state.focused&&setTimeout(Gg(Rc,a),0)}function i(){null==f&&(f=setTimeout(function(){f=null,c.cachedCharWidth=c.cachedTextHeight=c.cachedPaddingH=Xg=null,a.setSize()},100))}function j(){Qg(document.body,c.wrapper)?setTimeout(j,5e3):gg(window,"resize",i)}function k(b){mg(a,b)||cg(b)}function l(b){if(a.somethingSelected())c.inaccurateSelection&&(c.prevInput="",c.inaccurateSelection=!1,c.input.value=a.getSelection(),Bg(c.input));else{for(var d="",e=[],f=0;f<a.doc.sel.ranges.length;f++){var g=a.doc.sel.ranges[f].head.line,h={anchor:ob(g,0),head:ob(g+1,0)};e.push(h),d+=a.getRange(h.anchor,h.head)}"cut"==b.type?a.setSelections(e,null,sg):(c.prevInput="",c.input.value=d,Bg(c.input))}"cut"==b.type&&(a.state.cutIncoming=!0)}var c=a.display;fg(c.scroller,"mousedown",Bc(a,Xc)),b?fg(c.scroller,"dblclick",Bc(a,function(b){if(!mg(a,b)){var c=Wc(a,b);if(c&&!cd(a,b)&&!Vc(a.display,b)){_f(b);var d=Zd(a.doc,c);Db(a.doc,d.anchor,d.head)}}})):fg(c.scroller,"dblclick",function(b){mg(a,b)||_f(b)}),fg(c.lineSpace,"selectstart",function(a){Vc(c,a)||_f(a)}),w||fg(c.scroller,"contextmenu",function(b){yd(a,b)}),fg(c.scroller,"scroll",function(){c.scroller.clientHeight&&(gd(a,c.scroller.scrollTop),hd(a,c.scroller.scrollLeft,!0),hg(a,"scroll",a))}),fg(c.scrollbarV,"scroll",function(){c.scroller.clientHeight&&gd(a,c.scrollbarV.scrollTop)}),fg(c.scrollbarH,"scroll",function(){c.scroller.clientHeight&&hd(a,c.scrollbarH.scrollLeft)}),fg(c.scroller,"mousewheel",function(b){kd(a,b)}),fg(c.scroller,"DOMMouseScroll",function(b){kd(a,b)}),fg(c.scrollbarH,"mousedown",e),fg(c.scrollbarV,"mousedown",e),fg(c.wrapper,"scroll",function(){c.wrapper.scrollTop=c.wrapper.scrollLeft=0});var f;fg(window,"resize",i),setTimeout(j,5e3),fg(c.input,"keyup",Bc(a,td)),fg(c.input,"input",function(){g&&!d&&a.display.inputHasSelection&&(a.display.inputHasSelection=null),Oc(a)}),fg(c.input,"keydown",Bc(a,rd)),fg(c.input,"keypress",Bc(a,ud)),fg(c.input,"focus",Gg(vd,a)),fg(c.input,"blur",Gg(wd,a)),a.options.dragDrop&&(fg(c.scroller,"dragstart",function(b){fd(a,b)}),fg(c.scroller,"dragenter",k),fg(c.scroller,"dragover",k),fg(c.scroller,"drop",Bc(a,ed))),fg(c.scroller,"paste",function(b){Vc(c,b)||(a.state.pasteIncoming=!0,Rc(a),Oc(a))}),fg(c.input,"paste",function(){if(h&&!a.state.fakedLastChar&&!(new Date-a.state.lastMiddleDown<200)){var b=c.input.selectionStart,d=c.input.selectionEnd;c.input.value+="$",c.input.selectionStart=b,c.input.selectionEnd=d,a.state.fakedLastChar=!0}a.state.pasteIncoming=!0,Oc(a)}),fg(c.input,"cut",l),fg(c.input,"copy",l),m&&fg(c.sizer,"mouseup",function(){Rg()==c.input&&c.input.blur(),Rc(a)})}function Vc(a,b){for(var c=dg(b);c!=a.wrapper;c=c.parentNode)if(!c||c.ignoreEvents||c.parentNode==a.sizer&&c!=a.mover)return!0}function Wc(a,b,c,d){var e=a.display;if(!c){var f=dg(b);if(f==e.scrollbarH||f==e.scrollbarV||f==e.scrollbarFiller||f==e.gutterFiller)return null}var g,h,i=e.lineSpace.getBoundingClientRect();try{g=b.clientX-i.left,h=b.clientY-i.top}catch(b){return null}var k,j=sc(a,g,h);if(d&&1==j.xRel&&(k=Ef(a.doc,j.line).text).length==j.ch){var l=wg(k,k.length,a.options.tabSize)-k.length;j=ob(j.line,Math.round((g-Zb(a.display).left)/wc(a.display))-l)}return j}function Xc(a){if(!mg(this,a)){var b=this,c=b.display;if(c.shift=a.shiftKey,Vc(c,a))return h||(c.scroller.draggable=!1,setTimeout(function(){c.scroller.draggable=!0},100)),void 0;if(!cd(b,a)){var d=Wc(b,a);switch(window.focus(),eg(a)){case 1:d?$c(b,a,d):dg(a)==c.scroller&&_f(a);break;case 2:h&&(b.state.lastMiddleDown=+new Date),d&&Db(b.doc,d),setTimeout(Gg(Rc,b),20),_f(a);break;case 3:w&&yd(b,a)}}}}function $c(a,b,c){setTimeout(Gg(Sc,a),0);var e,d=+new Date;Zc&&Zc.time>d-400&&0==pb(Zc.pos,c)?e="triple":Yc&&Yc.time>d-400&&0==pb(Yc.pos,c)?(e="double",Zc={time:d,pos:c}):(e="single",Yc={time:d,pos:c});var f=a.doc.sel,g=s?b.metaKey:b.ctrlKey;a.options.dragDrop&&Wg&&!g&&!Tc(a)&&"single"==e&&f.contains(c)>-1&&f.somethingSelected()?_c(a,b,c):ad(a,b,c,e,g)}function _c(a,c,e){var f=a.display,g=Bc(a,function(i){h&&(f.scroller.draggable=!1),a.state.draggingText=!1,gg(document,"mouseup",g),gg(f.scroller,"drop",g),Math.abs(c.clientX-i.clientX)+Math.abs(c.clientY-i.clientY)<10&&(_f(i),Db(a.doc,e),Rc(a),b&&!d&&setTimeout(function(){document.body.focus(),Rc(a)},20))});h&&(f.scroller.draggable=!0),a.state.draggingText=g,f.scroller.dragDrop&&f.scroller.dragDrop(),fg(document,"mouseup",g),fg(f.scroller,"drop",g)}function ad(a,b,c,d,f){function p(b){if(0!=pb(o,b))if(o=b,"rect"==d){for(var e=[],f=a.options.tabSize,g=wg(Ef(i,c.line).text,c.ch,f),h=wg(Ef(i,b.line).text,b.ch,f),m=Math.min(g,h),n=Math.max(g,h),p=Math.min(c.line,b.line),q=Math.min(a.lastLine(),Math.max(c.line,b.line));q>=p;p++){var r=Ef(i,p).text,s=xg(r,m,f);m==n?e.push(new ub(ob(p,s),ob(p,s))):r.length>s&&e.push(new ub(ob(p,s),ob(p,xg(r,n,f))))}e.length||e.push(new ub(c,c)),Jb(i,vb(l.ranges.slice(0,k).concat(e),k),tg)}else{var t=j,u=t.anchor,v=b;if("single"!=d){if("double"==d)var w=Zd(i,b);else var w=new ub(ob(b.line,0),yb(i,ob(b.line+1,0)));pb(w.anchor,u)>0?(v=w.head,u=sb(t.from(),w.anchor)):(v=w.anchor,u=rb(t.to(),w.head))}var e=l.ranges.slice(0);e[k]=new ub(yb(i,u),v),Jb(i,vb(e,k),tg)}}function s(b){var c=++r,e=Wc(a,b,!0,"rect"==d);if(e)if(0!=pb(e,o)){Sc(a),p(e);var f=Q(h,i);(e.line>=f.to||e.line<f.from)&&setTimeout(Bc(a,function(){r==c&&s(b)}),150)}else{var g=b.clientY<q.top?-20:b.clientY>q.bottom?20:0;g&&setTimeout(Bc(a,function(){r==c&&(h.scroller.scrollTop+=g,s(b))}),50)}}function t(b){r=1/0,_f(b),Rc(a),gg(document,"mousemove",u),gg(document,"mouseup",v),i.history.lastSelOrigin=null}var h=a.display,i=a.doc;_f(b);var j,k,l=i.sel;if(f?(k=i.sel.contains(c),j=k>-1?i.sel.ranges[k]:new ub(c,c)):j=i.sel.primary(),b.altKey)d="rect",f||(j=new ub(c,c)),c=Wc(a,b,!0,!0),k=-1;else if("double"==d){var m=Zd(i,c);j=a.display.shift||i.extend?Cb(i,j,m.anchor,m.head):m}else if("triple"==d){var n=new ub(ob(c.line,0),yb(i,ob(c.line+1,0)));j=a.display.shift||i.extend?Cb(i,j,n.anchor,n.head):n}else j=Cb(i,j,c);f?k>-1?Fb(i,k,j,tg):(k=i.sel.ranges.length,Jb(i,vb(i.sel.ranges.concat([j]),k),{scroll:!1,origin:"*mouse"})):(k=0,Jb(i,new tb([j],0),tg));var o=c,q=h.wrapper.getBoundingClientRect(),r=0,u=Bc(a,function(a){(g&&!e?a.buttons:eg(a))?s(a):t(a)}),v=Bc(a,t);fg(document,"mousemove",u),fg(document,"mouseup",v)}function bd(a,b,c,d,e){try{var f=b.clientX,g=b.clientY}catch(b){return!1}if(f>=Math.floor(a.display.gutters.getBoundingClientRect().right))return!1;d&&_f(b);var h=a.display,i=h.lineDiv.getBoundingClientRect();if(g>i.bottom||!og(a,c))return bg(b);g-=i.top-h.viewOffset;for(var j=0;j<a.options.gutters.length;++j){var k=h.gutters.childNodes[j];if(k&&k.getBoundingClientRect().right>=f){var l=Jf(a.doc,g),m=a.options.gutters[j];return e(a,c,a,l,m,b),bg(b)}}}function cd(a,b){return bd(a,b,"gutterClick",!0,kg)}function ed(a){var c=this;if(!mg(c,a)&&!Vc(c.display,a)){_f(a),b&&(dd=+new Date);var d=Wc(c,a,!0),e=a.dataTransfer.files;if(d&&!Tc(c))if(e&&e.length&&window.FileReader&&window.File)for(var f=e.length,g=Array(f),h=0,i=function(a,b){var e=new FileReader;e.onload=Bc(c,function(){if(g[b]=e.result,++h==f){d=yb(c.doc,d);var a={from:d,to:d,text:bh(g.join("\n")),origin:"paste"};Gd(c.doc,a),Ib(c.doc,wb(d,Ad(a)))}}),e.readAsText(a)},j=0;f>j;++j)i(e[j],j);else{if(c.state.draggingText&&c.doc.sel.contains(d)>-1)return c.state.draggingText(a),setTimeout(Gg(Rc,c),20),void 0;try{var g=a.dataTransfer.getData("Text");if(g){var k=c.state.draggingText&&c.listSelections();if(Kb(c.doc,wb(d,d)),k)for(var j=0;j<k.length;++j)Md(c.doc,"",k[j].anchor,k[j].head,"drag");c.replaceSelection(g,"around","paste"),Rc(c)}}catch(a){}}}}function fd(a,c){if(b&&(!a.state.draggingText||+new Date-dd<100))return cg(c),void 0;if(!mg(a,c)&&!Vc(a.display,c)&&(c.dataTransfer.setData("Text",a.getSelection()),c.dataTransfer.setDragImage&&!l)){var d=Mg("img",null,null,"position: fixed; left: 0; top: 0;");d.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",k&&(d.width=d.height=1,a.display.wrapper.appendChild(d),d._top=d.offsetTop),c.dataTransfer.setDragImage(d,0,0),k&&d.parentNode.removeChild(d)}}function gd(b,c){Math.abs(b.doc.scrollTop-c)<2||(b.doc.scrollTop=c,a||V(b,{top:c}),b.display.scroller.scrollTop!=c&&(b.display.scroller.scrollTop=c),b.display.scrollbarV.scrollTop!=c&&(b.display.scrollbarV.scrollTop=c),a&&V(b),Tb(b,100))}function hd(a,b,c){(c?b==a.doc.scrollLeft:Math.abs(a.doc.scrollLeft-b)<2)||(b=Math.min(b,a.display.scroller.scrollWidth-a.display.scroller.clientWidth),a.doc.scrollLeft=b,R(a),a.display.scroller.scrollLeft!=b&&(a.display.scroller.scrollLeft=b),a.display.scrollbarH.scrollLeft!=b&&(a.display.scrollbarH.scrollLeft=b))}function kd(b,c){var d=c.wheelDeltaX,e=c.wheelDeltaY;null==d&&c.detail&&c.axis==c.HORIZONTAL_AXIS&&(d=c.detail),null==e&&c.detail&&c.axis==c.VERTICAL_AXIS?e=c.detail:null==e&&(e=c.wheelDelta);var f=b.display,g=f.scroller;if(d&&g.scrollWidth>g.clientWidth||e&&g.scrollHeight>g.clientHeight){if(e&&s&&h)a:for(var i=c.target,j=f.view;i!=g;i=i.parentNode)for(var l=0;l<j.length;l++)if(j[l].node==i){b.display.currentWheelTarget=i;break a}if(d&&!a&&!k&&null!=jd)return e&&gd(b,Math.max(0,Math.min(g.scrollTop+e*jd,g.scrollHeight-g.clientHeight))),hd(b,Math.max(0,Math.min(g.scrollLeft+d*jd,g.scrollWidth-g.clientWidth))),_f(c),f.wheelStartX=null,void 0;if(e&&null!=jd){var m=e*jd,n=b.doc.scrollTop,o=n+f.wrapper.clientHeight;0>m?n=Math.max(0,n+m-50):o=Math.min(b.doc.height,o+m+50),V(b,{top:n,bottom:o})}20>id&&(null==f.wheelStartX?(f.wheelStartX=g.scrollLeft,f.wheelStartY=g.scrollTop,f.wheelDX=d,f.wheelDY=e,setTimeout(function(){if(null!=f.wheelStartX){var a=g.scrollLeft-f.wheelStartX,b=g.scrollTop-f.wheelStartY,c=b&&f.wheelDY&&b/f.wheelDY||a&&f.wheelDX&&a/f.wheelDX;f.wheelStartX=f.wheelStartY=null,c&&(jd=(jd*id+c)/(id+1),++id)}},200)):(f.wheelDX+=d,f.wheelDY+=e))}}function ld(a,b,c){if("string"==typeof b&&(b=je[b],!b))return!1;a.display.pollingFast&&Pc(a)&&(a.display.pollingFast=!1);var d=a.display.shift,e=!1;try{Tc(a)&&(a.state.suppressEdits=!0),c&&(a.display.shift=!1),e=b(a)!=rg}finally{a.display.shift=d,a.state.suppressEdits=!1}return e}function md(a){var b=a.state.keyMaps.slice(0);return a.options.extraKeys&&b.push(a.options.extraKeys),b.push(a.options.keyMap),b}function od(a,b){var c=le(a.options.keyMap),d=c.auto;clearTimeout(nd),d&&!ne(b)&&(nd=setTimeout(function(){le(a.options.keyMap)==c&&(a.options.keyMap=d.call?d.call(null,a):d,G(a))},50));var e=oe(b,!0),f=!1;if(!e)return!1;var g=md(a);return f=b.shiftKey?me("Shift-"+e,g,function(b){return ld(a,b,!0)})||me(e,g,function(b){return("string"==typeof b?/^go[A-Z]/.test(b):b.motion)?ld(a,b):void 0}):me(e,g,function(b){return ld(a,b)}),f&&(_f(b),Sb(a),kg(a,"keyHandled",a,e,b)),f}function pd(a,b,c){var d=me("'"+c+"'",md(a),function(b){return ld(a,b,!0)});return d&&(_f(b),Sb(a),kg(a,"keyHandled",a,"'"+c+"'",b)),d}function rd(a){var c=this;if(Sc(c),!mg(c,a)){b&&27==a.keyCode&&(a.returnValue=!1);var d=a.keyCode;c.display.shift=16==d||a.shiftKey;var e=od(c,a);k&&(qd=e?d:null,!e&&88==d&&!dh&&(s?a.metaKey:a.ctrlKey)&&c.replaceSelection("",null,"cut")),18!=d||/\bCodeMirror-crosshair\b/.test(c.display.lineDiv.className)||sd(c)}}function sd(a){function c(a){18!=a.keyCode&&a.altKey||(Tg(b,"CodeMirror-crosshair"),gg(document,"keyup",c),gg(document,"mouseover",c))}var b=a.display.lineDiv;Ug(b,"CodeMirror-crosshair"),fg(document,"keyup",c),fg(document,"mouseover",c)}function td(a){mg(this,a)||16==a.keyCode&&(this.doc.sel.shift=!1)}function ud(a){var b=this;if(!mg(b,a)){var c=a.keyCode,e=a.charCode;if(k&&c==qd)return qd=null,_f(a),void 0;if(!(k&&(!a.which||a.which<10)||m)||!od(b,a)){var f=String.fromCharCode(null==e?c:e);pd(b,a,f)||(g&&!d&&(b.display.inputHasSelection=null),Oc(b))}}}function vd(a){"nocursor"!=a.options.readOnly&&(a.state.focused||(hg(a,"focus",a),a.state.focused=!0,Ug(a.display.wrapper,"CodeMirror-focused"),a.curOp||"\u200b"==a.display.prevInput||(Qc(a),h&&setTimeout(Gg(Qc,a,!0),0))),Nc(a),Sb(a))}function wd(a){a.state.focused&&(hg(a,"blur",a),a.state.focused=!1,Tg(a.display.wrapper,"CodeMirror-focused")),clearInterval(a.display.blinker),setTimeout(function(){a.state.focused||(a.display.shift=!1)},150)}function yd(a,b){function j(){if(null!=c.input.selectionStart){var b=c.input.value="\u200b"+(a.somethingSelected()?c.input.value:"");c.prevInput="\u200b",c.input.selectionStart=1,c.input.selectionEnd=b.length}}function l(){if(c.inputDiv.style.position="relative",c.input.style.cssText=i,d&&(c.scrollbarV.scrollTop=c.scroller.scrollTop=f),Nc(a),null!=c.input.selectionStart){(!g||d)&&j(),clearTimeout(xd);var b=0,e=function(){"\u200b"==c.prevInput&&0==c.input.selectionStart?Bc(a,je.selectAll)(a):b++<10?xd=setTimeout(e,500):Qc(a)};xd=setTimeout(e,200)}}if(!mg(a,b,"contextmenu")){var c=a.display;if(!Vc(c,b)&&!zd(a,b)){var e=Wc(a,b),f=c.scroller.scrollTop;if(e&&!k){var h=a.options.resetSelectionOnContextMenu;h&&-1==a.doc.sel.contains(e)&&Bc(a,Jb)(a.doc,wb(e),sg);var i=c.input.style.cssText;if(c.inputDiv.style.position="absolute",c.input.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(b.clientY-5)+"px; left: "+(b.clientX-5)+"px; z-index: 10