You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/07/27 15:11:49 UTC

[28/49] allura git commit: [#7897] ticket:820 Change lepture's editor to SimpleMDE and add Font Awesome

http://git-wip-us.apache.org/repos/asf/allura/blob/cb55aa89/Allura/allura/lib/widgets/resources/js/simplemde.min.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/simplemde.min.js b/Allura/allura/lib/widgets/resources/js/simplemde.min.js
new file mode 100644
index 0000000..1cef395
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/simplemde.min.js
@@ -0,0 +1,13 @@
+/*!
+ * SimpleMDE v1.2.1 (https://github.com/NextStepWebs/simplemde-markdown-editor)
+ * Copyright Next Step Webs, Inc.
+ * Licensed under the MIT license
+ */
+
+function fixShortcut(e){return e=isMac?e.replace("Ctrl","Cmd"):e.replace("Cmd","Ctrl")}function createIcon(e,t){t=t||{};var n=document.createElement("a"),r=t.shortcut||shortcuts[e];return r&&(r=fixShortcut(r),n.title=r,n.title=n.title.replace("Cmd","⌘"),isMac&&(n.title=n.title.replace("Alt","⌥"))),n.className=t.className||"icon-"+e,n}function createSep(){return el=document.createElement("i"),el.className="separator",el.innerHTML="|",el}function getState(e,t){t=t||e.getCursor("start");var n=e.getTokenAt(t);if(!n.type)return{};for(var r,i,o=n.type.split(" "),l={},s=0;s<o.length;s++)r=o[s],"strong"===r?l.bold=!0:"variable-2"===r?(i=e.getLine(t.line),/^\s*\d+\.\s/.test(i)?l["ordered-list"]=!0:l["unordered-list"]=!0):"atom"===r?l.quote=!0:"em"===r?l.italic=!0:"quote"===r&&(l.quote=!0);return l}function toggleFullScreen(e){var t=e.codemirror.getWrapperElement(),n=document,r=n.fullScreen||n.mozFullScreen||n.webkitFullScreen,i=function(){t.requestFullScreen?t.requestFullScreen():t.mozRe
 questFullScreen?t.mozRequestFullScreen():t.webkitRequestFullScreen&&t.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)},o=function(){n.cancelFullScreen?n.cancelFullScreen():n.mozCancelFullScreen?n.mozCancelFullScreen():n.webkitCancelFullScreen&&n.webkitCancelFullScreen()};r?o&&o():i()}function toggleBold(e){_toggleBlock(e,"bold","**")}function toggleItalic(e){_toggleBlock(e,"italic","*")}function toggleCodeBlock(e){_toggleBlock(e,"code","```\r\n","\r\n```")}function toggleBlockquote(e){var t=e.codemirror;_toggleLine(t,"quote")}function toggleUnOrderedList(e){var t=e.codemirror;_toggleLine(t,"unordered-list")}function toggleOrderedList(e){var t=e.codemirror;_toggleLine(t,"ordered-list")}function drawLink(e){var t=e.codemirror,n=getState(t);_replaceSelection(t,n.link,"[","](http://)")}function drawImage(e){var t=e.codemirror,n=getState(t);_replaceSelection(t,n.image,"![](http://",")")}function undo(e){var t=e.codemirror;t.undo(),t.focus()}function redo(e){var t=e.codemirror;t.red
 o(),t.focus()}function togglePreview(e){var t=document.getElementsByClassName("editor-toolbar")[0],n=e.toolbar.preview,r=e.constructor.markdown,i=e.codemirror,o=i.getWrapperElement(),l=o.lastChild;/editor-preview/.test(l.className)||(l=document.createElement("div"),l.className="editor-preview",o.appendChild(l)),/editor-preview-active/.test(l.className)?(l.className=l.className.replace(/\s*editor-preview-active\s*/g,""),n.className=n.className.replace(/\s*active\s*/g,""),t.className=t.className.replace(/\s*disabled-for-preview\s*/g,"")):(setTimeout(function(){l.className+=" editor-preview-active"},1),n.className+=" active",t.className+=" disabled-for-preview");var s=i.getValue();l.innerHTML=r(s)}function _replaceSelection(e,t,n,r){if(!/editor-preview-active/.test(e.getWrapperElement().lastChild.className)){var i,o=e.getCursor("start"),l=e.getCursor("end");t?(i=e.getLine(o.line),n=i.slice(0,o.ch),r=i.slice(o.ch),e.replaceRange(n+r,{line:o.line,ch:0})):(i=e.getSelection(),e.replaceSele
 ction(n+i+r),o.ch+=n.length,l.ch+=n.length),e.setSelection(o,l),e.focus()}}function _toggleLine(e,t){if(!/editor-preview-active/.test(e.getWrapperElement().lastChild.className)){for(var n=getState(e),r=e.getCursor("start"),i=e.getCursor("end"),o={quote:/^(\s*)\>\s+/,"unordered-list":/^(\s*)(\*|\-|\+)\s+/,"ordered-list":/^(\s*)\d+\.\s+/},l={quote:"> ","unordered-list":"* ","ordered-list":"1. "},s=r.line;s<=i.line;s++)!function(r){var i=e.getLine(r);i=n[t]?i.replace(o[t],"$1"):l[t]+i,e.replaceRange(i,{line:r,ch:0},{line:r,ch:99999999999999})}(s);e.focus()}}function _toggleBlock(e,t,n,r){if(!/editor-preview-active/.test(e.codemirror.getWrapperElement().lastChild.className)){r="undefined"==typeof r?n:r;var i,o=e.codemirror,l=getState(o),s=n,a=r,u=o.getCursor("start"),c=o.getCursor("end");l[t]?(i=o.getLine(u.line),s=i.slice(0,u.ch),a=i.slice(u.ch),"bold"==t?(s=s.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/,""),a=a.replace(/(\*\*|__)/,"")):"italic"==t&&(s=s.replace(/(\*|_)(?![\s\S]*(\*|_))/,""
 ),a=a.replace(/(\*|_)/,"")),o.replaceRange(s+a,{line:u.line,ch:0},{line:u.line,ch:99999999999999}),"bold"==t?(u.ch-=2,c.ch-=2):"italic"==t&&(u.ch-=1,c.ch-=1)):(i=o.getSelection(),"bold"==t?(i=i.split("**").join(""),i=i.split("__").join("")):"italic"==t&&(i=i.split("*").join(""),i=i.split("_").join("")),o.replaceSelection(s+i+a),u.ch+=n.length,c.ch=u.ch+i.length),o.setSelection(u,c),o.focus()}}function wordCount(e){var t=/[a-zA-Z0-9_\u0392-\u03c9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g,n=e.match(t),r=0;if(null===n)return r;for(var i=0;i<n.length;i++)r+=n[i].charCodeAt(0)>=19968?n[i].length:1;return r}function SimpleMDE(e){e=e||{},e.element&&(this.element=e.element),e.toolbar=e.toolbar===!1?!1:e.toolbar||SimpleMDE.toolbar,e.hasOwnProperty("status")||(e.status=["autosave","lines","words","cursor"]),this.options=e,this.render()}!function(e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else{if("function"==typeof define&&define.a
 md)return define([],e);this.CodeMirror=e()}}(function(){"use strict";function e(n,r){if(!(this instanceof e))return new e(n,r);this.options=r=r?Io(r):{},Io(Kl,r,!1),d(r);var i=r.value;"string"==typeof i&&(i=new ys(i,r.mode)),this.doc=i;var o=new e.inputStyles[r.inputStyle](this),l=this.display=new t(n,i,o);l.wrapper.CodeMirror=this,u(this),s(this),r.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),r.autofocus&&!Sl&&l.input.focus(),v(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,draggingText:!1,highlight:new To,keySeq:null,specialChars:null};var a=this;pl&&11>gl&&setTimeout(function(){a.display.input.reset(!0)},20),qn(this),Vo(),xn(this),this.curOp.forceUpdate=!0,Vi(this,i),r.autofocus&&!Sl||a.hasFocus()?setTimeout(Fo(pr,this),20):gr(this);for(var c in Xl)Xl.hasOwnProperty(c)&&Xl[c](this,r[c],Yl);C(this),r.finishInit&&r.finishInit(this);for(var h=0;h<es.length;++h)es[h
 ](this);Cn(this),ml&&r.lineWrapping&&"optimizelegibility"==getComputedStyle(l.lineDiv).textRendering&&(l.lineDiv.style.textRendering="auto")}function t(e,t,n){var r=this;this.input=n,r.scrollbarFiller=_o("div",null,"CodeMirror-scrollbar-filler"),r.scrollbarFiller.setAttribute("cm-not-content","true"),r.gutterFiller=_o("div",null,"CodeMirror-gutter-filler"),r.gutterFiller.setAttribute("cm-not-content","true"),r.lineDiv=_o("div",null,"CodeMirror-code"),r.selectionDiv=_o("div",null,null,"position: relative; z-index: 1"),r.cursorDiv=_o("div",null,"CodeMirror-cursors"),r.measure=_o("div",null,"CodeMirror-measure"),r.lineMeasure=_o("div",null,"CodeMirror-measure"),r.lineSpace=_o("div",[r.measure,r.lineMeasure,r.selectionDiv,r.cursorDiv,r.lineDiv],null,"position: relative; outline: none"),r.mover=_o("div",[_o("div",[r.lineSpace],"CodeMirror-lines")],null,"position: relative"),r.sizer=_o("div",[r.mover],"CodeMirror-sizer"),r.sizerWidth=null,r.heightForcer=_o("div",null,null,"position: absol
 ute; height: "+Ns+"px; width: 1px;"),r.gutters=_o("div",null,"CodeMirror-gutters"),r.lineGutter=null,r.scroller=_o("div",[r.sizer,r.heightForcer,r.gutters],"CodeMirror-scroll"),r.scroller.setAttribute("tabIndex","-1"),r.wrapper=_o("div",[r.scrollbarFiller,r.gutterFiller,r.scroller],"CodeMirror"),pl&&8>gl&&(r.gutters.style.zIndex=-1,r.scroller.style.paddingRight=0),ml||hl&&Sl||(r.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(r.wrapper):e(r.wrapper)),r.viewFrom=r.viewTo=t.first,r.reportedViewFrom=r.reportedViewTo=t.first,r.view=[],r.renderedView=null,r.externalMeasured=null,r.viewOffset=0,r.lastWrapHeight=r.lastWrapWidth=0,r.updateLineNumbers=null,r.nativeBarWidth=r.barHeight=r.barWidth=0,r.scrollbarsClipped=!1,r.lineNumWidth=r.lineNumInnerWidth=r.lineNumChars=null,r.alignWidgets=!1,r.cachedCharWidth=r.cachedTextHeight=r.cachedPaddingH=null,r.maxLine=null,r.maxLineLength=0,r.maxLineChanged=!1,r.wheelDX=r.wheelDY=r.wheelStartX=r.wheelStartY=null,r.shift=!1,r.selForContextMenu=
 null,r.activeTouch=null,n.init(r)}function n(t){t.doc.mode=e.getMode(t.options,t.doc.modeOption),r(t)}function r(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,Pt(e,100),e.state.modeGen++,e.curOp&&In(e)}function i(e){e.options.lineWrapping?(Gs(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(Us(e.display.wrapper,"CodeMirror-wrap"),f(e)),l(e),In(e),sn(e),setTimeout(function(){y(e)},100)}function o(e){var t=yn(e.display),n=e.options.lineWrapping,r=n&&Math.max(5,e.display.scroller.clientWidth/bn(e.display)-3);return function(i){if(bi(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;l<i.widgets.length;l++)i.widgets[l].height&&(o+=i.widgets[l].height);return n?o+(Math.ceil(i.text.length/r)||1)*t:o+t}}function l(e){var t=e.doc,n=o(e);t.iter(function(e){var t=n(e);t!=e.height&&Zi(e,t)})}function s(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s
 -\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),sn(e)}function a(e){u(e),In(e),setTimeout(function(){w(e)},20)}function u(e){var t=e.display.gutters,n=e.options.gutters;Ro(t);for(var r=0;r<n.length;++r){var i=n[r],o=t.appendChild(_o("div",null,"CodeMirror-gutter "+i));"CodeMirror-linenumbers"==i&&(e.display.lineGutter=o,o.style.width=(e.display.lineNumWidth||1)+"px")}t.style.display=r?"":"none",c(e)}function c(e){var t=e.display.gutters.offsetWidth;e.display.sizer.style.marginLeft=t+"px"}function h(e){if(0==e.height)return 0;for(var t,n=e.text.length,r=e;t=fi(r);){var i=t.find(0,!0);r=i.from.line,n+=i.from.ch-i.to.ch}for(r=e;t=di(r);){var i=t.find(0,!0);n-=r.text.length-i.from.ch,r=i.to.line,n+=r.text.length-i.to.ch}return n}function f(e){var t=e.display,n=e.doc;t.maxLine=Ki(n,n.first),t.maxLineLength=h(t.maxLine),t.maxLineChanged=!0,n.iter(function(e){var n=h(e);n>t.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)})}function d(e){var t=Do(e.gutters,"CodeMirror-linenumbers")
 ;-1==t&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function p(e){var t=e.display,n=t.gutters.offsetWidth,r=Math.round(e.doc.height+Ut(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+$t(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}function g(e,t,n){this.cm=n;var r=this.vert=_o("div",[_o("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=_o("div",[_o("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(r),e(i),Ss(r,"scroll",function(){r.clientHeight&&t(r.scrollTop,"vertical")}),Ss(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedOverlay=!1,pl&&8>gl&&(this.horiz.style.minHeight=this.vert.style
 .minWidth="18px")}function m(){}function v(t){t.display.scrollbars&&(t.display.scrollbars.clear(),t.display.scrollbars.addClass&&Us(t.display.wrapper,t.display.scrollbars.addClass)),t.display.scrollbars=new e.scrollbarModel[t.options.scrollbarStyle](function(e){t.display.wrapper.insertBefore(e,t.display.scrollbarFiller),Ss(e,"mousedown",function(){t.state.focused&&setTimeout(function(){t.display.input.focus()},0)}),e.setAttribute("cm-not-content","true")},function(e,n){"horizontal"==n?nr(t,e):tr(t,e)},t),t.display.scrollbars.addClass&&Gs(t.display.wrapper,t.display.scrollbars.addClass)}function y(e,t){t||(t=p(e));var n=e.display.barWidth,r=e.display.barHeight;b(e,t);for(var i=0;4>i&&n!=e.display.barWidth||r!=e.display.barHeight;i++)n!=e.display.barWidth&&e.options.lineWrapping&&D(e),b(e,p(e)),n=e.display.barWidth,r=e.display.barHeight}function b(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",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 x(e,t,n){var r=n&&null!=n.top?Math.max(0,n.top):e.scroller.scrollTop;r=Math.floor(r-qt(e));var i=n&&null!=n.bottom?n.bottom:r+e.wrapper.clientHeight,o=Ji(t,r),l=Ji(t,i);if(n&&n.ensure){var s=n.ensure.from.line,a=n.ensure.to.line;o>s?(o=s,l=Ji(t,eo(Ki(t,s))+e.wrapper.clientHeight)):Math.min(a,t.lastLine())>=l&&(o=Ji(t,eo(Ki(t,a))-e.wrapper.clientHeight),l=a)}return{from:o,to:Math.max(l,o+1)}}function w(e){var t=e.display,n=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var r=S(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutte
 rs.offsetWidth,o=r+"px",l=0;l<n.length;l++)if(!n[l].hidden){e.options.fixedGutter&&n[l].gutter&&(n[l].gutter.style.left=o);var s=n[l].alignable;if(s)for(var a=0;a<s.length;a++)s[a].style.left=o}e.options.fixedGutter&&(t.gutters.style.left=r+i+"px")}}function C(e){if(!e.options.lineNumbers)return!1;var t=e.doc,n=k(e.options,t.first+t.size-1),r=e.display;if(n.length!=r.lineNumChars){var i=r.measure.appendChild(_o("div",[_o("div",n)],"CodeMirror-linenumber CodeMirror-gutter-elt")),o=i.firstChild.offsetWidth,l=i.offsetWidth-o;return r.lineGutter.style.width="",r.lineNumInnerWidth=Math.max(o,r.lineGutter.offsetWidth-l)+1,r.lineNumWidth=r.lineNumInnerWidth+l,r.lineNumChars=r.lineNumInnerWidth?n.length:-1,r.lineGutter.style.width=r.lineNumWidth+"px",c(e),!0}return!1}function k(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function S(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function L(e,t,n){var r=e.display;this.viewport=t,this.
 visible=x(r,e.doc,t),this.editorIsHidden=!r.wrapper.offsetWidth,this.wrapperHeight=r.wrapper.clientHeight,this.wrapperWidth=r.wrapper.clientWidth,this.oldDisplayWidth=jt(e),this.force=n,this.dims=H(e),this.events=[]}function M(e){var t=e.display;!t.scrollbarsClipped&&t.scroller.offsetWidth&&(t.nativeBarWidth=t.scroller.offsetWidth-t.scroller.clientWidth,t.heightForcer.style.height=$t(e)+"px",t.sizer.style.marginBottom=-t.nativeBarWidth+"px",t.sizer.style.borderRightWidth=$t(e)+"px",t.scrollbarsClipped=!0)}function T(e,t){var n=e.display,r=e.doc;if(t.editorIsHidden)return zn(e),!1;if(!t.force&&t.visible.from>=n.viewFrom&&t.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==Rn(e))return!1;C(e)&&(zn(e),t.dims=H(e));var i=r.first+r.size,o=Math.max(t.visible.from-e.options.viewportMargin,r.first),l=Math.min(i,t.visible.to+e.options.viewportMargin);n.viewFrom<o&&o-n.viewFrom<20&&(o=Math.max(r.first,n.viewFrom)),n.viewTo>l&&n.viewTo
 -l<20&&(l=Math.min(i,n.viewTo)),Dl&&(o=vi(e.doc,o),l=yi(e.doc,l));var s=o!=n.viewFrom||l!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth;_n(e,o,l),n.viewOffset=eo(Ki(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";var a=Rn(e);if(!s&&0==a&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;var u=Uo();return a>4&&(n.lineDiv.style.display="none"),E(e,n.updateLineNumbers,t.dims),a>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,u&&Uo()!=u&&u.offsetHeight&&u.focus(),Ro(n.cursorDiv),Ro(n.selectionDiv),n.gutters.style.height=0,s&&(n.lastWrapHeight=t.wrapperHeight,n.lastWrapWidth=t.wrapperWidth,Pt(e,400)),n.updateLineNumbers=null,!0}function N(e,t){for(var n=t.viewport,r=!0;(r&&e.options.lineWrapping&&t.oldDisplayWidth!=jt(e)||(n&&null!=n.top&&(n={top:Math.min(e.doc.height+Ut(e.display)-Vt(e),n.top)}),t.visible=x(e.display,e.doc,n),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.displ
 ay.viewTo)))&&T(e,t);r=!1){D(e);var i=p(e);Ht(e),O(e,i),y(e,i)}t.signal(e,"update",e),(e.display.viewFrom!=e.display.reportedViewFrom||e.display.viewTo!=e.display.reportedViewTo)&&(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function A(e,t){var n=new L(e,t);if(T(e,n)){D(e),N(e,n);var r=p(e);Ht(e),O(e,r),y(e,r),n.finish()}}function O(e,t){e.display.sizer.style.minHeight=t.docHeight+"px";var n=t.docHeight+e.display.barHeight;e.display.heightForcer.style.top=n+"px",e.display.gutters.style.height=Math.max(n+$t(e),t.clientHeight)+"px"}function D(e){for(var t=e.display,n=t.lineDiv.offsetTop,r=0;r<t.view.length;r++){var i,o=t.view[r];if(!o.hidden){if(pl&&8>gl){var l=o.node.offsetTop+o.node.offsetHeight;i=l-n,n=l}else{var s=o.node.getBoundingClientRect();i=s.bottom-s.top}var a=o.line.height-i;if(2>i&&(i=yn(t)),(a>.001||-.001>a)&&(Zi(o.line,i),W(o.line),o.rest))for(var u=0;u<o.rest
 .length;u++)W(o.rest[u])}}}function W(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t)e.widgets[t].height=e.widgets[t].node.offsetHeight}function H(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:S(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:r,wrapperWidth:t.wrapper.clientWidth}}function E(e,t,n){function r(t){var n=t.nextSibling;return ml&&Ll&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}for(var i=e.display,o=e.options.lineNumbers,l=i.lineDiv,s=l.firstChild,a=i.view,u=i.viewFrom,c=0;c<a.length;c++){var h=a[c];if(h.hidden);else if(h.node&&h.node.parentNode==l){for(;s!=h.node;)s=r(s);var f=o&&null!=t&&u>=t&&h.lineNumber;h.changes&&(Do(h.changes,"gutter")>-1&&(f=!1),I(e,h,u,n)),f&&(Ro(h.lineNumber),h.lineNumber.appendChild(document.createTextNode(k(e.options,u
 )))),s=h.node.nextSibling}else{var d=U(e,h,u,n);l.insertBefore(d,s)}u+=h.size}for(;s;)s=r(s)}function I(e,t,n,r){for(var i=0;i<t.changes.length;i++){var o=t.changes[i];"text"==o?B(e,t):"gutter"==o?R(e,t,n,r):"class"==o?_(t):"widget"==o&&q(e,t,r)}t.changes=null}function F(e){return e.node==e.text&&(e.node=_o("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),pl&&8>gl&&(e.node.style.zIndex=2)),e.node}function z(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var n=F(e);e.background=n.insertBefore(_o("div",null,t),n.firstChild)}}function P(e,t){var n=e.display.externalMeasured;return n&&n.line==t.line?(e.display.externalMeasured=null,t.measure=n.measure,n.built):Ii(e,t)}function B(e,t){var n=t.text.className,r=P(e,t);t.text==t.no
 de&&(t.node=r.pre),t.text.parentNode.replaceChild(r.pre,t.text),t.text=r.pre,r.bgClass!=t.bgClass||r.textClass!=t.textClass?(t.bgClass=r.bgClass,t.textClass=r.textClass,_(t)):n&&(t.text.className=n)}function _(e){z(e),e.line.wrapClass?F(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function R(e,t,n,r){t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null);var i=t.line.gutterMarkers;if(e.options.lineNumbers||i){var o=F(t),l=t.gutter=_o("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?r.fixedPos:-r.gutterTotalWidth)+"px; width: "+r.gutterTotalWidth+"px");if(e.display.input.setUneditable(l),o.insertBefore(l,t.text),t.line.gutterClass&&(l.className+=" "+t.line.gutterClass),!e.options.lineNumbers||i&&i["CodeMirror-linenumbers"]||(t.lineNumber=l.appendChild(_o("div",k(e.options,n),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+r.gutterLeft["C
 odeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),i)for(var s=0;s<e.options.gutters.length;++s){var a=e.options.gutters[s],u=i.hasOwnProperty(a)&&i[a];u&&l.appendChild(_o("div",[u],"CodeMirror-gutter-elt","left: "+r.gutterLeft[a]+"px; width: "+r.gutterWidth[a]+"px"))}}}function q(e,t,n){t.alignable&&(t.alignable=null);for(var r,i=t.node.firstChild;i;i=r){var r=i.nextSibling;"CodeMirror-linewidget"==i.className&&t.node.removeChild(i)}G(e,t,n)}function U(e,t,n,r){var i=P(e,t);return t.text=t.node=i.pre,i.bgClass&&(t.bgClass=i.bgClass),i.textClass&&(t.textClass=i.textClass),_(t),R(e,t,n,r),G(e,t,r),t.node}function G(e,t,n){if($(e,t.line,t,n,!0),t.rest)for(var r=0;r<t.rest.length;r++)$(e,t.rest[r],t,n,!1)}function $(e,t,n,r,i){if(t.widgets)for(var o=F(n),l=0,s=t.widgets;l<s.length;++l){var a=s[l],u=_o("div",[a.node],"CodeMirror-linewidget");a.handleMouseEvents||u.setAttribute("cm-ignore-events","true"),j(a,u,n,r),e.display.input.setUneditable(u),i&&a.above?o.inse
 rtBefore(u,n.gutter||n.text):o.appendChild(u),wo(a,"redraw")}}function j(e,t,n,r){if(e.noHScroll){(n.alignable||(n.alignable=[])).push(t);var i=r.wrapperWidth;t.style.left=r.fixedPos+"px",e.coverGutter||(i-=r.gutterTotalWidth,t.style.paddingLeft=r.gutterTotalWidth+"px"),t.style.width=i+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-r.gutterTotalWidth+"px"))}function V(e){return Wl(e.line,e.ch)}function K(e,t){return Hl(e,t)<0?t:e}function X(e,t){return Hl(e,t)<0?e:t}function Y(e){e.state.focused||(e.display.input.focus(),pr(e))}function Z(e){return e.options.readOnly||e.doc.cantEdit}function Q(e,t,n,r,i){var o=e.doc;e.display.shift=!1,r||(r=o.sel);var l=e.state.pasteIncoming||"paste"==i,s=Vs(t),a=null;l&&r.ranges.length>1&&(El&&El.join("\n")==t?a=r.ranges.length%El.length==0&&Wo(El,Vs):s.length==r.ranges.length&&(a=Wo(s,function(e){return[e]})));for(var u=r.ranges.length-1;u>=0;u--){var c=r.ranges[u],h=c.from(),f=c.to();c.empty()&
 &(n&&n>0?h=Wl(h.line,h.ch-n):e.state.overwrite&&!l&&(f=Wl(f.line,Math.min(Ki(o,f.line).text.length,f.ch+Oo(s).length))));var d=e.curOp.updateInput,p={from:h,to:f,text:a?a[u%a.length]:s,origin:i||(l?"paste":e.state.cutIncoming?"cut":"+input")};kr(e.doc,p),wo(e,"inputRead",e,p)}t&&!l&&et(e,t),Ir(e),e.curOp.updateInput=d,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function J(e,t){var n=e.clipboardData&&e.clipboardData.getData("text/plain");return n?(e.preventDefault(),An(t,function(){Q(t,n,0,null,"paste")}),!0):void 0}function et(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<o.electricChars.length;s++)if(t.indexOf(o.electricChars.charAt(s))>-1){l=zr(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Ki(e.doc,i.head.line).text.slice(0,i.head.ch))
 &&(l=zr(e,i.head.line,"smart"));l&&wo(e,"electricInput",e,i.head.line)}}}function tt(e){for(var t=[],n=[],r=0;r<e.doc.sel.ranges.length;r++){var i=e.doc.sel.ranges[r].head.line,o={anchor:Wl(i,0),head:Wl(i+1,0)};n.push(o),t.push(e.getRange(o.anchor,o.head))}return{text:t,ranges:n}}function nt(e){e.setAttribute("autocorrect","off"),e.setAttribute("autocapitalize","off"),e.setAttribute("spellcheck","false")}function rt(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new To,this.inaccurateSelection=!1,this.hasSelection=!1,this.composing=null}function it(){var e=_o("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none"),t=_o("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");return ml?e.style.width="1000px":e.setAttribute("wrap","off"),kl&&(e.style.border="1px solid black"),nt(e),t}function ot(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling
 =new To,this.gracePeriod=!1}function lt(e,t){var n=Qt(e,t.line);if(!n||n.hidden)return null;var r=Ki(e.doc,t.line),i=Xt(n,r,t.line),o=to(r),l="left";if(o){var s=sl(o,t.ch);l=s%2?"right":"left"}var a=tn(i.map,t.ch,l);return a.offset="right"==a.collapse?a.end:a.start,a}function st(e,t){return t&&(e.bad=!0),e}function at(e,t,n){var r;if(t==e.display.lineDiv){if(r=e.display.lineDiv.childNodes[n],!r)return st(e.clipPos(Wl(e.display.viewTo-1)),!0);t=null,n=0}else for(r=t;;r=r.parentNode){if(!r||r==e.display.lineDiv)return null;if(r.parentNode&&r.parentNode==e.display.lineDiv)break}for(var i=0;i<e.display.view.length;i++){var o=e.display.view[i];if(o.node==r)return ut(o,t,n)}}function ut(e,t,n){function r(t,n,r){for(var i=-1;i<(c?c.length:0);i++)for(var o=0>i?u.map:c[i],l=0;l<o.length;l+=3){var s=o[l+2];if(s==t||s==n){var a=Qi(0>i?e.line:e.rest[i]),h=o[l]+r;return(0>r||s!=t)&&(h=o[l+(r?1:0)]),Wl(a,h)}}}var i=e.text.firstChild,o=!1;if(!t||!_s(i,t))return st(Wl(Qi(e.line),0),!0);if(t==i&&(o=
 !0,t=i.childNodes[n],n=0,!t)){var l=e.rest?Oo(e.rest):e.line;return st(Wl(Qi(l),l.text.length),o)}var s=3==t.nodeType?t:null,a=t;for(s||1!=t.childNodes.length||3!=t.firstChild.nodeType||(s=t.firstChild,n&&(n=s.nodeValue.length));a.parentNode!=i;)a=a.parentNode;var u=e.measure,c=u.maps,h=r(s,a,n);if(h)return st(h,o);for(var f=a.nextSibling,d=s?s.nodeValue.length-n:0;f;f=f.nextSibling){if(h=r(f,f.firstChild,0))return st(Wl(h.line,h.ch-d),o);d+=f.textContent.length}for(var p=a.previousSibling,d=n;p;p=p.previousSibling){if(h=r(p,p.firstChild,-1))return st(Wl(h.line,h.ch+d),o);d+=f.textContent.length}}function ct(e,t,n,r,i){function o(e){return function(t){return t.id==e}}function l(t){if(1==t.nodeType){var n=t.getAttribute("cm-text");if(null!=n)return""==n&&(n=t.textContent.replace(/\u200b/g,"")),void(s+=n);var u,c=t.getAttribute("cm-marker");if(c){var h=e.findMarks(Wl(r,0),Wl(i+1,0),o(+c));return void(h.length&&(u=h[0].find())&&(s+=Xi(e.doc,u.from,u.to).join("\n")))}if("false"==t.getAt
 tribute("contenteditable"))return;for(var f=0;f<t.childNodes.length;f++)l(t.childNodes[f]);/^(pre|div|p)$/i.test(t.nodeName)&&(a=!0)}else if(3==t.nodeType){var d=t.nodeValue;if(!d)return;a&&(s+="\n",a=!1),s+=d}}for(var s="",a=!1;l(t),t!=n;)t=t.nextSibling;return s}function ht(e,t){this.ranges=e,this.primIndex=t}function ft(e,t){this.anchor=e,this.head=t}function dt(e,t){var n=e[t];e.sort(function(e,t){return Hl(e.from(),t.from())}),t=Do(e,n);for(var r=1;r<e.length;r++){var i=e[r],o=e[r-1];if(Hl(o.to(),i.from())>=0){var l=X(o.from(),i.from()),s=K(o.to(),i.to()),a=o.empty()?i.from()==i.head:o.from()==o.head;t>=r&&--t,e.splice(--r,2,new ft(a?s:l,a?l:s))}}return new ht(e,t)}function pt(e,t){return new ht([new ft(e,t||e)],0)}function gt(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function mt(e,t){if(t.line<e.first)return Wl(e.first,0);var n=e.first+e.size-1;return t.line>n?Wl(n,Ki(e,n).text.length):vt(t,Ki(e,t.line).text.length)}function vt(e,t){var n=e.ch;return null==n||
 n>t?Wl(e.line,t):0>n?Wl(e.line,0):e}function yt(e,t){return t>=e.first&&t<e.first+e.size}function bt(e,t){for(var n=[],r=0;r<t.length;r++)n[r]=mt(e,t[r]);return n}function xt(e,t,n,r){if(e.cm&&e.cm.display.shift||e.extend){var i=t.anchor;if(r){var o=Hl(n,i)<0;o!=Hl(r,i)<0?(i=n,n=r):o!=Hl(n,r)<0&&(n=r)}return new ft(i,n)}return new ft(r||n,n)}function wt(e,t,n,r){Tt(e,new ht([xt(e,e.sel.primary(),t,n)],0),r)}function Ct(e,t,n){for(var r=[],i=0;i<e.sel.ranges.length;i++)r[i]=xt(e,e.sel.ranges[i],t[i],null);var o=dt(r,e.sel.primIndex);Tt(e,o,n)}function kt(e,t,n,r){var i=e.sel.ranges.slice(0);i[t]=n,Tt(e,dt(i,e.sel.primIndex),r)}function St(e,t,n,r){Tt(e,pt(t,n),r)}function Lt(e,t){var n={ranges:t.ranges,update:function(t){this.ranges=[];for(var n=0;n<t.length;n++)this.ranges[n]=new ft(mt(e,t[n].anchor),mt(e,t[n].head))}};return Ms(e,"beforeSelectionChange",e,n),e.cm&&Ms(e.cm,"beforeSelectionChange",e.cm,n),n.ranges!=t.ranges?dt(n.ranges,n.ranges.length-1):t}function Mt(e,t,n){var r=e.
 history.done,i=Oo(r);i&&i.ranges?(r[r.length-1]=t,Nt(e,t,n)):Tt(e,t,n)}function Tt(e,t,n){Nt(e,t,n),ao(e,e.sel,e.cm?e.cm.curOp.id:0/0,n)}function Nt(e,t,n){(Lo(e,"beforeSelectionChange")||e.cm&&Lo(e.cm,"beforeSelectionChange"))&&(t=Lt(e,t));var r=n&&n.bias||(Hl(t.primary().head,e.sel.primary().head)<0?-1:1);At(e,Dt(e,t,r,!0)),n&&n.scroll===!1||!e.cm||Ir(e.cm)}function At(e,t){t.equals(e.sel)||(e.sel=t,e.cm&&(e.cm.curOp.updateInput=e.cm.curOp.selectionChanged=!0,So(e.cm)),wo(e,"cursorActivity",e))}function Ot(e){At(e,Dt(e,e.sel,null,!1),Os)}function Dt(e,t,n,r){for(var i,o=0;o<t.ranges.length;o++){var l=t.ranges[o],s=Wt(e,l.anchor,n,r),a=Wt(e,l.head,n,r);(i||s!=l.anchor||a!=l.head)&&(i||(i=t.ranges.slice(0,o)),i[o]=new ft(s,a))}return i?dt(i,t.primIndex):t}function Wt(e,t,n,r){var i=!1,o=t,l=n||1;e.cantEdit=!1;e:for(;;){var s=Ki(e,o.line);if(s.markedSpans)for(var a=0;a<s.markedSpans.length;++a){var u=s.markedSpans[a],c=u.marker;if((null==u.from||(c.inclusiveLeft?u.from<=o.ch:u.from<o
 .ch))&&(null==u.to||(c.inclusiveRight?u.to>=o.ch:u.to>o.ch))){if(r&&(Ms(c,"beforeCursorEnter"),c.explicitlyCleared)){if(s.markedSpans){--a;continue}break}if(!c.atomic)continue;var h=c.find(0>l?-1:1);if(0==Hl(h,o)&&(h.ch+=l,h.ch<0?h=h.line>e.first?mt(e,Wl(h.line-1)):null:h.ch>s.text.length&&(h=h.line<e.first+e.size-1?Wl(h.line+1,0):null),!h)){if(i)return r?(e.cantEdit=!0,Wl(e.first,0)):Wt(e,t,n,!0);i=!0,h=t,l=-l}o=h;continue e}}return o}}function Ht(e){e.display.input.showSelection(e.display.input.prepareSelection())}function Et(e,t){for(var n=e.doc,r={},i=r.cursors=document.createDocumentFragment(),o=r.selection=document.createDocumentFragment(),l=0;l<n.sel.ranges.length;l++)if(t!==!1||l!=n.sel.primIndex){var s=n.sel.ranges[l],a=s.empty();(a||e.options.showCursorWhenSelecting)&&It(e,s,i),a||Ft(e,s,o)}return r}function It(e,t,n){var r=dn(e,t.head,"div",null,null,!e.options.singleCursorHeightPerLine),i=n.appendChild(_o("div"," ","CodeMirror-cursor"));if(i.style.left=r.left+"px",i.sty
 le.top=r.top+"px",i.style.height=Math.max(0,r.bottom-r.top)*e.options.cursorHeight+"px",r.other){var o=n.appendChild(_o("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));o.style.display="",o.style.left=r.other.left+"px",o.style.top=r.other.top+"px",o.style.height=.85*(r.other.bottom-r.other.top)+"px"}}function Ft(e,t,n){function r(e,t,n,r){0>t&&(t=0),t=Math.round(t),r=Math.round(r),s.appendChild(_o("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(null==n?c-e:n)+"px; height: "+(r-t)+"px"))}function i(t,n,i){function o(n,r){return fn(e,Wl(t,n),"div",h,r)}var s,a,h=Ki(l,t),f=h.text.length;return Qo(to(h),n||0,null==i?f:i,function(e,t,l){var h,d,p,g=o(e,"left");if(e==t)h=g,d=p=g.left;else{if(h=o(t-1,"right"),"rtl"==l){var m=g;g=h,h=m}d=g.left,p=h.right}null==n&&0==e&&(d=u),h.top-g.top>3&&(r(d,g.top,null,g.bottom),d=u,g.bottom<h.top&&r(d,g.bottom,null,h.top)),null==i&&t==f&&(p=c),(!s||g.top<s.top||g.top==s.top&&g.left<s.left)&&(s=g),(
 !a||h.bottom>a.bottom||h.bottom==a.bottom&&h.right>a.right)&&(a=h),u+1>d&&(d=u),r(d,h.top,p-d,h.bottom)}),{start:s,end:a}}var o=e.display,l=e.doc,s=document.createDocumentFragment(),a=Gt(e.display),u=a.left,c=Math.max(o.sizerWidth,jt(e)-o.sizer.offsetLeft)-a.right,h=t.from(),f=t.to();if(h.line==f.line)i(h.line,h.ch,f.ch);else{var d=Ki(l,h.line),p=Ki(l,f.line),g=gi(d)==gi(p),m=i(h.line,h.ch,g?d.text.length+1:null).end,v=i(f.line,g?0:null,f.ch).start;g&&(m.top<v.top-2?(r(m.right,m.top,null,m.bottom),r(u,v.top,v.left,v.bottom)):r(m.right,m.top,v.left-m.right,m.bottom)),m.bottom<v.top&&r(u,m.bottom,null,v.top)}n.appendChild(s)}function zt(e){if(e.state.focused){var t=e.display;clearInterval(t.blinker);var n=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0?t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(n=!n)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function Pt(e,t){e.doc.mode.startState&&e.
 doc.frontier<e.display.viewTo&&e.state.highlight.set(t,Fo(Bt,e))}function Bt(e){var t=e.doc;if(t.frontier<t.first&&(t.frontier=t.first),!(t.frontier>=e.display.viewTo)){var n=+new Date+e.options.workTime,r=ns(t.mode,Rt(e,t.frontier)),i=[];
+t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(t.frontier>=e.display.viewFrom){var l=o.styles,s=Di(e,o,r,!0);o.styles=s.styles;var a=o.styleClasses,u=s.classes;u?o.styleClasses=u:a&&(o.styleClasses=null);for(var c=!l||l.length!=o.styles.length||a!=u&&(!a||!u||a.bgClass!=u.bgClass||a.textClass!=u.textClass),h=0;!c&&h<l.length;++h)c=l[h]!=o.styles[h];c&&i.push(t.frontier),o.stateAfter=ns(t.mode,r)}else Hi(e,o.text,r),o.stateAfter=t.frontier%5==0?ns(t.mode,r):null;return++t.frontier,+new Date>n?(Pt(e,e.options.workDelay),!0):void 0}),i.length&&An(e,function(){for(var t=0;t<i.length;t++)Fn(e,i[t],"text")})}}function _t(e,t,n){for(var r,i,o=e.doc,l=n?-1:t-(e.doc.mode.innerMode?1e3:100),s=t;s>l;--s){if(s<=o.first)return o.first;var a=Ki(o,s-1);if(a.stateAfter&&(!n||s<=o.frontier))return s;var u=Hs(a.text,null,e.options.tabSize);(null==i||r>u)&&(i=s-1,r=u)}return i}function Rt(e,t,n){var r=e.doc,i=e.display;if(!r.mode.startState)return!0;var o=_t(e,t,n),l=o>
 r.first&&Ki(r,o-1).stateAfter;return l=l?ns(r.mode,l):rs(r.mode),r.iter(o,t,function(n){Hi(e,n.text,l);var s=o==t-1||o%5==0||o>=i.viewFrom&&o<i.viewTo;n.stateAfter=s?ns(r.mode,l):null,++o}),n&&(r.frontier=o),l}function qt(e){return e.lineSpace.offsetTop}function Ut(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function Gt(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=qo(e.measure,_o("pre","x")),n=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,r={left:parseInt(n.paddingLeft),right:parseInt(n.paddingRight)};return isNaN(r.left)||isNaN(r.right)||(e.cachedPaddingH=r),r}function $t(e){return Ns-e.display.nativeBarWidth}function jt(e){return e.display.scroller.clientWidth-$t(e)-e.display.barWidth}function Vt(e){return e.display.scroller.clientHeight-$t(e)-e.display.barHeight}function Kt(e,t,n){var r=e.options.lineWrapping,i=r&&jt(e);if(!t.measure.heights||r&&t.measure.width!=i){var o=t.measure.heights=[];if(r){t.measure.width=i;for(var l=t.text.firstChi
 ld.getClientRects(),s=0;s<l.length-1;s++){var a=l[s],u=l[s+1];Math.abs(a.bottom-u.bottom)>2&&o.push((a.bottom+u.top)/2-n.top)}}o.push(n.bottom-n.top)}}function Xt(e,t,n){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var r=0;r<e.rest.length;r++)if(e.rest[r]==t)return{map:e.measure.maps[r],cache:e.measure.caches[r]};for(var r=0;r<e.rest.length;r++)if(Qi(e.rest[r])>n)return{map:e.measure.maps[r],cache:e.measure.caches[r],before:!0}}function Yt(e,t){t=gi(t);var n=Qi(t),r=e.display.externalMeasured=new Hn(e.doc,t,n);r.lineN=n;var i=r.built=Ii(e,r);return r.text=i.pre,qo(e.display.lineMeasure,i.pre),r}function Zt(e,t,n,r){return en(e,Jt(e,t),n,r)}function Qt(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[Pn(e,t)];var n=e.display.externalMeasured;return n&&t>=n.lineN&&t<n.lineN+n.size?n:void 0}function Jt(e,t){var n=Qi(t),r=Qt(e,n);r&&!r.text?r=null:r&&r.changes&&I(e,r,n,H(e)),r||(r=Yt(e,t));var i=Xt(r,t,n);return{line:t,view:r,rect:null,map:i.ma
 p,cache:i.cache,before:i.before,hasHeights:!1}}function en(e,t,n,r,i){t.before&&(n=-1);var o,l=n+(r||"");return t.cache.hasOwnProperty(l)?o=t.cache[l]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(Kt(e,t.view,t.rect),t.hasHeights=!0),o=nn(e,t,n,r),o.bogus||(t.cache[l]=o)),{left:o.left,right:o.right,top:i?o.rtop:o.top,bottom:i?o.rbottom:o.bottom}}function tn(e,t,n){for(var r,i,o,l,s=0;s<e.length;s+=3){var a=e[s],u=e[s+1];if(a>t?(i=0,o=1,l="left"):u>t?(i=t-a,o=i+1):(s==e.length-3||t==u&&e[s+3]>t)&&(o=u-a,i=o-1,t>=u&&(l="right")),null!=i){if(r=e[s+2],a==u&&n==(r.insertLeft?"left":"right")&&(l=n),"left"==n&&0==i)for(;s&&e[s-2]==e[s-3]&&e[s-1].insertLeft;)r=e[(s-=3)+2],l="left";if("right"==n&&i==u-a)for(;s<e.length-3&&e[s+3]==e[s+4]&&!e[s+5].insertLeft;)r=e[(s+=3)+2],l="right";break}}return{node:r,start:i,end:o,collapse:l,coverStart:a,coverEnd:u}}function nn(e,t,n,r){var i,o=tn(t.map,n,r),l=o.node,s=o.start,a=o.end,u=o.collapse;if(3==l.nodeType){for(var c=0;4>c;c++
 ){for(;s&&Bo(t.line.text.charAt(o.coverStart+s));)--s;for(;o.coverStart+a<o.coverEnd&&Bo(t.line.text.charAt(o.coverStart+a));)++a;if(pl&&9>gl&&0==s&&a==o.coverEnd-o.coverStart)i=l.parentNode.getBoundingClientRect();else if(pl&&e.options.lineWrapping){var h=Fs(l,s,a).getClientRects();i=h.length?h["right"==r?h.length-1:0]:Pl}else i=Fs(l,s,a).getBoundingClientRect()||Pl;if(i.left||i.right||0==s)break;a=s,s-=1,u="right"}pl&&11>gl&&(i=rn(e.display.measure,i))}else{s>0&&(u=r="right");var h;i=e.options.lineWrapping&&(h=l.getClientRects()).length>1?h["right"==r?h.length-1:0]:l.getBoundingClientRect()}if(pl&&9>gl&&!s&&(!i||!i.left&&!i.right)){var f=l.parentNode.getClientRects()[0];i=f?{left:f.left,right:f.left+bn(e.display),top:f.top,bottom:f.bottom}:Pl}for(var d=i.top-t.rect.top,p=i.bottom-t.rect.top,g=(d+p)/2,m=t.view.measure.heights,c=0;c<m.length-1&&!(g<m[c]);c++);var v=c?m[c-1]:0,y=m[c],b={left:("right"==u?i.right:i.left)-t.rect.left,right:("left"==u?i.left:i.right)-t.rect.left,top:v,bo
 ttom:y};return i.left||i.right||(b.bogus=!0),e.options.singleCursorHeightPerLine||(b.rtop=d,b.rbottom=p),b}function rn(e,t){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!Zo(e))return t;var n=screen.logicalXDPI/screen.deviceXDPI,r=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*n,right:t.right*n,top:t.top*r,bottom:t.bottom*r}}function on(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(var t=0;t<e.rest.length;t++)e.measure.caches[t]={}}function ln(e){e.display.externalMeasure=null,Ro(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++)on(e.display.view[t])}function sn(e){ln(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function an(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function un(){return window.pageYOffset||(document.documentElement||docume
 nt.body).scrollTop}function cn(e,t,n,r){if(t.widgets)for(var i=0;i<t.widgets.length;++i)if(t.widgets[i].above){var o=Ci(t.widgets[i]);n.top+=o,n.bottom+=o}if("line"==r)return n;r||(r="local");var l=eo(t);if("local"==r?l+=qt(e.display):l-=e.display.viewOffset,"page"==r||"window"==r){var s=e.display.lineSpace.getBoundingClientRect();l+=s.top+("window"==r?0:un());var a=s.left+("window"==r?0:an());n.left+=a,n.right+=a}return n.top+=l,n.bottom+=l,n}function hn(e,t,n){if("div"==n)return t;var r=t.left,i=t.top;if("page"==n)r-=an(),i-=un();else if("local"==n||!n){var o=e.display.sizer.getBoundingClientRect();r+=o.left,i+=o.top}var l=e.display.lineSpace.getBoundingClientRect();return{left:r-l.left,top:i-l.top}}function fn(e,t,n,r,i){return r||(r=Ki(e.doc,t.line)),cn(e,r,Zt(e,r,t.ch,i),n)}function dn(e,t,n,r,i,o){function l(t,l){var s=en(e,i,t,l?"right":"left",o);return l?s.left=s.right:s.right=s.left,cn(e,r,s,n)}function s(e,t){var n=a[t],r=n.level%2;return e==Jo(n)&&t&&n.level<a[t-1].level?
 (n=a[--t],e=el(n)-(n.level%2?0:1),r=!0):e==el(n)&&t<a.length-1&&n.level<a[t+1].level&&(n=a[++t],e=Jo(n)-n.level%2,r=!1),r&&e==n.to&&e>n.from?l(e-1):l(e,r)}r=r||Ki(e.doc,t.line),i||(i=Jt(e,r));var a=to(r),u=t.ch;if(!a)return l(u);var c=sl(a,u),h=s(u,c);return null!=Qs&&(h.other=s(u,Qs)),h}function pn(e,t){var n=0,t=mt(e.doc,t);e.options.lineWrapping||(n=bn(e.display)*t.ch);var r=Ki(e.doc,t.line),i=eo(r)+qt(e.display);return{left:n,right:n,top:i,bottom:i+r.height}}function gn(e,t,n,r){var i=Wl(e,t);return i.xRel=r,n&&(i.outside=!0),i}function mn(e,t,n){var r=e.doc;if(n+=e.display.viewOffset,0>n)return gn(r.first,0,!0,-1);var i=Ji(r,n),o=r.first+r.size-1;if(i>o)return gn(r.first+r.size-1,Ki(r,o).text.length,!0,1);0>t&&(t=0);for(var l=Ki(r,i);;){var s=vn(e,l,i,t,n),a=di(l),u=a&&a.find(0,!0);if(!a||!(s.ch>u.from.ch||s.ch==u.from.ch&&s.xRel>0))return s;i=Qi(l=u.to.line)}}function vn(e,t,n,r,i){function o(r){var i=dn(e,Wl(n,r),"line",t,u);return s=!0,l>i.bottom?i.left-a:l<i.top?i.left+a:(s
 =!1,i.left)}var l=i-eo(t),s=!1,a=2*e.display.wrapper.clientWidth,u=Jt(e,t),c=to(t),h=t.text.length,f=tl(t),d=nl(t),p=o(f),g=s,m=o(d),v=s;if(r>m)return gn(n,d,v,1);for(;;){if(c?d==f||d==ul(t,f,1):1>=d-f){for(var y=p>r||m-r>=r-p?f:d,b=r-(y==f?p:m);Bo(t.text.charAt(y));)++y;var x=gn(n,y,y==f?g:v,-1>b?-1:b>1?1:0);return x}var w=Math.ceil(h/2),C=f+w;if(c){C=f;for(var k=0;w>k;++k)C=ul(t,C,1)}var S=o(C);S>r?(d=C,m=S,(v=s)&&(m+=1e3),h=w):(f=C,p=S,g=s,h-=w)}}function yn(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Il){Il=_o("pre");for(var t=0;49>t;++t)Il.appendChild(document.createTextNode("x")),Il.appendChild(_o("br"));Il.appendChild(document.createTextNode("x"))}qo(e.measure,Il);var n=Il.offsetHeight/50;return n>3&&(e.cachedTextHeight=n),Ro(e.measure),n||1}function bn(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=_o("span","xxxxxxxxxx"),n=_o("pre",[t]);qo(e.measure,n);var r=t.getBoundingClientRect(),i=(r.right-r.left)/10;return i>2&&(e.cachedCharWidth=i)
 ,i||10}function xn(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:++_l},Bl?Bl.ops.push(e.curOp):e.curOp.ownsGroup=Bl={ops:[e.curOp],delayedCallbacks:[]}}function wn(e){var t=e.delayedCallbacks,n=0;do{for(;n<t.length;n++)t[n]();for(var r=0;r<e.ops.length;r++){var i=e.ops[r];if(i.cursorActivityHandlers)for(;i.cursorActivityCalled<i.cursorActivityHandlers.length;)i.cursorActivityHandlers[i.cursorActivityCalled++](i.cm)}}while(n<t.length)}function Cn(e){var t=e.curOp,n=t.ownsGroup;if(n)try{wn(n)}finally{Bl=null;for(var r=0;r<n.ops.length;r++)n.ops[r].cm.curOp=null;kn(n)}}function kn(e){for(var t=e.ops,n=0;n<t.length;n++)Sn(t[n]);for(var n=0;n<t.length;n++)Ln(t[n]);for(var n=0;n<t.length;n++)Mn(t[n]);for(var n=0;n<t.length;n++)Tn(t[n]);for(var n=0;n<t.length;n++)Nn(t[n])}func
 tion Sn(e){var t=e.cm,n=t.display;M(t),e.updateMaxLine&&f(t),e.mustUpdate=e.viewChanged||e.forceUpdate||null!=e.scrollTop||e.scrollToPos&&(e.scrollToPos.from.line<n.viewFrom||e.scrollToPos.to.line>=n.viewTo)||n.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new L(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function Ln(e){e.updatedDisplay=e.mustUpdate&&T(e.cm,e.update)}function Mn(e){var t=e.cm,n=t.display;e.updatedDisplay&&D(t),e.barMeasure=p(t),n.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Zt(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+$t(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-jt(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function Tn(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adju
 stWidthTo+"px",e.maxScrollLeft<t.doc.scrollLeft&&nr(t,Math.min(t.display.scroller.scrollLeft,e.maxScrollLeft),!0),t.display.maxLineChanged=!1),e.preparedSelection&&t.display.input.showSelection(e.preparedSelection),e.updatedDisplay&&O(t,e.barMeasure),(e.updatedDisplay||e.startHeight!=t.doc.height)&&y(t,e.barMeasure),e.selectionChanged&&zt(t),t.state.focused&&e.updateInput&&t.display.input.reset(e.typing),e.focus&&e.focus==Uo()&&Y(e.cm)}function Nn(e){var t=e.cm,n=t.display,r=t.doc;if(e.updatedDisplay&&N(t,e.update),null==n.wheelStartX||null==e.scrollTop&&null==e.scrollLeft&&!e.scrollToPos||(n.wheelStartX=n.wheelStartY=null),null==e.scrollTop||n.scroller.scrollTop==e.scrollTop&&!e.forceScroll||(r.scrollTop=Math.max(0,Math.min(n.scroller.scrollHeight-n.scroller.clientHeight,e.scrollTop)),n.scrollbars.setScrollTop(r.scrollTop),n.scroller.scrollTop=r.scrollTop),null==e.scrollLeft||n.scroller.scrollLeft==e.scrollLeft&&!e.forceScroll||(r.scrollLeft=Math.max(0,Math.min(n.scroller.scrollWid
 th-jt(t),e.scrollLeft)),n.scrollbars.setScrollLeft(r.scrollLeft),n.scroller.scrollLeft=r.scrollLeft,w(t)),e.scrollToPos){var i=Dr(t,mt(r,e.scrollToPos.from),mt(r,e.scrollToPos.to),e.scrollToPos.margin);e.scrollToPos.isCursor&&t.state.focused&&Or(t,i)}var o=e.maybeHiddenMarkers,l=e.maybeUnhiddenMarkers;if(o)for(var s=0;s<o.length;++s)o[s].lines.length||Ms(o[s],"hide");if(l)for(var s=0;s<l.length;++s)l[s].lines.length&&Ms(l[s],"unhide");n.wrapper.offsetHeight&&(r.scrollTop=t.display.scroller.scrollTop),e.changeObjs&&Ms(t,"changes",t,e.changeObjs),e.update&&e.update.finish()}function An(e,t){if(e.curOp)return t();xn(e);try{return t()}finally{Cn(e)}}function On(e,t){return function(){if(e.curOp)return t.apply(e,arguments);xn(e);try{return t.apply(e,arguments)}finally{Cn(e)}}}function Dn(e){return function(){if(this.curOp)return e.apply(this,arguments);xn(this);try{return e.apply(this,arguments)}finally{Cn(this)}}}function Wn(e){return function(){var t=this.cm;if(!t||t.curOp)return e.app
 ly(this,arguments);xn(t);try{return e.apply(this,arguments)}finally{Cn(t)}}}function Hn(e,t,n){this.line=t,this.rest=mi(t),this.size=this.rest?Qi(Oo(this.rest))-n+1:1,this.node=this.text=null,this.hidden=bi(e,t)}function En(e,t,n){for(var r,i=[],o=t;n>o;o=r){var l=new Hn(e.doc,Ki(e.doc,o),o);r=o+l.size,i.push(l)}return i}function In(e,t,n,r){null==t&&(t=e.doc.first),null==n&&(n=e.doc.first+e.doc.size),r||(r=0);var i=e.display;if(r&&n<i.viewTo&&(null==i.updateLineNumbers||i.updateLineNumbers>t)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Dl&&vi(e.doc,t)<i.viewTo&&zn(e);else if(n<=i.viewFrom)Dl&&yi(e.doc,n+r)>i.viewFrom?zn(e):(i.viewFrom+=r,i.viewTo+=r);else if(t<=i.viewFrom&&n>=i.viewTo)zn(e);else if(t<=i.viewFrom){var o=Bn(e,n,n+r,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=r):zn(e)}else if(n>=i.viewTo){var o=Bn(e,t,t,-1);o?(i.view=i.view.slice(0,o.index),i.viewTo=o.lineN):zn(e)}else{var l=Bn(e,t,t,-1),s=Bn(e,n,n+r,1);l&&s?(i.view=i.view.slice(0,l
 .index).concat(En(e,l.lineN,s.lineN)).concat(i.view.slice(s.index)),i.viewTo+=r):zn(e)}var a=i.externalMeasured;a&&(n<a.lineN?a.lineN+=r:t<a.lineN+a.size&&(i.externalMeasured=null))}function Fn(e,t,n){e.curOp.viewChanged=!0;var r=e.display,i=e.display.externalMeasured;if(i&&t>=i.lineN&&t<i.lineN+i.size&&(r.externalMeasured=null),!(t<r.viewFrom||t>=r.viewTo)){var o=r.view[Pn(e,t)];if(null!=o.node){var l=o.changes||(o.changes=[]);-1==Do(l,n)&&l.push(n)}}}function zn(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function Pn(e,t){if(t>=e.display.viewTo)return null;if(t-=e.display.viewFrom,0>t)return null;for(var n=e.display.view,r=0;r<n.length;r++)if(t-=n[r].size,0>t)return r}function Bn(e,t,n,r){var i,o=Pn(e,t),l=e.display.view;if(!Dl||n==e.doc.first+e.doc.size)return{index:o,lineN:n};for(var s=0,a=e.display.viewFrom;o>s;s++)a+=l[s].size;if(a!=t){if(r>0){if(o==l.length-1)return null;i=a+l[o].size-t,o++}else i=a-t;t+=i,n+=i}for(;vi(e.doc,n)!
 =n;){if(o==(0>r?0:l.length-1))return null;n+=r*l[o-(0>r?1:0)].size,o+=r}return{index:o,lineN:n}}function _n(e,t,n){var r=e.display,i=r.view;0==i.length||t>=r.viewTo||n<=r.viewFrom?(r.view=En(e,t,n),r.viewFrom=t):(r.viewFrom>t?r.view=En(e,t,r.viewFrom).concat(r.view):r.viewFrom<t&&(r.view=r.view.slice(Pn(e,t))),r.viewFrom=t,r.viewTo<n?r.view=r.view.concat(En(e,r.viewTo,n)):r.viewTo>n&&(r.view=r.view.slice(0,Pn(e,n)))),r.viewTo=n}function Rn(e){for(var t=e.display.view,n=0,r=0;r<t.length;r++){var i=t[r];i.hidden||i.node&&!i.changes||++n}return n}function qn(e){function t(){i.activeTouch&&(o=setTimeout(function(){i.activeTouch=null},1e3),l=i.activeTouch,l.end=+new Date)}function n(e){if(1!=e.touches.length)return!1;var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}function r(e,t){if(null==t.left)return!0;var n=t.left-e.left,r=t.top-e.top;return n*n+r*r>400}var i=e.display;Ss(i.scroller,"mousedown",On(e,Vn)),pl&&11>gl?Ss(i.scroller,"dblclick",On(e,function(t){if(!ko(e,t)){var n=jn(e,
 t);if(n&&!Qn(e,t)&&!$n(e.display,t)){ws(t);var r=e.findWordAt(n);wt(e.doc,r.anchor,r.head)}}})):Ss(i.scroller,"dblclick",function(t){ko(e,t)||ws(t)}),Al||Ss(i.scroller,"contextmenu",function(t){mr(e,t)});var o,l={end:0};Ss(i.scroller,"touchstart",function(e){if(!n(e)){clearTimeout(o);var t=+new Date;i.activeTouch={start:t,moved:!1,prev:t-l.end<=300?l:null},1==e.touches.length&&(i.activeTouch.left=e.touches[0].pageX,i.activeTouch.top=e.touches[0].pageY)}}),Ss(i.scroller,"touchmove",function(){i.activeTouch&&(i.activeTouch.moved=!0)}),Ss(i.scroller,"touchend",function(n){var o=i.activeTouch;if(o&&!$n(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 ft(s,s):!o.prev.prev||r(o,o.prev.prev)?e.findWordAt(s):new ft(Wl(s.line,0),mt(e.doc,Wl(s.line+1,0))),e.setSelection(l.anchor,l.head),e.focus(),ws(n)}t()}),Ss(i.scroller,"touchcancel",t),Ss(i.scroller,"scroll",function(){i.scroller.clientHeight&&(tr(e,i.scroller.scrollT
 op),nr(e,i.scroller.scrollLeft,!0),Ms(e,"scroll",e))}),Ss(i.scroller,"mousewheel",function(t){rr(e,t)}),Ss(i.scroller,"DOMMouseScroll",function(t){rr(e,t)}),Ss(i.wrapper,"scroll",function(){i.wrapper.scrollTop=i.wrapper.scrollLeft=0}),i.dragFunctions={simple:function(t){ko(e,t)||ks(t)},start:function(t){er(e,t)},drop:On(e,Jn)};var s=i.input.getField();Ss(s,"keyup",function(t){hr.call(e,t)}),Ss(s,"keydown",On(e,ur)),Ss(s,"keypress",On(e,fr)),Ss(s,"focus",Fo(pr,e)),Ss(s,"blur",Fo(gr,e))}function Un(t,n,r){var i=r&&r!=e.Init;if(!n!=!i){var o=t.display.dragFunctions,l=n?Ss:Ls;l(t.display.scroller,"dragstart",o.start),l(t.display.scroller,"dragenter",o.simple),l(t.display.scroller,"dragover",o.simple),l(t.display.scroller,"drop",o.drop)}}function Gn(e){var t=e.display;(t.lastWrapHeight!=t.wrapper.clientHeight||t.lastWrapWidth!=t.wrapper.clientWidth)&&(t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize())}function $n(e,t){for(var n=bo(t);n!=e.wrapp
 er;n=n.parentNode)if(!n||1==n.nodeType&&"true"==n.getAttribute("cm-ignore-events")||n.parentNode==e.sizer&&n!=e.mover)return!0}function jn(e,t,n,r){var i=e.display;if(!n&&"true"==bo(t).getAttribute("cm-not-content"))return null;var o,l,s=i.lineSpace.getBoundingClientRect();try{o=t.clientX-s.left,l=t.clientY-s.top}catch(t){return null}var a,u=mn(e,o,l);if(r&&1==u.xRel&&(a=Ki(e.doc,u.line).text).length==u.ch){var c=Hs(a,a.length,e.options.tabSize)-a.length;u=Wl(u.line,Math.max(0,Math.round((o-Gt(e.display).left)/bn(e.display))-c))}return u}function Vn(e){var t=this,n=t.display;if(!(n.activeTouch&&n.input.supportsTouch()||ko(t,e))){if(n.shift=e.shiftKey,$n(n,e))return void(ml||(n.scroller.draggable=!1,setTimeout(function(){n.scroller.draggable=!0},100)));if(!Qn(t,e)){var r=jn(t,e);switch(window.focus(),xo(e)){case 1:r?Kn(t,e,r):bo(e)==n.scroller&&ws(e);break;case 2:ml&&(t.state.lastMiddleDown=+new Date),r&&wt(t.doc,r),setTimeout(function(){n.input.focus()},20),ws(e);break;case 3:Al?mr(
 t,e):dr(t)}}}}function Kn(e,t,n){pl?setTimeout(Fo(Y,e),0):e.curOp.focus=Uo();var r,i=+new Date;zl&&zl.time>i-400&&0==Hl(zl.pos,n)?r="triple":Fl&&Fl.time>i-400&&0==Hl(Fl.pos,n)?(r="double",zl={time:i,pos:n}):(r="single",Fl={time:i,pos:n});var o,l=e.doc.sel,s=Ll?t.metaKey:t.ctrlKey;e.options.dragDrop&&js&&!Z(e)&&"single"==r&&(o=l.contains(n))>-1&&(Hl((o=l.ranges[o]).from(),n)<0||n.xRel>0)&&(Hl(o.to(),n)>0||n.xRel<0)?Xn(e,t,n,s):Yn(e,t,n,r,s)}function Xn(e,t,n,r){var i=e.display,o=+new Date,l=On(e,function(s){ml&&(i.scroller.draggable=!1),e.state.draggingText=!1,Ls(document,"mouseup",l),Ls(i.scroller,"drop",l),Math.abs(t.clientX-s.clientX)+Math.abs(t.clientY-s.clientY)<10&&(ws(s),!r&&+new Date-200<o&&wt(e.doc,n),ml||pl&&9==gl?setTimeout(function(){document.body.focus(),i.input.focus()},20):i.input.focus())});ml&&(i.scroller.draggable=!0),e.state.draggingText=l,i.scroller.dragDrop&&i.scroller.dragDrop(),Ss(document,"mouseup",l),Ss(i.scroller,"drop",l)}function Yn(e,t,n,r,i){function o(t
 ){if(0!=Hl(m,t))if(m=t,"rect"==r){for(var i=[],o=e.options.tabSize,l=Hs(Ki(u,n.line).text,n.ch,o),s=Hs(Ki(u,t.line).text,t.ch,o),a=Math.min(l,s),d=Math.max(l,s),p=Math.min(n.line,t.line),g=Math.min(e.lastLine(),Math.max(n.line,t.line));g>=p;p++){var v=Ki(u,p).text,y=No(v,a,o);a==d?i.push(new ft(Wl(p,y),Wl(p,y))):v.length>y&&i.push(new ft(Wl(p,y),Wl(p,No(v,d,o))))}i.length||i.push(new ft(n,n)),Tt(u,dt(f.ranges.slice(0,h).concat(i),h),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var b=c,x=b.anchor,w=t;if("single"!=r){if("double"==r)var C=e.findWordAt(t);else var C=new ft(Wl(t.line,0),mt(u,Wl(t.line+1,0)));Hl(C.anchor,x)>0?(w=C.head,x=X(b.from(),C.anchor)):(w=C.anchor,x=K(b.to(),C.head))}var i=f.ranges.slice(0);i[h]=new ft(mt(u,x),w),Tt(u,dt(i,h),Ds)}}function l(t){var n=++y,i=jn(e,t,!0,"rect"==r);if(i)if(0!=Hl(i,m)){e.curOp.focus=Uo(),o(i);var s=x(a,u);(i.line>=s.to||i.line<s.from)&&setTimeout(On(e,function(){y==n&&l(t)}),150)}else{var c=t.clientY<v.top?-20:t.clientY>v.bottom
 ?20:0;c&&setTimeout(On(e,function(){y==n&&(a.scroller.scrollTop+=c,l(t))}),50)}}function s(e){y=1/0,ws(e),a.input.focus(),Ls(document,"mousemove",b),Ls(document,"mouseup",w),u.history.lastSelOrigin=null}var a=e.display,u=e.doc;ws(t);var c,h,f=u.sel,d=f.ranges;if(i&&!t.shiftKey?(h=u.sel.contains(n),c=h>-1?d[h]:new ft(n,n)):(c=u.sel.primary(),h=u.sel.primIndex),t.altKey)r="rect",i||(c=new ft(n,n)),n=jn(e,t,!0,!0),h=-1;else if("double"==r){var p=e.findWordAt(n);c=e.display.shift||u.extend?xt(u,c,p.anchor,p.head):p}else if("triple"==r){var g=new ft(Wl(n.line,0),mt(u,Wl(n.line+1,0)));c=e.display.shift||u.extend?xt(u,c,g.anchor,g.head):g}else c=xt(u,c,n);i?-1==h?(h=d.length,Tt(u,dt(d.concat([c]),h),{scroll:!1,origin:"*mouse"})):d.length>1&&d[h].empty()&&"single"==r&&!t.shiftKey?(Tt(u,dt(d.slice(0,h).concat(d.slice(h+1)),0)),f=u.sel):kt(u,h,c,Ds):(h=0,Tt(u,new ht([c],0),Ds),f=u.sel);var m=n,v=a.wrapper.getBoundingClientRect(),y=0,b=On(e,function(e){xo(e)?l(e):s(e)}),w=On(e,s);Ss(document,"
 mousemove",b),Ss(document,"mouseup",w)}function Zn(e,t,n,r,i){try{var o=t.clientX,l=t.clientY}catch(t){return!1}if(o>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;r&&ws(t);var s=e.display,a=s.lineDiv.getBoundingClientRect();if(l>a.bottom||!Lo(e,n))return yo(t);l-=a.top-s.viewOffset;for(var u=0;u<e.options.gutters.length;++u){var c=s.gutters.childNodes[u];if(c&&c.getBoundingClientRect().right>=o){var h=Ji(e.doc,l),f=e.options.gutters[u];return i(e,n,e,h,f,t),yo(t)}}}function Qn(e,t){return Zn(e,t,"gutterClick",!0,wo)}function Jn(e){var t=this;if(!ko(t,e)&&!$n(t.display,e)){ws(e),pl&&(Rl=+new Date);var n=jn(t,e,!0),r=e.dataTransfer.files;if(n&&!Z(t))if(r&&r.length&&window.FileReader&&window.File)for(var i=r.length,o=Array(i),l=0,s=function(e,r){var s=new FileReader;s.onload=On(t,function(){if(o[r]=s.result,++l==i){n=mt(t.doc,n);var e={from:n,to:n,text:Vs(o.join("\n")),origin:"paste"};kr(t.doc,e),Mt(t.doc,pt(n,Vl(e)))}}),s.readAsText(e)},a=0;i>a;++a)s(r[a],a);el
 se{if(t.state.draggingText&&t.doc.sel.contains(n)>-1)return t.state.draggingText(e),void setTimeout(function(){t.display.input.focus()},20);try{var o=e.dataTransfer.getData("Text");if(o){if(t.state.draggingText&&!(Ll?e.altKey:e.ctrlKey))var u=t.listSelections();if(Nt(t.doc,pt(n,n)),u)for(var a=0;a<u.length;++a)Ar(t.doc,"",u[a].anchor,u[a].head,"drag");t.replaceSelection(o,"around","paste"),t.display.input.focus()}}catch(e){}}}}function er(e,t){if(pl&&(!e.state.draggingText||+new Date-Rl<100))return void ks(t);if(!ko(e,t)&&!$n(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.setDragImage&&!xl)){var n=_o("img",null,null,"position: fixed; left: 0; top: 0;");n.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",bl&&(n.width=n.height=1,e.display.wrapper.appendChild(n),n._top=n.offsetTop),t.dataTransfer.setDragImage(n,0,0),bl&&n.parentNode.removeChild(n)}}function tr(e,t){Math.abs(e.doc.scrollTop-t)<2||(e.doc.scrollTop=t,hl||A(e,{t
 op:t}),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t),e.display.scrollbars.setScrollTop(t),hl&&A(e),Pt(e,100))}function nr(e,t,n){(n?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)||(t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth),e.doc.scrollLeft=t,w(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function rr(e,t){var n=Gl(t),r=n.x,i=n.y,o=e.display,l=o.scroller;if(r&&l.scrollWidth>l.clientWidth||i&&l.scrollHeight>l.clientHeight){if(i&&Ll&&ml)e:for(var s=t.target,a=o.view;s!=l;s=s.parentNode)for(var u=0;u<a.length;u++)if(a[u].node==s){e.display.currentWheelTarget=s;break e}if(r&&!hl&&!bl&&null!=Ul)return i&&tr(e,Math.max(0,Math.min(l.scrollTop+i*Ul,l.scrollHeight-l.clientHeight))),nr(e,Math.max(0,Math.min(l.scrollLeft+r*Ul,l.scrollWidth-l.clientWidth))),ws(t),void(o.wheelStartX=null);if(i&&null!=Ul){var c=i*Ul,h=e.doc.scrollTop,f=h+o.wrapper.clientHeight;0>c?h=Math.max(0
 ,h+c-50):f=Math.min(e.doc.height,f+c+50),A(e,{top:h,bottom:f})}20>ql&&(null==o.wheelStartX?(o.wheelStartX=l.scrollLeft,o.wheelStartY=l.scrollTop,o.wheelDX=r,o.wheelDY=i,setTimeout(function(){if(null!=o.wheelStartX){var e=l.scrollLeft-o.wheelStartX,t=l.scrollTop-o.wheelStartY,n=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,n&&(Ul=(Ul*ql+n)/(ql+1),++ql)}},200)):(o.wheelDX+=r,o.wheelDY+=i))}}function ir(e,t,n){if("string"==typeof t&&(t=is[t],!t))return!1;e.display.input.ensurePolled();var r=e.display.shift,i=!1;try{Z(e)&&(e.state.suppressEdits=!0),n&&(e.display.shift=!1),i=t(e)!=As}finally{e.display.shift=r,e.state.suppressEdits=!1}return i}function or(e,t,n){for(var r=0;r<e.state.keyMaps.length;r++){var i=ls(t,e.state.keyMaps[r],n,e);if(i)return i}return e.options.extraKeys&&ls(t,e.options.extraKeys,n,e)||ls(t,e.options.keyMap,n,e)}function lr(e,t,n,r){var i=e.state.keySeq;if(i){if(ss(t))return"handled";$l.set(50,function(){e.state.keySeq==i&&(e
 .state.keySeq=null,e.display.input.reset())}),t=i+" "+t}var o=or(e,t,r);return"multi"==o&&(e.state.keySeq=t),"handled"==o&&wo(e,"keyHandled",e,t,n),("handled"==o||"multi"==o)&&(ws(n),zt(e)),i&&!o&&/\'$/.test(t)?(ws(n),!0):!!o}function sr(e,t){var n=as(t,!0);return n?t.shiftKey&&!e.state.keySeq?lr(e,"Shift-"+n,t,function(t){return ir(e,t,!0)})||lr(e,n,t,function(t){return("string"==typeof t?/^go[A-Z]/.test(t):t.motion)?ir(e,t):void 0}):lr(e,n,t,function(t){return ir(e,t)}):!1}function ar(e,t,n){return lr(e,"'"+n+"'",t,function(t){return ir(e,t,!0)})}function ur(e){var t=this;if(t.curOp.focus=Uo(),!ko(t,e)){pl&&11>gl&&27==e.keyCode&&(e.returnValue=!1);var n=e.keyCode;t.display.shift=16==n||e.shiftKey;var r=sr(t,e);bl&&(jl=r?n:null,!r&&88==n&&!Xs&&(Ll?e.metaKey:e.ctrlKey)&&t.replaceSelection("",null,"cut")),18!=n||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||cr(t)}}function cr(e){function t(e){18!=e.keyCode&&e.altKey||(Us(n,"CodeMirror-crosshair"),Ls(document,"keyup",t
 ),Ls(document,"mouseover",t))}var n=e.display.lineDiv;Gs(n,"CodeMirror-crosshair"),Ss(document,"keyup",t),Ss(document,"mouseover",t)}function hr(e){16==e.keyCode&&(this.doc.sel.shift=!1),ko(this,e)}function fr(e){var t=this;if(!($n(t.display,e)||ko(t,e)||e.ctrlKey&&!e.altKey||Ll&&e.metaKey)){var n=e.keyCode,r=e.charCode;if(bl&&n==jl)return jl=null,void ws(e);if(!bl||e.which&&!(e.which<10)||!sr(t,e)){var i=String.fromCharCode(null==r?n:r);ar(t,e,i)||t.display.input.onKeyPress(e)}}}function dr(e){e.state.delayingBlurEvent=!0,setTimeout(function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,gr(e))},100)}function pr(e){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(Ms(e,"focus",e),e.state.focused=!0,Gs(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),ml&&setTimeout(function(){e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),zt(e))}fu
 nction gr(e){e.state.delayingBlurEvent||(e.state.focused&&(Ms(e,"blur",e),e.state.focused=!1,Us(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150))}function mr(e,t){$n(e.display,t)||vr(e,t)||e.display.input.onContextMenu(t)}function vr(e,t){return Lo(e,"gutterContextMenu")?Zn(e,t,"gutterContextMenu",!1,Ms):!1}function yr(e,t){if(Hl(e,t.from)<0)return e;if(Hl(e,t.to)<=0)return Vl(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+=Vl(t).ch-t.to.ch),Wl(n,r)}function br(e,t){for(var n=[],r=0;r<e.sel.ranges.length;r++){var i=e.sel.ranges[r];n.push(new ft(yr(i.anchor,t),yr(i.head,t)))}return dt(n,e.sel.primIndex)}function xr(e,t,n){return e.line==t.line?Wl(n.line,e.ch-t.ch+n.ch):Wl(n.line+(e.line-t.line),e.ch)}function wr(e,t,n){for(var r=[],i=Wl(e.first,0),o=i,l=0;l<t.length;l++){var s=t[l],a=xr(s.from,i,o),u=xr(Vl(s),i,o);if(i=s.to,o=u,"around"==n){var c=e.s
 el.ranges[l],h=Hl(c.head,c.anchor)<0;r[l]=new ft(h?u:a,h?a:u)}else r[l]=new ft(a,a)}return new ht(r,e.sel.primIndex)}function Cr(e,t,n){var r={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){this.canceled=!0}};return n&&(r.update=function(t,n,r,i){t&&(this.from=mt(e,t)),n&&(this.to=mt(e,n)),r&&(this.text=r),void 0!==i&&(this.origin=i)}),Ms(e,"beforeChange",e,r),e.cm&&Ms(e.cm,"beforeChange",e.cm,r),r.canceled?null:{from:r.from,to:r.to,text:r.text,origin:r.origin}}function kr(e,t,n){if(e.cm){if(!e.cm.curOp)return On(e.cm,kr)(e,t,n);if(e.cm.state.suppressEdits)return}if(!(Lo(e,"beforeChange")||e.cm&&Lo(e.cm,"beforeChange"))||(t=Cr(e,t,!0))){var r=Ol&&!n&&oi(e,t.from,t.to);if(r)for(var i=r.length-1;i>=0;--i)Sr(e,{from:r[i].from,to:r[i].to,text:i?[""]:t.text});else Sr(e,t)}}function Sr(e,t){if(1!=t.text.length||""!=t.text[0]||0!=Hl(t.from,t.to)){var n=br(e,t);lo(e,t,n,e.cm?e.cm.curOp.id:0/0),Tr(e,t,n,ni(e,t));var r=[];ji(e,function(e,n){n||-1!=Do(r,e.history
 )||(vo(e.history,t),r.push(e.history)),Tr(e,t,null,ni(e,t))})}}function Lr(e,t,n){if(!e.cm||!e.cm.state.suppressEdits){for(var r,i=e.history,o=e.sel,l="undo"==t?i.done:i.undone,s="undo"==t?i.undone:i.done,a=0;a<l.length&&(r=l[a],n?!r.ranges||r.equals(e.sel):r.ranges);a++);if(a!=l.length){for(i.lastOrigin=i.lastSelOrigin=null;r=l.pop(),r.ranges;){if(uo(r,s),n&&!r.equals(e.sel))return void Tt(e,r,{clearRedo:!1});o=r}var u=[];uo(o,s),s.push({changes:u,generation:i.generation}),i.generation=r.generation||++i.maxGeneration;for(var c=Lo(e,"beforeChange")||e.cm&&Lo(e.cm,"beforeChange"),a=r.changes.length-1;a>=0;--a){var h=r.changes[a];if(h.origin=t,c&&!Cr(e,h,!1))return void(l.length=0);u.push(ro(e,h));var f=a?br(e,h):Oo(l);Tr(e,h,f,ii(e,h)),!a&&e.cm&&e.cm.scrollIntoView({from:h.from,to:Vl(h)});var d=[];ji(e,function(e,t){t||-1!=Do(d,e.history)||(vo(e.history,h),d.push(e.history)),Tr(e,h,null,ii(e,h))})}}}}function Mr(e,t){if(0!=t&&(e.first+=t,e.sel=new ht(Wo(e.sel.ranges,function(e){retur
 n new ft(Wl(e.anchor.line+t,e.anchor.ch),Wl(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){In(e.cm,e.first,e.first-t,t);for(var n=e.cm.display,r=n.viewFrom;r<n.viewTo;r++)Fn(e.cm,r,"gutter")}}function Tr(e,t,n,r){if(e.cm&&!e.cm.curOp)return On(e.cm,Tr)(e,t,n,r);if(t.to.line<e.first)return void Mr(e,t.text.length-1-(t.to.line-t.from.line));if(!(t.from.line>e.lastLine())){if(t.from.line<e.first){var i=t.text.length-1-(e.first-t.from.line);Mr(e,i),t={from:Wl(e.first,0),to:Wl(t.to.line+i,t.to.ch),text:[Oo(t.text)],origin:t.origin}}var o=e.lastLine();t.to.line>o&&(t={from:t.from,to:Wl(o,Ki(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=Xi(e,t.from,t.to),n||(n=br(e,t)),e.cm?Nr(e.cm,t,r):Ui(e,t,r),Nt(e,n,Os)}}function Nr(e,t,n){var r=e.doc,i=e.display,l=t.from,s=t.to,a=!1,u=l.line;e.options.lineWrapping||(u=Qi(gi(Ki(r,l.line))),r.iter(u,s.line+1,function(e){return e==i.maxLine?(a=!0,!0):void 0})),r.sel.contains(t.from,t.to)>-1&&So(e),Ui(r,t,n,o(e)),e.options.lineWrappi
 ng||(r.iter(u,l.line+t.text.length,function(e){var t=h(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,a=!1)
+}),a&&(e.curOp.updateMaxLine=!0)),r.frontier=Math.min(r.frontier,l.line),Pt(e,400);var c=t.text.length-(s.line-l.line)-1;t.full?In(e):l.line!=s.line||1!=t.text.length||qi(e.doc,t)?In(e,l.line,s.line+1,c):Fn(e,l.line,"text");var f=Lo(e,"changes"),d=Lo(e,"change");if(d||f){var p={from:l,to:s,text:t.text,removed:t.removed,origin:t.origin};d&&wo(e,"change",e,p),f&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(p)}e.display.selForContextMenu=null}function Ar(e,t,n,r,i){if(r||(r=n),Hl(r,n)<0){var o=r;r=n,n=o}"string"==typeof t&&(t=Vs(t)),kr(e,{from:n,to:r,text:t,origin:i})}function Or(e,t){if(!ko(e,"scrollCursorIntoView")){var n=e.display,r=n.sizer.getBoundingClientRect(),i=null;if(t.top+r.top<0?i=!0:t.bottom+r.top>(window.innerHeight||document.documentElement.clientHeight)&&(i=!1),null!=i&&!Cl){var o=_o("div","​",null,"position: absolute; top: "+(t.top-n.viewOffset-qt(e.display))+"px; height: "+(t.bottom-t.top+$t(e)+n.barHeight)+"px; left: "+t.left+"px; width: 2px;");e.display.line
 Space.appendChild(o),o.scrollIntoView(i),e.display.lineSpace.removeChild(o)}}}function Dr(e,t,n,r){null==r&&(r=0);for(var i=0;5>i;i++){var o=!1,l=dn(e,t),s=n&&n!=t?dn(e,n):l,a=Hr(e,Math.min(l.left,s.left),Math.min(l.top,s.top)-r,Math.max(l.left,s.left),Math.max(l.bottom,s.bottom)+r),u=e.doc.scrollTop,c=e.doc.scrollLeft;if(null!=a.scrollTop&&(tr(e,a.scrollTop),Math.abs(e.doc.scrollTop-u)>1&&(o=!0)),null!=a.scrollLeft&&(nr(e,a.scrollLeft),Math.abs(e.doc.scrollLeft-c)>1&&(o=!0)),!o)break}return l}function Wr(e,t,n,r,i){var o=Hr(e,t,n,r,i);null!=o.scrollTop&&tr(e,o.scrollTop),null!=o.scrollLeft&&nr(e,o.scrollLeft)}function Hr(e,t,n,r,i){var o=e.display,l=yn(e.display);0>n&&(n=0);var s=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:o.scroller.scrollTop,a=Vt(e),u={};i-n>a&&(i=n+a);var c=e.doc.height+Ut(o),h=l>n,f=i>c-l;if(s>n)u.scrollTop=h?0:n;else if(i>s+a){var d=Math.min(n,(f?c:i)-a);d!=s&&(u.scrollTop=d)}var p=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:o.scroller.scrollLe
 ft,g=jt(e)-(e.options.fixedGutter?o.gutters.offsetWidth:0),m=r-t>g;return m&&(r=t+g),10>t?u.scrollLeft=0:p>t?u.scrollLeft=Math.max(0,t-(m?0:10)):r>g+p-3&&(u.scrollLeft=r+(m?0:10)-g),u}function Er(e,t,n){(null!=t||null!=n)&&Fr(e),null!=t&&(e.curOp.scrollLeft=(null==e.curOp.scrollLeft?e.doc.scrollLeft:e.curOp.scrollLeft)+t),null!=n&&(e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+n)}function Ir(e){Fr(e);var t=e.getCursor(),n=t,r=t;e.options.lineWrapping||(n=t.ch?Wl(t.line,t.ch-1):t,r=Wl(t.line,t.ch+1)),e.curOp.scrollToPos={from:n,to:r,margin:e.options.cursorScrollMargin,isCursor:!0}}function Fr(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var n=pn(e,t.from),r=pn(e,t.to),i=Hr(e,Math.min(n.left,r.left),Math.min(n.top,r.top)-t.margin,Math.max(n.right,r.right),Math.max(n.bottom,r.bottom)+t.margin);e.scrollTo(i.scrollLeft,i.scrollTop)}}function zr(e,t,n,r){var i,o=e.doc;null==n&&(n="add"),"smart"==n&&(o.mode.indent?i=Rt(e,t):n="prev");var l=e.o
 ptions.tabSize,s=Ki(o,t),a=Hs(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==As||u>150)){if(!r)return;n="prev"}}else u=0,n="not";"prev"==n?u=t>o.first?Hs(Ki(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="",f=0;if(e.options.indentWithTabs)for(var d=Math.floor(u/l);d;--d)f+=l,h+="	";if(u>f&&(h+=Ao(u-f)),h!=c)return Ar(o,h,Wl(t,0),Wl(t,c.length),"+input"),s.stateAfter=null,!0;for(var d=0;d<o.sel.ranges.length;d++){var p=o.sel.ranges[d];if(p.head.line==t&&p.head.ch<c.length){var f=Wl(t,c.length);kt(o,d,new ft(f,f));break}}}function Pr(e,t,n,r){var i=t,o=t;return"number"==typeof t?o=Ki(e,gt(e,t)):i=Qi(t),null==i?null:(r(o,i)&&e.cm&&Fn(e.cm,i,n),o)}function Br(e,t){for(var n=e.doc.sel.ranges,r=[],i=0;i<n.length;i++){for(var o=t(n[i]);r.length&&Hl(o.from,Oo(r).to)<=0;
 ){var l=r.pop();if(Hl(l.from,o.from)<0){o.from=l.from;break}}r.push(o)}An(e,function(){for(var t=r.length-1;t>=0;t--)Ar(e.doc,"",r[t].from,r[t].to,"+delete");Ir(e)})}function _r(e,t,n,r,i){function o(){var t=s+n;return t<e.first||t>=e.first+e.size?h=!1:(s=t,c=Ki(e,t))}function l(e){var t=(i?ul:cl)(c,a,n,!0);if(null==t){if(e||!o())return h=!1;a=i?(0>n?nl:tl)(c):0>n?c.text.length:0}else a=t;return!0}var s=t.line,a=t.ch,u=n,c=Ki(e,s),h=!0;if("char"==r)l();else if("column"==r)l(!0);else if("word"==r||"group"==r)for(var f=null,d="group"==r,p=e.cm&&e.cm.getHelper(t,"wordChars"),g=!0;!(0>n)||l(!g);g=!1){var m=c.text.charAt(a)||"\n",v=zo(m,p)?"w":d&&"\n"==m?"n":!d||/\s/.test(m)?null:"p";if(!d||g||v||(v="s"),f&&f!=v){0>n&&(n=1,l());break}if(v&&(f=v),n>0&&!l(!g))break}var y=Wt(e,Wl(s,a),u,!0);return h||(y.hitSide=!0),y}function Rr(e,t,n,r){var i,o=e.doc,l=t.left;if("page"==r){var s=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight);i=t.top+n*(s-
 (0>n?1.5:.5)*yn(e.display))}else"line"==r&&(i=n>0?t.bottom+3:t.top-3);for(;;){var a=mn(e,l,i);if(!a.outside)break;if(0>n?0>=i:i>=o.height){a.hitSide=!0;break}i+=5*n}return a}function qr(t,n,r,i){e.defaults[t]=n,r&&(Xl[t]=i?function(e,t,n){n!=Yl&&r(e,t,n)}:r)}function Ur(e){for(var t,n,r,i,o=e.split(/-(?!$)/),e=o[o.length-1],l=0;l<o.length-1;l++){var s=o[l];if(/^(cmd|meta|m)$/i.test(s))i=!0;else if(/^a(lt)?$/i.test(s))t=!0;else if(/^(c|ctrl|control)$/i.test(s))n=!0;else{if(!/^s(hift)$/i.test(s))throw new Error("Unrecognized modifier name: "+s);r=!0}}return t&&(e="Alt-"+e),n&&(e="Ctrl-"+e),i&&(e="Cmd-"+e),r&&(e="Shift-"+e),e}function Gr(e){return"string"==typeof e?os[e]:e}function $r(e,t,n,r,i){if(r&&r.shared)return jr(e,t,n,r,i);if(e.cm&&!e.cm.curOp)return On(e.cm,$r)(e,t,n,r,i);var o=new hs(e,i),l=Hl(t,n);if(r&&Io(r,o,!1),l>0||0==l&&o.clearWhenEmpty!==!1)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=_o("span",[o.replacedWith],"CodeMirror-widget"),r.handleMouseEvents||o.wi
 dgetNode.setAttribute("cm-ignore-events","true"),r.insertLeft&&(o.widgetNode.insertLeft=!0)),o.collapsed){if(pi(e,t.line,t,n,o)||t.line!=n.line&&pi(e,n.line,t,n,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");Dl=!0}o.addToHistory&&lo(e,{from:t,to:n,origin:"markText"},e.sel,0/0);var s,a=t.line,u=e.cm;if(e.iter(a,n.line+1,function(e){u&&o.collapsed&&!u.options.lineWrapping&&gi(e)==u.display.maxLine&&(s=!0),o.collapsed&&a!=t.line&&Zi(e,0),Jr(e,new Yr(o,a==t.line?t.ch:null,a==n.line?n.ch:null)),++a}),o.collapsed&&e.iter(t.line,n.line+1,function(t){bi(e,t)&&Zi(t,0)}),o.clearOnEnter&&Ss(o,"beforeCursorEnter",function(){o.clear()}),o.readOnly&&(Ol=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++cs,o.atomic=!0),u){if(s&&(u.curOp.updateMaxLine=!0),o.collapsed)In(u,t.line,n.line+1);else if(o.className||o.title||o.startStyle||o.endStyle||o.css)for(var c=t.line;c<=n.line;c++)Fn(u,c,"text");o.atomic&&Ot(u.doc),wo(
 u,"markerAdded",u,o)}return o}function jr(e,t,n,r,i){r=Io(r),r.shared=!1;var o=[$r(e,t,n,r,i)],l=o[0],s=r.widgetNode;return ji(e,function(e){s&&(r.widgetNode=s.cloneNode(!0)),o.push($r(e,mt(e,t),mt(e,n),r,i));for(var a=0;a<e.linked.length;++a)if(e.linked[a].isParent)return;l=Oo(o)}),new fs(o,l)}function Vr(e){return e.findMarks(Wl(e.first,0),e.clipPos(Wl(e.lastLine())),function(e){return e.parent})}function Kr(e,t){for(var n=0;n<t.length;n++){var r=t[n],i=r.find(),o=e.clipPos(i.from),l=e.clipPos(i.to);if(Hl(o,l)){var s=$r(e,o,l,r.primary,r.primary.type);r.markers.push(s),s.parent=r}}}function Xr(e){for(var t=0;t<e.length;t++){var n=e[t],r=[n.primary.doc];ji(n.primary.doc,function(e){r.push(e)});for(var i=0;i<n.markers.length;i++){var o=n.markers[i];-1==Do(r,o.doc)&&(o.parent=null,n.markers.splice(i--,1))}}}function Yr(e,t,n){this.marker=e,this.from=t,this.to=n}function Zr(e,t){if(e)for(var n=0;n<e.length;++n){var r=e[n];if(r.marker==t)return r}}function Qr(e,t){for(var n,r=0;r<e.len
 gth;++r)e[r]!=t&&(n||(n=[])).push(e[r]);return n}function Jr(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}function ei(e,t,n){if(e)for(var r,i=0;i<e.length;++i){var o=e[i],l=o.marker,s=null==o.from||(l.inclusiveLeft?o.from<=t:o.from<t);if(s||o.from==t&&"bookmark"==l.type&&(!n||!o.marker.insertLeft)){var a=null==o.to||(l.inclusiveRight?o.to>=t:o.to>t);(r||(r=[])).push(new Yr(l,o.from,a?null:o.to))}}return r}function ti(e,t,n){if(e)for(var r,i=0;i<e.length;++i){var o=e[i],l=o.marker,s=null==o.to||(l.inclusiveRight?o.to>=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.from<t);(r||(r=[])).push(new Yr(l,a?null:o.from-t,null==o.to?null:o.to-t))}}return r}function ni(e,t){if(t.full)return null;var n=yt(e,t.from.line)&&Ki(e,t.from.line).markedSpans,r=yt(e,t.to.line)&&Ki(e,t.to.line).markedSpans;if(!n&&!r)return null;var i=t.from.ch,o=t.to.ch,l=0==Hl(t.from,t.to),s=ei(n,i,l),a=t
 i(r,o,l),u=1==t.text.length,c=Oo(t.text).length+(u?i:0);if(s)for(var h=0;h<s.length;++h){var f=s[h];if(null==f.to){var d=Zr(a,f.marker);d?u&&(f.to=null==d.to?null:d.to+c):f.to=i}}if(a)for(var h=0;h<a.length;++h){var f=a[h];if(null!=f.to&&(f.to+=c),null==f.from){var d=Zr(s,f.marker);d||(f.from=c,u&&(s||(s=[])).push(f))}else f.from+=c,u&&(s||(s=[])).push(f)}s&&(s=ri(s)),a&&a!=s&&(a=ri(a));var p=[s];if(!u){var g,m=t.text.length-2;if(m>0&&s)for(var h=0;h<s.length;++h)null==s[h].to&&(g||(g=[])).push(new Yr(s[h].marker,null,null));for(var h=0;m>h;++h)p.push(g);p.push(a)}return p}function ri(e){for(var t=0;t<e.length;++t){var n=e[t];null!=n.from&&n.from==n.to&&n.marker.clearWhenEmpty!==!1&&e.splice(t--,1)}return e.length?e:null}function ii(e,t){var n=fo(e,t),r=ni(e,t);if(!n)return r;if(!r)return n;for(var i=0;i<n.length;++i){var o=n[i],l=r[i];if(o&&l)e:for(var s=0;s<l.length;++s){for(var a=l[s],u=0;u<o.length;++u)if(o[u].marker==a.marker)continue e;o.push(a)}else l&&(n[i]=l)}return n}funct
 ion oi(e,t,n){var r=null;if(e.iter(t.line,n.line+1,function(e){if(e.markedSpans)for(var t=0;t<e.markedSpans.length;++t){var n=e.markedSpans[t].marker;!n.readOnly||r&&-1!=Do(r,n)||(r||(r=[])).push(n)}}),!r)return null;for(var i=[{from:t,to:n}],o=0;o<r.length;++o)for(var l=r[o],s=l.find(0),a=0;a<i.length;++a){var u=i[a];if(!(Hl(u.to,s.from)<0||Hl(u.from,s.to)>0)){var c=[a,1],h=Hl(u.from,s.from),f=Hl(u.to,s.to);(0>h||!l.inclusiveLeft&&!h)&&c.push({from:u.from,to:s.from}),(f>0||!l.inclusiveRight&&!f)&&c.push({from:s.to,to:u.to}),i.splice.apply(i,c),a+=c.length-1}}return i}function li(e){var t=e.markedSpans;if(t){for(var n=0;n<t.length;++n)t[n].marker.detachLine(e);e.markedSpans=null}}function si(e,t){if(t){for(var n=0;n<t.length;++n)t[n].marker.attachLine(e);e.markedSpans=t}}function ai(e){return e.inclusiveLeft?-1:0}function ui(e){return e.inclusiveRight?1:0}function ci(e,t){var n=e.lines.length-t.lines.length;if(0!=n)return n;var r=e.find(),i=t.find(),o=Hl(r.from,i.from)||ai(e)-ai(t);
 if(o)return-o;var l=Hl(r.to,i.to)||ui(e)-ui(t);return l?l:t.id-e.id}function hi(e,t){var n,r=Dl&&e.markedSpans;if(r)for(var i,o=0;o<r.length;++o)i=r[o],i.marker.collapsed&&null==(t?i.from:i.to)&&(!n||ci(n,i.marker)<0)&&(n=i.marker);return n}function fi(e){return hi(e,!0)}function di(e){return hi(e,!1)}function pi(e,t,n,r,i){var o=Ki(e,t),l=Dl&&o.markedSpans;if(l)for(var s=0;s<l.length;++s){var a=l[s];if(a.marker.collapsed){var u=a.marker.find(0),c=Hl(u.from,n)||ai(a.marker)-ai(i),h=Hl(u.to,r)||ui(a.marker)-ui(i);if(!(c>=0&&0>=h||0>=c&&h>=0)&&(0>=c&&(Hl(u.to,n)>0||a.marker.inclusiveRight&&i.inclusiveLeft)||c>=0&&(Hl(u.from,r)<0||a.marker.inclusiveLeft&&i.inclusiveRight)))return!0}}}function gi(e){for(var t;t=fi(e);)e=t.find(-1,!0).line;return e}function mi(e){for(var t,n;t=di(e);)e=t.find(1,!0).line,(n||(n=[])).push(e);return n}function vi(e,t){var n=Ki(e,t),r=gi(n);return n==r?t:Qi(r)}function yi(e,t){if(t>e.lastLine())return t;var n,r=Ki(e,t);if(!bi(e,r))return t;for(;n=di(r);)r=n.
 find(1,!0).line;return Qi(r)+1}function bi(e,t){var n=Dl&&t.markedSpans;if(n)for(var r,i=0;i<n.length;++i)if(r=n[i],r.marker.collapsed){if(null==r.from)return!0;if(!r.marker.widgetNode&&0==r.from&&r.marker.inclusiveLeft&&xi(e,t,r))return!0}}function xi(e,t,n){if(null==n.to){var r=n.marker.find(1,!0);return xi(e,r.line,Zr(r.line.markedSpans,n.marker))}if(n.marker.inclusiveRight&&n.to==t.text.length)return!0;for(var i,o=0;o<t.markedSpans.length;++o)if(i=t.markedSpans[o],i.marker.collapsed&&!i.marker.widgetNode&&i.from==n.to&&(null==i.to||i.to!=n.from)&&(i.marker.inclusiveLeft||n.marker.inclusiveRight)&&xi(e,t,i))return!0}function wi(e,t,n){eo(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Er(e,null,n)}function Ci(e){if(null!=e.height)return e.height;var t=e.doc.cm;if(!t)return 0;if(!_s(document.body,e.node)){var n="position: relative;";e.coverGutter&&(n+="margin-left: -"+t.display.gutters.offsetWidth+"px;"),e.noHScroll&&(n+="width: "+t.display.wrapper.clientWidth+"px;"),qo(t.displa
 y.measure,_o("div",[e.node],null,n))}return e.height=e.node.offsetHeight}function ki(e,t,n,r){var i=new ds(e,n,r),o=e.cm;return o&&i.noHScroll&&(o.display.alignWidgets=!0),Pr(e,t,"widget",function(t){var n=t.widgets||(t.widgets=[]);if(null==i.insertAt?n.push(i):n.splice(Math.min(n.length-1,Math.max(0,i.insertAt)),0,i),i.line=t,o&&!bi(e,t)){var r=eo(t)<e.scrollTop;Zi(t,t.height+Ci(i)),r&&Er(o,null,i.height),o.curOp.forceUpdate=!0}return!0}),i}function Si(e,t,n,r){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),null!=e.order&&(e.order=null),li(e),si(e,n);var i=r?r(e):1;i!=e.height&&Zi(e,i)}function Li(e){e.parent=null,li(e)}function Mi(e,t){if(e)for(;;){var n=e.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!n)break;e=e.slice(0,n.index)+e.slice(n.index+n[0].length);var r=n[1]?"bgClass":"textClass";null==t[r]?t[r]=n[2]:new RegExp("(?:^|s)"+n[2]+"(?:$|s)").test(t[r])||(t[r]+=" "+n[2])}return e}function Ti(t,n){if(t.blankLine)return t.blankLine(n);if(t.innerMode){var 
 r=e.innerMode(t,n);return r.mode.blankLine?r.mode.blankLine(r.state):void 0}}function Ni(t,n,r,i){for(var o=0;10>o;o++){i&&(i[0]=e.innerMode(t,r).mode);var l=t.token(n,r);if(n.pos>n.start)return l}throw new Error("Mode "+t.name+" failed to advance stream.")}function Ai(e,t,n,r){function i(e){return{start:h.start,end:h.pos,string:h.current(),type:o||null,state:e?ns(l.mode,c):c}}var o,l=e.doc,s=l.mode;t=mt(l,t);var a,u=Ki(l,t.line),c=Rt(e,t.line,n),h=new us(u.text,e.options.tabSize);for(r&&(a=[]);(r||h.pos<t.ch)&&!h.eol();)h.start=h.pos,o=Ni(s,h,c),r&&a.push(i(!0));return r?a:i()}function Oi(e,t,n,r,i,o,l){var s=n.flattenSpans;null==s&&(s=e.options.flattenSpans);var a,u=0,c=null,h=new us(t,e.options.tabSize),f=e.options.addModeClass&&[null];for(""==t&&Mi(Ti(n,r),o);!h.eol();){if(h.pos>e.options.maxHighlightLength?(s=!1,l&&Hi(e,t,r,h.pos),h.pos=t.length,a=null):a=Mi(Ni(n,h,r,f),o),f){var d=f[0].name;d&&(a="m-"+(a?d+" "+a:d))}if(!s||c!=a){for(;u<h.start;)u=Math.min(h.start,u+5e4),i(u,c)
 ;c=a}h.start=h.pos}for(;u<h.pos;){var p=Math.min(h.pos,u+5e4);i(p,c),u=p}}function Di(e,t,n,r){var i=[e.state.modeGen],o={};Oi(e,t.text,e.doc.mode,n,function(e,t){i.push(e,t)},o,r);for(var l=0;l<e.state.overlays.length;++l){var s=e.state.overlays[l],a=1,u=0;Oi(e,t.text,s.mode,!0,function(e,t){for(var n=a;e>u;){var r=i[a];r>e&&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,"cm-overlay "+t),a=n+2;else for(;a>n;n+=2){var o=i[n+1];i[n+1]=(o?o+" ":"")+"cm-overlay "+t}},o)}return{styles:i,classes:o.bgClass||o.textClass?o:null}}function Wi(e,t,n){if(!t.styles||t.styles[0]!=e.state.modeGen){var r=Di(e,t,t.stateAfter=Rt(e,Qi(t)));t.styles=r.styles,r.classes?t.styleClasses=r.classes:t.styleClasses&&(t.styleClasses=null),n===e.doc.frontier&&e.doc.frontier++}return t.styles}function Hi(e,t,n,r){var i=e.doc.mode,o=new us(t,e.options.tabSize);for(o.start=o.pos=r||0,""==t&&Ti(i,n);!o.eol()&&o.pos<=e.options.maxHighlightLength;)Ni(i,o,n),o.start=o.pos}function Ei(e,
 t){if(!e||/^\s*$/.test(e))return null;var n=t.addModeClass?ms:gs;return n[e]||(n[e]=e.replace(/\S+/g,"cm-$&"))}function Ii(e,t){var n=_o("span",null,null,ml?"padding-right: .1px":null),r={pre:_o("pre",[n],"CodeMirror-line"),content:n,col:0,pos:0,cm:e,splitSpaces:(pl||ml)&&e.getOption("lineWrapping")};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var o,l=i?t.rest[i-1]:t.line;r.pos=0,r.addToken=zi,Yo(e.display.measure)&&(o=to(l))&&(r.addToken=Bi(r.addToken,o)),r.map=[];var s=t!=e.display.externalMeasured&&Qi(l);Ri(l,r,Wi(e,l,s)),l.styleClasses&&(l.styleClasses.bgClass&&(r.bgClass=$o(l.styleClasses.bgClass,r.bgClass||"")),l.styleClasses.textClass&&(r.textClass=$o(l.styleClasses.textClass,r.textClass||""))),0==r.map.length&&r.map.push(0,0,r.content.appendChild(Xo(e.display.measure))),0==i?(t.measure.map=r.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(r.map),(t.measure.caches||(t.measure.caches=[])).push({}))}return ml&&/\bcm-tab\b/.test(r.content.lastCh
 ild.className)&&(r.content.className="cm-tab-wrap-hack"),Ms(e,"renderLine",e,t.line,r.pre),r.pre.className&&(r.textClass=$o(r.pre.className,r.textClass||"")),r}function Fi(e){var t=_o("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function zi(e,t,n,r,i,o,l){if(t){var s=e.splitSpaces?t.replace(/ {3,}/g,Pi):t,a=e.cm.state.specialChars,u=!1;if(a.test(t))for(var c=document.createDocumentFragment(),h=0;;){a.lastIndex=h;var f=a.exec(t),d=f?f.index-h:t.length-h;if(d){var p=document.createTextNode(s.slice(h,h+d));c.appendChild(pl&&9>gl?_o("span",[p]):p),e.map.push(e.pos,e.pos+d,p),e.col+=d,e.pos+=d}if(!f)break;if(h+=d+1,"	"==f[0]){var g=e.cm.options.tabSize,m=g-e.col%g,p=c.appendChild(_o("span",Ao(m),"cm-tab"));p.setAttribute("role","presentation"),p.setAttribute("cm-text","	"),e.col+=m}else{var p=e.cm.options.specialCharPlaceholder(f[0]);p.setAttribute("cm-text",f[0]),c.appendChild(pl&&9>gl?_o("span",[p]):p),e.col+=1}
 e.map.push(e.pos,e.pos+1,p),e.pos++}else{e.col+=t.length;var c=document.createTextNode(s);e.map.push(e.pos,e.pos+t.length,c),pl&&9>gl&&(u=!0),e.pos+=t.length}if(n||r||i||u||l){var v=n||"";r&&(v+=r),i&&(v+=i);var y=_o("span",[c],v,l);return o&&(y.title=o),e.content.appendChild(y)}e.content.appendChild(c)}}function Pi(e){for(var t=" ",n=0;n<e.length-2;++n)t+=n%2?" ":" ";return t+=" "}function Bi(e,t){return function(n,r,i,o,l,s,a){i=i?i+" cm-force-border":"cm-force-border";for(var u=n.pos,c=u+r.length;;){for(var h=0;h<t.length;h++){var f=t[h];if(f.to>u&&f.from<=u)break}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 _i(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}function Ri(e,t,n){var r=
 e.markedSpans,i=e.text,o=0;if(r)for(var l,s,a,u,c,h,f,d=i.length,p=0,g=1,m="",v=0;;){if(v==p){a=u=c=h=s="",f=null,v=1/0;for(var y=[],b=0;b<r.length;++b){var x=r[b],w=x.marker;"bookmark"==w.type&&x.from==p&&w.widgetNode?y.push(w):x.from<=p&&(null==x.to||x.to>p||w.collapsed&&x.to==p&&x.from==p)?(null!=x.to&&x.to!=p&&v>x.to&&(v=x.to,u=""),w.className&&(a+=" "+w.className),w.css&&(s=w.css),w.startStyle&&x.from==p&&(c+=" "+w.startStyle),w.endStyle&&x.to==v&&(u+=" "+w.endStyle),w.title&&!h&&(h=w.title),w.collapsed&&(!f||ci(f.marker,w)<0)&&(f=x)):x.from>p&&v>x.from&&(v=x.from)}if(f&&(f.from||0)==p){if(_i(t,(null==f.to?d+1:f.to)-p,f.marker,null==f.from),null==f.to)return;f.to==p&&(f=!1)}if(!f&&y.length)for(var b=0;b<y.length;++b)_i(t,0,y[b])}if(p>=d)break;for(var C=Math.min(d,v);;){if(m){var k=p+m.length;if(!f){var S=k>C?m.slice(0,C-p):m;t.addToken(t,S,l?l+a:a,c,p+S.length==v?u:"",h,s)}if(k>=C){m=m.slice(C-p),p=C;break}p=k,c=""}m=i.slice(o,o=n[g++]),l=Ei(n[g++],t.cm.options)}}else for(var g
 =1;g<n.length;g+=2)t.addToken(t,i.slice(o,o=n[g]),Ei(n[g+1],t.cm.options))}function qi(e,t){return 0==t.from.ch&&0==t.to.ch&&""==Oo(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function Ui(e,t,n,r){function i(e){return n?n[e]:null}function o(e,n,i){Si(e,n,i,r),wo(e,"change",e,t)}function l(e,t){for(var n=e,o=[];t>n;++n)o.push(new ps(u[n],i(n),r));return o}var s=t.from,a=t.to,u=t.text,c=Ki(e,s.line),h=Ki(e,a.line),f=Oo(u),d=i(u.length-1),p=a.line-s.line;if(t.full)e.insert(0,l(0,u.length)),e.remove(u.length,e.size-u.length);else if(qi(e,t)){var g=l(0,u.length-1);o(h,h.text,d),p&&e.remove(s.line,p),g.length&&e.insert(s.line,g)}else if(c==h)if(1==u.length)o(c,c.text.slice(0,s.ch)+f+c.text.slice(a.ch),d);else{var g=l(1,u.length-1);g.push(new ps(f+c.text.slice(a.ch),d,r)),o(c,c.text.slice(0,s.ch)+u[0],i(0)),e.insert(s.line+1,g)}else if(1==u.length)o(c,c.text.slice(0,s.ch)+u[0]+h.text.slice(a.ch),i(0)),e.remove(s.line+1,p);else{o(c,c.text.slice(0,s.ch)+u[0],i(0)),o(h,f+h.text.slice
 (a.ch),d);var g=l(1,u.length-1);p>1&&e.remove(s.line+1,p-1),e.insert(s.line+1,g)}wo(e,"change",e,t)}function Gi(e){this.lines=e,this.parent=null;for(var t=0,n=0;t<e.length;++t)e[t].parent=this,n+=e[t].height;this.height=n}function $i(e){this.children=e;for(var t=0,n=0,r=0;r<e.length;++r){var i=e[r];t+=i.chunkSize(),n+=i.height,i.parent=this}this.size=t,this.height=n,this.parent=null}function ji(e,t,n){function r(e,i,o){if(e.linked)for(var l=0;l<e.linked.length;++l){var s=e.linked[l];if(s.doc!=i){var a=o&&s.sharedHist;(!n||a)&&(t(s.doc,a),r(s.doc,e,a))}}}r(e,null,!0)}function Vi(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,l(e),n(e),e.options.lineWrapping||f(e),e.options.mode=t.modeOption,In(e)}function Ki(e,t){if(t-=e.first,0>t||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(o>t){n=i;break}t-=o}return n.lines[t]}function Xi(e,t,n){var r=[]
 ,i=t.line;return e.iter(t.line,n.line+1,function(e){var o=e.text;i==n.line&&(o=o.slice(0,n.ch)),i==t.line&&(o=o.slice(t.ch)),r.push(o),++i}),r}function Yi(e,t,n){var r=[];return e.iter(t,n,function(e){r.push(e.text)}),r}function Zi(e,t){var n=t-e.height;if(n)for(var r=e;r;r=r.parent)r.height+=n}function Qi(e){if(null==e.parent)return null;for(var t=e.parent,n=Do(t.lines,e),r=t.parent;r;t=r,r=r.parent)for(var i=0;r.children[i]!=t;++i)n+=r.children[i].chunkSize();return n+t.first}function Ji(e,t){var n=e.first;e:do{for(var r=0;r<e.children.length;++r){var i=e.children[r],o=i.height;if(o>t){e=i;continue e}t-=o,n+=i.chunkSize()}return n}while(!e.lines);for(var r=0;r<e.lines.length;++r){var l=e.lines[r],s=l.height;if(s>t)break;t-=s}return n+r}function eo(e){e=gi(e);for(var t=0,n=e.parent,r=0;r<n.lines.length;++r){var i=n.lines[r];if(i==e)break;t+=i.height}for(var o=n.parent;o;n=o,o=n.parent)for(var r=0;r<o.children.length;++r){var l=o.children[r];if(l==n)break;t+=l.height}return t}functi
 on to(e){var t=e.order;return null==t&&(t=e.order=Js(e.text)),t}function no(e){this.done=[],this.undone=[],this.undoDepth=1/0,this.lastModTime=this.lastSelTime=0,this.lastOp=this.lastSelOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=e||1}function ro(e,t){var n={from:V(t.from),to:Vl(t),text:Xi(e,t.from,t.to)};return co(e,n,t.from.line,t.to.line+1),ji(e,function(e){co(e,n,t.from.line,t.to.line+1)},!0),n}function io(e){for(;e.length;){var t=Oo(e);if(!t.ranges)break;e.pop()}}function oo(e,t){return t?(io(e.done),Oo(e.done)):e.done.length&&!Oo(e.done).ranges?Oo(e.done):e.done.length>1&&!e.done[e.done.length-2].ranges?(e.done.pop(),Oo(e.done)):void 0}function lo(e,t,n,r){var i=e.history;i.undone.length=0;var o,l=+new Date;if((i.lastOp==r||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&e.cm&&i.lastModTime>l-e.cm.options.historyEventDelay||"*"==t.origin.charAt(0)))&&(o=oo(i,i.lastOp==r))){var s=Oo(o.changes);0==Hl(t.from,t.to)&&0==Hl(t.from,s
 .to)?s.to=Vl(t):o.changes.push(ro(e,t))}else{var a=Oo(i.done);for(a&&a.ranges||uo(e.sel,i.done),o={changes:[ro(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=l,i.lastOp=i.lastSelOp=r,i.lastOrigin=i.lastSelOrigin=t.origin,s||Ms(e,"historyAdded")}function so(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 ao(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||so(e,o,Oo(i.done),t))?i.do

<TRUNCATED>