diff --git a/simplemde.min.css b/simplemde.min.css index 727a7ae..828d86a 100644 --- a/simplemde.min.css +++ b/simplemde.min.css @@ -1,3 +1,9 @@ +/*! + * SimpleMDE v1.1.6 (https://github.com/NextStepWebs/simplemde-markdown-editor) + * Copyright Next Step Webs, Inc. + * Licensed under the MIT license + */ + .CodeMirror{height:auto;min-height:300px;border:1px solid #ddd;border-bottom-left-radius:4px;border-bottom-right-radius:4px;padding:10px}:-webkit-full-screen{background:#f9f9f5;padding:.5em 1em;width:100%;height:100%}:-moz-full-screen{padding:.5em 1em;background:#f9f9f5;width:100%;height:100%}.editor-wrapper{font:16px/1.62 "Helvetica Neue","Xin Gothic","Hiragino Sans GB","WenQuanYi Micro Hei","Microsoft YaHei",sans-serif;color:#2c3e50}.editor-wrapper input.title{font:18px "Helvetica Neue","Xin Gothic","Hiragino Sans GB","WenQuanYi Micro Hei","Microsoft YaHei",sans-serif;background:0 0;padding:4px;width:100%;border:none;outline:0;opacity:.6}.editor-toolbar{position:relative;opacity:.6;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;padding:0 10px;border-top:1px solid #bbb;border-left:1px solid #bbb;border-right:1px solid #bbb;border-top-left-radius:4px;border-top-right-radius:4px}.editor-toolbar:after,.editor-toolbar:before{display:block;content:' ';height:1px}.editor-toolbar:before{margin-bottom:8px}.editor-toolbar:after{margin-top:8px}.editor-toolbar:hover,.editor-wrapper input.title:focus,.editor-wrapper input.title:hover{opacity:.8}.editor-toolbar a{display:inline-block;text-align:center;text-decoration:none!important;color:#2c3e50!important;width:30px;height:30px;margin:0;border:1px solid transparent;border-radius:3px;cursor:pointer}.editor-toolbar a.active,.editor-toolbar a:hover{background:#fcfcfc;border-color:#95a5a6}.editor-toolbar a:before{line-height:30px}.editor-toolbar i.separator{display:inline-block;width:0;border-left:1px solid #d9d9d9;border-right:1px solid #fff;color:transparent;text-indent:-10px;margin:0 6px}.editor-toolbar a.icon-fullscreen{position:absolute;right:10px}.editor-toolbar.disabled-for-preview a:not(.fa-eye){pointer-events:none;background:#fff;border:none}.editor-statusbar{padding:8px 10px;font-size:12px;color:#959694;text-align:right}.editor-statusbar span{display:inline-block;min-width:4em;margin-left:1em}.editor-statusbar .lines:before{content:'lines: '}.editor-statusbar .words:before{content:'words: '}.editor-preview{padding:10px;position:absolute;width:100%;height:100%;top:0;left:0;background:#fafafa;z-index:9999;overflow:auto;display:none}.editor-preview-active{display:block}.editor-preview>p{margin-top:0}.editor-preview pre{background:#eee;margin-bottom:10px}.CodeMirror-scroll{overflow:auto}.CodeMirror-lines{padding:4px 0}.CodeMirror pre{padding:0 4px}.CodeMirror-scrollbar-filler{background-color:#fff}.CodeMirror div.CodeMirror-cursor{border-left:1px solid #000;z-index:3}.CodeMirror div.CodeMirror-secondarycursor{border-left:1px solid silver}.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor{width:auto;border:0;background:#7e7;z-index:1}.cm-s-paper .cm-keyword{color:#555}.cm-s-paper .cm-atom,.cm-s-paper .cm-number{color:#7f8c8d}.cm-s-paper .cm-def{color:#00f}.cm-s-paper .cm-variable{color:#000}.cm-s-paper .cm-variable-2{color:#555}.cm-s-paper .cm-variable-3{color:#085}.cm-s-paper .cm-operator,.cm-s-paper .cm-property{color:#000}.cm-s-paper .cm-comment{color:#959595}.cm-s-paper .cm-string{color:#7f8c8d}.cm-s-paper .cm-string-2{color:#f50}.cm-s-paper .cm-meta{color:#555}.cm-s-paper .cm-error{color:red}.cm-s-paper .cm-builtin,.cm-s-paper .cm-qualifier{color:#555}.cm-s-paper .cm-bracket{color:#997}.cm-s-paper .cm-attribute,.cm-s-paper .cm-tag{color:#7f8c8d}.cm-s-paper .cm-header{color:#000}.cm-s-paper .cm-quote{color:#888}.cm-s-paper .cm-hr{color:#999}.cm-s-paper .cm-link{color:#7f8c8d}.cm-negative{color:#d44}.cm-positive{color:#292}.cm-header,.cm-strong{font-weight:700}.cm-em{font-style:italic}.cm-link{text-decoration:underline}.cm-invalidchar{color:red}div.CodeMirror span.CodeMirror-matchingbracket{color:#0f0}div.CodeMirror span.CodeMirror-nonmatchingbracket{color:#f22}.CodeMirror{position:relative;overflow:hidden}.CodeMirror-scroll{margin-bottom:-30px;margin-right:-30px;padding-bottom:30px;padding-right:30px;height:100%;min-height:300px;outline:0;position:relative}.CodeMirror-sizer{position:relative}.CodeMirror-hscrollbar,.CodeMirror-scrollbar-filler,.CodeMirror-vscrollbar{position:absolute;z-index:6;display:none}.CodeMirror-vscrollbar{right:0;top:0;overflow-x:hidden;overflow-y:scroll}.CodeMirror-hscrollbar{bottom:0;left:0;overflow-y:hidden;overflow-x:scroll}.CodeMirror-scrollbar-filler{right:0;bottom:0;z-index:6}.CodeMirror-lines{cursor:text}.CodeMirror pre{-moz-border-radius:0;-webkit-border-radius:0;-o-border-radius:0;border-radius:0;border-width:0;background:0 0;font-family:inherit;font-size:inherit;margin:0;white-space:pre-wrap;word-wrap:normal;line-height:inherit;color:inherit;z-index:2;position:relative;overflow:visible}.CodeMirror-wrap pre{word-wrap:break-word;white-space:pre-wrap;word-break:normal}.CodeMirror-linebackground{position:absolute;left:0;right:0;top:0;bottom:0;z-index:0}.CodeMirror-linewidget{position:relative;z-index:2;overflow:auto}.CodeMirror-widget{display:inline-block}.CodeMirror-wrap .CodeMirror-scroll{overflow-x:hidden}.CodeMirror-measure{position:absolute;width:100%;height:0;overflow:hidden;visibility:hidden}.CodeMirror-measure pre{position:static}.CodeMirror div.CodeMirror-cursor{position:absolute;visibility:hidden;border-right:none;width:0}.CodeMirror-focused div.CodeMirror-cursor{visibility:visible}.CodeMirror-selected{background:#d9d9d9}.CodeMirror-focused .CodeMirror-selected{background:#BDC3C7}.cm-searching{background:#ffa;background:rgba(255,255,0,.4)}@media print{.CodeMirror div.CodeMirror-cursor{visibility:hidden}}.CodeMirror .CodeMirror-code .cm-header-1{font-size:200%;line-height:200%}.CodeMirror .CodeMirror-code .cm-header-2{font-size:160%;line-height:160%}.CodeMirror .CodeMirror-code .cm-header-3{font-size:125%;line-height:125%}.CodeMirror .CodeMirror-code .cm-header-4{font-size:110%;line-height:110%}.CodeMirror .CodeMirror-code .cm-comment{background:#eee;border-radius:2px}/*! * Font Awesome 4.3.0 by @davegandy - http://fontawesome.io - @fontawesome * License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License) diff --git a/simplemde.min.js b/simplemde.min.js index 9515d73..7d6c612 100644 --- a/simplemde.min.js +++ b/simplemde.min.js @@ -1,3 +1,9 @@ +/*! + * SimpleMDE v1.1.6 (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\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=19968?n[i].length:1;return r}function SimpleMDE(e){e=e||{},e.element&&(this.element=e.element),e.toolbar=e.toolbar||SimpleMDE.toolbar,e.hasOwnProperty("status")||(e.status=["lines","words","cursor"]),this.options=e,this.element&&this.render()}!function(e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else{if("function"==typeof define&&define.amd)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;hgl&&(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,zt(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;lt.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.gutters.offsetWidth,o=r+"px",l=0;l=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)&&(Pn(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.viewFroml&&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,zt(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.display.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;rgl){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=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;igl&&(e.node.style.zIndex=2)),e.node}function P(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 z(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=z(e,t);t.text==t.node&&(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){P(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["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),i)for(var s=0;s1&&(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-1){l=Pr(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=Pr(e,i.head.line,"smart"));l&&wo(e,"electricInput",e,i.head.line)}}}function tt(e){for(var t=[],n=[],r=0;ri?u.map:c[i],l=0;li?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.getAttribute("contenteditable"))return;for(var f=0;f=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.linen?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=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.linet&&(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.bottoma.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.top0?t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(n=!n)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function zt(e,t){e.doc.mode.startState&&e.doc.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&&hn?(zt(e,e.options.workDelay),!0):void 0}),i.length&&An(e,function(){for(var t=0;tl;--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&&o2&&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;rn)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=n.lineN&&tt?(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(;sc;c++){for(;s&&Bo(t.line.text.charAt(o.coverStart+s));)--s;for(;o.coverStart+agl&&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]:zl}else i=Fs(l,s,a).getBoundingClientRect()||zl;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}:zl}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;cn.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:lm)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=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.adjustWidthTo+"px",e.maxScrollLefto;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&&nt)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Dl&&vi(e.doc,t)i.viewFrom?Pn(e):(i.viewFrom+=r,i.viewTo+=r);else if(t<=i.viewFrom&&n>=i.viewTo)Pn(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):Pn(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):Pn(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):Pn(e)}var a=i.externalMeasured;a&&(n=i.lineN&&t=r.viewTo)){var o=r.view[zn(e,t)];if(null!=o.node){var l=o.changes||(o.changes=[]);-1==Do(l,n)&&l.push(n)}}}function Pn(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function zn(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;rt)return r}function Bn(e,t,n,r){var i,o=zn(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.viewFromn&&(r.view=r.view.slice(0,zn(e,n)))),r.viewTo=n}function Rn(e){for(var t=e.display.view,n=0,r=0;r400}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.scrollTop),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.wrapper;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;Pl&&Pl.time>i-400&&0==Hl(Pl.pos,n)?r="triple":Fl&&Fl.time>i-400&&0==Hl(Fl.pos,n)?(r="double",Pl={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=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.linev.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=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);else{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;al.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;uc?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;rgl&&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()),Pt(e))}function 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=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=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){return 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;re.lastLine())){if(t.from.lineo&&(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.lineWrapping||(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),zt(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.lineSpace.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.scrollLeft,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 Pr(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.options.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=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+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=Po(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;l0||0==l&&o.clearWhenEmpty!==!1)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=_o("span",[o.replacedWith],"CodeMirror-widget"),r.handleMouseEvents||o.widgetNode.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=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=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 h=0;hh;++h)p.push(g);p.push(a)}return p}function ri(e){for(var t=0;t0)){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=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;io;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.pose.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(;uu;){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]),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=Pi,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.lastChild.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 Pi(e,t,n,r,i,o,l){if(t){var s=e.splitSpaces?t.replace(/ {3,}/g,zi):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 zi(e){for(var t=" ",n=0;nu&&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;bp||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=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;gn;++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;tt||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;rt){e=i;continue e}t-=o,n+=i.chunkSize()}return n}while(!e.lines);for(var r=0;rt)break;t-=s}return n+r}function eo(e){e=gi(e);for(var t=0,n=e.parent,r=0;r1&&!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.done[i.done.length-1]=t:uo(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=n,r&&r.clearRedo!==!1&&io(i.undone)}function uo(e,t){var n=Oo(t);n&&n.ranges&&n.equals(e)||t.push(e)}function co(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 ho(e){if(!e)return null;for(var t,n=0;n-1&&(Oo(s)[h]=c[h],delete c[h])}}}return i}function go(e,t,n,r){n0}function Mo(e){e.prototype.on=function(e,t){Ss(this,e,t)},e.prototype.off=function(e,t){Ls(this,e,t)}}function To(){this.id=null}function No(e,t,n){for(var r=0,i=0;;){var o=e.indexOf(" ",r);-1==o&&(o=e.length);var l=o-r;if(o==e.length||i+l>=t)return r+Math.min(l,t-i);if(i+=o-r,i+=n-i%n,r=o+1,i>=t)return r}}function Ao(e){for(;Es.length<=e;)Es.push(Oo(Es)+" ");return Es[e]}function Oo(e){return e[e.length-1]}function Do(e,t){for(var n=0;n-1&&zs(e)?!0:t.test(e):zs(e)}function zo(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function Bo(e){return e.charCodeAt(0)>=768&&Bs.test(e)}function _o(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;o0;--t)e.removeChild(e.firstChild);return e}function qo(e,t){return Ro(e).appendChild(t)}function Uo(){return document.activeElement}function Go(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function $o(e,t){for(var n=e.split(" "),r=0;r2&&!(pl&&8>gl))}var n=Rs?_o("span","​"):_o("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return n.setAttribute("cm-text",""),n}function Yo(e){if(null!=qs)return qs;var t=qo(e,document.createTextNode("AخA")),n=Fs(t,0,1).getBoundingClientRect();if(!n||n.left==n.right)return!1;var r=Fs(t,1,2).getBoundingClientRect();return qs=r.right-n.right<3}function Zo(e){if(null!=Ys)return Ys;var t=qo(e,_o("span","x")),n=t.getBoundingClientRect(),r=Fs(t,0,1).getBoundingClientRect();return Ys=Math.abs(n.left-r.left)>1}function Qo(e,t,n,r){if(!e)return r(t,n,"ltr");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"),i=!0)}i||r(t,n,"ltr")}function Jo(e){return e.level%2?e.to:e.from}function el(e){return e.level%2?e.from:e.to}function tl(e){var t=to(e);return t?Jo(t[0]):0}function nl(e){var t=to(e);return t?el(Oo(t)):e.text.length}function rl(e,t){var n=Ki(e.doc,t),r=gi(n);r!=n&&(t=Qi(r));var i=to(r),o=i?i[0].level%2?nl(r):tl(r):0;return Wl(t,o)}function il(e,t){for(var n,r=Ki(e.doc,t);n=di(r);)r=n.find(1,!0).line,t=null;var i=to(r),o=i?i[0].level%2?tl(r):nl(r):r.text.length;return Wl(null==t?Qi(r):t,o)}function ol(e,t){var n=rl(e,t.line),r=Ki(e.doc,n.line),i=to(r);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 Wl(n.line,l?0:o)}return n}function ll(e,t,n){var r=e[0].level;return t==r?!0:n==r?!1:n>t}function sl(e,t){Qs=null;for(var n,r=0;rt)return r;if(i.from==t||i.to==t){if(null!=n)return ll(e,i.level,e[n].level)?(i.from!=i.to&&(Qs=n),r):(i.from!=i.to&&(Qs=r),n);n=r}}return n}function al(e,t,n,r){if(!r)return t+n;do t+=n;while(t>0&&Bo(e.text.charAt(t)));return t}function ul(e,t,n,r){var i=to(e);if(!i)return cl(e,t,n,r);for(var o=sl(i,t),l=i[o],s=al(e,t,l.level%2?-n:n,r);;){if(s>l.from&&s0==l.level%2?l.to:l.from);if(l=i[o+=n],!l)return null;s=n>0==l.level%2?al(e,l.to,-1,r):al(e,l.from,1,r)}}function cl(e,t,n,r){var i=t+n;if(r)for(;i>0&&Bo(e.text.charAt(i));)i+=n;return 0>i||i>e.text.length?null:i}var hl=/gecko\/\d/i.test(navigator.userAgent),fl=/MSIE \d/.test(navigator.userAgent),dl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),pl=fl||dl,gl=pl&&(fl?document.documentMode||6:dl[1]),ml=/WebKit\//.test(navigator.userAgent),vl=ml&&/Qt\/\d+\.\d+/.test(navigator.userAgent),yl=/Chrome\//.test(navigator.userAgent),bl=/Opera\//.test(navigator.userAgent),xl=/Apple Computer/.test(navigator.vendor),wl=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),Cl=/PhantomJS/.test(navigator.userAgent),kl=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),Sl=kl||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),Ll=kl||/Mac/.test(navigator.platform),Ml=/win/i.test(navigator.platform),Tl=bl&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);