(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.CodeMirror=t()})(this,function(){"use strict";function e(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function t(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function n(e,n){return t(e).appendChild(n)}function r(e,t,n,r){var i=document.createElement(e);if(n&&(i.className=n),r&&(i.style.cssText=r),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o=t)return l+(t-o);l+=s-o,l+=n-l%n,o=s+1}}function h(e,t){for(var n=0;n=t)return r+Math.min(l,t-i);if(i+=o-r,i+=n-i%n,r=o+1,i>=t)return r}}function p(e){for(;Ql.length<=e;)Ql.push(g(Ql)+" ");return Ql[e]}function g(e){return e[e.length-1]}function v(e,t){for(var n=[],r=0;r"€"&&(e.toUpperCase()!=e.toLowerCase()||Jl.test(e))}function x(e,t){return t?!!(t.source.indexOf("\\w")>-1&&w(e))||t.test(e):w(e)}function C(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function S(e){return e.charCodeAt(0)>=768&&es.test(e)}function L(e,t,n){for(;(n<0?t>0:tn?-1:1;;){if(t==n)return t;var i=(t+n)/2,o=r<0?Math.ceil(i):Math.floor(i);if(o==t)return e(o)?t:n;e(o)?n=o:t=o+r}}function T(e,t,n){var o=this;this.input=n,o.scrollbarFiller=r("div",null,"CodeMirror-scrollbar-filler"),o.scrollbarFiller.setAttribute("cm-not-content","true"),o.gutterFiller=r("div",null,"CodeMirror-gutter-filler"),o.gutterFiller.setAttribute("cm-not-content","true"),o.lineDiv=i("div",null,"CodeMirror-code"),o.selectionDiv=r("div",null,null,"position: relative; z-index: 1"),o.cursorDiv=r("div",null,"CodeMirror-cursors"),o.measure=r("div",null,"CodeMirror-measure"),o.lineMeasure=r("div",null,"CodeMirror-measure"),o.lineSpace=i("div",[o.measure,o.lineMeasure,o.selectionDiv,o.cursorDiv,o.lineDiv],null,"position: relative; outline: none");var l=i("div",[o.lineSpace],"CodeMirror-lines");o.mover=r("div",[l],null,"position: relative"),o.sizer=r("div",[o.mover],"CodeMirror-sizer"),o.sizerWidth=null,o.heightForcer=r("div",null,null,"position: absolute; height: "+Yl+"px; width: 1px;"),o.gutters=r("div",null,"CodeMirror-gutters"),o.lineGutter=null,o.scroller=r("div",[o.sizer,o.heightForcer,o.gutters],"CodeMirror-scroll"),o.scroller.setAttribute("tabIndex","-1"),o.wrapper=r("div",[o.scrollbarFiller,o.gutterFiller,o.scroller],"CodeMirror"),Cl&&Sl<8&&(o.gutters.style.zIndex=-1,o.scroller.style.paddingRight=0),Ll||yl&&Hl||(o.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(o.wrapper):e(o.wrapper)),o.viewFrom=o.viewTo=t.first,o.reportedViewFrom=o.reportedViewTo=t.first,o.view=[],o.renderedView=null,o.externalMeasured=null,o.viewOffset=0,o.lastWrapHeight=o.lastWrapWidth=0,o.updateLineNumbers=null,o.nativeBarWidth=o.barHeight=o.barWidth=0,o.scrollbarsClipped=!1,o.lineNumWidth=o.lineNumInnerWidth=o.lineNumChars=null,o.alignWidgets=!1,o.cachedCharWidth=o.cachedTextHeight=o.cachedPaddingH=null,o.maxLine=null,o.maxLineLength=0,o.maxLineChanged=!1,o.wheelDX=o.wheelDY=o.wheelStartX=o.wheelStartY=null,o.shift=!1,o.selForContextMenu=null,o.activeTouch=null,n.init(o)}function M(e,t){if(t-=e.first,t<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var n=e;!n.lines;)for(var r=0;;++r){var i=n.children[r],o=i.chunkSize();if(t=e.first&&tn?F(n,M(e,n).text.length):j(t,M(e,t.line).text.length)}function j(e,t){var n=e.ch;return null==n||n>t?F(e.line,t):n<0?F(e.line,0):e}function V(e,t){for(var n=[],r=0;r=t:o.to>t);(r||(r=[])).push(new Y(l,o.from,a?null:o.to))}}return r}function Q(e,t,n){var r;if(e)for(var i=0;i=t:o.to>t);if(s||o.from==t&&"bookmark"==l.type&&(!n||o.marker.insertLeft)){var a=null==o.from||(l.inclusiveLeft?o.from<=t:o.from0&&s)for(var x=0;x0)){var c=[a,1],f=z(u.from,s.from),d=z(u.to,s.to);(f<0||!l.inclusiveLeft&&!f)&&c.push({from:u.from,to:s.from}),(d>0||!l.inclusiveRight&&!d)&&c.push({from:s.to,to:u.to}),i.splice.apply(i,c),a+=c.length-3}}return i}function ne(e){var t=e.markedSpans;if(t){for(var n=0;nt)&&(!n||le(n,o.marker)<0)&&(n=o.marker)}return n}function fe(e,t,n,r,i){var o=M(e,t),l=ns&&o.markedSpans;if(l)for(var s=0;s=0&&f<=0||c<=0&&f>=0)&&(c<=0&&(a.marker.inclusiveRight&&i.inclusiveLeft?z(u.to,n)>=0:z(u.to,n)>0)||c>=0&&(a.marker.inclusiveRight&&i.inclusiveLeft?z(u.from,r)<=0:z(u.from,r)<0)))return!0}}}function he(e){for(var t;t=ae(e);)e=t.find(-1,!0).line;return e}function de(e){for(var t;t=ue(e);)e=t.find(1,!0).line;return e}function pe(e){for(var t,n;t=ue(e);)e=t.find(1,!0).line,(n||(n=[])).push(e);return n}function ge(e,t){var n=M(e,t),r=he(n);return n==r?t:D(r)}function ve(e,t){if(t>e.lastLine())return t;var n,r=M(e,t);if(!me(e,r))return t;for(;n=ue(r);)r=n.find(1,!0).line;return D(r)+1}function me(e,t){var n=ns&&t.markedSpans;if(n)for(var r=void 0,i=0;it.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)})}function Ce(e,t,n,r){if(!e)return r(t,n,"ltr",0);for(var i=!1,o=0;ot||t==n&&l.to==t)&&(r(Math.max(l.from,t),Math.min(l.to,n),1==l.level?"rtl":"ltr",o),i=!0)}i||r(t,n,"ltr")}function Se(e,t,n){var r;rs=null;for(var i=0;it)return i;o.to==t&&(o.from!=o.to&&"before"==n?r=i:rs=i),o.from==t&&(o.from!=o.to&&"before"!=n?r=i:rs=i)}return null!=r?r:rs}function Le(e,t){var n=e.order;return null==n&&(n=e.order=is(e.text,t)),n}function ke(e,t){return e._handlers&&e._handlers[t]||os}function Te(e,t,n){if(e.removeEventListener)e.removeEventListener(t,n,!1);else if(e.detachEvent)e.detachEvent("on"+t,n);else{var r=e._handlers,i=r&&r[t];if(i){var o=h(i,n);o>-1&&(r[t]=i.slice(0,o).concat(i.slice(o+1)))}}}function Me(e,t){var n=ke(e,t);if(n.length)for(var r=Array.prototype.slice.call(arguments,2),i=0;i0}function De(e){e.prototype.on=function(e,t){ls(this,e,t)},e.prototype.off=function(e,t){Te(this,e,t)}}function We(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function He(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function Pe(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function Fe(e){We(e),He(e)}function ze(e){return e.target||e.srcElement}function Ee(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),Pl&&e.ctrlKey&&1==t&&(t=3),t}function Ie(e){if(null==Vl){var t=r("span","​");n(e,r("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(Vl=t.offsetWidth<=1&&t.offsetHeight>2&&!(Cl&&Sl<8))}var i=Vl?r("span","​"):r("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return i.setAttribute("cm-text",""),i}function Re(e){if(null!=Kl)return Kl;var r=n(e,document.createTextNode("AخA")),i=Il(r,0,1).getBoundingClientRect(),o=Il(r,1,2).getBoundingClientRect();return t(e),!(!i||i.left==i.right)&&(Kl=o.right-i.right<3)}function Be(e){if(null!=fs)return fs;var t=n(e,r("span","x")),i=t.getBoundingClientRect(),o=Il(t,0,1).getBoundingClientRect();return fs=Math.abs(i.left-o.left)>1}function Ge(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),hs[e]=t}function Ue(e,t){ds[e]=t}function je(e){if("string"==typeof e&&ds.hasOwnProperty(e))e=ds[e];else if(e&&"string"==typeof e.name&&ds.hasOwnProperty(e.name)){var t=ds[e.name];"string"==typeof t&&(t={name:t}),e=b(t,e),e.name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return je("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return je("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function Ve(e,t){t=je(t);var n=hs[t.name];if(!n)return Ve(e,"text/plain");var r=n(e,t);if(ps.hasOwnProperty(t.name)){var i=ps[t.name];for(var o in i)i.hasOwnProperty(o)&&(r.hasOwnProperty(o)&&(r["_"+o]=r[o]),r[o]=i[o])}if(r.name=t.name,t.helperType&&(r.helperType=t.helperType),t.modeProps)for(var l in t.modeProps)r[l]=t.modeProps[l];return r}function Ke(e,t){var n=ps.hasOwnProperty(e)?ps[e]:ps[e]={};c(t,n)}function Xe(e,t){if(!0===t)return t;if(e.copyState)return e.copyState(t);var n={};for(var r in t){var i=t[r];i instanceof Array&&(i=i.concat([])),n[r]=i}return n}function Ye(e,t){for(var n;e.innerMode&&(n=e.innerMode(t),n&&n.mode!=e);)t=n.state,e=n.mode;return n||{mode:e,state:t}}function _e(e,t,n){return!e.startState||e.startState(t,n)}function qe(e,t,n,r){var i=[e.state.modeGen],o={};rt(e,t.text,e.doc.mode,n,function(e,t){return i.push(e,t)},o,r);for(var l=n.state,s=function(r){n.baseTokens=i;var s=e.state.overlays[r],a=1,u=0;n.state=!0,rt(e,t.text,s.mode,n,function(e,t){for(var n=a;ue&&i.splice(a,1,e,i[a+1],r),a+=2,u=Math.min(e,r)}if(t)if(s.opaque)i.splice(n,a-n,e,"overlay "+t),a=n+2;else for(;ne.options.maxHighlightLength&&Xe(e.doc.mode,r.state),o=qe(e,t,r);i&&(r.state=i),t.stateAfter=r.save(!i),t.styles=o.styles,o.classes?t.styleClasses=o.classes:t.styleClasses&&(t.styleClasses=null),n===e.doc.highlightFrontier&&(e.doc.modeFrontier=Math.max(e.doc.modeFrontier,++e.doc.highlightFrontier))}return t.styles}function Ze(e,t,n){var r=e.doc,i=e.display;if(!r.mode.startState)return new ms(r,!0,t);var o=it(e,t,n),l=o>r.first&&M(r,o-1).stateAfter,s=l?ms.fromSaved(r,l,o):new ms(r,_e(r.mode),o);return r.iter(o,t,function(n){Qe(e,n.text,s);var r=s.line;n.stateAfter=r==t-1||r%5==0||r>=i.viewFrom&&rt.start)return o}throw new Error("Mode "+e.name+" failed to advance stream.")}function tt(e,t,n,r){var i,o=e.doc,l=o.mode;t=U(o,t);var s,a=M(o,t.line),u=Ze(e,t.line,n),c=new gs(a.text,e.options.tabSize,u);for(r&&(s=[]);(r||c.pose.options.maxHighlightLength?(s=!1,l&&Qe(e,t,r,f.pos),f.pos=t.length,a=null):a=nt(et(n,f,r.state,h),o),h){var d=h[0].name;d&&(a="m-"+(a?d+" "+a:d))}if(!s||c!=a){for(;ul;--s){if(s<=o.first)return o.first;var a=M(o,s-1),u=a.stateAfter;if(u&&(!n||s+(u instanceof vs?u.lookAhead:0)<=o.modeFrontier))return s;var c=f(a.text,null,e.options.tabSize);(null==i||r>c)&&(i=s-1,r=c)}return i}function ot(e,t){if(e.modeFrontier=Math.min(e.modeFrontier,t),!(e.highlightFrontiern;r--){var i=M(e,r).stateAfter;if(i&&(!(i instanceof vs)||r+i.lookAhead1&&!/ /.test(e))return e;for(var n=t,r="",i=0;iu&&f.from<=u));h++);if(f.to>=c)return e(n,r,i,o,l,s,a);e(n,r.slice(0,f.to-u),i,o,null,s,a),o=null,r=r.slice(f.to-u),u=f.to}}}function pt(e,t,n,r){var i=!r&&n.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!r&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",n.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t,e.trailingSpace=!1}function gt(e,t,n){var r=e.markedSpans,i=e.text,o=0;if(r)for(var l,s,a,u,c,f,h,d=i.length,p=0,g=1,v="",m=0;;){if(m==p){a=u=c=f=s="",h=null,m=1/0;for(var y=[],b=void 0,w=0;wp||C.collapsed&&x.to==p&&x.from==p)?(null!=x.to&&x.to!=p&&m>x.to&&(m=x.to,u=""),C.className&&(a+=" "+C.className),C.css&&(s=(s?s+";":"")+C.css),C.startStyle&&x.from==p&&(c+=" "+C.startStyle),C.endStyle&&x.to==m&&(b||(b=[])).push(C.endStyle,x.to),C.title&&!f&&(f=C.title),C.collapsed&&(!h||le(h.marker,C)<0)&&(h=x)):x.from>p&&m>x.from&&(m=x.from)}if(b)for(var S=0;S=d)break;for(var k=Math.min(d,m);;){if(v){var T=p+v.length;if(!h){var M=T>k?v.slice(0,k-p):v;t.addToken(t,M,l?l+a:a,c,p+M.length==m?u:"",f,s)}if(T>=k){v=v.slice(k-p),p=k;break}p=T,c=""}v=i.slice(o,o=n[g++]),l=at(n[g++],t.cm.options)}}else for(var A=1;A2&&o.push((a.bottom+u.top)/2-n.top)}}o.push(n.bottom-n.top)}}function Vt(e,t,n){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var r=0;rn)return{map:e.measure.maps[i],cache:e.measure.caches[i],before:!0}}function Kt(e,t){t=he(t);var r=D(t),i=e.display.externalMeasured=new vt(e.doc,t,r);i.lineN=r;var o=i.built=ut(e,i);return i.text=o.pre,n(e.display.lineMeasure,o.pre),i}function Xt(e,t,n,r){return qt(e,_t(e,t),n,r)}function Yt(e,t){if(t>=e.display.viewFrom&&t=n.lineN&&tt)&&(o=a-s,i=o-1,t>=a&&(l="right")),null!=i){if(r=e[u+2],s==a&&n==(r.insertLeft?"left":"right")&&(l=n),"left"==n&&0==i)for(;u&&e[u-2]==e[u-3]&&e[u-1].insertLeft;)r=e[2+(u-=3)],l="left";if("right"==n&&i==a-s)for(;u=0&&(n=e[i]).left==n.right;i--);return n}function Qt(e,t,n,r){var i,o=$t(t.map,n,r),l=o.node,s=o.start,a=o.end,u=o.collapse;if(3==l.nodeType){for(var c=0;c<4;c++){for(;s&&S(t.line.text.charAt(o.coverStart+s));)--s;for(;o.coverStart+a0&&(u=r="right"),i=e.options.lineWrapping&&(f=l.getClientRects()).length>1?f["right"==r?f.length-1:0]:l.getBoundingClientRect()}if(Cl&&Sl<9&&!s&&(!i||!i.left&&!i.right)){var h=l.parentNode.getClientRects()[0];i=h?{left:h.left,right:h.left+xn(e.display),top:h.top,bottom:h.bottom}:ks}for(var d=i.top-t.rect.top,p=i.bottom-t.rect.top,g=(d+p)/2,v=t.view.measure.heights,m=0;m=r.text.length?(u=r.text.length,c="before"):u<=0&&(u=0,c="after"),!a)return l("before"==c?u-1:u,"before"==c);var f=Se(a,u,c),h=rs,d=s(u,f,"before"==c);return null!=h&&(d.other=s(u,h,"before"!=c)),d}function fn(e,t){var n=0;t=U(e.doc,t),e.options.lineWrapping||(n=xn(e.display)*t.ch);var r=M(e.doc,t.line),i=be(r)+Et(e.display);return{left:n,right:n,top:i,bottom:i+r.height}}function hn(e,t,n,r,i){var o=F(e,t,n);return o.xRel=i,r&&(o.outside=!0),o}function dn(e,t,n){var r=e.doc;if(n+=e.display.viewOffset,n<0)return hn(r.first,0,null,!0,-1);var i=W(r,n),o=r.first+r.size-1;if(i>o)return hn(r.first+r.size-1,M(r,o).text.length,null,!0,1);t<0&&(t=0);for(var l=M(r,i);;){var s=mn(e,l,i,t,n),a=ce(l,s.ch+(s.xRel>0?1:0));if(!a)return s;var u=a.find(1);if(u.line==i)return u;l=M(r,i=u.line)}}function pn(e,t,n,r){r-=ln(t);var i=t.text.length,o=k(function(t){return qt(e,n,t-1).bottom<=r},i,0);return i=k(function(t){return qt(e,n,t).top>r},o,i),{begin:o,end:i}}function gn(e,t,n,r){n||(n=_t(e,t));var i=sn(e,t,qt(e,n,r),"line").top;return pn(e,t,n,i)}function vn(e,t,n,r){return!(e.bottom<=n)&&(e.top>n||(r?e.left:e.right)>t)}function mn(e,t,n,r,i){i-=be(t);var o=_t(e,t),l=ln(t),s=0,a=t.text.length,u=!0,c=Le(t,e.doc.direction);if(c){var f=(e.options.lineWrapping?bn:yn)(e,t,n,o,c,r,i);u=1!=f.level,s=u?f.from:f.to-1,a=u?f.to:f.from-1}var h,d,p=null,g=null,v=k(function(t){var n=qt(e,o,t);return n.top+=l,n.bottom+=l,!!vn(n,r,i,!1)&&(n.top<=i&&n.left<=r&&(p=t,g=n),!0)},s,a),m=!1;if(g){var y=r-g.left=w.bottom}return v=L(t.text,v,1),hn(n,v,d,m,r-h)}function yn(e,t,n,r,i,o,l){var s=k(function(s){var a=i[s],u=1!=a.level;return vn(cn(e,F(n,u?a.to:a.from,u?"before":"after"),"line",t,r),o,l,!0)},0,i.length-1),a=i[s];if(s>0){var u=1!=a.level,c=cn(e,F(n,u?a.from:a.to,u?"after":"before"),"line",t,r);vn(c,o,l,!0)&&c.top>l&&(a=i[s-1])}return a}function bn(e,t,n,r,i,o,l){var s=pn(e,t,r,l),a=s.begin,u=s.end;/\s/.test(t.text.charAt(u-1))&&u--;for(var c=null,f=null,h=0;h=u||d.to<=a)){var p=1!=d.level,g=qt(e,r,p?Math.min(u,d.to)-1:Math.max(a,d.from)).right,v=gv)&&(c=d,f=v)}}return c||(c=i[i.length-1]),c.fromu&&(c={from:c.from,to:u,level:c.level}),c}function wn(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==ws){ws=r("pre");for(var i=0;i<49;++i)ws.appendChild(document.createTextNode("x")),ws.appendChild(r("br"));ws.appendChild(document.createTextNode("x"))}n(e.measure,ws);var o=ws.offsetHeight/50;return o>3&&(e.cachedTextHeight=o),t(e.measure),o||1}function xn(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=r("span","xxxxxxxxxx"),i=r("pre",[t]);n(e.measure,i);var o=t.getBoundingClientRect(),l=(o.right-o.left)/10;return l>2&&(e.cachedCharWidth=l),l||10}function Cn(e){for(var t=e.display,n={},r={},i=t.gutters.clientLeft,o=t.gutters.firstChild,l=0;o;o=o.nextSibling,++l)n[e.options.gutters[l]]=o.offsetLeft+o.clientLeft+i,r[e.options.gutters[l]]=o.clientWidth;return{fixedPos:Sn(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:r,wrapperWidth:t.wrapper.clientWidth}}function Sn(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function Ln(e){var t=wn(e.display),n=e.options.lineWrapping,r=n&&Math.max(5,e.display.scroller.clientWidth/xn(e.display)-3);return function(i){if(me(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;l=e.display.viewTo)return null;if(t-=e.display.viewFrom,t<0)return null;for(var n=e.display.view,r=0;r=e.display.viewTo||s.to().line0?t.blinker=setInterval(function(){return t.cursorDiv.style.visibility=(n=!n)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function Pn(e){e.state.focused||(e.display.input.focus(),zn(e))}function Fn(e){e.state.delayingBlurEvent=!0,setTimeout(function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,En(e))},100)}function zn(e,t){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(Me(e,"focus",e,t),e.state.focused=!0,s(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),Ll&&setTimeout(function(){return e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),Hn(e))}function En(e,t){e.state.delayingBlurEvent||(e.state.focused&&(Me(e,"blur",e,t),e.state.focused=!1,Gl(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150))}function In(e){for(var t=e.display,n=t.lineDiv.offsetTop,r=0;r.005||a<-.005)&&(O(i.line,o),Rn(i.line),i.rest))for(var u=0;u=l&&(o=W(t,be(M(t,a))-e.wrapper.clientHeight),l=a)}return{from:o,to:Math.max(l,o+1)}}function Gn(e){var t=e.display,n=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var r=Sn(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=r+"px",l=0;l(window.innerHeight||document.documentElement.clientHeight)&&(o=!1),null!=o&&!Ol){var l=r("div","​",null,"position: absolute;\n top: "+(t.top-n.viewOffset-Et(e.display))+"px;\n height: "+(t.bottom-t.top+Bt(e)+n.barHeight)+"px;\n left: "+t.left+"px; width: "+Math.max(2,t.right-t.left)+"px;");e.display.lineSpace.appendChild(l),l.scrollIntoView(o),e.display.lineSpace.removeChild(l)}}}function Vn(e,t,n,r){var i;null==r&&(r=0),e.options.lineWrapping||t!=n||(t=t.ch?F(t.line,"before"==t.sticky?t.ch-1:t.ch,"after"):t,n="before"==t.sticky?F(t.line,t.ch+1,"before"):t);for(var o=0;o<5;o++){var l=!1,s=cn(e,t),a=n&&n!=t?cn(e,n):s;i={left:Math.min(s.left,a.left),top:Math.min(s.top,a.top)-r,right:Math.max(s.left,a.left),bottom:Math.max(s.bottom,a.bottom)+r};var u=Xn(e,i),c=e.doc.scrollTop,f=e.doc.scrollLeft;if(null!=u.scrollTop&&(Jn(e,u.scrollTop),Math.abs(e.doc.scrollTop-c)>1&&(l=!0)),null!=u.scrollLeft&&(tr(e,u.scrollLeft),Math.abs(e.doc.scrollLeft-f)>1&&(l=!0)),!l)break}return i}function Kn(e,t){var n=Xn(e,t);null!=n.scrollTop&&Jn(e,n.scrollTop),null!=n.scrollLeft&&tr(e,n.scrollLeft)}function Xn(e,t){var n=e.display,r=wn(e.display);t.top<0&&(t.top=0);var i=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:n.scroller.scrollTop,o=Ut(e),l={};t.bottom-t.top>o&&(t.bottom=t.top+o);var s=e.doc.height+It(n),a=t.tops-r;if(t.topi+o){var c=Math.min(t.top,(u?s:t.bottom)-o);c!=i&&(l.scrollTop=c)}var f=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:n.scroller.scrollLeft,h=Gt(e)-(e.options.fixedGutter?n.gutters.offsetWidth:0),d=t.right-t.left>h;return d&&(t.right=t.left+h),t.left<10?l.scrollLeft=0:t.lefth+f-3&&(l.scrollLeft=t.right+(d?0:10)-h),l}function Yn(e,t){null!=t&&(Zn(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+t)}function _n(e){Zn(e);var t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function qn(e,t,n){null==t&&null==n||Zn(e),null!=t&&(e.curOp.scrollLeft=t),null!=n&&(e.curOp.scrollTop=n)}function $n(e,t){Zn(e),e.curOp.scrollToPos=t}function Zn(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var n=fn(e,t.from),r=fn(e,t.to);Qn(e,n,r,t.margin)}}function Qn(e,t,n,r){var i=Xn(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});qn(e,i.scrollLeft,i.scrollTop)}function Jn(e,t){Math.abs(e.doc.scrollTop-t)<2||(yl||Dr(e,{top:t}),er(e,t,!0),yl&&Dr(e),Lr(e,100))}function er(e,t,n){t=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 tr(e,t,n,r){t=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,Gn(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function nr(e){var t=e.display,n=t.gutters.offsetWidth,r=Math.round(e.doc.height+It(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+Bt(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}function rr(e,t){t||(t=nr(e));var n=e.display.barWidth,r=e.display.barHeight;ir(e,t);for(var i=0;i<4&&n!=e.display.barWidth||r!=e.display.barHeight;i++)n!=e.display.barWidth&&e.options.lineWrapping&&In(e),ir(e,nr(e)),n=e.display.barWidth,r=e.display.barHeight}function ir(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=""}function or(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&Gl(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new As[e.options.scrollbarStyle](function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),ls(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?tr(e,t):Jn(e,t)},e),e.display.scrollbars.addClass&&s(e.display.wrapper,e.display.scrollbars.addClass)}function lr(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Ns},yt(e.curOp)}function sr(e){var t=e.curOp;wt(t,function(e){for(var t=0;t=n.viewTo)||n.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new Os(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function cr(e){e.updatedDisplay=e.mustUpdate&&Nr(e.cm,e.update)}function fr(e){var t=e.cm,n=t.display;e.updatedDisplay&&In(t),e.barMeasure=nr(t),n.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Xt(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+Bt(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-Gt(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function hr(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeftt)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)ns&&ge(e.doc,t)i.viewFrom?wr(e):(i.viewFrom+=r,i.viewTo+=r);else if(t<=i.viewFrom&&n>=i.viewTo)wr(e);else if(t<=i.viewFrom){var o=xr(e,n,n+r,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=r):wr(e)}else if(n>=i.viewTo){var l=xr(e,t,t,-1);l?(i.view=i.view.slice(0,l.index),i.viewTo=l.lineN):wr(e)}else{var s=xr(e,t,t,-1),a=xr(e,n,n+r,1);s&&a?(i.view=i.view.slice(0,s.index).concat(mt(e,s.lineN,a.lineN)).concat(i.view.slice(a.index)),i.viewTo+=r):wr(e)}var u=i.externalMeasured;u&&(n=i.lineN&&t=r.viewTo)){var o=r.view[Mn(e,t)];if(null!=o.node){var l=o.changes||(o.changes=[]);-1==h(l,n)&&l.push(n)}}}function wr(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function xr(e,t,n,r){var i,o=Mn(e,t),l=e.display.view;if(!ns||n==e.doc.first+e.doc.size)return{index:o,lineN:n};for(var s=e.display.viewFrom,a=0;a0){if(o==l.length-1)return null;i=s+l[o].size-t,o++}else i=s-t;t+=i,n+=i}for(;ge(e.doc,n)!=n;){if(o==(r<0?0:l.length-1))return null;n+=r*l[o-(r<0?1:0)].size,o+=r}return{index:o,lineN:n}}function Cr(e,t,n){var r=e.display,i=r.view;0==i.length||t>=r.viewTo||n<=r.viewFrom?(r.view=mt(e,t,n),r.viewFrom=t):(r.viewFrom>t?r.view=mt(e,t,r.viewFrom).concat(r.view):r.viewFromn&&(r.view=r.view.slice(0,Mn(e,n)))),r.viewTo=n}function Sr(e){for(var t=e.display.view,n=0,r=0;r=e.display.viewTo)){var n=+new Date+e.options.workTime,r=Ze(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 l=o.styles,s=o.text.length>e.options.maxHighlightLength?Xe(t.mode,r.state):null,a=qe(e,o,r,!0);s&&(r.state=s),o.styles=a.styles;var u=o.styleClasses,c=a.classes;c?o.styleClasses=c:u&&(o.styleClasses=null);for(var f=!l||l.length!=o.styles.length||u!=c&&(!u||!c||u.bgClass!=c.bgClass||u.textClass!=c.textClass),h=0;!f&&hn)return Lr(e,e.options.workDelay),!0}),t.highlightFrontier=r.line,t.modeFrontier=Math.max(t.modeFrontier,r.line),i.length&&pr(e,function(){for(var t=0;t=r.viewFrom&&n.visible.to<=r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&0==Sr(e))return!1;Un(e)&&(wr(e),n.dims=Cn(e));var o=i.first+i.size,l=Math.max(n.visible.from-e.options.viewportMargin,i.first),s=Math.min(o,n.visible.to+e.options.viewportMargin);r.viewFroms&&r.viewTo-s<20&&(s=Math.min(o,r.viewTo)),ns&&(l=ge(e.doc,l),s=ve(e.doc,s));var a=l!=r.viewFrom||s!=r.viewTo||r.lastWrapHeight!=n.wrapperHeight||r.lastWrapWidth!=n.wrapperWidth;Cr(e,l,s),r.viewOffset=be(M(e.doc,r.viewFrom)),e.display.mover.style.top=r.viewOffset+"px";var u=Sr(e);if(!a&&0==u&&!n.force&&r.renderedView==r.view&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo))return!1;var c=Mr(e);return u>4&&(r.lineDiv.style.display="none"),Wr(e,r.updateLineNumbers,n.dims),u>4&&(r.lineDiv.style.display=""),r.renderedView=r.view,Ar(c),t(r.cursorDiv),t(r.selectionDiv),r.gutters.style.height=r.sizer.style.minHeight=0,a&&(r.lastWrapHeight=n.wrapperHeight,r.lastWrapWidth=n.wrapperWidth,Lr(e,400)),r.updateLineNumbers=null,!0}function Or(e,t){for(var n=t.viewport,r=!0;(r&&e.options.lineWrapping&&t.oldDisplayWidth!=Gt(e)||(n&&null!=n.top&&(n={top:Math.min(e.doc.height+It(e.display)-Ut(e),n.top)}),t.visible=Bn(e.display,e.doc,n),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&Nr(e,t);r=!1){In(e);var i=nr(e);An(e),rr(e,i),Pr(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 Dr(e,t){var n=new Os(e,t);if(Nr(e,n)){In(e),Or(e,n);var r=nr(e);An(e),rr(e,r),Pr(e,r),n.finish()}}function Wr(e,n,r){function i(t){var n=t.nextSibling;return Ll&&Pl&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}for(var o=e.display,l=e.options.lineNumbers,s=o.lineDiv,a=s.firstChild,u=o.view,c=o.viewFrom,f=0;f-1&&(p=!1),St(e,d,c,r)),p&&(t(d.lineNumber),d.lineNumber.appendChild(document.createTextNode(P(e.options,c)))),a=d.node.nextSibling}else{var g=Dt(e,d,c,r);s.insertBefore(g,a)}c+=d.size}for(;a;)a=i(a)}function Hr(e){var t=e.display.gutters.offsetWidth;e.display.sizer.style.marginLeft=t+"px"}function Pr(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+Bt(e)+"px"}function Fr(e){var n=e.display.gutters,i=e.options.gutters;t(n);for(var o=0;o-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function Er(e){var t=e.wheelDeltaX,n=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==n&&e.detail&&e.axis==e.VERTICAL_AXIS?n=e.detail:null==n&&(n=e.wheelDelta),{x:t,y:n}}function Ir(e){var t=Er(e);return t.x*=Ws,t.y*=Ws,t}function Rr(e,t){var n=Er(t),r=n.x,i=n.y,o=e.display,l=o.scroller,s=l.scrollWidth>l.clientWidth,a=l.scrollHeight>l.clientHeight;if(r&&s||i&&a){if(i&&Pl&&Ll)e:for(var u=t.target,c=o.view;u!=l;u=u.parentNode)for(var f=0;f=0){var l=B(o.from(),i.from()),s=R(o.to(),i.to()),a=o.empty()?i.from()==i.head:o.from()==o.head;r<=t&&--t,e.splice(--r,2,new Ps(a?s:l,a?l:s))}}return new Hs(e,t)}function Gr(e,t){return new Hs([new Ps(e,t||e)],0)}function Ur(e){return e.text?F(e.from.line+e.text.length-1,g(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function jr(e,t){if(z(e,t.from)<0)return e;if(z(e,t.to)<=0)return Ur(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+=Ur(t).ch-t.to.ch),F(n,r)}function Vr(e,t){for(var n=[],r=0;r1&&e.remove(s.line+1,p-1),e.insert(s.line+1,y)}xt(e,"change",e,t)}function Zr(e,t,n){function r(e,i,o){if(e.linked)for(var l=0;l1&&!e.done[e.done.length-2].ranges?(e.done.pop(),g(e.done)):void 0}function oi(e,t,n,r){var i=e.history;i.undone.length=0;var o,l,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=ii(i,i.lastOp==r)))l=g(o.changes),0==z(t.from,t.to)&&0==z(t.from,l.to)?l.to=Ur(t):o.changes.push(ni(e,t));else{var a=g(i.done);for(a&&a.ranges||ai(e.sel,i.done),o={changes:[ni(e,t)],generation:i.generation},i.done.push(o);i.done.length>i.undoDepth;)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(n),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=s,i.lastOp=i.lastSelOp=r,i.lastOrigin=i.lastSelOrigin=t.origin,l||Me(e,"historyAdded")}function li(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 si(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||li(e,o,g(i.done),t))?i.done[i.done.length-1]=t:ai(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=n,r&&!1!==r.clearRedo&&ri(i.undone)}function ai(e,t){var n=g(t);n&&n.ranges&&n.equals(e)||t.push(e)}function ui(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 ci(e){if(!e)return null;for(var t,n=0;n-1&&(g(s)[f]=u[f],delete u[f])}}}return r}function pi(e,t,n,r){if(r){var i=e.anchor;if(n){var o=z(t,i)<0;o!=z(n,i)<0?(i=t,t=n):o!=z(t,n)<0&&(t=n)}return new Ps(i,t)}return new Ps(n||t,t)}function gi(e,t,n,r,i){null==i&&(i=e.cm&&(e.cm.display.shift||e.extend)),xi(e,new Hs([pi(e.sel.primary(),t,n,i)],0),r)}function vi(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&&(Me(a,"beforeCursorEnter"),a.explicitlyCleared)){if(o.markedSpans){--l;continue}break}if(!a.atomic)continue;if(n){var u=a.find(r<0?1:-1),c=void 0;if((r<0?a.inclusiveRight:a.inclusiveLeft)&&(u=Ai(e,u,-r,u&&u.line==t.line?o:null)),u&&u.line==t.line&&(c=z(u,n))&&(r<0?c<0:c>0))return Ti(e,u,t,r,i)}var f=a.find(r<0?-1:1);return(r<0?a.inclusiveLeft:a.inclusiveRight)&&(f=Ai(e,f,r,f.line==t.line?o:null)),f?Ti(e,f,t,r,i):null}}return t}function Mi(e,t,n,r,i){var o=r||1,l=Ti(e,t,n,o,i)||!i&&Ti(e,t,n,o,!0)||Ti(e,t,n,-o,i)||!i&&Ti(e,t,n,-o,!0);return l||(e.cantEdit=!0,F(e.first,0))}function Ai(e,t,n,r){return n<0&&0==t.ch?t.line>e.first?U(e,F(t.line-1)):null:n>0&&t.ch==(r||M(e,t.line)).text.length?t.line=0;--i)Wi(e,{from:r[i].from,to:r[i].to,text:i?[""]:t.text,origin:t.origin});else Wi(e,t)}}function Wi(e,t){if(1!=t.text.length||""!=t.text[0]||0!=z(t.from,t.to)){var n=Vr(e,t);oi(e,t,n,e.cm?e.cm.curOp.id:NaN),Fi(e,t,n,J(e,t));var r=[];Zr(e,function(e,n){n||-1!=h(r,e.history)||(Bi(e.history,t),r.push(e.history)),Fi(e,t,null,J(e,t))})}}function Hi(e,t,n){var r=e.cm&&e.cm.state.suppressEdits;if(!r||n){for(var i,o=e.history,l=e.sel,s="undo"==t?o.done:o.undone,a="undo"==t?o.undone:o.done,u=0;u=0;--p){var v=d(p);if(v)return v.v}}}}function Pi(e,t){if(0!=t&&(e.first+=t,e.sel=new Hs(v(e.sel.ranges,function(e){return new Ps(F(e.anchor.line+t,e.anchor.ch),F(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){yr(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:F(o,M(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=A(e,t.from,t.to),n||(n=Vr(e,t)),e.cm?zi(e.cm,t,r):$r(e,t,r),Ci(e,n,ql)}}function zi(e,t,n){var r=e.doc,i=e.display,o=t.from,l=t.to,s=!1,a=o.line;e.options.lineWrapping||(a=D(he(M(r,o.line))),r.iter(a,l.line+1,function(e){if(e==i.maxLine)return s=!0,!0})),r.sel.contains(t.from,t.to)>-1&&Ne(e),$r(r,t,n,Ln(e)),e.options.lineWrapping||(r.iter(a,o.line+t.text.length,function(e){var t=we(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,s=!1)}),s&&(e.curOp.updateMaxLine=!0)),ot(r,o.line),Lr(e,400);var u=t.text.length-(l.line-o.line)-1;t.full?yr(e):o.line!=l.line||1!=t.text.length||qr(e.doc,t)?yr(e,o.line,l.line+1,u):br(e,o.line,"text");var c=Oe(e,"changes"),f=Oe(e,"change");if(f||c){var h={from:o,to:l,text:t.text,removed:t.removed,origin:t.origin};f&&xt(e,"change",e,h),c&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(h)}e.display.selForContextMenu=null}function Ei(e,t,n,r,i){var o;(r||(r=n),z(r,n)<0)&&(o=[r,n],n=o[0],r=o[1]);"string"==typeof t&&(t=e.splitLines(t)),Di(e,{from:n,to:r,text:t,origin:i})}function Ii(e,t,n,r){n0||0==s&&!1!==l.clearWhenEmpty)return l;if(l.replacedWith&&(l.collapsed=!0,l.widgetNode=i("span",[l.replacedWith],"CodeMirror-widget"),r.handleMouseEvents||l.widgetNode.setAttribute("cm-ignore-events","true"),r.insertLeft&&(l.widgetNode.insertLeft=!0)),l.collapsed){if(fe(e,t.line,t,n,l)||t.line!=n.line&&fe(e,n.line,t,n,l))throw new Error("Inserting collapsed marker partially overlapping an existing one");X()}l.addToHistory&&oi(e,{from:t,to:n,origin:"markText"},e.sel,NaN);var a,u=t.line,f=e.cm;if(e.iter(u,n.line+1,function(e){f&&l.collapsed&&!f.options.lineWrapping&&he(e)==f.display.maxLine&&(a=!0),l.collapsed&&u!=t.line&&O(e,0),$(e,new Y(l,u==t.line?t.ch:null,u==n.line?n.ch:null)),++u}),l.collapsed&&e.iter(t.line,n.line+1,function(t){me(e,t)&&O(t,0)}),l.clearOnEnter&&ls(l,"beforeCursorEnter",function(){return l.clear()}),l.readOnly&&(K(),(e.history.done.length||e.history.undone.length)&&e.clearHistory()),l.collapsed&&(l.id=++zs,l.atomic=!0),f){if(a&&(f.curOp.updateMaxLine=!0),l.collapsed)yr(f,t.line,n.line+1);else if(l.className||l.title||l.startStyle||l.endStyle||l.css)for(var h=t.line;h<=n.line;h++)br(f,h,"text");l.atomic&&Li(f.doc),xt(f,"markerAdded",f,l)}return l}function Yi(e,t,n,r,i){r=c(r),r.shared=!1;var o=[Xi(e,t,n,r,i)],l=o[0],s=r.widgetNode;return Zr(e,function(e){s&&(r.widgetNode=s.cloneNode(!0)),o.push(Xi(e,U(e,t),U(e,n),r,i));for(var a=0;a-1)return t.state.draggingText(e),void setTimeout(function(){return t.display.input.focus()},20);try{var u=e.dataTransfer.getData("Text");if(u){var c;if(t.state.draggingText&&!t.state.draggingText.copy&&(c=t.listSelections()),Ci(t.doc,Gr(n,n)),c)for(var f=0;f=0;t--)Ei(e.doc,"",r[t].from,r[t].to,"+delete");_n(e)})}function po(e,t,n){var r=L(e.text,t+n,n);return r<0||r>e.text.length?null:r}function go(e,t,n){var r=po(e,t.ch,n);return null==r?null:new F(t.line,r,n<0?"after":"before")}function vo(e,t,n,r,i){if(e){var o=Le(n,t.doc.direction);if(o){var l,s=i<0?g(o):o[0],a=i<0==(1==s.level),u=a?"after":"before";if(s.level>0||"rtl"==t.doc.direction){var c=_t(t,n);l=i<0?n.text.length-1:0;var f=qt(t,c,l).top;l=k(function(e){return qt(t,c,e).top==f},i<0==(1==s.level)?s.from:s.to-1,l),"before"==u&&(l=po(n,l,1))}else l=i<0?s.to:s.from;return new F(r,l,u)}}return new F(r,i<0?n.text.length:0,i<0?"before":"after")}function mo(e,t,n,r){var i=Le(t,e.doc.direction);if(!i)return go(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=Se(i,n.ch,n.sticky),l=i[o];if("ltr"==e.doc.direction&&l.level%2==0&&(r>0?l.to>n.ch:l.from=l.from&&h>=c.begin)){var d=f?"before":"after";return new F(n.line,h,d)}}var p=function(e,t,r){for(var o=function(e,t){return t?new F(n.line,a(e,1),"before"):new F(n.line,e,"after")};e>=0&&e0==(1!=l.level),u=s?r.begin:a(r.end,-1);if(l.from<=u&&u0?c.end:a(c.begin,-1);return null==v||r>0&&v==t.text.length||(g=p(r>0?0:i.length-1,r,u(v)),!g)?null:g}function yo(e,t){var n=M(e.doc,t),r=he(n);return r!=n&&(t=D(r)),vo(!0,e,r,t,1)}function bo(e,t){var n=M(e.doc,t),r=de(n);return r!=n&&(t=D(r)),vo(!0,e,n,t,-1)}function wo(e,t){var n=yo(e,t.line),r=M(e.doc,n.line),i=Le(r,e.doc.direction);if(!i||0==i[0].level){var o=Math.max(0,r.text.search(/\S/)),l=t.line==n.line&&t.ch<=o&&t.ch;return F(n.line,l?0:o,n.sticky)}return n}function xo(e,t,n){if("string"==typeof t&&(t=$s[t],!t))return!1;e.display.input.ensurePolled();var r=e.display.shift,i=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),n&&(e.display.shift=!1),i=t(e)!=_l}finally{e.display.shift=r,e.state.suppressEdits=!1}return i}function Co(e,t,n){for(var r=0;r-1&&(z((i=s.ranges[i]).from(),t)<0||t.xRel>0)&&(z(i.to(),t)>0||t.xRel<0)?zo(e,r,t,o):Io(e,r,t,o)}function zo(e,t,n,r){var i=e.display,o=!1,l=gr(e,function(t){Ll&&(i.scroller.draggable=!1),e.state.draggingText=!1,Te(i.wrapper.ownerDocument,"mouseup",l),Te(i.wrapper.ownerDocument,"mousemove",s),Te(i.scroller,"dragstart",a),Te(i.scroller,"drop",l),o||(We(t),r.addNew||gi(e.doc,n,null,null,r.extend),Ll||Cl&&9==Sl?setTimeout(function(){i.wrapper.ownerDocument.body.focus(),i.input.focus()},20):i.input.focus())}),s=function(e){o=o||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},a=function(){return o=!0};Ll&&(i.scroller.draggable=!0),e.state.draggingText=l,l.copy=!r.moveOnDrag,i.scroller.dragDrop&&i.scroller.dragDrop(),ls(i.wrapper.ownerDocument,"mouseup",l),ls(i.wrapper.ownerDocument,"mousemove",s),ls(i.scroller,"dragstart",a),ls(i.scroller,"drop",l),Fn(e),setTimeout(function(){return i.input.focus()},20)}function Eo(e,t,n){if("char"==n)return new Ps(t,t);if("word"==n)return e.findWordAt(t);if("line"==n)return new Ps(F(t.line,0),U(e.doc,F(t.line+1,0)));var r=n(e,t);return new Ps(r.from,r.to)}function Io(e,t,n,r){function i(t){if(0!=z(m,t))if(m=t,"rectangle"==r.unit){for(var i=[],o=e.options.tabSize,l=f(M(u,n.line).text,n.ch,o),s=f(M(u,t.line).text,t.ch,o),a=Math.min(l,s),g=Math.max(l,s),v=Math.min(n.line,t.line),y=Math.min(e.lastLine(),Math.max(n.line,t.line));v<=y;v++){var b=M(u,v).text,w=d(b,a,o);a==g?i.push(new Ps(F(v,w),F(v,w))):b.length>w&&i.push(new Ps(F(v,w),F(v,d(b,g,o))))}i.length||i.push(new Ps(n,n)),xi(u,Br(p.ranges.slice(0,h).concat(i),h),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var x,C=c,S=Eo(e,t,r.unit),L=C.anchor;z(S.anchor,L)>0?(x=S.head,L=B(C.from(),S.anchor)):(x=S.anchor,L=R(C.to(),S.head));var k=p.ranges.slice(0);k[h]=Ro(e,new Ps(U(u,L),x)),xi(u,Br(k,h),$l)}}function o(t){var n=++b,s=Tn(e,t,!0,"rectangle"==r.unit);if(s)if(0!=z(s,m)){e.curOp.focus=l(),i(s);var c=Bn(a,u);(s.line>=c.to||s.liney.bottom?20:0;f&&setTimeout(gr(e,function(){b==n&&(a.scroller.scrollTop+=f,o(t))}),50)}}function s(t){e.state.selectingText=!1,b=1/0,We(t),a.input.focus(),Te(a.wrapper.ownerDocument,"mousemove",w),Te(a.wrapper.ownerDocument,"mouseup",x),u.history.lastSelOrigin=null}var a=e.display,u=e.doc;We(t);var c,h,p=u.sel,g=p.ranges;if(r.addNew&&!r.extend?(h=u.sel.contains(n),c=h>-1?g[h]:new Ps(n,n)):(c=u.sel.primary(),h=u.sel.primIndex),"rectangle"==r.unit)r.addNew||(c=new Ps(n,n)),n=Tn(e,t,!0,!0),h=-1;else{var v=Eo(e,n,r.unit);c=r.extend?pi(c,v.anchor,v.head,r.extend):v}r.addNew?-1==h?(h=g.length,xi(u,Br(g.concat([c]),h),{scroll:!1,origin:"*mouse"})):g.length>1&&g[h].empty()&&"char"==r.unit&&!r.extend?(xi(u,Br(g.slice(0,h).concat(g.slice(h+1)),0),{scroll:!1,origin:"*mouse"}),p=u.sel):mi(u,h,c,$l):(h=0,xi(u,new Hs([c],0),$l),p=u.sel);var m=n,y=a.wrapper.getBoundingClientRect(),b=0,w=gr(e,function(e){0!==e.buttons&&Ee(e)?o(e):s(e)}),x=gr(e,s);e.state.selectingText=x,ls(a.wrapper.ownerDocument,"mousemove",w),ls(a.wrapper.ownerDocument,"mouseup",x)}function Ro(e,t){var n=t.anchor,r=t.head,i=M(e.doc,n.line);if(0==z(n,r)&&n.sticky==r.sticky)return t;var o=Le(i);if(!o)return t;var l=Se(o,n.ch,n.sticky),s=o[l];if(s.from!=n.ch&&s.to!=n.ch)return t;var a,u=l+(s.from==n.ch==(1!=s.level)?0:1);if(0==u||u==o.length)return t;if(r.line!=n.line)a=(r.line-n.line)*("ltr"==e.doc.direction?1:-1)>0;else{var c=Se(o,r.ch,r.sticky),f=c-l||(r.ch-n.ch)*(1==s.level?-1:1);a=c==u-1||c==u?f<0:f>0}var h=o[u+(a?-1:0)],d=a==(1==h.level),p=d?h.from:h.to,g=d?"after":"before";return n.ch==p&&n.sticky==g?t:new Ps(new F(n.line,p,g),r)}function Bo(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(t){return!1}if(i>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;r&&We(t);var l=e.display,s=l.lineDiv.getBoundingClientRect();if(o>s.bottom||!Oe(e,n))return Pe(t);o-=s.top-l.viewOffset;for(var a=0;a=i){var c=W(e.doc,o),f=e.options.gutters[a];return Me(e,n,e,c,f,t),Pe(t)}}}function Go(e,t){return Bo(e,t,"gutterClick",!0)}function Uo(e,t){zt(e.display,t)||jo(e,t)||Ae(e,t,"contextmenu")||e.display.input.onContextMenu(t)}function jo(e,t){return!!Oe(e,"gutterContextMenu")&&Bo(e,t,"gutterContextMenu",!1)}function Vo(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),nn(e)}function Ko(e){function t(t,r,i,o){e.defaults[t]=r,i&&(n[t]=o?function(e,t,n){n!=ta&&i(e,t,n)}:i)}var n=e.optionHandlers;e.defineOption=t,e.Init=ta,t("value","",function(e,t){return e.setValue(t)},!0),t("mode",null,function(e,t){e.doc.modeOption=t,Yr(e)},!0),t("indentUnit",2,Yr,!0),t("indentWithTabs",!1),t("smartIndent",!0),t("tabSize",4,function(e){_r(e),nn(e),yr(e)},!0),t("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(F(r,o))}r++});for(var i=n.length-1;i>=0;i--)Ei(e.doc,t,n[i],F(n[i].line,n[i].ch+t.length))}}),t("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g,function(e,t,n){e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),n!=ta&&e.refresh()}),t("specialCharPlaceholder",ct,function(e){return e.refresh()},!0),t("electricChars",!0),t("inputStyle",Hl?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),t("spellcheck",!1,function(e,t){return e.getInputField().spellcheck=t},!0),t("rtlMoveVisually",!zl),t("wholeLineUpdateBefore",!0),t("theme","default",function(e){Vo(e),Xo(e)},!0),t("keyMap","default",function(e,t,n){var r=fo(t),i=n!=ta&&fo(n);i&&i.detach&&i.detach(e,r),r.attach&&r.attach(e,i||null)}),t("extraKeys",null),t("configureMouse",null),t("lineWrapping",!1,_o,!0),t("gutters",[],function(e){zr(e.options),Xo(e)},!0),t("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?Sn(e.display)+"px":"0",e.refresh()},!0),t("coverGutterNextToScrollbar",!1,function(e){return rr(e)},!0),t("scrollbarStyle","native",function(e){or(e),rr(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),t("lineNumbers",!1,function(e){zr(e.options),Xo(e)},!0),t("firstLineNumber",1,Xo,!0),t("lineNumberFormatter",function(e){return e},Xo,!0),t("showCursorWhenSelecting",!1,An,!0),t("resetSelectionOnContextMenu",!0),t("lineWiseCopyCut",!0),t("pasteLinesPerSelection",!0),t("readOnly",!1,function(e,t){"nocursor"==t&&(En(e),e.display.input.blur()),e.display.input.readOnlyChanged(t)}),t("disableInput",!1,function(e,t){t||e.display.input.reset()},!0),t("dragDrop",!0,Yo), t("allowDropFileTypes",null),t("cursorBlinkRate",530),t("cursorScrollMargin",0),t("cursorHeight",1,An,!0),t("singleCursorHeightPerLine",!0,An,!0),t("workTime",100),t("workDelay",100),t("flattenSpans",!0,_r,!0),t("addModeClass",!1,_r,!0),t("pollInterval",100),t("undoDepth",200,function(e,t){return e.doc.history.undoDepth=t}),t("historyEventDelay",1250),t("viewportMargin",10,function(e){return e.refresh()},!0),t("maxHighlightLength",1e4,_r,!0),t("moveInputWithCursor",!0,function(e,t){t||e.display.input.resetPosition()}),t("tabindex",null,function(e,t){return e.display.input.getField().tabIndex=t||""}),t("autofocus",null),t("direction","ltr",function(e,t){return e.doc.setDirection(t)},!0),t("phrases",null)}function Xo(e){Fr(e),yr(e),Gn(e)}function Yo(e,t,n){var r=n&&n!=ta;if(!t!=!r){var i=e.display.dragFunctions,o=t?ls:Te;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 _o(e){e.options.lineWrapping?(s(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(Gl(e.display.wrapper,"CodeMirror-wrap"),xe(e)),kn(e),yr(e),nn(e),setTimeout(function(){return rr(e)},100)}function qo(e,t){var n=this;if(!(this instanceof qo))return new qo(e,t);this.options=t=t?c(t):{},c(na,t,!1),zr(t);var r=t.value;"string"==typeof r?r=new Bs(r,t.mode,null,t.lineSeparator,t.direction):t.mode&&(r.modeOption=t.mode),this.doc=r;var i=new qo.inputStyles[t.inputStyle](this),o=this.display=new T(e,r,i);for(var l in o.wrapper.CodeMirror=this,Fr(this),Vo(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),or(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 jl,keySeq:null,specialChars:null},t.autofocus&&!Hl&&o.input.focus(),Cl&&Sl<11&&setTimeout(function(){return n.display.input.reset(!0)},20),$o(this),no(),lr(this),this.curOp.forceUpdate=!0,Qr(this,r),t.autofocus&&!Hl||this.hasFocus()?setTimeout(u(zn,this),20):En(this),ra)ra.hasOwnProperty(l)&&ra[l](n,t[l],ta);Un(this),t.finishInit&&t.finishInit(this);for(var s=0;s400}var i=e.display;ls(i.scroller,"mousedown",gr(e,Wo)),ls(i.scroller,"dblclick",Cl&&Sl<11?gr(e,function(t){if(!Ae(e,t)){var n=Tn(e,t);if(n&&!Go(e,t)&&!zt(e.display,t)){We(t);var r=e.findWordAt(n);gi(e.doc,r.anchor,r.head)}}}):function(t){return Ae(e,t)||We(t)}),Bl||ls(i.scroller,"contextmenu",function(t){return Uo(e,t)});var o,l={end:0};ls(i.scroller,"touchstart",function(t){if(!Ae(e,t)&&!n(t)&&!Go(e,t)){i.input.ensurePolled(),clearTimeout(o);var r=+new Date;i.activeTouch={start:r,moved:!1,prev:r-l.end<=300?l:null},1==t.touches.length&&(i.activeTouch.left=t.touches[0].pageX,i.activeTouch.top=t.touches[0].pageY)}}),ls(i.scroller,"touchmove",function(){i.activeTouch&&(i.activeTouch.moved=!0)}),ls(i.scroller,"touchend",function(n){var o=i.activeTouch;if(o&&!zt(i,n)&&null!=o.left&&!o.moved&&new Date-o.start<300){var l,s=e.coordsChar(i.activeTouch,"page");l=!o.prev||r(o,o.prev)?new Ps(s,s):!o.prev.prev||r(o,o.prev.prev)?e.findWordAt(s):new Ps(F(s.line,0),U(e.doc,F(s.line+1,0))),e.setSelection(l.anchor,l.head),e.focus(),We(n)}t()}),ls(i.scroller,"touchcancel",t),ls(i.scroller,"scroll",function(){i.scroller.clientHeight&&(Jn(e,i.scroller.scrollTop),tr(e,i.scroller.scrollLeft,!0),Me(e,"scroll",e))}),ls(i.scroller,"mousewheel",function(t){return Rr(e,t)}),ls(i.scroller,"DOMMouseScroll",function(t){return Rr(e,t)}),ls(i.wrapper,"scroll",function(){return i.wrapper.scrollTop=i.wrapper.scrollLeft=0}),i.dragFunctions={enter:function(t){Ae(e,t)||Fe(t)},over:function(t){Ae(e,t)||(Ji(e,t),Fe(t))},start:function(t){return Qi(e,t)},drop:gr(e,Zi),leave:function(t){Ae(e,t)||eo(e)}};var s=i.input.getField();ls(s,"keyup",function(t){return No.call(e,t)}),ls(s,"keydown",gr(e,Mo)),ls(s,"keypress",gr(e,Oo)),ls(s,"focus",function(t){return zn(e,t)}),ls(s,"blur",function(t){return En(e,t)})}function Zo(e,t,n,r){var i,o=e.doc;null==n&&(n="add"),"smart"==n&&(o.mode.indent?i=Ze(e,t).state:n="prev");var l=e.options.tabSize,s=M(o,t),a=f(s.text,null,l);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==_l||u>150)){if(!r)return;n="prev"}}else u=0,n="not";"prev"==n?u=t>o.first?f(M(o,t-1).text,null,l):0:"add"==n?u=a+e.options.indentUnit:"subtract"==n?u=a-e.options.indentUnit:"number"==typeof n&&(u=a+n),u=Math.max(0,u);var h="",d=0;if(e.options.indentWithTabs)for(var g=Math.floor(u/l);g;--g)d+=l,h+="\t";if(d1)if(oa&&oa.text.join("\n")==t){if(r.ranges.length%oa.text.length==0){u=[];for(var c=0;c=0;f--){var h=r.ranges[f],d=h.from(),p=h.to();h.empty()&&(n&&n>0?d=F(d.line,d.ch-n):e.state.overwrite&&!s?p=F(p.line,Math.min(M(o,p.line).text.length,p.ch+g(a).length)):oa&&oa.lineWise&&oa.text.join("\n")==t&&(d=p=F(d.line,0))),l=e.curOp.updateInput;var m={from:d,to:p,text:u?u[f%u.length]:a,origin:i||(s?"paste":e.state.cutIncoming?"cut":"+input")};Di(e.doc,m),xt(e,"inputRead",e,m)}t&&!s&&tl(e,t),_n(e),e.curOp.updateInput=l,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function el(e,t){var n=e.clipboardData&&e.clipboardData.getData("Text");if(n)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||pr(t,function(){return Jo(t,n,0,null,"paste")}),!0}function tl(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),l=!1;if(o.electricChars){for(var s=0;s-1){l=Zo(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(M(e.doc,i.head.line).text.slice(0,i.head.ch))&&(l=Zo(e,i.head.line,"smart"));l&&xt(e,"electricInput",e,i.head.line)}}}function nl(e){for(var t=[],n=[],r=0;rr&&(Zo(t,o.head.line,e,!0),r=o.head.line,i==t.doc.sel.primIndex&&_n(t));else{var l=o.from(),s=o.to(),a=Math.max(r,l.line);r=Math.min(t.lastLine(),s.line-(s.ch?0:1))+1;for(var u=a;u0&&mi(t.doc,i,new Ps(l,c[i].to()),ql)}}}),getTokenAt:function(e,t){return tt(this,e,t)},getLineTokens:function(e,t){return tt(this,F(e),t,!0)},getTokenTypeAt:function(e){e=U(this.doc,e);var t,n=$e(this,M(this.doc,e.line)),r=0,i=(n.length-1)/2,o=e.ch;if(0==o)t=n[2];else for(;;){var l=r+i>>1;if((l?n[2*l-1]:0)>=o)i=l;else{if(!(n[2*l+1]o&&(e=o,i=!0),r=M(this.doc,e)}else r=e;return sn(this,r,{top:0,left:0},t||"page",n||i).top+(i?this.doc.height-be(r):0)},defaultTextHeight:function(){return wn(this.display)},defaultCharWidth:function(){return xn(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=cn(this,U(this.doc,e));var l=e.bottom,s=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),o.sizer.appendChild(t),"over"==r)l=e.top;else if("above"==r||"near"==r){var a=Math.max(o.wrapper.clientHeight,this.doc.height),u=Math.max(o.sizer.clientWidth,o.lineSpace.clientWidth);("above"==r||e.bottom+t.offsetHeight>a)&&e.top>t.offsetHeight?l=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=a&&(l=e.bottom),s+t.offsetWidth>u&&(s=u-t.offsetWidth)}t.style.top=l+"px",t.style.left=t.style.right="","right"==i?(s=o.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?s=0:"middle"==i&&(s=(o.sizer.clientWidth-t.offsetWidth)/2),t.style.left=s+"px"),n&&Kn(this,{left:s,top:l,right:s+t.offsetWidth,bottom:l+t.offsetHeight})},triggerOnKeyDown:vr(Mo),triggerOnKeyPress:vr(Oo),triggerOnKeyUp:No,triggerOnMouseDown:vr(Wo),execCommand:function(e){if($s.hasOwnProperty(e))return $s[e].call(null,this)},triggerElectric:vr(function(e){tl(this,e)}),findPosH:function(e,t,n,r){var i=this,o=1;t<0&&(o=-1,t=-t);for(var l=U(this.doc,e),s=0;s0&&s(n.charAt(r-1));)--r;for(;i.5)&&kn(this),Me(this,"refresh",this)}),swapDoc:vr(function(e){var t=this.doc;return t.cm=null,Qr(this,e),nn(this),this.display.input.reset(),qn(this,e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,xt(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}},De(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 ll(e,t,n,r,i){function o(){var r=t.line+n;return!(r=e.first+e.size)&&(t=new F(r,t.ch,t.sticky),u=M(e,r))}function l(r){var l;if(l=i?mo(e.cm,u,t,n):go(u,t,n),null==l){if(r||!o())return!1;t=vo(i,e.cm,u,t.line,n)}else t=l;return!0}var s=t,a=n,u=M(e,t.line);if("char"==r)l();else if("column"==r)l(!0);else if("word"==r||"group"==r)for(var c=null,f="group"==r,h=e.cm&&e.cm.getHelper(t,"wordChars"),d=!0;!(n<0)||l(!d);d=!1){var p=u.text.charAt(t.ch)||"\n",g=x(p,h)?"w":f&&"\n"==p?"n":!f||/\s/.test(p)?null:"p";if(!f||d||g||(g="s"),c&&c!=g){n<0&&(n=1,l(),t.sticky="after");break}if(g&&(c=g),n>0&&!l(!d))break}var v=Mi(e,t,s,a,!0);return E(s,v)&&(v.hitSide=!0),v}function sl(e,t,n,r){var i,o,l=e.doc,s=t.left;if("page"==r){var a=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),u=Math.max(a-.5*wn(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(;o=dn(e,s,i),o.outside;){if(n<0?i<=0:i>=l.height){o.hitSide=!0;break}i+=5*n}return o}function al(e,t){var n=Yt(e,t.line);if(!n||n.hidden)return null;var r=M(e.doc,t.line),i=Vt(n,r,t.line),o=Le(r,e.doc.direction),l="left";if(o){var s=Se(o,t.ch);l=s%2?"right":"left"}var a=$t(i.map,t.ch,l);return a.offset="right"==a.collapse?a.end:a.start,a}function ul(e){for(var t=e;t;t=t.parentNode)if(/CodeMirror-gutter-wrapper/.test(t.className))return!0;return!1}function cl(e,t){return t&&(e.bad=!0),e}function fl(e,t,n,r,i){function o(e){return function(t){return t.id==e}}function l(){c&&(u+=f,h&&(u+=f),c=h=!1)}function s(e){e&&(l(),u+=e)}function a(t){if(1==t.nodeType){var n=t.getAttribute("cm-text");if(n)return void s(n);var u,d=t.getAttribute("cm-marker");if(d){var p=e.findMarks(F(r,0),F(i+1,0),o(+d));return void(p.length&&(u=p[0].find(0))&&s(A(e.doc,u.from,u.to).join(f)))}if("false"==t.getAttribute("contenteditable"))return;var g=/^(pre|div|p|li|table|br)$/i.test(t.nodeName);if(!/^br$/i.test(t.nodeName)&&0==t.textContent.length)return;g&&l();for(var v=0;v=15&&(Ml=!1,Ll=!0);var Il,Rl=Pl&&(kl||Ml&&(null==El||El<12.11)),Bl=yl||Cl&&Sl>=9,Gl=function(t,n){var r=t.className,i=e(n).exec(r);if(i){var o=r.slice(i.index+i[0].length);t.className=r.slice(0,i.index)+(o?i[1]+o:"")}};Il=document.createRange?function(e,t,n,r){var i=document.createRange();return i.setEnd(r||e,n),i.setStart(e,t),i}:function(e,t,n){var r=document.body.createTextRange();try{r.moveToElementText(e.parentNode)}catch(e){return r}return r.collapse(!0),r.moveEnd("character",n),r.moveStart("character",t),r};var Ul=function(e){e.select()};Dl?Ul=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:Cl&&(Ul=function(e){try{e.select()}catch(e){}});var jl=function(){this.id=null};jl.prototype.set=function(e,t){clearTimeout(this.id),this.id=setTimeout(t,e)};var Vl,Kl,Xl,Yl=30,_l={toString:function(){return"CodeMirror.Pass"}},ql={scroll:!1},$l={origin:"*mouse"},Zl={origin:"+move"},Ql=[""],Jl=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,es=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/,ts=!1,ns=!1,rs=null,is=function(){function e(e){return e<=247?n.charAt(e):1424<=e&&e<=1524?"R":1536<=e&&e<=1785?r.charAt(e-1536):1774<=e&&e<=2220?"r":8192<=e&&e<=8203?"w":8204==e?"b":"L"}function t(e,t,n){this.level=e,this.from=t,this.to=n}var n="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",r="nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111",i=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,o=/[stwN]/,l=/[LRr]/,s=/[Lb1n]/,a=/[1n]/;return function(n,r){var u="ltr"==r?"L":"R";if(0==n.length||"ltr"==r&&!i.test(n))return!1;for(var c=n.length,f=[],h=0;h=this.string.length},gs.prototype.sol=function(){return this.pos==this.lineStart},gs.prototype.peek=function(){return this.string.charAt(this.pos)||void 0},gs.prototype.next=function(){if(this.post},gs.prototype.eatSpace=function(){for(var e=this,t=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++e.pos;return this.pos>t},gs.prototype.skipToEnd=function(){this.pos=this.string.length},gs.prototype.skipTo=function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},gs.prototype.backUp=function(e){this.pos-=e},gs.prototype.column=function(){return this.lastColumnPos0?null:(r&&!1!==t&&(this.pos+=r[0].length),r)}var i=function(e){return n?e.toLowerCase():e},o=this.string.substr(this.pos,e.length);if(i(o)==i(e))return!1!==t&&(this.pos+=e.length),!0},gs.prototype.current=function(){return this.string.slice(this.start,this.pos)},gs.prototype.hideFirstChars=function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}},gs.prototype.lookAhead=function(e){var t=this.lineOracle;return t&&t.lookAhead(e)},gs.prototype.baseToken=function(){var e=this.lineOracle;return e&&e.baseToken(this.pos)};var vs=function(e,t){this.state=e,this.lookAhead=t},ms=function(e,t,n,r){this.state=t,this.doc=e,this.line=n,this.maxLookAhead=r||0,this.baseTokens=null,this.baseTokenPos=1};ms.prototype.lookAhead=function(e){var t=this.doc.getLine(this.line+e);return null!=t&&e>this.maxLookAhead&&(this.maxLookAhead=e),t},ms.prototype.baseToken=function(e){var t=this;if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=e;)t.baseTokenPos+=2;var n=this.baseTokens[this.baseTokenPos+1];return{type:n&&n.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}},ms.prototype.nextLine=function(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--},ms.fromSaved=function(e,t,n){return t instanceof vs?new ms(e,Xe(e.mode,t.state),n,t.lookAhead):new ms(e,Xe(e.mode,t),n)},ms.prototype.save=function(e){var t=!1!==e?Xe(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new vs(t,this.maxLookAhead):t};var ys=function(e,t,n){this.start=e.start,this.end=e.pos,this.string=e.current(),this.type=t||null,this.state=n},bs=function(e,t,n){this.text=e,re(this,t),this.height=n?n(this):1};bs.prototype.lineNo=function(){return D(this)},De(bs);var ws,xs={},Cs={},Ss=null,Ls=null,ks={left:0,right:0,top:0,bottom:0},Ts=function(e,t,n){this.cm=n;var i=this.vert=r("div",[r("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),o=this.horiz=r("div",[r("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar") ;i.tabIndex=o.tabIndex=-1,e(i),e(o),ls(i,"scroll",function(){i.clientHeight&&t(i.scrollTop,"vertical")}),ls(o,"scroll",function(){o.clientWidth&&t(o.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,Cl&&Sl<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};Ts.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.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}},Ts.prototype.setScrollLeft=function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")},Ts.prototype.setScrollTop=function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")},Ts.prototype.zeroWidthHack=function(){var e=Pl&&!Nl?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new jl,this.disableVert=new jl},Ts.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)},Ts.prototype.clear=function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)};var Ms=function(){};Ms.prototype.update=function(){return{bottom:0,right:0}},Ms.prototype.setScrollLeft=function(){},Ms.prototype.setScrollTop=function(){},Ms.prototype.clear=function(){};var As={native:Ts,null:Ms},Ns=0,Os=function(e,t,n){var r=e.display;this.viewport=t,this.visible=Bn(r,e.doc,t),this.editorIsHidden=!r.wrapper.offsetWidth,this.wrapperHeight=r.wrapper.clientHeight,this.wrapperWidth=r.wrapper.clientWidth,this.oldDisplayWidth=Gt(e),this.force=n,this.dims=Cn(e),this.events=[]};Os.prototype.signal=function(e,t){Oe(e,t)&&this.events.push(arguments)},Os.prototype.finish=function(){for(var e=this,t=0;t=0&&z(e,i.to())<=0)return r}return-1};var Ps=function(e,t){this.anchor=e,this.head=t};Ps.prototype.from=function(){return B(this.anchor,this.head)},Ps.prototype.to=function(){return R(this.anchor,this.head)},Ps.prototype.empty=function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch},Ui.prototype={chunkSize:function(){return this.lines.length},removeInner:function(e,t){for(var n=this,r=e,i=e+t;r1||!(this.children[0]instanceof Ui))){var a=[];this.collapse(a),this.children=[new Ui(a)],this.children[0].parent=this}},collapse:function(e){for(var t=this,n=0;n50){for(var s=o.lines.length%25+25,a=s;a10);e.parent.maybeSpill()}},iterN:function(e,t,n){for(var r=this,i=0;it.display.maxLineLength&&(t.display.maxLine=c,t.display.maxLineLength=f,t.display.maxLineChanged=!0)}null!=i&&t&&this.collapsed&&yr(t,i,o+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,t&&Li(t.doc)),t&&xt(t,"markerCleared",t,this,i,o),n&&sr(t),this.parent&&this.parent.clear()}},Es.prototype.find=function(e,t){var n,r,i=this;null==e&&"bookmark"==this.type&&(e=1);for(var o=0;o=0;u--)Di(r,i[u]);a?wi(this,a):this.cm&&_n(this.cm)}),undo:mr(function(){Hi(this,"undo")}),redo:mr(function(){Hi(this,"redo")}),undoSelection:mr(function(){Hi(this,"undo",!0)}),redoSelection:mr(function(){Hi(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=U(this,e),t=U(this,t);var r=[],i=e.line;return this.iter(e.line,t.line+1,function(o){var l=o.markedSpans;if(l)for(var s=0;s=a.to||null==a.from&&i!=e.line||null!=a.from&&i==t.line&&a.from>=t.ch||n&&!n(a.marker)||r.push(a.marker.parent||a.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}),U(this,F(n,t))},indexFromPos:function(e){e=U(this,e);var t=e.ch;if(e.linet&&(t=e.from),null!=e.to&&e.to0)i=new F(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),F(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var l=M(e.doc,i.line-1).text;l&&(i=new F(i.line,1),e.replaceRange(o.charAt(0)+e.doc.lineSeparator()+l.charAt(l.length-1),F(i.line-1,l.length-1),i,"+transpose"))}n.push(new Ps(i,i))}e.setSelections(n)})},newlineAndIndent:function(e){return pr(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;re&&0==z(t,this.pos)&&n==this.button};var ta={toString:function(){return"CodeMirror.Init"}},na={},ra={};qo.defaults=na,qo.optionHandlers=ra;var ia=[];qo.defineInitHook=function(e){return ia.push(e)};var oa=null,la=function(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new jl,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};la.prototype.init=function(e){function t(e){if(!Ae(i,e)){if(i.somethingSelected())Qo({lineWise:!1,text:i.getSelections()}),"cut"==e.type&&i.replaceSelection("",null,"cut");else{if(!i.options.lineWiseCopyCut)return;var t=nl(i);Qo({lineWise:!0,text:t.text}),"cut"==e.type&&i.operation(function(){i.setSelections(t.ranges,0,ql),i.replaceSelection("",null,"cut")})}if(e.clipboardData){e.clipboardData.clearData();var n=oa.text.join("\n");if(e.clipboardData.setData("Text",n),e.clipboardData.getData("Text")==n)return void e.preventDefault()}var l=il(),s=l.firstChild;i.display.lineSpace.insertBefore(l,i.display.lineSpace.firstChild),s.value=oa.text.join("\n");var a=document.activeElement;Ul(s),setTimeout(function(){i.display.lineSpace.removeChild(l),a.focus(),a==o&&r.showPrimarySelection()},50)}}var n=this,r=this,i=r.cm,o=r.div=e.lineDiv;rl(o,i.options.spellcheck),ls(o,"paste",function(e){Ae(i,e)||el(e,i)||Sl<=11&&setTimeout(gr(i,function(){return n.updateFromDOM()}),20)}),ls(o,"compositionstart",function(e){n.composing={data:e.data,done:!1}}),ls(o,"compositionupdate",function(e){n.composing||(n.composing={data:e.data,done:!1})}),ls(o,"compositionend",function(e){n.composing&&(e.data!=n.composing.data&&n.readFromDOMSoon(),n.composing.done=!0)}),ls(o,"touchstart",function(){return r.forceCompositionEnd()}),ls(o,"input",function(){n.composing||n.readFromDOMSoon()}),ls(o,"copy",t),ls(o,"cut",t)},la.prototype.prepareSelection=function(){var e=Nn(this.cm,!1);return e.focus=this.cm.state.focused,e},la.prototype.showSelection=function(e,t){e&&this.cm.display.view.length&&((e.focus||t)&&this.showPrimarySelection(),this.showMultipleSelections(e))},la.prototype.getSelection=function(){return this.cm.display.wrapper.ownerDocument.getSelection()},la.prototype.showPrimarySelection=function(){var e=this.getSelection(),t=this.cm,n=t.doc.sel.primary(),r=n.from(),i=n.to();if(t.display.viewTo==t.display.viewFrom||r.line>=t.display.viewTo||i.line=t.display.viewFrom&&al(t,r)||{node:s[0].measure.map[2],offset:0},u=i.liner.firstLine()&&(l=F(l.line-1,M(r.doc,l.line-1).length)),s.ch==M(r.doc,s.line).text.length&&s.linei.viewTo-1)return!1;l.line==i.viewFrom||0==(e=Mn(r,l.line))?(t=D(i.view[0].line),n=i.view[0].node):(t=D(i.view[e].line),n=i.view[e-1].node.nextSibling);var a,u,c=Mn(r,s.line);if(c==i.view.length-1?(a=i.viewTo-1,u=i.lineDiv.lastChild):(a=D(i.view[c+1].line)-1,u=i.view[c+1].node.previousSibling),!n)return!1;for(var f=r.doc.splitLines(fl(r,n,u,t,a)),h=A(r.doc,F(t,0),F(a,M(r.doc,a).text.length));f.length>1&&h.length>1;)if(g(f)==g(h))f.pop(),h.pop(),a--;else{if(f[0]!=h[0])break;f.shift(),h.shift(),t++}for(var d=0,p=0,v=f[0],m=h[0],y=Math.min(v.length,m.length);dl.ch&&b.charCodeAt(b.length-p-1)==w.charCodeAt(w.length-p-1);)d--,p++;f[f.length-1]=b.slice(0,b.length-p).replace(/^\u200b+/,""),f[0]=f[0].slice(d).replace(/\u200b+$/,"");var C=F(t,d),S=F(a,h.length?g(h).length-p:0);return f.length>1||f[0]||z(C,S)?(Ei(r.doc,f,C,S,"+input"),!0):void 0},la.prototype.ensurePolled=function(){this.forceCompositionEnd()},la.prototype.reset=function(){this.forceCompositionEnd()},la.prototype.forceCompositionEnd=function(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())},la.prototype.readFromDOMSoon=function(){var e=this;null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout(function(){if(e.readDOMTimeout=null,e.composing){if(!e.composing.done)return;e.composing=null}e.updateFromDOM()},80))},la.prototype.updateFromDOM=function(){var e=this;!this.cm.isReadOnly()&&this.pollContent()||pr(this.cm,function(){return yr(e.cm)})},la.prototype.setUneditable=function(e){e.contentEditable="false"},la.prototype.onKeyPress=function(e){0==e.charCode||this.composing||(e.preventDefault(),this.cm.isReadOnly()||gr(this.cm,Jo)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0))},la.prototype.readOnlyChanged=function(e){this.div.contentEditable=String("nocursor"!=e)},la.prototype.onContextMenu=function(){},la.prototype.resetPosition=function(){},la.prototype.needsContentAttribute=!0;var sa=function(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new jl,this.hasSelection=!1,this.composing=null};sa.prototype.init=function(e){function t(e){if(!Ae(i,e)){if(i.somethingSelected())Qo({lineWise:!1,text:i.getSelections()});else{if(!i.options.lineWiseCopyCut)return;var t=nl(i);Qo({lineWise:!0,text:t.text}),"cut"==e.type?i.setSelections(t.ranges,null,ql):(r.prevInput="",o.value=t.text.join("\n"),Ul(o))}"cut"==e.type&&(i.state.cutIncoming=!0)}}var n=this,r=this,i=this.cm;this.createField(e);var o=this.textarea;e.wrapper.insertBefore(this.wrapper,e.wrapper.firstChild),Dl&&(o.style.width="0px"),ls(o,"input",function(){Cl&&Sl>=9&&n.hasSelection&&(n.hasSelection=null),r.poll()}),ls(o,"paste",function(e){Ae(i,e)||el(e,i)||(i.state.pasteIncoming=!0,r.fastPoll())}),ls(o,"cut",t),ls(o,"copy",t),ls(e.scroller,"paste",function(t){zt(e,t)||Ae(i,t)||(i.state.pasteIncoming=!0,r.focus())}),ls(e.lineSpace,"selectstart",function(t){zt(e,t)||We(t)}),ls(o,"compositionstart",function(){var e=i.getCursor("from");r.composing&&r.composing.range.clear(),r.composing={start:e,range:i.markText(e,i.getCursor("to"),{className:"CodeMirror-composing"})}}),ls(o,"compositionend",function(){r.composing&&(r.poll(),r.composing.range.clear(),r.composing=null)})},sa.prototype.createField=function(e){this.wrapper=il(),this.textarea=this.wrapper.firstChild},sa.prototype.prepareSelection=function(){var e=this.cm,t=e.display,n=e.doc,r=Nn(e);if(e.options.moveInputWithCursor){var i=cn(e,n.sel.primary().head,"div"),o=t.wrapper.getBoundingClientRect(),l=t.lineDiv.getBoundingClientRect();r.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,i.top+l.top-o.top)),r.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,i.left+l.left-o.left))}return r},sa.prototype.showSelection=function(e){var t=this.cm,r=t.display;n(r.cursorDiv,e.cursors),n(r.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},sa.prototype.reset=function(e){if(!this.contextMenuPending&&!this.composing){var t=this.cm;if(t.somethingSelected()){this.prevInput="";var n=t.getSelection();this.textarea.value=n,t.state.focused&&Ul(this.textarea),Cl&&Sl>=9&&(this.hasSelection=n)}else e||(this.prevInput=this.textarea.value="",Cl&&Sl>=9&&(this.hasSelection=null))}},sa.prototype.getField=function(){return this.textarea},sa.prototype.supportsTouch=function(){return!1},sa.prototype.focus=function(){if("nocursor"!=this.cm.options.readOnly&&(!Hl||l()!=this.textarea))try{this.textarea.focus()}catch(e){}},sa.prototype.blur=function(){this.textarea.blur()},sa.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0},sa.prototype.receivedFocus=function(){this.slowPoll()},sa.prototype.slowPoll=function(){var e=this;this.pollingFast||this.polling.set(this.cm.options.pollInterval,function(){e.poll(),e.cm.state.focused&&e.slowPoll()})},sa.prototype.fastPoll=function(){function e(){var r=n.poll();r||t?(n.pollingFast=!1,n.slowPoll()):(t=!0,n.polling.set(60,e))}var t=!1,n=this;n.pollingFast=!0,n.polling.set(20,e)},sa.prototype.poll=function(){var e=this,t=this.cm,n=this.textarea,r=this.prevInput;if(this.contextMenuPending||!t.state.focused||us(n)&&!r&&!this.composing||t.isReadOnly()||t.options.disableInput||t.state.keySeq)return!1;var i=n.value;if(i==r&&!t.somethingSelected())return!1;if(Cl&&Sl>=9&&this.hasSelection===i||Pl&&/[\uf700-\uf7ff]/.test(i))return t.display.input.reset(),!1;if(t.doc.sel==t.display.selForContextMenu){var o=i.charCodeAt(0);if(8203!=o||r||(r="​"),8666==o)return this.reset(),this.cm.execCommand("undo")}for(var l=0,s=Math.min(r.length,i.length);l1e3||i.indexOf("\n")>-1?n.value=e.prevInput="":e.prevInput=i,e.composing&&(e.composing.range.clear(),e.composing.range=t.markText(e.composing.start,t.getCursor("to"),{className:"CodeMirror-composing"}))}),!0},sa.prototype.ensurePolled=function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},sa.prototype.onKeyPress=function(){Cl&&Sl>=9&&(this.hasSelection=null),this.fastPoll()},sa.prototype.onContextMenu=function(e){function t(){if(null!=l.selectionStart){var e=i.somethingSelected(),t="​"+(e?l.value:"");l.value="⇚",l.value=t,r.prevInput=e?"":"​",l.selectionStart=1,l.selectionEnd=t.length,o.selForContextMenu=i.doc.sel}}function n(){if(r.contextMenuPending=!1,r.wrapper.style.cssText=f,l.style.cssText=c,Cl&&Sl<9&&o.scrollbars.setScrollTop(o.scroller.scrollTop=a),null!=l.selectionStart){(!Cl||Cl&&Sl<9)&&t();var e=0,n=function(){o.selForContextMenu==i.doc.sel&&0==l.selectionStart&&l.selectionEnd>0&&"​"==r.prevInput?gr(i,Ni)(i):e++<10?o.detectingSelectAll=setTimeout(n,500):(o.selForContextMenu=null,o.input.reset())};o.detectingSelectAll=setTimeout(n,200)}}var r=this,i=r.cm,o=i.display,l=r.textarea,s=Tn(i,e),a=o.scroller.scrollTop;if(s&&!Ml){var u=i.options.resetSelectionOnContextMenu;u&&-1==i.doc.sel.contains(s)&&gr(i,xi)(i.doc,Gr(s),ql);var c=l.style.cssText,f=r.wrapper.style.cssText;r.wrapper.style.cssText="position: absolute";var h,d=r.wrapper.getBoundingClientRect();if(l.style.cssText="position: absolute; width: 30px; height: 30px;\n top: "+(e.clientY-d.top-5)+"px; left: "+(e.clientX-d.left-5)+"px;\n z-index: 1000; background: "+(Cl?"rgba(255, 255, 255, .05)":"transparent")+";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",Ll&&(h=window.scrollY),o.input.focus(),Ll&&window.scrollTo(null,h),o.input.reset(),i.somethingSelected()||(l.value=r.prevInput=" "),r.contextMenuPending=!0,o.selForContextMenu=i.doc.sel,clearTimeout(o.detectingSelectAll),Cl&&Sl>=9&&t(),Bl){Fe(e);var p=function(){Te(window,"mouseup",p),setTimeout(n,20)};ls(window,"mouseup",p)}else setTimeout(n,50)}},sa.prototype.readOnlyChanged=function(e){e||this.reset(),this.textarea.disabled="nocursor"==e},sa.prototype.setUneditable=function(){},sa.prototype.needsContentAttribute=!1,Ko(qo),ol(qo);var aa="iter insert remove copy getEditor constructor".split(" ");for(var ua in Bs.prototype)Bs.prototype.hasOwnProperty(ua)&&h(aa,ua)<0&&(qo.prototype[ua]=function(e){return function(){return e.apply(this.doc,arguments)}}(Bs.prototype[ua]));return De(Bs),qo.inputStyles={textarea:sa,contenteditable:la},qo.defineMode=function(e){qo.defaults.mode||"null"==e||(qo.defaults.mode=e),Ge.apply(this,arguments)},qo.defineMIME=Ue,qo.defineMode("null",function(){return{token:function(e){return e.skipToEnd()}}}),qo.defineMIME("text/plain","null"),qo.defineExtension=function(e,t){qo.prototype[e]=t},qo.defineDocExtension=function(e,t){Bs.prototype[e]=t},qo.fromTextArea=pl,gl(qo),qo.version="5.40.5",qo}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function t(t,n,r){function i(t){var n=e.wheelEventPixels(t)["horizontal"==o.orientation?"x":"y"],r=o.pos;o.moveTo(o.pos+n),o.pos!=r&&e.e_preventDefault(t)}this.orientation=n,this.scroll=r,this.screen=this.total=this.size=1,this.pos=0,this.node=document.createElement("div"),this.node.className=t+"-"+n,this.inner=this.node.appendChild(document.createElement("div"));var o=this;e.on(this.inner,"mousedown",function(t){function n(){e.off(document,"mousemove",r),e.off(document,"mouseup",n)}function r(e){if(1!=e.which)return n();o.moveTo(s+(e[i]-l)*(o.total/o.size))}if(1==t.which){e.e_preventDefault(t);var i="horizontal"==o.orientation?"pageX":"pageY",l=t[i],s=o.pos;e.on(document,"mousemove",r),e.on(document,"mouseup",n)}}),e.on(this.node,"click",function(t){e.e_preventDefault(t);var n,r=o.inner.getBoundingClientRect();n="horizontal"==o.orientation?t.clientXr.right?1:0:t.clientYr.bottom?1:0,o.moveTo(o.pos+n*o.screen)}),e.on(this.node,"mousewheel",i),e.on(this.node,"DOMMouseScroll",i)}function n(e,n,r){this.addClass=e,this.horiz=new t(e,"horizontal",r),n(this.horiz.node),this.vert=new t(e,"vertical",r),n(this.vert.node),this.width=null}t.prototype.setPos=function(e,t){return e<0&&(e=0),e>this.total-this.screen&&(e=this.total-this.screen),!(!t&&e==this.pos)&&(this.pos=e,this.inner.style["horizontal"==this.orientation?"left":"top"]=e*(this.size/this.total)+"px",!0)},t.prototype.moveTo=function(e){this.setPos(e)&&this.scroll(e,this.orientation)};var r=10;t.prototype.update=function(e,t,n){var i=this.screen!=t||this.total!=e||this.size!=n;i&&(this.screen=t,this.total=e,this.size=n);var o=this.screen*(this.size/this.total);oe.clientWidth+1,i=e.scrollHeight>e.clientHeight+1;return this.vert.node.style.display=i?"block":"none",this.horiz.node.style.display=r?"block":"none",i&&(this.vert.update(e.scrollHeight,e.clientHeight,e.viewHeight-(r?n:0)),this.vert.node.style.bottom=r?n+"px":"0"),r&&(this.horiz.update(e.scrollWidth,e.clientWidth,e.viewWidth-(i?n:0)-e.barLeft),this.horiz.node.style.right=i?n+"px":"0",this.horiz.node.style.left=e.barLeft+"px"),{right:i?n:0,bottom:r?n:0}},n.prototype.setScrollTop=function(e){this.vert.setPos(e)},n.prototype.setScrollLeft=function(e){this.horiz.setPos(e)},n.prototype.clear=function(){var e=this.horiz.node.parentNode;e.removeChild(this.horiz.node),e.removeChild(this.vert.node)},e.scrollbarModel.simple=function(e,t){return new n("CodeMirror-simplescroll",e,t)},e.scrollbarModel.overlay=function(e,t){return new n("CodeMirror-overlayscroll",e,t)}}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function t(e){for(var t=0;t-1?i+t.length:i}var o=t.exec(n?e.slice(n):e);return o?o.index+n+(r?o[0].length:0):-1}var r=Array.prototype.slice.call(arguments,1);return{startState:function(){return{outer:e.startState(t),innerActive:null,inner:null}},copyState:function(n){return{outer:e.copyState(t,n.outer),innerActive:n.innerActive,inner:n.innerActive&&e.copyState(n.innerActive.mode,n.inner)}},token:function(i,o){if(o.innerActive){var l=o.innerActive;u=i.string;if(!l.close&&i.sol())return o.innerActive=o.inner=null,this.token(i,o);h=l.close?n(u,l.close,i.pos,l.parseDelimiters):-1;if(h==i.pos&&!l.parseDelimiters)return i.match(l.close),o.innerActive=o.inner=null,l.delimStyle&&l.delimStyle+" "+l.delimStyle+"-close";h>-1&&(i.string=u.slice(0,h));var s=l.mode.token(i,o.inner);return h>-1&&(i.string=u),h==i.pos&&l.parseDelimiters&&(o.innerActive=o.inner=null),l.innerStyle&&(s=s?s+" "+l.innerStyle:l.innerStyle),s}for(var a=1/0,u=i.string,c=0;c2&&c.token&&"string"!=typeof c.token){r.pending=[];for(var d=2;d-1)return e.Pass;var l=r.indent.length-1,s=t[r.state];e:for(;;){for(var u=0;u{function e(e){if(e.target.src)throw new URIError("The script "+e.target.src+" didn't load correctly.");if(e.target.href)throw new URIError("The style "+e.target.href+" didn't load correctly.")}function t(e){e.target.src&&console.info("The script "+e.target.src+" loaded."),e.target.href&&console.info("The style "+e.target.href+" loaded.")}function r(r){let o=document.createElement("script");o.onerror=e,o.onload=t,r.differ&&(o.defer=!0),r.async&&(o.async=!0),o.type="text/javascript",o.src=r.dir+r.js,document.body.appendChild(o)}function o(r){let o=document.createElement("link");o.onerror=e,o.onload=t,o.rel="stylesheet",document.head.appendChild(o),o.href=r.dir+r.css}void 0===window.wpcm&&(window.wpcm={}),void 0===window.wpcm.codeEditor&&(window.wpcm.codeEditor={}),assets=wpcm.assets,document.addEventListener("DOMContentLoaded",(function(e){console.log("doc ready"),(document.querySelectorAll(".code-block > pre.CodeMirror").length>0||"admin"==wpcm.view)&&function(e){for(let t=0;t pre.CodeMirror");e.addNotice();for(let o=0;o{s.setOption("styleActiveLine",!1)})),s.on("focus",(e=>{s.setOption("styleActiveLine",i.styleActiveLine)}))),t.autoLoadMode(s,i.mode),!0===i.showPanel&&e.panelOptions.showPanel&&(s.getWrapperElement().querySelector(".CodeMirror-simplescroll-vertical"),e.addPanel(s,i)),e.editors.push(s);let r=new CustomEvent("wpcm_editor_loaded",{detail:s});document.dispatchEvent(r)},e.addNotice=function(){const e=document.createElement("div");e.className="CodeMirror-notice",document.body.appendChild(e)},e.showNotice=function(e,t){const o=document.querySelector(".CodeMirror-notice");o.innerHTML=e,o.setAttribute("style","bottom: 15px"),setTimeout((()=>{o.removeAttribute("style")}),3e3)},e.addPanel=function(t,o){const n=document.createElement("div"),i=document.createElement("div"),d=document.createElement("div"),s=document.createElement("span"),r=t.getWrapperElement();if(n.className="CodeMirror-panel",i.className="info-panel",e.editorOptions.maxHeight&&i.classList.add("max-height"),d.className="control-panel","no"!==o.languageLabel&&(s.textContent=o?.fileName?o.fileName:o.language,s.className="language "+o.modeName.toLowerCase()),i.appendChild(s),window.wpcm.panelOptions.runButton&&e.executableModes.includes(o.mode)){let t=document.createElement("span"),o=document.createElement("b");t.classList="tool",t.setAttribute("data-tip","Execute Code"),o.className="run-code execute-code",t.onclick=e.executeCode,t.appendChild(o),d.appendChild(t)}if(window.wpcm.panelOptions.fullScreenButton){const t=document.createElement("span"),o=document.createElement("b");t.classList="tool",t.setAttribute("data-tip","Full Screen"),o.className="fullscreen maximize",o.onclick=e.setFullScreen,t.appendChild(o),d.appendChild(t)}if(window.wpcm.panelOptions.copyButton&&!o.disableCopy){const t=document.createElement("span"),o=document.createElement("b");t.classList="tool",t.setAttribute("data-tip","Copy Code"),o.className="copy",o.onclick=e.copyToClipboard,t.appendChild(o),d.appendChild(t)}i.appendChild(d),n.appendChild(i),r.insertBefore(n,r.firstChild)},e.setFullScreen=function(){const t=this,o=t.closest(".code-block").id,n=e.editors[o],i=document.getElementById("wpadminbar"),d=t.closest(".CodeMirror");t.classList.contains("maximize")?(t.classList.remove("maximize"),t.classList.add("restore"),d.classList.add("CodeMirror-fullscreen"),void 0!==i&&null!=i&&t.closest(".CodeMirror").style.setProperty("top",`${i.clientHeight}px`),e.editorOptions.maxHeight&&(d.style.removeProperty("height"),d.style.setProperty("padding-bottom","2rem")),document.documentElement.style.setProperty("overflow","hidden")):(t.classList.remove("restore"),t.classList.add("maximize"),d.classList.remove("CodeMirror-fullscreen"),d.style.removeProperty("top"),document.documentElement.style.removeProperty("overflow"),e.editorOptions.maxHeight?d.style.setProperty("height",e.editorOptions.maxHeight):d.style.removeProperty("padding-bottom")),n.refresh()},e.copyToClipboard=function(){const t=this.closest(".code-block").id,o=e.editors[t].getValue();let n;if(window.clipboardData)window.clipboardData.setData("Text",o);else{const e=document.createElement("textarea");e.className="CodeMirror-ClipBoard",document.body.appendChild(e),e.appendChild(document.createTextNode(o)),e.select();try{n=document.execCommand("copy")?"Copied to clipboard":"Can not copied"}catch(e){n="Oops, unable to copy"}e.remove()}e.showNotice(n,"")}}(window.wpcm,window.CodeMirror),!1===window.wpcm.executed&&(window.wpcm.executed=!0,wpcm.frontEndInitialization()),window.addEventListener("load",(function(){console.log("window ready"),setTimeout((()=>{for(let e=0;e768){$('header nav .menu-item-has-children').hover(function(){$(this).find('ul').fadeIn('fast');},function(){$(this).find('ul').fadeOut('fast');});}} $('.search-field').attr('placeholder','');});}(jQuery));