| @@ -1 +1,13945 @@ | ||
| 1 | -(()=>{var e={665(){document.body.addEventListener("click",function(e){const t=e.target;if("A"===t.tagName&&t.hasAttribute("data-hf-confirm")){if(window.confirm(t.getAttribute("data-hf-confirm")))return;e.preventDefault()}},!0)},688(){function e(e){const r=this.getAttribute("data-tab-target");if("submissions"!==r){for(let e=0;e<n.length;e++)n[e].classList.toggle("nav-tab-active",n[e]===this);this.blur();for(let e=0;e<t.length;e++){const n=t[e];n.classList.toggle("hf-tab-active",n.getAttribute("data-tab")===r)}if(document.title=document.title.replace(document.title.split(" - ").shift(),`${this.innerText} `),window.history){let e=window.location.href;e=e.replace(/&tab=\w+/,""),e+=`&tab=${r}`,window.history.replaceState({tab:r},document.title,e)}e.preventDefault()}}const t=document.querySelectorAll(".hf-tab"),n=document.querySelectorAll("#hf-tabs-nav a");for(let t=0;t<n.length;t++)n[t].addEventListener("click",e)},819(e,t,n){!function(e){e.defineOption("autoCloseTags",!1,function(a,l,s){if(s!=e.Init&&s&&a.removeKeyMap("autoCloseTags"),l){var c={name:"autoCloseTags"};"object"==typeof l&&!1===l.whenClosing||(c["'/'"]=function(t){return function(t){return t.getOption("disableInput")?e.Pass:r(t,!0)}(t)}),"object"==typeof l&&!1===l.whenOpening||(c["'>'"]=function(r){return function(r){if(r.getOption("disableInput"))return e.Pass;for(var a=r.listSelections(),l=[],s=r.getOption("autoCloseTags"),c=0;c<a.length;c++){if(!a[c].empty())return e.Pass;var u=a[c].head,d=r.getTokenAt(u),f=e.innerMode(r.getMode(),d.state),h=f.state,p=f.mode.xmlCurrentTag&&f.mode.xmlCurrentTag(h),m=p&&p.name;if(!m)return e.Pass;var g="html"==f.mode.configuration,v="object"==typeof s&&s.dontCloseTags||g&&t,y="object"==typeof s&&s.indentTags||g&&n;d.end>u.ch&&(m=m.slice(0,m.length-d.end+u.ch));var b=m.toLowerCase();if(!m||"string"==d.type&&(d.end!=u.ch||!/[\"\']/.test(d.string.charAt(d.string.length-1))||1==d.string.length)||"tag"==d.type&&p.close||d.string.indexOf("/")==u.ch-d.start-1||v&&i(v,b)>-1||o(r,f.mode.xmlCurrentContext&&f.mode.xmlCurrentContext(h)||[],m,u,!0))return e.Pass;var w="object"==typeof s&&s.emptyTags;if(w&&i(w,m)>-1)l[c]={text:"/>",newPos:e.Pos(u.line,u.ch+2)};else{var x=y&&i(y,b)>-1;l[c]={indent:x,text:">"+(x?"\n\n":"")+"</"+m+">",newPos:x?e.Pos(u.line+1,0):e.Pos(u.line,u.ch+1)}}}var k="object"==typeof s&&s.dontIndentOnAutoClose;for(c=a.length-1;c>=0;c--){var C=l[c];r.replaceRange(C.text,a[c].head,a[c].anchor,"+insert");var _=r.listSelections().slice(0);_[c]={head:C.newPos,anchor:C.newPos},r.setSelections(_),!k&&C.indent&&(r.indentLine(C.newPos.line,null,!0),r.indentLine(C.newPos.line+1,null,!0))}}(r)}),a.addKeyMap(c)}});var t=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],n=["applet","blockquote","body","button","div","dl","fieldset","form","frameset","h1","h2","h3","h4","h5","h6","head","html","iframe","layer","legend","object","ol","p","select","table","ul"];function r(t,n){for(var r=t.listSelections(),i=[],a=n?"/":"</",l=t.getOption("autoCloseTags"),s="object"==typeof l&&l.dontIndentOnSlash,c=0;c<r.length;c++){if(!r[c].empty())return e.Pass;var u=r[c].head,d=t.getTokenAt(u),f=e.innerMode(t.getMode(),d.state),h=f.state;if(n&&("string"==d.type||"<"!=d.string.charAt(0)||d.start!=u.ch-1))return e.Pass;var p,m="xml"!=f.mode.name&&"htmlmixed"==t.getMode().name;if(m&&"javascript"==f.mode.name)p=a+"script";else if(m&&"css"==f.mode.name)p=a+"style";else{var g=f.mode.xmlCurrentContext&&f.mode.xmlCurrentContext(h),v=g.length?g[g.length-1]:"";if(!g||g.length&&o(t,g,v,u))return e.Pass;p=a+v}">"!=t.getLine(u.line).charAt(d.end)&&(p+=">"),i[c]=p}if(t.replaceSelections(i),r=t.listSelections(),!s)for(c=0;c<r.length;c++)(c==r.length-1||r[c].head.line<r[c+1].head.line)&&t.indentLine(r[c].head.line)}function i(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;n<r;++n)if(e[n]==t)return n;return-1}function o(t,n,r,i,o){if(!e.scanForClosingTag)return!1;var a=Math.min(t.lastLine()+1,i.line+500),l=e.scanForClosingTag(t,i,null,a);if(!l||l.tag!=r)return!1;for(var s=o?1:0,c=n.length-1;c>=0&&n[c]==r;c--)++s;for(i=l.to,c=1;c<s;c++){var u=e.scanForClosingTag(t,i,null,a);if(!u||u.tag!=r)return!1;i=u.to}return!0}e.commands.closeTag=function(e){return r(e)}}(n(237),n(753))},115(e,t,n){!function(e){"use strict";function t(e){e.state.tagHit&&e.state.tagHit.clear(),e.state.tagOther&&e.state.tagOther.clear(),e.state.tagHit=e.state.tagOther=null}function n(n){n.state.failedTagMatch=!1,n.operation(function(){if(t(n),!n.somethingSelected()){var r=n.getCursor(),i=n.getViewport();i.from=Math.min(i.from,r.line),i.to=Math.max(r.line+1,i.to);var o=e.findMatchingTag(n,r,i);if(o){if(n.state.matchBothTags){var a="open"==o.at?o.open:o.close;a&&(n.state.tagHit=n.markText(a.from,a.to,{className:"CodeMirror-matchingtag"}))}var l="close"==o.at?o.open:o.close;l?n.state.tagOther=n.markText(l.from,l.to,{className:"CodeMirror-matchingtag"}):n.state.failedTagMatch=!0}}})}function r(e){e.state.failedTagMatch&&n(e)}e.defineOption("matchTags",!1,function(i,o,a){a&&a!=e.Init&&(i.off("cursorActivity",n),i.off("viewportChange",r),t(i)),o&&(i.state.matchBothTags="object"==typeof o&&o.bothTags,i.on("cursorActivity",n),i.on("viewportChange",r),n(i))}),e.commands.toMatchingTag=function(t){var n=e.findMatchingTag(t,t.getCursor());if(n){var r="close"==n.at?n.open:n.close;r&&t.extendSelection(r.to,r.from)}}}(n(237),n(753))},753(e,t,n){!function(e){"use strict";var t=e.Pos;function n(e,t){return e.line-t.line||e.ch-t.ch}var r="A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",i=new RegExp("<(/?)(["+r+"]["+r+"-:.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*)","g");function o(e,t,n,r){this.line=t,this.ch=n,this.cm=e,this.text=e.getLine(t),this.min=r?Math.max(r.from,e.firstLine()):e.firstLine(),this.max=r?Math.min(r.to-1,e.lastLine()):e.lastLine()}function a(e,n){var r=e.cm.getTokenTypeAt(t(e.line,n));return r&&/\btag\b/.test(r)}function l(e){if(!(e.line>=e.max))return e.ch=0,e.text=e.cm.getLine(++e.line),!0}function s(e){if(!(e.line<=e.min))return e.text=e.cm.getLine(--e.line),e.ch=e.text.length,!0}function c(e){for(;;){var t=e.text.indexOf(">",e.ch);if(-1==t){if(l(e))continue;return}if(a(e,t+1)){var n=e.text.lastIndexOf("/",t),r=n>-1&&!/\S/.test(e.text.slice(n+1,t));return e.ch=t+1,r?"selfClose":"regular"}e.ch=t+1}}function u(e){for(;;){var t=e.ch?e.text.lastIndexOf("<",e.ch-1):-1;if(-1==t){if(s(e))continue;return}if(a(e,t+1)){i.lastIndex=t,e.ch=t;var n=i.exec(e.text);if(n&&n.index==t)return n}else e.ch=t}}function d(e){for(;;){i.lastIndex=e.ch;var t=i.exec(e.text);if(!t){if(l(e))continue;return}if(a(e,t.index+1))return e.ch=t.index+t[0].length,t;e.ch=t.index+1}}function f(e){for(;;){var t=e.ch?e.text.lastIndexOf(">",e.ch-1):-1;if(-1==t){if(s(e))continue;return}if(a(e,t+1)){var n=e.text.lastIndexOf("/",t),r=n>-1&&!/\S/.test(e.text.slice(n+1,t));return e.ch=t+1,r?"selfClose":"regular"}e.ch=t}}function h(e,n){for(var r=[];;){var i,o=d(e),a=e.line,l=e.ch-(o?o[0].length:0);if(!o||!(i=c(e)))return;if("selfClose"!=i)if(o[1]){for(var s=r.length-1;s>=0;--s)if(r[s]==o[2]){r.length=s;break}if(s<0&&(!n||n==o[2]))return{tag:o[2],from:t(a,l),to:t(e.line,e.ch)}}else r.push(o[2])}}function p(e,n){for(var r=[];;){var i=f(e);if(!i)return;if("selfClose"!=i){var o=e.line,a=e.ch,l=u(e);if(!l)return;if(l[1])r.push(l[2]);else{for(var s=r.length-1;s>=0;--s)if(r[s]==l[2]){r.length=s;break}if(s<0&&(!n||n==l[2]))return{tag:l[2],from:t(e.line,e.ch),to:t(o,a)}}}else u(e)}}e.registerHelper("fold","xml",function(e,r){for(var i=new o(e,r.line,0);;){var a=d(i);if(!a||i.line!=r.line)return;var l=c(i);if(!l)return;if(!a[1]&&"selfClose"!=l){var s=t(i.line,i.ch),u=h(i,a[2]);return u&&n(u.from,s)>0?{from:s,to:u.from}:null}}}),e.findMatchingTag=function(e,r,i){var a=new o(e,r.line,r.ch,i);if(-1!=a.text.indexOf(">")||-1!=a.text.indexOf("<")){var l=c(a),s=l&&t(a.line,a.ch),d=l&&u(a);if(l&&d&&!(n(a,r)>0)){var f={from:t(a.line,a.ch),to:s,tag:d[2]};return"selfClose"==l?{open:f,close:null,at:"open"}:d[1]?{open:p(a,d[2]),close:f,at:"close"}:{open:f,close:h(a=new o(e,s.line,s.ch,i),d[2]),at:"open"}}}},e.findEnclosingTag=function(e,t,n,r){for(var i=new o(e,t.line,t.ch,n);;){var a=p(i,r);if(!a)break;var l=h(new o(e,t.line,t.ch,n),a.tag);if(l)return{open:a,close:l}}},e.scanForClosingTag=function(e,t,n,r){return h(new o(e,t.line,t.ch,r?{from:0,to:r}:null),n)}}(n(237))},237(e){e.exports=function(){"use strict";var e=navigator.userAgent,t=navigator.platform,n=/gecko\/\d/i.test(e),r=/MSIE \d/.test(e),i=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(e),o=/Edge\/(\d+)/.exec(e),a=r||i||o,l=a&&(r?document.documentMode||6:+(o||i)[1]),s=!o&&/WebKit\//.test(e),c=s&&/Qt\/\d+\.\d+/.test(e),u=!o&&/Chrome\/(\d+)/.exec(e),d=u&&+u[1],f=/Opera\//.test(e),h=/Apple Computer/.test(navigator.vendor),p=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(e),m=/PhantomJS/.test(e),g=h&&(/Mobile\/\w+/.test(e)||navigator.maxTouchPoints>2),v=/Android/.test(e),y=g||v||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(e),b=g||/Mac/.test(t),w=/\bCrOS\b/.test(e),x=/win/i.test(t),k=f&&e.match(/Version\/(\d*\.\d*)/);k&&(k=Number(k[1])),k&&k>=15&&(f=!1,s=!0);var C=b&&(c||f&&(null==k||k<12.11)),_=n||a&&l>=9;function S(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}var T,L=function(e,t){var n=e.className,r=S(t).exec(n);if(r){var i=n.slice(r.index+r[0].length);e.className=n.slice(0,r.index)+(i?r[1]+i:"")}};function M(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function N(e,t){return M(e).appendChild(t)}function A(e,t,n,r){var i=document.createElement(e);if(n&&(i.className=n),r&&(i.style.cssText=r),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o<t.length;++o)i.appendChild(t[o]);return i}function O(e,t,n,r){var i=A(e,t,n,r);return i.setAttribute("role","presentation"),i}function D(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do{if(11==t.nodeType&&(t=t.host),t==e)return!0}while(t=t.parentNode)}function F(e){var t,n=e.ownerDocument||e;try{t=e.activeElement}catch(e){t=n.body||null}for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t}function E(e,t){var n=e.className;S(t).test(n)||(e.className+=(n?" ":"")+t)}function P(e,t){for(var n=e.split(" "),r=0;r<n.length;r++)n[r]&&!S(n[r]).test(t)&&(t+=" "+n[r]);return t}T=document.createRange?function(e,t,n,r){var i=document.createRange();return i.setEnd(r||e,n),i.setStart(e,t),i}:function(e,t,n){var r=document.body.createTextRange();try{r.moveToElementText(e.parentNode)}catch(e){return r}return r.collapse(!0),r.moveEnd("character",n),r.moveStart("character",t),r};var W=function(e){e.select()};function z(e){return e.display.wrapper.ownerDocument}function H(e){return I(e.display.wrapper)}function I(e){return e.getRootNode?e.getRootNode():e.ownerDocument}function R(e){return z(e).defaultView}function B(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function j(e,t,n){for(var r in t||(t={}),e)!Object.prototype.hasOwnProperty.call(e,r)||!1===n&&Object.prototype.hasOwnProperty.call(t,r)||(t[r]=e[r]);return t}function q(e,t,n,r,i){null==t&&-1==(t=e.search(/[^\s\u00a0]/))&&(t=e.length);for(var o=r||0,a=i||0;;){var l=e.indexOf("\t",o);if(l<0||l>=t)return a+(t-o);a+=l-o,a+=n-a%n,o=l+1}}g?W=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:a&&(W=function(e){try{e.select()}catch(e){}});var U=function(){this.id=null,this.f=null,this.time=0,this.handler=B(this.onTimeout,this)};function V(e,t){for(var n=0;n<e.length;++n)if(e[n]==t)return n;return-1}U.prototype.onTimeout=function(e){e.id=0,e.time<=+new Date?e.f():setTimeout(e.handler,e.time-+new Date)},U.prototype.set=function(e,t){this.f=t;var n=+new Date+e;(!this.id||n<this.time)&&(clearTimeout(this.id),this.id=setTimeout(this.handler,e),this.time=n)};var K={toString:function(){return"CodeMirror.Pass"}},$={scroll:!1},G={origin:"*mouse"},X={origin:"+move"};function Y(e,t,n){for(var r=0,i=0;;){var o=e.indexOf("\t",r);-1==o&&(o=e.length);var a=o-r;if(o==e.length||i+a>=t)return r+Math.min(a,t-i);if(i+=o-r,r=o+1,(i+=n-i%n)>=t)return r}}var Z=[""];function Q(e){for(;Z.length<=e;)Z.push(J(Z)+" ");return Z[e]}function J(e){return e[e.length-1]}function ee(e,t){for(var n=[],r=0;r<e.length;r++)n[r]=t(e[r],r);return n}function te(){}function ne(e,t){var n;return Object.create?n=Object.create(e):(te.prototype=e,n=new te),t&&j(t,n),n}var re=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;function ie(e){return/\w/.test(e)||e>""&&(e.toUpperCase()!=e.toLowerCase()||re.test(e))}function oe(e,t){return t?!!(t.source.indexOf("\\w")>-1&&ie(e))||t.test(e):ie(e)}function ae(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}var le=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;function se(e){return e.charCodeAt(0)>=768&&le.test(e)}function ce(e,t,n){for(;(n<0?t>0:t<e.length)&&se(e.charAt(t));)t+=n;return t}function ue(e,t,n){for(var r=t>n?-1:1;;){if(t==n)return t;var i=(t+n)/2,o=r<0?Math.ceil(i):Math.floor(i);if(o==t)return e(o)?t:n;e(o)?n=o:t=o+r}}var de=null;function fe(e,t,n){var r;de=null;for(var i=0;i<e.length;++i){var o=e[i];if(o.from<t&&o.to>t)return i;o.to==t&&(o.from!=o.to&&"before"==n?r=i:de=i),o.from==t&&(o.from!=o.to&&"before"!=n?r=i:de=i)}return null!=r?r:de}var he=function(){function e(e){return e<=247?"bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN".charAt(e):1424<=e&&e<=1524?"R":1536<=e&&e<=1785?"nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111".charAt(e-1536):1774<=e&&e<=2220?"r":8192<=e&&e<=8203?"w":8204==e?"b":"L"}var t=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,n=/[stwN]/,r=/[LRr]/,i=/[Lb1n]/,o=/[1n]/;function a(e,t,n){this.level=e,this.from=t,this.to=n}return function(l,s){var c="ltr"==s?"L":"R";if(0==l.length||"ltr"==s&&!t.test(l))return!1;for(var u=l.length,d=[],f=0;f<u;++f)d.push(e(l.charCodeAt(f)));for(var h=0,p=c;h<u;++h){var m=d[h];"m"==m?d[h]=p:p=m}for(var g=0,v=c;g<u;++g){var y=d[g];"1"==y&&"r"==v?d[g]="n":r.test(y)&&(v=y,"r"==y&&(d[g]="R"))}for(var b=1,w=d[0];b<u-1;++b){var x=d[b];"+"==x&&"1"==w&&"1"==d[b+1]?d[b]="1":","!=x||w!=d[b+1]||"1"!=w&&"n"!=w||(d[b]=w),w=x}for(var k=0;k<u;++k){var C=d[k];if(","==C)d[k]="N";else if("%"==C){var _=void 0;for(_=k+1;_<u&&"%"==d[_];++_);for(var S=k&&"!"==d[k-1]||_<u&&"1"==d[_]?"1":"N",T=k;T<_;++T)d[T]=S;k=_-1}}for(var L=0,M=c;L<u;++L){var N=d[L];"L"==M&&"1"==N?d[L]="L":r.test(N)&&(M=N)}for(var A=0;A<u;++A)if(n.test(d[A])){var O=void 0;for(O=A+1;O<u&&n.test(d[O]);++O);for(var D="L"==(A?d[A-1]:c),F=D==("L"==(O<u?d[O]:c))?D?"L":"R":c,E=A;E<O;++E)d[E]=F;A=O-1}for(var P,W=[],z=0;z<u;)if(i.test(d[z])){var H=z;for(++z;z<u&&i.test(d[z]);++z);W.push(new a(0,H,z))}else{var I=z,R=W.length,B="rtl"==s?1:0;for(++z;z<u&&"L"!=d[z];++z);for(var j=I;j<z;)if(o.test(d[j])){I<j&&(W.splice(R,0,new a(1,I,j)),R+=B);var q=j;for(++j;j<z&&o.test(d[j]);++j);W.splice(R,0,new a(2,q,j)),R+=B,I=j}else++j;I<z&&W.splice(R,0,new a(1,I,z))}return"ltr"==s&&(1==W[0].level&&(P=l.match(/^\s+/))&&(W[0].from=P[0].length,W.unshift(new a(0,0,P[0].length))),1==J(W).level&&(P=l.match(/\s+$/))&&(J(W).to-=P[0].length,W.push(new a(0,u-P[0].length,u)))),"rtl"==s?W.reverse():W}}();function pe(e,t){var n=e.order;return null==n&&(n=e.order=he(e.text,t)),n}var me=[],ge=function(e,t,n){if(e.addEventListener)e.addEventListener(t,n,!1);else if(e.attachEvent)e.attachEvent("on"+t,n);else{var r=e._handlers||(e._handlers={});r[t]=(r[t]||me).concat(n)}};function ve(e,t){return e._handlers&&e._handlers[t]||me}function ye(e,t,n){if(e.removeEventListener)e.removeEventListener(t,n,!1);else if(e.detachEvent)e.detachEvent("on"+t,n);else{var r=e._handlers,i=r&&r[t];if(i){var o=V(i,n);o>-1&&(r[t]=i.slice(0,o).concat(i.slice(o+1)))}}}function be(e,t){var n=ve(e,t);if(n.length)for(var r=Array.prototype.slice.call(arguments,2),i=0;i<n.length;++i)n[i].apply(null,r)}function we(e,t,n){return"string"==typeof t&&(t={type:t,preventDefault:function(){this.defaultPrevented=!0}}),be(e,n||t.type,e,t),Te(t)||t.codemirrorIgnore}function xe(e){var t=e._handlers&&e._handlers.cursorActivity;if(t)for(var n=e.curOp.cursorActivityHandlers||(e.curOp.cursorActivityHandlers=[]),r=0;r<t.length;++r)-1==V(n,t[r])&&n.push(t[r])}function ke(e,t){return ve(e,t).length>0}function Ce(e){e.prototype.on=function(e,t){ge(this,e,t)},e.prototype.off=function(e,t){ye(this,e,t)}}function _e(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function Se(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function Te(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function Le(e){_e(e),Se(e)}function Me(e){return e.target||e.srcElement}function Ne(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),b&&e.ctrlKey&&1==t&&(t=3),t}var Ae,Oe,De=function(){if(a&&l<9)return!1;var e=A("div");return"draggable"in e||"dragDrop"in e}();function Fe(e){if(null==Ae){var t=A("span","");N(e,A("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(Ae=t.offsetWidth<=1&&t.offsetHeight>2&&!(a&&l<8))}var n=Ae?A("span",""):A("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return n.setAttribute("cm-text",""),n}function Ee(e){if(null!=Oe)return Oe;var t=N(e,document.createTextNode("AخA")),n=T(t,0,1).getBoundingClientRect(),r=T(t,1,2).getBoundingClientRect();return M(e),!(!n||n.left==n.right)&&(Oe=r.right-n.right<3)}var Pe,We=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,n=[],r=e.length;t<=r;){var i=e.indexOf("\n",t);-1==i&&(i=e.length);var o=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),a=o.indexOf("\r");-1!=a?(n.push(o.slice(0,a)),t+=a+1):(n.push(o),t=i+1)}return n}:function(e){return e.split(/\r\n?|\n/)},ze=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(e){return!1}}:function(e){var t;try{t=e.ownerDocument.selection.createRange()}catch(e){}return!(!t||t.parentElement()!=e)&&0!=t.compareEndPoints("StartToEnd",t)},He="oncopy"in(Pe=A("div"))||(Pe.setAttribute("oncopy","return;"),"function"==typeof Pe.oncopy),Ie=null;var Re={},Be={};function je(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),Re[e]=t}function qe(e){if("string"==typeof e&&Be.hasOwnProperty(e))e=Be[e];else if(e&&"string"==typeof e.name&&Be.hasOwnProperty(e.name)){var t=Be[e.name];"string"==typeof t&&(t={name:t}),(e=ne(t,e)).name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return qe("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return qe("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function Ue(e,t){t=qe(t);var n=Re[t.name];if(!n)return Ue(e,"text/plain");var r=n(e,t);if(Ve.hasOwnProperty(t.name)){var i=Ve[t.name];for(var o in i)i.hasOwnProperty(o)&&(r.hasOwnProperty(o)&&(r["_"+o]=r[o]),r[o]=i[o])}if(r.name=t.name,t.helperType&&(r.helperType=t.helperType),t.modeProps)for(var a in t.modeProps)r[a]=t.modeProps[a];return r}var Ve={};function Ke(e,t){j(t,Ve.hasOwnProperty(e)?Ve[e]:Ve[e]={})}function $e(e,t){if(!0===t)return t;if(e.copyState)return e.copyState(t);var n={};for(var r in t){var i=t[r];i instanceof Array&&(i=i.concat([])),n[r]=i}return n}function Ge(e,t){for(var n;e.innerMode&&(n=e.innerMode(t))&&n.mode!=e;)t=n.state,e=n.mode;return n||{mode:e,state:t}}function Xe(e,t,n){return!e.startState||e.startState(t,n)}var Ye=function(e,t,n){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0,this.lineOracle=n};function Ze(e,t){if((t-=e.first)<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var n=e;!n.lines;)for(var r=0;;++r){var i=n.children[r],o=i.chunkSize();if(t<o){n=i;break}t-=o}return n.lines[t]}function Qe(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 Je(e,t,n){var r=[];return e.iter(t,n,function(e){r.push(e.text)}),r}function et(e,t){var n=t-e.height;if(n)for(var r=e;r;r=r.parent)r.height+=n}function tt(e){if(null==e.parent)return null;for(var t=e.parent,n=V(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 nt(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(t<o){e=i;continue e}t-=o,n+=i.chunkSize()}return n}while(!e.lines);for(var a=0;a<e.lines.length;++a){var l=e.lines[a].height;if(t<l)break;t-=l}return n+a}function rt(e,t){return t>=e.first&&t<e.first+e.size}function it(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function ot(e,t,n){if(void 0===n&&(n=null),!(this instanceof ot))return new ot(e,t,n);this.line=e,this.ch=t,this.sticky=n}function at(e,t){return e.line-t.line||e.ch-t.ch}function lt(e,t){return e.sticky==t.sticky&&0==at(e,t)}function st(e){return ot(e.line,e.ch)}function ct(e,t){return at(e,t)<0?t:e}function ut(e,t){return at(e,t)<0?e:t}function dt(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function ft(e,t){if(t.line<e.first)return ot(e.first,0);var n=e.first+e.size-1;return t.line>n?ot(n,Ze(e,n).text.length):function(e,t){var n=e.ch;return null==n||n>t?ot(e.line,t):n<0?ot(e.line,0):e}(t,Ze(e,t.line).text.length)}function ht(e,t){for(var n=[],r=0;r<t.length;r++)n[r]=ft(e,t[r]);return n}Ye.prototype.eol=function(){return this.pos>=this.string.length},Ye.prototype.sol=function(){return this.pos==this.lineStart},Ye.prototype.peek=function(){return this.string.charAt(this.pos)||void 0},Ye.prototype.next=function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},Ye.prototype.eat=function(e){var t=this.string.charAt(this.pos);if("string"==typeof e?t==e:t&&(e.test?e.test(t):e(t)))return++this.pos,t},Ye.prototype.eatWhile=function(e){for(var t=this.pos;this.eat(e););return this.pos>t},Ye.prototype.eatSpace=function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},Ye.prototype.skipToEnd=function(){this.pos=this.string.length},Ye.prototype.skipTo=function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},Ye.prototype.backUp=function(e){this.pos-=e},Ye.prototype.column=function(){return this.lastColumnPos<this.start&&(this.lastColumnValue=q(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?q(this.string,this.lineStart,this.tabSize):0)},Ye.prototype.indentation=function(){return q(this.string,null,this.tabSize)-(this.lineStart?q(this.string,this.lineStart,this.tabSize):0)},Ye.prototype.match=function(e,t,n){if("string"!=typeof e){var r=this.string.slice(this.pos).match(e);return r&&r.index>0?null:(r&&!1!==t&&(this.pos+=r[0].length),r)}var i=function(e){return n?e.toLowerCase():e};if(i(this.string.substr(this.pos,e.length))==i(e))return!1!==t&&(this.pos+=e.length),!0},Ye.prototype.current=function(){return this.string.slice(this.start,this.pos)},Ye.prototype.hideFirstChars=function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}},Ye.prototype.lookAhead=function(e){var t=this.lineOracle;return t&&t.lookAhead(e)},Ye.prototype.baseToken=function(){var e=this.lineOracle;return e&&e.baseToken(this.pos)};var pt=function(e,t){this.state=e,this.lookAhead=t},mt=function(e,t,n,r){this.state=t,this.doc=e,this.line=n,this.maxLookAhead=r||0,this.baseTokens=null,this.baseTokenPos=1};function gt(e,t,n,r){var i=[e.state.modeGen],o={};St(e,t.text,e.doc.mode,n,function(e,t){return i.push(e,t)},o,r);for(var a=n.state,l=function(r){n.baseTokens=i;var l=e.state.overlays[r],s=1,c=0;n.state=!0,St(e,t.text,l.mode,n,function(e,t){for(var n=s;c<e;){var r=i[s];r>e&&i.splice(s,1,e,i[s+1],r),s+=2,c=Math.min(e,r)}if(t)if(l.opaque)i.splice(n,s-n,e,"overlay "+t),s=n+2;else for(;n<s;n+=2){var o=i[n+1];i[n+1]=(o?o+" ":"")+"overlay "+t}},o),n.state=a,n.baseTokens=null,n.baseTokenPos=1},s=0;s<e.state.overlays.length;++s)l(s);return{styles:i,classes:o.bgClass||o.textClass?o:null}}function vt(e,t,n){if(!t.styles||t.styles[0]!=e.state.modeGen){var r=yt(e,tt(t)),i=t.text.length>e.options.maxHighlightLength&&$e(e.doc.mode,r.state),o=gt(e,t,r);i&&(r.state=i),t.stateAfter=r.save(!i),t.styles=o.styles,o.classes?t.styleClasses=o.classes:t.styleClasses&&(t.styleClasses=null),n===e.doc.highlightFrontier&&(e.doc.modeFrontier=Math.max(e.doc.modeFrontier,++e.doc.highlightFrontier))}return t.styles}function yt(e,t,n){var r=e.doc,i=e.display;if(!r.mode.startState)return new mt(r,!0,t);var o=function(e,t,n){for(var r,i,o=e.doc,a=n?-1:t-(e.doc.mode.innerMode?1e3:100),l=t;l>a;--l){if(l<=o.first)return o.first;var s=Ze(o,l-1),c=s.stateAfter;if(c&&(!n||l+(c instanceof pt?c.lookAhead:0)<=o.modeFrontier))return l;var u=q(s.text,null,e.options.tabSize);(null==i||r>u)&&(i=l-1,r=u)}return i}(e,t,n),a=o>r.first&&Ze(r,o-1).stateAfter,l=a?mt.fromSaved(r,a,o):new mt(r,Xe(r.mode),o);return r.iter(o,t,function(n){bt(e,n.text,l);var r=l.line;n.stateAfter=r==t-1||r%5==0||r>=i.viewFrom&&r<i.viewTo?l.save():null,l.nextLine()}),n&&(r.modeFrontier=l.line),l}function bt(e,t,n,r){var i=e.doc.mode,o=new Ye(t,e.options.tabSize,n);for(o.start=o.pos=r||0,""==t&&wt(i,n.state);!o.eol();)xt(i,o,n.state),o.start=o.pos}function wt(e,t){if(e.blankLine)return e.blankLine(t);if(e.innerMode){var n=Ge(e,t);return n.mode.blankLine?n.mode.blankLine(n.state):void 0}}function xt(e,t,n,r){for(var i=0;i<10;i++){r&&(r[0]=Ge(e,n).mode);var o=e.token(t,n);if(t.pos>t.start)return o}throw new Error("Mode "+e.name+" failed to advance stream.")}mt.prototype.lookAhead=function(e){var t=this.doc.getLine(this.line+e);return null!=t&&e>this.maxLookAhead&&(this.maxLookAhead=e),t},mt.prototype.baseToken=function(e){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=e;)this.baseTokenPos+=2;var t=this.baseTokens[this.baseTokenPos+1];return{type:t&&t.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}},mt.prototype.nextLine=function(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--},mt.fromSaved=function(e,t,n){return t instanceof pt?new mt(e,$e(e.mode,t.state),n,t.lookAhead):new mt(e,$e(e.mode,t),n)},mt.prototype.save=function(e){var t=!1!==e?$e(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new pt(t,this.maxLookAhead):t};var kt=function(e,t,n){this.start=e.start,this.end=e.pos,this.string=e.current(),this.type=t||null,this.state=n};function Ct(e,t,n,r){var i,o,a=e.doc,l=a.mode,s=Ze(a,(t=ft(a,t)).line),c=yt(e,t.line,n),u=new Ye(s.text,e.options.tabSize,c);for(r&&(o=[]);(r||u.pos<t.ch)&&!u.eol();)u.start=u.pos,i=xt(l,u,c.state),r&&o.push(new kt(u,i,$e(a.mode,c.state)));return r?o:new kt(u,i,c.state)}function _t(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 St(e,t,n,r,i,o,a){var l=n.flattenSpans;null==l&&(l=e.options.flattenSpans);var s,c=0,u=null,d=new Ye(t,e.options.tabSize,r),f=e.options.addModeClass&&[null];for(""==t&&_t(wt(n,r.state),o);!d.eol();){if(d.pos>e.options.maxHighlightLength?(l=!1,a&&bt(e,t,r,d.pos),d.pos=t.length,s=null):s=_t(xt(n,d,r.state,f),o),f){var h=f[0].name;h&&(s="m-"+(s?h+" "+s:h))}if(!l||u!=s){for(;c<d.start;)i(c=Math.min(d.start,c+5e3),u);u=s}d.start=d.pos}for(;c<d.pos;){var p=Math.min(d.pos,c+5e3);i(p,u),c=p}}var Tt=!1,Lt=!1;function Mt(e,t,n){this.marker=e,this.from=t,this.to=n}function Nt(e,t){if(e)for(var n=0;n<e.length;++n){var r=e[n];if(r.marker==t)return r}}function At(e,t){for(var n,r=0;r<e.length;++r)e[r]!=t&&(n||(n=[])).push(e[r]);return n}function Ot(e,t){if(t.full)return null;var n=rt(e,t.from.line)&&Ze(e,t.from.line).markedSpans,r=rt(e,t.to.line)&&Ze(e,t.to.line).markedSpans;if(!n&&!r)return null;var i=t.from.ch,o=t.to.ch,a=0==at(t.from,t.to),l=function(e,t,n){var r;if(e)for(var i=0;i<e.length;++i){var o=e[i],a=o.marker;if(null==o.from||(a.inclusiveLeft?o.from<=t:o.from<t)||o.from==t&&"bookmark"==a.type&&(!n||!o.marker.insertLeft)){var l=null==o.to||(a.inclusiveRight?o.to>=t:o.to>t);(r||(r=[])).push(new Mt(a,o.from,l?null:o.to))}}return r}(n,i,a),s=function(e,t,n){var r;if(e)for(var i=0;i<e.length;++i){var o=e[i],a=o.marker;if(null==o.to||(a.inclusiveRight?o.to>=t:o.to>t)||o.from==t&&"bookmark"==a.type&&(!n||o.marker.insertLeft)){var l=null==o.from||(a.inclusiveLeft?o.from<=t:o.from<t);(r||(r=[])).push(new Mt(a,l?null:o.from-t,null==o.to?null:o.to-t))}}return r}(r,o,a),c=1==t.text.length,u=J(t.text).length+(c?i:0);if(l)for(var d=0;d<l.length;++d){var f=l[d];if(null==f.to){var h=Nt(s,f.marker);h?c&&(f.to=null==h.to?null:h.to+u):f.to=i}}if(s)for(var p=0;p<s.length;++p){var m=s[p];null!=m.to&&(m.to+=u),null==m.from?Nt(l,m.marker)||(m.from=u,c&&(l||(l=[])).push(m)):(m.from+=u,c&&(l||(l=[])).push(m))}l&&(l=Dt(l)),s&&s!=l&&(s=Dt(s));var g=[l];if(!c){var v,y=t.text.length-2;if(y>0&&l)for(var b=0;b<l.length;++b)null==l[b].to&&(v||(v=[])).push(new Mt(l[b].marker,null,null));for(var w=0;w<y;++w)g.push(v);g.push(s)}return g}function Dt(e){for(var t=0;t<e.length;++t){var n=e[t];null!=n.from&&n.from==n.to&&!1!==n.marker.clearWhenEmpty&&e.splice(t--,1)}return e.length?e:null}function Ft(e){var t=e.markedSpans;if(t){for(var n=0;n<t.length;++n)t[n].marker.detachLine(e);e.markedSpans=null}}function Et(e,t){if(t){for(var n=0;n<t.length;++n)t[n].marker.attachLine(e);e.markedSpans=t}}function Pt(e){return e.inclusiveLeft?-1:0}function Wt(e){return e.inclusiveRight?1:0}function zt(e,t){var n=e.lines.length-t.lines.length;if(0!=n)return n;var r=e.find(),i=t.find(),o=at(r.from,i.from)||Pt(e)-Pt(t);return o?-o:at(r.to,i.to)||Wt(e)-Wt(t)||t.id-e.id}function Ht(e,t){var n,r=Lt&&e.markedSpans;if(r)for(var i=void 0,o=0;o<r.length;++o)(i=r[o]).marker.collapsed&&null==(t?i.from:i.to)&&(!n||zt(n,i.marker)<0)&&(n=i.marker);return n}function It(e){return Ht(e,!0)}function Rt(e){return Ht(e,!1)}function Bt(e,t){var n,r=Lt&&e.markedSpans;if(r)for(var i=0;i<r.length;++i){var o=r[i];o.marker.collapsed&&(null==o.from||o.from<t)&&(null==o.to||o.to>t)&&(!n||zt(n,o.marker)<0)&&(n=o.marker)}return n}function jt(e,t,n,r,i){var o=Ze(e,t),a=Lt&&o.markedSpans;if(a)for(var l=0;l<a.length;++l){var s=a[l];if(s.marker.collapsed){var c=s.marker.find(0),u=at(c.from,n)||Pt(s.marker)-Pt(i),d=at(c.to,r)||Wt(s.marker)-Wt(i);if(!(u>=0&&d<=0||u<=0&&d>=0)&&(u<=0&&(s.marker.inclusiveRight&&i.inclusiveLeft?at(c.to,n)>=0:at(c.to,n)>0)||u>=0&&(s.marker.inclusiveRight&&i.inclusiveLeft?at(c.from,r)<=0:at(c.from,r)<0)))return!0}}}function qt(e){for(var t;t=It(e);)e=t.find(-1,!0).line;return e}function Ut(e,t){var n=Ze(e,t),r=qt(n);return n==r?t:tt(r)}function Vt(e,t){if(t>e.lastLine())return t;var n,r=Ze(e,t);if(!Kt(e,r))return t;for(;n=Rt(r);)r=n.find(1,!0).line;return tt(r)+1}function Kt(e,t){var n=Lt&&t.markedSpans;if(n)for(var r=void 0,i=0;i<n.length;++i)if((r=n[i]).marker.collapsed){if(null==r.from)return!0;if(!r.marker.widgetNode&&0==r.from&&r.marker.inclusiveLeft&&$t(e,t,r))return!0}}function $t(e,t,n){if(null==n.to){var r=n.marker.find(1,!0);return $t(e,r.line,Nt(r.line.markedSpans,n.marker))}if(n.marker.inclusiveRight&&n.to==t.text.length)return!0;for(var i=void 0,o=0;o<t.markedSpans.length;++o)if((i=t.markedSpans[o]).marker.collapsed&&!i.marker.widgetNode&&i.from==n.to&&(null==i.to||i.to!=n.from)&&(i.marker.inclusiveLeft||n.marker.inclusiveRight)&&$t(e,t,i))return!0}function Gt(e){for(var t=0,n=(e=qt(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;o=(n=o).parent)for(var a=0;a<o.children.length;++a){var l=o.children[a];if(l==n)break;t+=l.height}return t}function Xt(e){if(0==e.height)return 0;for(var t,n=e.text.length,r=e;t=It(r);){var i=t.find(0,!0);r=i.from.line,n+=i.from.ch-i.to.ch}for(r=e;t=Rt(r);){var o=t.find(0,!0);n-=r.text.length-o.from.ch,n+=(r=o.to.line).text.length-o.to.ch}return n}function Yt(e){var t=e.display,n=e.doc;t.maxLine=Ze(n,n.first),t.maxLineLength=Xt(t.maxLine),t.maxLineChanged=!0,n.iter(function(e){var n=Xt(e);n>t.maxLineLength&&(t.maxLineLength=n,t.maxLine=e)})}var Zt=function(e,t,n){this.text=e,Et(this,t),this.height=n?n(this):1};function Qt(e){e.parent=null,Ft(e)}Zt.prototype.lineNo=function(){return tt(this)},Ce(Zt);var Jt={},en={};function tn(e,t){if(!e||/^\s*$/.test(e))return null;var n=t.addModeClass?en:Jt;return n[e]||(n[e]=e.replace(/\S+/g,"cm-$&"))}function nn(e,t){var n=O("span",null,null,s?"padding-right: .1px":null),r={pre:O("pre",[n],"CodeMirror-line"),content:n,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:e.getOption("lineWrapping")};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var o=i?t.rest[i-1]:t.line,a=void 0;r.pos=0,r.addToken=on,Ee(e.display.measure)&&(a=pe(o,e.doc.direction))&&(r.addToken=an(r.addToken,a)),r.map=[],sn(o,r,vt(e,o,t!=e.display.externalMeasured&&tt(o))),o.styleClasses&&(o.styleClasses.bgClass&&(r.bgClass=P(o.styleClasses.bgClass,r.bgClass||"")),o.styleClasses.textClass&&(r.textClass=P(o.styleClasses.textClass,r.textClass||""))),0==r.map.length&&r.map.push(0,0,r.content.appendChild(Fe(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({}))}if(s){var l=r.content.lastChild;(/\bcm-tab\b/.test(l.className)||l.querySelector&&l.querySelector(".cm-tab"))&&(r.content.className="cm-tab-wrap-hack")}return be(e,"renderLine",e,t.line,r.pre),r.pre.className&&(r.textClass=P(r.pre.className,r.textClass||"")),r}function rn(e){var t=A("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function on(e,t,n,r,i,o,s){if(t){var c,u=e.splitSpaces?function(e,t){if(e.length>1&&!/ /.test(e))return e;for(var n=t,r="",i=0;i<e.length;i++){var o=e.charAt(i);" "!=o||!n||i!=e.length-1&&32!=e.charCodeAt(i+1)||(o=" "),r+=o,n=" "==o}return r}(t,e.trailingSpace):t,d=e.cm.state.specialChars,f=!1;if(d.test(t)){c=document.createDocumentFragment();for(var h=0;;){d.lastIndex=h;var p=d.exec(t),m=p?p.index-h:t.length-h;if(m){var g=document.createTextNode(u.slice(h,h+m));a&&l<9?c.appendChild(A("span",[g])):c.appendChild(g),e.map.push(e.pos,e.pos+m,g),e.col+=m,e.pos+=m}if(!p)break;h+=m+1;var v=void 0;if("\t"==p[0]){var y=e.cm.options.tabSize,b=y-e.col%y;(v=c.appendChild(A("span",Q(b),"cm-tab"))).setAttribute("role","presentation"),v.setAttribute("cm-text","\t"),e.col+=b}else"\r"==p[0]||"\n"==p[0]?((v=c.appendChild(A("span","\r"==p[0]?"␍":"","cm-invalidchar"))).setAttribute("cm-text",p[0]),e.col+=1):((v=e.cm.options.specialCharPlaceholder(p[0])).setAttribute("cm-text",p[0]),a&&l<9?c.appendChild(A("span",[v])):c.appendChild(v),e.col+=1);e.map.push(e.pos,e.pos+1,v),e.pos++}}else e.col+=t.length,c=document.createTextNode(u),e.map.push(e.pos,e.pos+t.length,c),a&&l<9&&(f=!0),e.pos+=t.length;if(e.trailingSpace=32==u.charCodeAt(t.length-1),n||r||i||f||o||s){var w=n||"";r&&(w+=r),i&&(w+=i);var x=A("span",[c],w,o);if(s)for(var k in s)s.hasOwnProperty(k)&&"style"!=k&&"class"!=k&&x.setAttribute(k,s[k]);return e.content.appendChild(x)}e.content.appendChild(c)}}function an(e,t){return function(n,r,i,o,a,l,s){i=i?i+" cm-force-border":"cm-force-border";for(var c=n.pos,u=c+r.length;;){for(var d=void 0,f=0;f<t.length&&!((d=t[f]).to>c&&d.from<=c);f++);if(d.to>=u)return e(n,r,i,o,a,l,s);e(n,r.slice(0,d.to-c),i,o,null,l,s),o=null,r=r.slice(d.to-c),c=d.to}}}function ln(e,t,n,r){var i=!r&&n.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!r&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",n.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t,e.trailingSpace=!1}function sn(e,t,n){var r=e.markedSpans,i=e.text,o=0;if(r)for(var a,l,s,c,u,d,f,h=i.length,p=0,m=1,g="",v=0;;){if(v==p){s=c=u=l="",f=null,d=null,v=1/0;for(var y=[],b=void 0,w=0;w<r.length;++w){var x=r[w],k=x.marker;if("bookmark"==k.type&&x.from==p&&k.widgetNode)y.push(k);else if(x.from<=p&&(null==x.to||x.to>p||k.collapsed&&x.to==p&&x.from==p)){if(null!=x.to&&x.to!=p&&v>x.to&&(v=x.to,c=""),k.className&&(s+=" "+k.className),k.css&&(l=(l?l+";":"")+k.css),k.startStyle&&x.from==p&&(u+=" "+k.startStyle),k.endStyle&&x.to==v&&(b||(b=[])).push(k.endStyle,x.to),k.title&&((f||(f={})).title=k.title),k.attributes)for(var C in k.attributes)(f||(f={}))[C]=k.attributes[C];k.collapsed&&(!d||zt(d.marker,k)<0)&&(d=x)}else x.from>p&&v>x.from&&(v=x.from)}if(b)for(var _=0;_<b.length;_+=2)b[_+1]==v&&(c+=" "+b[_]);if(!d||d.from==p)for(var S=0;S<y.length;++S)ln(t,0,y[S]);if(d&&(d.from||0)==p){if(ln(t,(null==d.to?h+1:d.to)-p,d.marker,null==d.from),null==d.to)return;d.to==p&&(d=!1)}}if(p>=h)break;for(var T=Math.min(h,v);;){if(g){var L=p+g.length;if(!d){var M=L>T?g.slice(0,T-p):g;t.addToken(t,M,a?a+s:s,u,p+M.length==v?c:"",l,f)}if(L>=T){g=g.slice(T-p),p=T;break}p=L,u=""}g=i.slice(o,o=n[m++]),a=tn(n[m++],t.cm.options)}}else for(var N=1;N<n.length;N+=2)t.addToken(t,i.slice(o,o=n[N]),tn(n[N+1],t.cm.options))}function cn(e,t,n){this.line=t,this.rest=function(e){for(var t,n;t=Rt(e);)e=t.find(1,!0).line,(n||(n=[])).push(e);return n}(t),this.size=this.rest?tt(J(this.rest))-n+1:1,this.node=this.text=null,this.hidden=Kt(e,t)}function un(e,t,n){for(var r,i=[],o=t;o<n;o=r){var a=new cn(e.doc,Ze(e.doc,o),o);r=o+a.size,i.push(a)}return i}var dn=null;var fn=null;function hn(e,t){var n=ve(e,t);if(n.length){var r,i=Array.prototype.slice.call(arguments,2);dn?r=dn.delayedCallbacks:fn?r=fn:(r=fn=[],setTimeout(pn,0));for(var o=function(e){r.push(function(){return n[e].apply(null,i)})},a=0;a<n.length;++a)o(a)}}function pn(){var e=fn;fn=null;for(var t=0;t<e.length;++t)e[t]()}function mn(e,t,n,r){for(var i=0;i<t.changes.length;i++){var o=t.changes[i];"text"==o?yn(e,t):"gutter"==o?wn(e,t,n,r):"class"==o?bn(e,t):"widget"==o&&xn(e,t,r)}t.changes=null}function gn(e){return e.node==e.text&&(e.node=A("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),a&&l<8&&(e.node.style.zIndex=2)),e.node}function vn(e,t){var n=e.display.externalMeasured;return n&&n.line==t.line?(e.display.externalMeasured=null,t.measure=n.measure,n.built):nn(e,t)}function yn(e,t){var n=t.text.className,r=vn(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,bn(e,t)):n&&(t.text.className=n)}function bn(e,t){(function(e,t){var n=t.bgClass?t.bgClass+" "+(t.line.bgClass||""):t.line.bgClass;if(n&&(n+=" CodeMirror-linebackground"),t.background)n?t.background.className=n:(t.background.parentNode.removeChild(t.background),t.background=null);else if(n){var r=gn(t);t.background=r.insertBefore(A("div",null,n),r.firstChild),e.display.input.setUneditable(t.background)}})(e,t),t.line.wrapClass?gn(t).className=t.line.wrapClass:t.node!=t.text&&(t.node.className="");var n=t.textClass?t.textClass+" "+(t.line.textClass||""):t.line.textClass;t.text.className=n||""}function wn(e,t,n,r){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var i=gn(t);t.gutterBackground=A("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?r.fixedPos:-r.gutterTotalWidth)+"px; width: "+r.gutterTotalWidth+"px"),e.display.input.setUneditable(t.gutterBackground),i.insertBefore(t.gutterBackground,t.text)}var o=t.line.gutterMarkers;if(e.options.lineNumbers||o){var a=gn(t),l=t.gutter=A("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?r.fixedPos:-r.gutterTotalWidth)+"px");if(l.setAttribute("aria-hidden","true"),e.display.input.setUneditable(l),a.insertBefore(l,t.text),t.line.gutterClass&&(l.className+=" "+t.line.gutterClass),!e.options.lineNumbers||o&&o["CodeMirror-linenumbers"]||(t.lineNumber=l.appendChild(A("div",it(e.options,n),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+r.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),o)for(var s=0;s<e.display.gutterSpecs.length;++s){var c=e.display.gutterSpecs[s].className,u=o.hasOwnProperty(c)&&o[c];u&&l.appendChild(A("div",[u],"CodeMirror-gutter-elt","left: "+r.gutterLeft[c]+"px; width: "+r.gutterWidth[c]+"px"))}}}function xn(e,t,n){t.alignable&&(t.alignable=null);for(var r=S("CodeMirror-linewidget"),i=t.node.firstChild,o=void 0;i;i=o)o=i.nextSibling,r.test(i.className)&&t.node.removeChild(i);Cn(e,t,n)}function kn(e,t,n,r){var i=vn(e,t);return t.text=t.node=i.pre,i.bgClass&&(t.bgClass=i.bgClass),i.textClass&&(t.textClass=i.textClass),bn(e,t),wn(e,t,n,r),Cn(e,t,r),t.node}function Cn(e,t,n){if(_n(e,t.line,t,n,!0),t.rest)for(var r=0;r<t.rest.length;r++)_n(e,t.rest[r],t,n,!1)}function _n(e,t,n,r,i){if(t.widgets)for(var o=gn(n),a=0,l=t.widgets;a<l.length;++a){var s=l[a],c=A("div",[s.node],"CodeMirror-linewidget"+(s.className?" "+s.className:""));s.handleMouseEvents||c.setAttribute("cm-ignore-events","true"),Sn(s,c,n,r),e.display.input.setUneditable(c),i&&s.above?o.insertBefore(c,n.gutter||n.text):o.appendChild(c),hn(s,"redraw")}}function Sn(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 Tn(e){if(null!=e.height)return e.height;var t=e.doc.cm;if(!t)return 0;if(!D(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;"),N(t.display.measure,A("div",[e.node],null,n))}return e.height=e.node.parentNode.offsetHeight}function Ln(e,t){for(var n=Me(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 Mn(e){return e.lineSpace.offsetTop}function Nn(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function An(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=N(e.measure,A("pre","x","CodeMirror-line-like")),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 On(e){return 50-e.display.nativeBarWidth}function Dn(e){return e.display.scroller.clientWidth-On(e)-e.display.barWidth}function Fn(e){return e.display.scroller.clientHeight-On(e)-e.display.barHeight}function En(e,t,n){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};if(e.rest){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 i=0;i<e.rest.length;i++)if(tt(e.rest[i])>n)return{map:e.measure.maps[i],cache:e.measure.caches[i],before:!0}}}function Pn(e,t,n,r){return Hn(e,zn(e,t),n,r)}function Wn(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[mr(e,t)];var n=e.display.externalMeasured;return n&&t>=n.lineN&&t<n.lineN+n.size?n:void 0}function zn(e,t){var n=tt(t),r=Wn(e,n);r&&!r.text?r=null:r&&r.changes&&(mn(e,r,n,ur(e)),e.curOp.forceUpdate=!0),r||(r=function(e,t){var n=tt(t=qt(t)),r=e.display.externalMeasured=new cn(e.doc,t,n);r.lineN=n;var i=r.built=nn(e,r);return r.text=i.pre,N(e.display.lineMeasure,i.pre),r}(e,t));var i=En(r,t,n);return{line:t,view:r,rect:null,map:i.map,cache:i.cache,before:i.before,hasHeights:!1}}function Hn(e,t,n,r,i){t.before&&(n=-1);var o,s=n+(r||"");return t.cache.hasOwnProperty(s)?o=t.cache[s]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(function(e,t,n){var r=e.options.lineWrapping,i=r&&Dn(e);if(!t.measure.heights||r&&t.measure.width!=i){var o=t.measure.heights=[];if(r){t.measure.width=i;for(var a=t.text.firstChild.getClientRects(),l=0;l<a.length-1;l++){var s=a[l],c=a[l+1];Math.abs(s.bottom-c.bottom)>2&&o.push((s.bottom+c.top)/2-n.top)}}o.push(n.bottom-n.top)}}(e,t.view,t.rect),t.hasHeights=!0),(o=function(e,t,n,r){var i,o=Bn(t.map,n,r),s=o.node,c=o.start,u=o.end,d=o.collapse;if(3==s.nodeType){for(var f=0;f<4;f++){for(;c&&se(t.line.text.charAt(o.coverStart+c));)--c;for(;o.coverStart+u<o.coverEnd&&se(t.line.text.charAt(o.coverStart+u));)++u;if((i=a&&l<9&&0==c&&u==o.coverEnd-o.coverStart?s.parentNode.getBoundingClientRect():jn(T(s,c,u).getClientRects(),r)).left||i.right||0==c)break;u=c,c-=1,d="right"}a&&l<11&&(i=function(e,t){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!function(e){if(null!=Ie)return Ie;var t=N(e,A("span","x")),n=t.getBoundingClientRect(),r=T(t,0,1).getBoundingClientRect();return Ie=Math.abs(n.left-r.left)>1}(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}}(e.display.measure,i))}else{var h;c>0&&(d=r="right"),i=e.options.lineWrapping&&(h=s.getClientRects()).length>1?h["right"==r?h.length-1:0]:s.getBoundingClientRect()}if(a&&l<9&&!c&&(!i||!i.left&&!i.right)){var p=s.parentNode.getClientRects()[0];i=p?{left:p.left,right:p.left+cr(e.display),top:p.top,bottom:p.bottom}:Rn}for(var m=i.top-t.rect.top,g=i.bottom-t.rect.top,v=(m+g)/2,y=t.view.measure.heights,b=0;b<y.length-1&&!(v<y[b]);b++);var w=b?y[b-1]:0,x=y[b],k={left:("right"==d?i.right:i.left)-t.rect.left,right:("left"==d?i.left:i.right)-t.rect.left,top:w,bottom:x};return i.left||i.right||(k.bogus=!0),e.options.singleCursorHeightPerLine||(k.rtop=m,k.rbottom=g),k}(e,t,n,r)).bogus||(t.cache[s]=o)),{left:o.left,right:o.right,top:i?o.rtop:o.top,bottom:i?o.rbottom:o.bottom}}var In,Rn={left:0,right:0,top:0,bottom:0};function Bn(e,t,n){for(var r,i,o,a,l,s,c=0;c<e.length;c+=3)if(l=e[c],s=e[c+1],t<l?(i=0,o=1,a="left"):t<s?o=1+(i=t-l):(c==e.length-3||t==s&&e[c+3]>t)&&(i=(o=s-l)-1,t>=s&&(a="right")),null!=i){if(r=e[c+2],l==s&&n==(r.insertLeft?"left":"right")&&(a=n),"left"==n&&0==i)for(;c&&e[c-2]==e[c-3]&&e[c-1].insertLeft;)r=e[2+(c-=3)],a="left";if("right"==n&&i==s-l)for(;c<e.length-3&&e[c+3]==e[c+4]&&!e[c+5].insertLeft;)r=e[(c+=3)+2],a="right";break}return{node:r,start:i,end:o,collapse:a,coverStart:l,coverEnd:s}}function jn(e,t){var n=Rn;if("left"==t)for(var r=0;r<e.length&&(n=e[r]).left==n.right;r++);else for(var i=e.length-1;i>=0&&(n=e[i]).left==n.right;i--);return n}function qn(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 Un(e){e.display.externalMeasure=null,M(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++)qn(e.display.view[t])}function Vn(e){Un(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function Kn(e){return u&&v?-(e.body.getBoundingClientRect().left-parseInt(getComputedStyle(e.body).marginLeft)):e.defaultView.pageXOffset||(e.documentElement||e.body).scrollLeft}function $n(e){return u&&v?-(e.body.getBoundingClientRect().top-parseInt(getComputedStyle(e.body).marginTop)):e.defaultView.pageYOffset||(e.documentElement||e.body).scrollTop}function Gn(e){var t=qt(e).widgets,n=0;if(t)for(var r=0;r<t.length;++r)t[r].above&&(n+=Tn(t[r]));return n}function Xn(e,t,n,r,i){if(!i){var o=Gn(t);n.top+=o,n.bottom+=o}if("line"==r)return n;r||(r="local");var a=Gt(t);if("local"==r?a+=Mn(e.display):a-=e.display.viewOffset,"page"==r||"window"==r){var l=e.display.lineSpace.getBoundingClientRect();a+=l.top+("window"==r?0:$n(z(e)));var s=l.left+("window"==r?0:Kn(z(e)));n.left+=s,n.right+=s}return n.top+=a,n.bottom+=a,n}function Yn(e,t,n){if("div"==n)return t;var r=t.left,i=t.top;if("page"==n)r-=Kn(z(e)),i-=$n(z(e));else if("local"==n||!n){var o=e.display.sizer.getBoundingClientRect();r+=o.left,i+=o.top}var a=e.display.lineSpace.getBoundingClientRect();return{left:r-a.left,top:i-a.top}}function Zn(e,t,n,r,i){return r||(r=Ze(e.doc,t.line)),Xn(e,r,Pn(e,r,t.ch,i),n)}function Qn(e,t,n,r,i,o){function a(t,a){var l=Hn(e,i,t,a?"right":"left",o);return a?l.left=l.right:l.right=l.left,Xn(e,r,l,n)}r=r||Ze(e.doc,t.line),i||(i=zn(e,r));var l=pe(r,e.doc.direction),s=t.ch,c=t.sticky;if(s>=r.text.length?(s=r.text.length,c="before"):s<=0&&(s=0,c="after"),!l)return a("before"==c?s-1:s,"before"==c);function u(e,t,n){return a(n?e-1:e,1==l[t].level!=n)}var d=fe(l,s,c),f=de,h=u(s,d,"before"==c);return null!=f&&(h.other=u(s,f,"before"!=c)),h}function Jn(e,t){var n=0;t=ft(e.doc,t),e.options.lineWrapping||(n=cr(e.display)*t.ch);var r=Ze(e.doc,t.line),i=Gt(r)+Mn(e.display);return{left:n,right:n,top:i,bottom:i+r.height}}function er(e,t,n,r,i){var o=ot(e,t,n);return o.xRel=i,r&&(o.outside=r),o}function tr(e,t,n){var r=e.doc;if((n+=e.display.viewOffset)<0)return er(r.first,0,null,-1,-1);var i=nt(r,n),o=r.first+r.size-1;if(i>o)return er(r.first+r.size-1,Ze(r,o).text.length,null,1,1);t<0&&(t=0);for(var a=Ze(r,i);;){var l=or(e,a,i,t,n),s=Bt(a,l.ch+(l.xRel>0||l.outside>0?1:0));if(!s)return l;var c=s.find(1);if(c.line==i)return c;a=Ze(r,i=c.line)}}function nr(e,t,n,r){r-=Gn(t);var i=t.text.length,o=ue(function(t){return Hn(e,n,t-1).bottom<=r},i,0);return{begin:o,end:i=ue(function(t){return Hn(e,n,t).top>r},o,i)}}function rr(e,t,n,r){return n||(n=zn(e,t)),nr(e,t,n,Xn(e,t,Hn(e,n,r),"line").top)}function ir(e,t,n,r){return!(e.bottom<=n)&&(e.top>n||(r?e.left:e.right)>t)}function or(e,t,n,r,i){i-=Gt(t);var o=zn(e,t),a=Gn(t),l=0,s=t.text.length,c=!0,u=pe(t,e.doc.direction);if(u){var d=(e.options.lineWrapping?lr:ar)(e,t,n,o,u,r,i);l=(c=1!=d.level)?d.from:d.to-1,s=c?d.to:d.from-1}var f,h,p=null,m=null,g=ue(function(t){var n=Hn(e,o,t);return n.top+=a,n.bottom+=a,!!ir(n,r,i,!1)&&(n.top<=i&&n.left<=r&&(p=t,m=n),!0)},l,s),v=!1;if(m){var y=r-m.left<m.right-r,b=y==c;g=p+(b?0:1),h=b?"after":"before",f=y?m.left:m.right}else{c||g!=s&&g!=l||g++,h=0==g?"after":g==t.text.length?"before":Hn(e,o,g-(c?1:0)).bottom+a<=i==c?"after":"before";var w=Qn(e,ot(n,g,h),"line",t,o);f=w.left,v=i<w.top?-1:i>=w.bottom?1:0}return er(n,g=ce(t.text,g,1),h,v,r-f)}function ar(e,t,n,r,i,o,a){var l=ue(function(l){var s=i[l],c=1!=s.level;return ir(Qn(e,ot(n,c?s.to:s.from,c?"before":"after"),"line",t,r),o,a,!0)},0,i.length-1),s=i[l];if(l>0){var c=1!=s.level,u=Qn(e,ot(n,c?s.from:s.to,c?"after":"before"),"line",t,r);ir(u,o,a,!0)&&u.top>a&&(s=i[l-1])}return s}function lr(e,t,n,r,i,o,a){var l=nr(e,t,r,a),s=l.begin,c=l.end;/\s/.test(t.text.charAt(c-1))&&c--;for(var u=null,d=null,f=0;f<i.length;f++){var h=i[f];if(!(h.from>=c||h.to<=s)){var p=Hn(e,r,1!=h.level?Math.min(c,h.to)-1:Math.max(s,h.from)).right,m=p<o?o-p+1e9:p-o;(!u||d>m)&&(u=h,d=m)}}return u||(u=i[i.length-1]),u.from<s&&(u={from:s,to:u.to,level:u.level}),u.to>c&&(u={from:u.from,to:c,level:u.level}),u}function sr(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==In){In=A("pre",null,"CodeMirror-line-like");for(var t=0;t<49;++t)In.appendChild(document.createTextNode("x")),In.appendChild(A("br"));In.appendChild(document.createTextNode("x"))}N(e.measure,In);var n=In.offsetHeight/50;return n>3&&(e.cachedTextHeight=n),M(e.measure),n||1}function cr(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=A("span","xxxxxxxxxx"),n=A("pre",[t],"CodeMirror-line-like");N(e.measure,n);var r=t.getBoundingClientRect(),i=(r.right-r.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function ur(e){for(var t=e.display,n={},r={},i=t.gutters.clientLeft,o=t.gutters.firstChild,a=0;o;o=o.nextSibling,++a){var l=e.display.gutterSpecs[a].className;n[l]=o.offsetLeft+o.clientLeft+i,r[l]=o.clientWidth}return{fixedPos:dr(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:n,gutterWidth:r,wrapperWidth:t.wrapper.clientWidth}}function dr(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function fr(e){var t=sr(e.display),n=e.options.lineWrapping,r=n&&Math.max(5,e.display.scroller.clientWidth/cr(e.display)-3);return function(i){if(Kt(e.doc,i))return 0;var o=0;if(i.widgets)for(var a=0;a<i.widgets.length;a++)i.widgets[a].height&&(o+=i.widgets[a].height);return n?o+(Math.ceil(i.text.length/r)||1)*t:o+t}}function hr(e){var t=e.doc,n=fr(e);t.iter(function(e){var t=n(e);t!=e.height&&et(e,t)})}function pr(e,t,n,r){var i=e.display;if(!n&&"true"==Me(t).getAttribute("cm-not-content"))return null;var o,a,l=i.lineSpace.getBoundingClientRect();try{o=t.clientX-l.left,a=t.clientY-l.top}catch(e){return null}var s,c=tr(e,o,a);if(r&&c.xRel>0&&(s=Ze(e.doc,c.line).text).length==c.ch){var u=q(s,s.length,e.options.tabSize)-s.length;c=ot(c.line,Math.max(0,Math.round((o-An(e.display).left)/cr(e.display))-u))}return c}function mr(e,t){if(t>=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;for(var n=e.display.view,r=0;r<n.length;r++)if((t-=n[r].size)<0)return r}function gr(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)Lt&&Ut(e.doc,t)<i.viewTo&&yr(e);else if(n<=i.viewFrom)Lt&&Vt(e.doc,n+r)>i.viewFrom?yr(e):(i.viewFrom+=r,i.viewTo+=r);else if(t<=i.viewFrom&&n>=i.viewTo)yr(e);else if(t<=i.viewFrom){var o=br(e,n,n+r,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=r):yr(e)}else if(n>=i.viewTo){var a=br(e,t,t,-1);a?(i.view=i.view.slice(0,a.index),i.viewTo=a.lineN):yr(e)}else{var l=br(e,t,t,-1),s=br(e,n,n+r,1);l&&s?(i.view=i.view.slice(0,l.index).concat(un(e,l.lineN,s.lineN)).concat(i.view.slice(s.index)),i.viewTo+=r):yr(e)}var c=i.externalMeasured;c&&(n<c.lineN?c.lineN+=r:t<c.lineN+c.size&&(i.externalMeasured=null))}function vr(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[mr(e,t)];if(null!=o.node){var a=o.changes||(o.changes=[]);-1==V(a,n)&&a.push(n)}}}function yr(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function br(e,t,n,r){var i,o=mr(e,t),a=e.display.view;if(!Lt||n==e.doc.first+e.doc.size)return{index:o,lineN:n};for(var l=e.display.viewFrom,s=0;s<o;s++)l+=a[s].size;if(l!=t){if(r>0){if(o==a.length-1)return null;i=l+a[o].size-t,o++}else i=l-t;t+=i,n+=i}for(;Ut(e.doc,n)!=n;){if(o==(r<0?0:a.length-1))return null;n+=r*a[o-(r<0?1:0)].size,o+=r}return{index:o,lineN:n}}function wr(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 xr(e){e.display.input.showSelection(e.display.input.prepareSelection())}function kr(e,t){void 0===t&&(t=!0);var n=e.doc,r={},i=r.cursors=document.createDocumentFragment(),o=r.selection=document.createDocumentFragment(),a=e.options.$customCursor;a&&(t=!0);for(var l=0;l<n.sel.ranges.length;l++)if(t||l!=n.sel.primIndex){var s=n.sel.ranges[l];if(!(s.from().line>=e.display.viewTo||s.to().line<e.display.viewFrom)){var c=s.empty();if(a){var u=a(e,s);u&&Cr(e,u,i)}else(c||e.options.showCursorWhenSelecting)&&Cr(e,s.head,i);c||Sr(e,s,o)}}return r}function Cr(e,t,n){var r=Qn(e,t,"div",null,null,!e.options.singleCursorHeightPerLine),i=n.appendChild(A("div"," ","CodeMirror-cursor"));if(i.style.left=r.left+"px",i.style.top=r.top+"px",i.style.height=Math.max(0,r.bottom-r.top)*e.options.cursorHeight+"px",/\bcm-fat-cursor\b/.test(e.getWrapperElement().className)){var o=Zn(e,t,"div",null,null),a=o.right-o.left;i.style.width=(a>0?a:e.defaultCharWidth())+"px"}if(r.other){var l=n.appendChild(A("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));l.style.display="",l.style.left=r.other.left+"px",l.style.top=r.other.top+"px",l.style.height=.85*(r.other.bottom-r.other.top)+"px"}}function _r(e,t){return e.top-t.top||e.left-t.left}function Sr(e,t,n){var r=e.display,i=e.doc,o=document.createDocumentFragment(),a=An(e.display),l=a.left,s=Math.max(r.sizerWidth,Dn(e)-r.sizer.offsetLeft)-a.right,c="ltr"==i.direction;function u(e,t,n,r){t<0&&(t=0),t=Math.round(t),r=Math.round(r),o.appendChild(A("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px;\n top: "+t+"px; width: "+(null==n?s-e:n)+"px;\n height: "+(r-t)+"px"))}function d(t,n,r){var o,a,d=Ze(i,t),f=d.text.length;function h(n,r){return Zn(e,ot(t,n),"div",d,r)}function p(t,n,r){var i=rr(e,d,null,t),o="ltr"==n==("after"==r)?"left":"right";return h("after"==r?i.begin:i.end-(/\s/.test(d.text.charAt(i.end-1))?2:1),o)[o]}var m=pe(d,i.direction);return function(e,t,n,r){if(!e)return r(t,n,"ltr",0);for(var i=!1,o=0;o<e.length;++o){var a=e[o];(a.from<n&&a.to>t||t==n&&a.to==t)&&(r(Math.max(a.from,t),Math.min(a.to,n),1==a.level?"rtl":"ltr",o),i=!0)}i||r(t,n,"ltr")}(m,n||0,null==r?f:r,function(e,t,i,d){var g="ltr"==i,v=h(e,g?"left":"right"),y=h(t-1,g?"right":"left"),b=null==n&&0==e,w=null==r&&t==f,x=0==d,k=!m||d==m.length-1;if(y.top-v.top<=3){var C=(c?w:b)&&k,_=(c?b:w)&&x?l:(g?v:y).left,S=C?s:(g?y:v).right;u(_,v.top,S-_,v.bottom)}else{var T,L,M,N;g?(T=c&&b&&x?l:v.left,L=c?s:p(e,i,"before"),M=c?l:p(t,i,"after"),N=c&&w&&k?s:y.right):(T=c?p(e,i,"before"):l,L=!c&&b&&x?s:v.right,M=!c&&w&&k?l:y.left,N=c?p(t,i,"after"):s),u(T,v.top,L-T,v.bottom),v.bottom<y.top&&u(l,v.bottom,null,y.top),u(M,y.top,N-M,y.bottom)}(!o||_r(v,o)<0)&&(o=v),_r(y,o)<0&&(o=y),(!a||_r(v,a)<0)&&(a=v),_r(y,a)<0&&(a=y)}),{start:o,end:a}}var f=t.from(),h=t.to();if(f.line==h.line)d(f.line,f.ch,h.ch);else{var p=Ze(i,f.line),m=Ze(i,h.line),g=qt(p)==qt(m),v=d(f.line,f.ch,g?p.text.length+1:null).end,y=d(h.line,g?0:null,h.ch).start;g&&(v.top<y.top-2?(u(v.right,v.top,null,v.bottom),u(l,y.top,y.left,y.bottom)):u(v.right,v.top,y.left-v.right,v.bottom)),v.bottom<y.top&&u(l,v.bottom,null,y.top)}n.appendChild(o)}function Tr(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(){e.hasFocus()||Ar(e),t.cursorDiv.style.visibility=(n=!n)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function Lr(e){e.hasFocus()||(e.display.input.focus(),e.state.focused||Nr(e))}function Mr(e){e.state.delayingBlurEvent=!0,setTimeout(function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,e.state.focused&&Ar(e))},100)}function Nr(e,t){e.state.delayingBlurEvent&&!e.state.draggingText&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(be(e,"focus",e,t),e.state.focused=!0,E(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),s&&setTimeout(function(){return e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),Tr(e))}function Ar(e,t){e.state.delayingBlurEvent||(e.state.focused&&(be(e,"blur",e,t),e.state.focused=!1,L(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150))}function Or(e){for(var t=e.display,n=t.lineDiv.offsetTop,r=Math.max(0,t.scroller.getBoundingClientRect().top),i=t.lineDiv.getBoundingClientRect().top,o=0,s=0;s<t.view.length;s++){var c=t.view[s],u=e.options.lineWrapping,d=void 0,f=0;if(!c.hidden){if(i+=c.line.height,a&&l<8){var h=c.node.offsetTop+c.node.offsetHeight;d=h-n,n=h}else{var p=c.node.getBoundingClientRect();d=p.bottom-p.top,!u&&c.text.firstChild&&(f=c.text.firstChild.getBoundingClientRect().right-p.left-1)}var m=c.line.height-d;if((m>.005||m<-.005)&&(i<r&&(o-=m),et(c.line,d),Dr(c.line),c.rest))for(var g=0;g<c.rest.length;g++)Dr(c.rest[g]);if(f>e.display.sizerWidth){var v=Math.ceil(f/cr(e.display));v>e.display.maxLineLength&&(e.display.maxLineLength=v,e.display.maxLine=c.line,e.display.maxLineChanged=!0)}}}Math.abs(o)>2&&(t.scroller.scrollTop+=o)}function Dr(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t){var n=e.widgets[t],r=n.node.parentNode;r&&(n.height=r.offsetHeight)}}function Fr(e,t,n){var r=n&&null!=n.top?Math.max(0,n.top):e.scroller.scrollTop;r=Math.floor(r-Mn(e));var i=n&&null!=n.bottom?n.bottom:r+e.wrapper.clientHeight,o=nt(t,r),a=nt(t,i);if(n&&n.ensure){var l=n.ensure.from.line,s=n.ensure.to.line;l<o?(o=l,a=nt(t,Gt(Ze(t,l))+e.wrapper.clientHeight)):Math.min(s,t.lastLine())>=a&&(o=nt(t,Gt(Ze(t,s))-e.wrapper.clientHeight),a=s)}return{from:o,to:Math.max(a,o+1)}}function Er(e,t){var n=e.display,r=sr(e.display);t.top<0&&(t.top=0);var i=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:n.scroller.scrollTop,o=Fn(e),a={};t.bottom-t.top>o&&(t.bottom=t.top+o);var l=e.doc.height+Nn(n),s=t.top<r,c=t.bottom>l-r;if(t.top<i)a.scrollTop=s?0:t.top;else if(t.bottom>i+o){var u=Math.min(t.top,(c?l:t.bottom)-o);u!=i&&(a.scrollTop=u)}var d=e.options.fixedGutter?0:n.gutters.offsetWidth,f=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:n.scroller.scrollLeft-d,h=Dn(e)-n.gutters.offsetWidth,p=t.right-t.left>h;return p&&(t.right=t.left+h),t.left<10?a.scrollLeft=0:t.left<f?a.scrollLeft=Math.max(0,t.left+d-(p?0:10)):t.right>h+f-3&&(a.scrollLeft=t.right+(p?0:10)-h),a}function Pr(e,t){null!=t&&(Hr(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+t)}function Wr(e){Hr(e);var t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function zr(e,t,n){null==t&&null==n||Hr(e),null!=t&&(e.curOp.scrollLeft=t),null!=n&&(e.curOp.scrollTop=n)}function Hr(e){var t=e.curOp.scrollToPos;t&&(e.curOp.scrollToPos=null,Ir(e,Jn(e,t.from),Jn(e,t.to),t.margin))}function Ir(e,t,n,r){var i=Er(e,{left:Math.min(t.left,n.left),top:Math.min(t.top,n.top)-r,right:Math.max(t.right,n.right),bottom:Math.max(t.bottom,n.bottom)+r});zr(e,i.scrollLeft,i.scrollTop)}function Rr(e,t){Math.abs(e.doc.scrollTop-t)<2||(n||hi(e,{top:t}),Br(e,t,!0),n&&hi(e),si(e,100))}function Br(e,t,n){t=Math.max(0,Math.min(e.display.scroller.scrollHeight-e.display.scroller.clientHeight,t)),(e.display.scroller.scrollTop!=t||n)&&(e.doc.scrollTop=t,e.display.scrollbars.setScrollTop(t),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t))}function jr(e,t,n,r){t=Math.max(0,Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth)),(n?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)&&!r||(e.doc.scrollLeft=t,gi(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function qr(e){var t=e.display,n=t.gutters.offsetWidth,r=Math.round(e.doc.height+Nn(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+On(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:n}}var Ur=function(e,t,n){this.cm=n;var r=this.vert=A("div",[A("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=A("div",[A("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");r.tabIndex=i.tabIndex=-1,e(r),e(i),ge(r,"scroll",function(){r.clientHeight&&t(r.scrollTop,"vertical")}),ge(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,a&&l<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};Ur.prototype.update=function(e){var t=e.scrollWidth>e.clientWidth+1,n=e.scrollHeight>e.clientHeight+1,r=e.nativeBarWidth;if(n){this.vert.style.display="block",this.vert.style.bottom=t?r+"px":"0";var i=e.viewHeight-(t?r:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+i)+"px"}else this.vert.scrollTop=0,this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=n?r+"px":"0",this.horiz.style.left=e.barLeft+"px";var o=e.viewWidth-e.barLeft-(n?r:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+o)+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedZeroWidth&&e.clientHeight>0&&(0==r&&this.zeroWidthHack(),this.checkedZeroWidth=!0),{right:n?r:0,bottom:t?r:0}},Ur.prototype.setScrollLeft=function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")},Ur.prototype.setScrollTop=function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")},Ur.prototype.zeroWidthHack=function(){var e=b&&!p?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.visibility=this.vert.style.visibility="hidden",this.disableHoriz=new U,this.disableVert=new U},Ur.prototype.enableZeroWidthBar=function(e,t,n){e.style.visibility="",t.set(1e3,function r(){var i=e.getBoundingClientRect();("vert"==n?document.elementFromPoint(i.right-1,(i.top+i.bottom)/2):document.elementFromPoint((i.right+i.left)/2,i.bottom-1))!=e?e.style.visibility="hidden":t.set(1e3,r)})},Ur.prototype.clear=function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)};var Vr=function(){};function Kr(e,t){t||(t=qr(e));var n=e.display.barWidth,r=e.display.barHeight;$r(e,t);for(var i=0;i<4&&n!=e.display.barWidth||r!=e.display.barHeight;i++)n!=e.display.barWidth&&e.options.lineWrapping&&Or(e),$r(e,qr(e)),n=e.display.barWidth,r=e.display.barHeight}function $r(e,t){var n=e.display,r=n.scrollbars.update(t);n.sizer.style.paddingRight=(n.barWidth=r.right)+"px",n.sizer.style.paddingBottom=(n.barHeight=r.bottom)+"px",n.heightForcer.style.borderBottom=r.bottom+"px solid transparent",r.right&&r.bottom?(n.scrollbarFiller.style.display="block",n.scrollbarFiller.style.height=r.bottom+"px",n.scrollbarFiller.style.width=r.right+"px"):n.scrollbarFiller.style.display="",r.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(n.gutterFiller.style.display="block",n.gutterFiller.style.height=r.bottom+"px",n.gutterFiller.style.width=t.gutterWidth+"px"):n.gutterFiller.style.display=""}Vr.prototype.update=function(){return{bottom:0,right:0}},Vr.prototype.setScrollLeft=function(){},Vr.prototype.setScrollTop=function(){},Vr.prototype.clear=function(){};var Gr={native:Ur,null:Vr};function Xr(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&L(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new Gr[e.options.scrollbarStyle](function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),ge(t,"mousedown",function(){e.state.focused&&setTimeout(function(){return e.display.input.focus()},0)}),t.setAttribute("cm-not-content","true")},function(t,n){"horizontal"==n?jr(e,t):Rr(e,t)},e),e.display.scrollbars.addClass&&E(e.display.wrapper,e.display.scrollbars.addClass)}var Yr=0;function Zr(e){var t;e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:0,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Yr,markArrays:null},t=e.curOp,dn?dn.ops.push(t):t.ownsGroup=dn={ops:[t],delayedCallbacks:[]}}function Qr(e){var t=e.curOp;t&&function(e,t){var n=e.ownsGroup;if(n)try{!function(e){var t=e.delayedCallbacks,n=0;do{for(;n<t.length;n++)t[n].call(null);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++].call(null,i.cm)}}while(n<t.length)}(n)}finally{dn=null,t(n)}}(t,function(e){for(var t=0;t<e.ops.length;t++)e.ops[t].cm.curOp=null;!function(e){for(var t=e.ops,n=0;n<t.length;n++)Jr(t[n]);for(var r=0;r<t.length;r++)ei(t[r]);for(var i=0;i<t.length;i++)ti(t[i]);for(var o=0;o<t.length;o++)ni(t[o]);for(var a=0;a<t.length;a++)ri(t[a])}(e)})}function Jr(e){var t=e.cm,n=t.display;(function(e){var t=e.display;!t.scrollbarsClipped&&t.scroller.offsetWidth&&(t.nativeBarWidth=t.scroller.offsetWidth-t.scroller.clientWidth,t.heightForcer.style.height=On(e)+"px",t.sizer.style.marginBottom=-t.nativeBarWidth+"px",t.sizer.style.borderRightWidth=On(e)+"px",t.scrollbarsClipped=!0)})(t),e.updateMaxLine&&Yt(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 ui(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function ei(e){e.updatedDisplay=e.mustUpdate&&di(e.cm,e.update)}function ti(e){var t=e.cm,n=t.display;e.updatedDisplay&&Or(t),e.barMeasure=qr(t),n.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Pn(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+On(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,n.sizer.offsetLeft+e.adjustWidthTo-Dn(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=n.input.prepareSelection())}function ni(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft<t.doc.scrollLeft&&jr(t,Math.min(t.display.scroller.scrollLeft,e.maxScrollLeft),!0),t.display.maxLineChanged=!1);var n=e.focus&&e.focus==F(H(t));e.preparedSelection&&t.display.input.showSelection(e.preparedSelection,n),(e.updatedDisplay||e.startHeight!=t.doc.height)&&Kr(t,e.barMeasure),e.updatedDisplay&&mi(t,e.barMeasure),e.selectionChanged&&Tr(t),t.state.focused&&e.updateInput&&t.display.input.reset(e.typing),n&&Lr(e.cm)}function ri(e){var t=e.cm,n=t.display,r=t.doc;e.updatedDisplay&&fi(t,e.update),null==n.wheelStartX||null==e.scrollTop&&null==e.scrollLeft&&!e.scrollToPos||(n.wheelStartX=n.wheelStartY=null),null!=e.scrollTop&&Br(t,e.scrollTop,e.forceScroll),null!=e.scrollLeft&&jr(t,e.scrollLeft,!0,!0),e.scrollToPos&&function(e,t){if(!we(e,"scrollCursorIntoView")){var n=e.display,r=n.sizer.getBoundingClientRect(),i=null,o=n.wrapper.ownerDocument;if(t.top+r.top<0?i=!0:t.bottom+r.top>(o.defaultView.innerHeight||o.documentElement.clientHeight)&&(i=!1),null!=i&&!m){var a=A("div","",null,"position: absolute;\n top: "+(t.top-n.viewOffset-Mn(e.display))+"px;\n height: "+(t.bottom-t.top+On(e)+n.barHeight)+"px;\n left: "+t.left+"px; width: "+Math.max(2,t.right-t.left)+"px;");e.display.lineSpace.appendChild(a),a.scrollIntoView(i),e.display.lineSpace.removeChild(a)}}}(t,function(e,t,n,r){var i;null==r&&(r=0),e.options.lineWrapping||t!=n||(n="before"==t.sticky?ot(t.line,t.ch+1,"before"):t,t=t.ch?ot(t.line,"before"==t.sticky?t.ch-1:t.ch,"after"):t);for(var o=0;o<5;o++){var a=!1,l=Qn(e,t),s=n&&n!=t?Qn(e,n):l,c=Er(e,i={left:Math.min(l.left,s.left),top:Math.min(l.top,s.top)-r,right:Math.max(l.left,s.left),bottom:Math.max(l.bottom,s.bottom)+r}),u=e.doc.scrollTop,d=e.doc.scrollLeft;if(null!=c.scrollTop&&(Rr(e,c.scrollTop),Math.abs(e.doc.scrollTop-u)>1&&(a=!0)),null!=c.scrollLeft&&(jr(e,c.scrollLeft),Math.abs(e.doc.scrollLeft-d)>1&&(a=!0)),!a)break}return i}(t,ft(r,e.scrollToPos.from),ft(r,e.scrollToPos.to),e.scrollToPos.margin));var i=e.maybeHiddenMarkers,o=e.maybeUnhiddenMarkers;if(i)for(var a=0;a<i.length;++a)i[a].lines.length||be(i[a],"hide");if(o)for(var l=0;l<o.length;++l)o[l].lines.length&&be(o[l],"unhide");n.wrapper.offsetHeight&&(r.scrollTop=t.display.scroller.scrollTop),e.changeObjs&&be(t,"changes",t,e.changeObjs),e.update&&e.update.finish()}function ii(e,t){if(e.curOp)return t();Zr(e);try{return t()}finally{Qr(e)}}function oi(e,t){return function(){if(e.curOp)return t.apply(e,arguments);Zr(e);try{return t.apply(e,arguments)}finally{Qr(e)}}}function ai(e){return function(){if(this.curOp)return e.apply(this,arguments);Zr(this);try{return e.apply(this,arguments)}finally{Qr(this)}}}function li(e){return function(){var t=this.cm;if(!t||t.curOp)return e.apply(this,arguments);Zr(t);try{return e.apply(this,arguments)}finally{Qr(t)}}}function si(e,t){e.doc.highlightFrontier<e.display.viewTo&&e.state.highlight.set(t,B(ci,e))}function ci(e){var t=e.doc;if(!(t.highlightFrontier>=e.display.viewTo)){var n=+new Date+e.options.workTime,r=yt(e,t.highlightFrontier),i=[];t.iter(r.line,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(r.line>=e.display.viewFrom){var a=o.styles,l=o.text.length>e.options.maxHighlightLength?$e(t.mode,r.state):null,s=gt(e,o,r,!0);l&&(r.state=l),o.styles=s.styles;var c=o.styleClasses,u=s.classes;u?o.styleClasses=u:c&&(o.styleClasses=null);for(var d=!a||a.length!=o.styles.length||c!=u&&(!c||!u||c.bgClass!=u.bgClass||c.textClass!=u.textClass),f=0;!d&&f<a.length;++f)d=a[f]!=o.styles[f];d&&i.push(r.line),o.stateAfter=r.save(),r.nextLine()}else o.text.length<=e.options.maxHighlightLength&&bt(e,o.text,r),o.stateAfter=r.line%5==0?r.save():null,r.nextLine();if(+new Date>n)return si(e,e.options.workDelay),!0}),t.highlightFrontier=r.line,t.modeFrontier=Math.max(t.modeFrontier,r.line),i.length&&ii(e,function(){for(var t=0;t<i.length;t++)vr(e,i[t],"text")})}}var ui=function(e,t,n){var r=e.display;this.viewport=t,this.visible=Fr(r,e.doc,t),this.editorIsHidden=!r.wrapper.offsetWidth,this.wrapperHeight=r.wrapper.clientHeight,this.wrapperWidth=r.wrapper.clientWidth,this.oldDisplayWidth=Dn(e),this.force=n,this.dims=ur(e),this.events=[]};function di(e,t){var n=e.display,r=e.doc;if(t.editorIsHidden)return yr(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==wr(e))return!1;vi(e)&&(yr(e),t.dims=ur(e));var i=r.first+r.size,o=Math.max(t.visible.from-e.options.viewportMargin,r.first),a=Math.min(i,t.visible.to+e.options.viewportMargin);n.viewFrom<o&&o-n.viewFrom<20&&(o=Math.max(r.first,n.viewFrom)),n.viewTo>a&&n.viewTo-a<20&&(a=Math.min(i,n.viewTo)),Lt&&(o=Ut(e.doc,o),a=Vt(e.doc,a));var l=o!=n.viewFrom||a!=n.viewTo||n.lastWrapHeight!=t.wrapperHeight||n.lastWrapWidth!=t.wrapperWidth;(function(e,t,n){var r=e.display;0==r.view.length||t>=r.viewTo||n<=r.viewFrom?(r.view=un(e,t,n),r.viewFrom=t):(r.viewFrom>t?r.view=un(e,t,r.viewFrom).concat(r.view):r.viewFrom<t&&(r.view=r.view.slice(mr(e,t))),r.viewFrom=t,r.viewTo<n?r.view=r.view.concat(un(e,r.viewTo,n)):r.viewTo>n&&(r.view=r.view.slice(0,mr(e,n)))),r.viewTo=n})(e,o,a),n.viewOffset=Gt(Ze(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";var c=wr(e);if(!l&&0==c&&!t.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;var u=function(e){if(e.hasFocus())return null;var t=F(H(e));if(!t||!D(e.display.lineDiv,t))return null;var n={activeElt:t};if(window.getSelection){var r=R(e).getSelection();r.anchorNode&&r.extend&&D(e.display.lineDiv,r.anchorNode)&&(n.anchorNode=r.anchorNode,n.anchorOffset=r.anchorOffset,n.focusNode=r.focusNode,n.focusOffset=r.focusOffset)}return n}(e);return c>4&&(n.lineDiv.style.display="none"),function(e,t,n){var r=e.display,i=e.options.lineNumbers,o=r.lineDiv,a=o.firstChild;function l(t){var n=t.nextSibling;return s&&b&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),n}for(var c=r.view,u=r.viewFrom,d=0;d<c.length;d++){var f=c[d];if(f.hidden);else if(f.node&&f.node.parentNode==o){for(;a!=f.node;)a=l(a);var h=i&&null!=t&&t<=u&&f.lineNumber;f.changes&&(V(f.changes,"gutter")>-1&&(h=!1),mn(e,f,u,n)),h&&(M(f.lineNumber),f.lineNumber.appendChild(document.createTextNode(it(e.options,u)))),a=f.node.nextSibling}else{var p=kn(e,f,u,n);o.insertBefore(p,a)}u+=f.size}for(;a;)a=l(a)}(e,n.updateLineNumbers,t.dims),c>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,function(e){if(e&&e.activeElt&&e.activeElt!=F(I(e.activeElt))&&(e.activeElt.focus(),!/^(INPUT|TEXTAREA)$/.test(e.activeElt.nodeName)&&e.anchorNode&&D(document.body,e.anchorNode)&&D(document.body,e.focusNode))){var t=e.activeElt.ownerDocument,n=t.defaultView.getSelection(),r=t.createRange();r.setEnd(e.anchorNode,e.anchorOffset),r.collapse(!1),n.removeAllRanges(),n.addRange(r),n.extend(e.focusNode,e.focusOffset)}}(u),M(n.cursorDiv),M(n.selectionDiv),n.gutters.style.height=n.sizer.style.minHeight=0,l&&(n.lastWrapHeight=t.wrapperHeight,n.lastWrapWidth=t.wrapperWidth,si(e,400)),n.updateLineNumbers=null,!0}function fi(e,t){for(var n=t.viewport,r=!0;;r=!1){if(r&&e.options.lineWrapping&&t.oldDisplayWidth!=Dn(e))r&&(t.visible=Fr(e.display,e.doc,n));else if(n&&null!=n.top&&(n={top:Math.min(e.doc.height+Nn(e.display)-Fn(e),n.top)}),t.visible=Fr(e.display,e.doc,n),t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)break;if(!di(e,t))break;Or(e);var i=qr(e);xr(e),Kr(e,i),mi(e,i),t.force=!1}t.signal(e,"update",e),e.display.viewFrom==e.display.reportedViewFrom&&e.display.viewTo==e.display.reportedViewTo||(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function hi(e,t){var n=new ui(e,t);if(di(e,n)){Or(e),fi(e,n);var r=qr(e);xr(e),Kr(e,r),mi(e,r),n.finish()}}function pi(e){var t=e.gutters.offsetWidth;e.sizer.style.marginLeft=t+"px",hn(e,"gutterChanged",e)}function mi(e,t){e.display.sizer.style.minHeight=t.docHeight+"px",e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=t.docHeight+e.display.barHeight+On(e)+"px"}function gi(e){var t=e.display,n=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var r=dr(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=r+"px",a=0;a<n.length;a++)if(!n[a].hidden){e.options.fixedGutter&&(n[a].gutter&&(n[a].gutter.style.left=o),n[a].gutterBackground&&(n[a].gutterBackground.style.left=o));var l=n[a].alignable;if(l)for(var s=0;s<l.length;s++)l[s].style.left=o}e.options.fixedGutter&&(t.gutters.style.left=r+i+"px")}}function vi(e){if(!e.options.lineNumbers)return!1;var t=e.doc,n=it(e.options,t.first+t.size-1),r=e.display;if(n.length!=r.lineNumChars){var i=r.measure.appendChild(A("div",[A("div",n)],"CodeMirror-linenumber CodeMirror-gutter-elt")),o=i.firstChild.offsetWidth,a=i.offsetWidth-o;return r.lineGutter.style.width="",r.lineNumInnerWidth=Math.max(o,r.lineGutter.offsetWidth-a)+1,r.lineNumWidth=r.lineNumInnerWidth+a,r.lineNumChars=r.lineNumInnerWidth?n.length:-1,r.lineGutter.style.width=r.lineNumWidth+"px",pi(e.display),!0}return!1}function yi(e,t){for(var n=[],r=!1,i=0;i<e.length;i++){var o=e[i],a=null;if("string"!=typeof o&&(a=o.style,o=o.className),"CodeMirror-linenumbers"==o){if(!t)continue;r=!0}n.push({className:o,style:a})}return t&&!r&&n.push({className:"CodeMirror-linenumbers",style:null}),n}function bi(e){var t=e.gutters,n=e.gutterSpecs;M(t),e.lineGutter=null;for(var r=0;r<n.length;++r){var i=n[r],o=i.className,a=i.style,l=t.appendChild(A("div",null,"CodeMirror-gutter "+o));a&&(l.style.cssText=a),"CodeMirror-linenumbers"==o&&(e.lineGutter=l,l.style.width=(e.lineNumWidth||1)+"px")}t.style.display=n.length?"":"none",pi(e)}function wi(e){bi(e.display),gr(e),gi(e)}function xi(e,t,r,i){var o=this;this.input=r,o.scrollbarFiller=A("div",null,"CodeMirror-scrollbar-filler"),o.scrollbarFiller.setAttribute("cm-not-content","true"),o.gutterFiller=A("div",null,"CodeMirror-gutter-filler"),o.gutterFiller.setAttribute("cm-not-content","true"),o.lineDiv=O("div",null,"CodeMirror-code"),o.selectionDiv=A("div",null,null,"position: relative; z-index: 1"),o.cursorDiv=A("div",null,"CodeMirror-cursors"),o.measure=A("div",null,"CodeMirror-measure"),o.lineMeasure=A("div",null,"CodeMirror-measure"),o.lineSpace=O("div",[o.measure,o.lineMeasure,o.selectionDiv,o.cursorDiv,o.lineDiv],null,"position: relative; outline: none");var c=O("div",[o.lineSpace],"CodeMirror-lines");o.mover=A("div",[c],null,"position: relative"),o.sizer=A("div",[o.mover],"CodeMirror-sizer"),o.sizerWidth=null,o.heightForcer=A("div",null,null,"position: absolute; height: 50px; width: 1px;"),o.gutters=A("div",null,"CodeMirror-gutters"),o.lineGutter=null,o.scroller=A("div",[o.sizer,o.heightForcer,o.gutters],"CodeMirror-scroll"),o.scroller.setAttribute("tabIndex","-1"),o.wrapper=A("div",[o.scrollbarFiller,o.gutterFiller,o.scroller],"CodeMirror"),u&&105===d&&(o.wrapper.style.clipPath="inset(0px)"),o.wrapper.setAttribute("translate","no"),a&&l<8&&(o.gutters.style.zIndex=-1,o.scroller.style.paddingRight=0),s||n&&y||(o.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(o.wrapper):e(o.wrapper)),o.viewFrom=o.viewTo=t.first,o.reportedViewFrom=o.reportedViewTo=t.first,o.view=[],o.renderedView=null,o.externalMeasured=null,o.viewOffset=0,o.lastWrapHeight=o.lastWrapWidth=0,o.updateLineNumbers=null,o.nativeBarWidth=o.barHeight=o.barWidth=0,o.scrollbarsClipped=!1,o.lineNumWidth=o.lineNumInnerWidth=o.lineNumChars=null,o.alignWidgets=!1,o.cachedCharWidth=o.cachedTextHeight=o.cachedPaddingH=null,o.maxLine=null,o.maxLineLength=0,o.maxLineChanged=!1,o.wheelDX=o.wheelDY=o.wheelStartX=o.wheelStartY=null,o.shift=!1,o.selForContextMenu=null,o.activeTouch=null,o.gutterSpecs=yi(i.gutters,i.lineNumbers),bi(o),r.init(o)}ui.prototype.signal=function(e,t){ke(e,t)&&this.events.push(arguments)},ui.prototype.finish=function(){for(var e=0;e<this.events.length;e++)be.apply(null,this.events[e])};var ki=0,Ci=null;function _i(e){var t=e.wheelDeltaX,n=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==n&&e.detail&&e.axis==e.VERTICAL_AXIS?n=e.detail:null==n&&(n=e.wheelDelta),{x:t,y:n}}function Si(e){var t=_i(e);return t.x*=Ci,t.y*=Ci,t}function Ti(e,t){u&&102==d&&(null==e.display.chromeScrollHack?e.display.sizer.style.pointerEvents="none":clearTimeout(e.display.chromeScrollHack),e.display.chromeScrollHack=setTimeout(function(){e.display.chromeScrollHack=null,e.display.sizer.style.pointerEvents=""},100));var r=_i(t),i=r.x,o=r.y,a=Ci;0===t.deltaMode&&(i=t.deltaX,o=t.deltaY,a=1);var l=e.display,c=l.scroller,h=c.scrollWidth>c.clientWidth,p=c.scrollHeight>c.clientHeight;if(i&&h||o&&p){if(o&&b&&s)e:for(var m=t.target,g=l.view;m!=c;m=m.parentNode)for(var v=0;v<g.length;v++)if(g[v].node==m){e.display.currentWheelTarget=m;break e}if(i&&!n&&!f&&null!=a)return o&&p&&Rr(e,Math.max(0,c.scrollTop+o*a)),jr(e,Math.max(0,c.scrollLeft+i*a)),(!o||o&&p)&&_e(t),void(l.wheelStartX=null);if(o&&null!=a){var y=o*a,w=e.doc.scrollTop,x=w+l.wrapper.clientHeight;y<0?w=Math.max(0,w+y-50):x=Math.min(e.doc.height,x+y+50),hi(e,{top:w,bottom:x})}ki<20&&0!==t.deltaMode&&(null==l.wheelStartX?(l.wheelStartX=c.scrollLeft,l.wheelStartY=c.scrollTop,l.wheelDX=i,l.wheelDY=o,setTimeout(function(){if(null!=l.wheelStartX){var e=c.scrollLeft-l.wheelStartX,t=c.scrollTop-l.wheelStartY,n=t&&l.wheelDY&&t/l.wheelDY||e&&l.wheelDX&&e/l.wheelDX;l.wheelStartX=l.wheelStartY=null,n&&(Ci=(Ci*ki+n)/(ki+1),++ki)}},200)):(l.wheelDX+=i,l.wheelDY+=o))}}a?Ci=-.53:n?Ci=15:u?Ci=-.7:h&&(Ci=-1/3);var Li=function(e,t){this.ranges=e,this.primIndex=t};Li.prototype.primary=function(){return this.ranges[this.primIndex]},Li.prototype.equals=function(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(var t=0;t<this.ranges.length;t++){var n=this.ranges[t],r=e.ranges[t];if(!lt(n.anchor,r.anchor)||!lt(n.head,r.head))return!1}return!0},Li.prototype.deepCopy=function(){for(var e=[],t=0;t<this.ranges.length;t++)e[t]=new Mi(st(this.ranges[t].anchor),st(this.ranges[t].head));return new Li(e,this.primIndex)},Li.prototype.somethingSelected=function(){for(var e=0;e<this.ranges.length;e++)if(!this.ranges[e].empty())return!0;return!1},Li.prototype.contains=function(e,t){t||(t=e);for(var n=0;n<this.ranges.length;n++){var r=this.ranges[n];if(at(t,r.from())>=0&&at(e,r.to())<=0)return n}return-1};var Mi=function(e,t){this.anchor=e,this.head=t};function Ni(e,t,n){var r=e&&e.options.selectionsMayTouch,i=t[n];t.sort(function(e,t){return at(e.from(),t.from())}),n=V(t,i);for(var o=1;o<t.length;o++){var a=t[o],l=t[o-1],s=at(l.to(),a.from());if(r&&!a.empty()?s>0:s>=0){var c=ut(l.from(),a.from()),u=ct(l.to(),a.to()),d=l.empty()?a.from()==a.head:l.from()==l.head;o<=n&&--n,t.splice(--o,2,new Mi(d?u:c,d?c:u))}}return new Li(t,n)}function Ai(e,t){return new Li([new Mi(e,t||e)],0)}function Oi(e){return e.text?ot(e.from.line+e.text.length-1,J(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function Di(e,t){if(at(e,t.from)<0)return e;if(at(e,t.to)<=0)return Oi(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+=Oi(t).ch-t.to.ch),ot(n,r)}function Fi(e,t){for(var n=[],r=0;r<e.sel.ranges.length;r++){var i=e.sel.ranges[r];n.push(new Mi(Di(i.anchor,t),Di(i.head,t)))}return Ni(e.cm,n,e.sel.primIndex)}function Ei(e,t,n){return e.line==t.line?ot(n.line,e.ch-t.ch+n.ch):ot(n.line+(e.line-t.line),e.ch)}function Pi(e){e.doc.mode=Ue(e.options,e.doc.modeOption),Wi(e)}function Wi(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.modeFrontier=e.doc.highlightFrontier=e.doc.first,si(e,100),e.state.modeGen++,e.curOp&&gr(e)}function zi(e,t){return 0==t.from.ch&&0==t.to.ch&&""==J(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function Hi(e,t,n,r){function i(e){return n?n[e]:null}function o(e,n,i){(function(e,t,n,r){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),null!=e.order&&(e.order=null),Ft(e),Et(e,n);var i=r?r(e):1;i!=e.height&&et(e,i)})(e,n,i,r),hn(e,"change",e,t)}function a(e,t){for(var n=[],o=e;o<t;++o)n.push(new Zt(c[o],i(o),r));return n}var l=t.from,s=t.to,c=t.text,u=Ze(e,l.line),d=Ze(e,s.line),f=J(c),h=i(c.length-1),p=s.line-l.line;if(t.full)e.insert(0,a(0,c.length)),e.remove(c.length,e.size-c.length);else if(zi(e,t)){var m=a(0,c.length-1);o(d,d.text,h),p&&e.remove(l.line,p),m.length&&e.insert(l.line,m)}else if(u==d)if(1==c.length)o(u,u.text.slice(0,l.ch)+f+u.text.slice(s.ch),h);else{var g=a(1,c.length-1);g.push(new Zt(f+u.text.slice(s.ch),h,r)),o(u,u.text.slice(0,l.ch)+c[0],i(0)),e.insert(l.line+1,g)}else if(1==c.length)o(u,u.text.slice(0,l.ch)+c[0]+d.text.slice(s.ch),i(0)),e.remove(l.line+1,p);else{o(u,u.text.slice(0,l.ch)+c[0],i(0)),o(d,f+d.text.slice(s.ch),h);var v=a(1,c.length-1);p>1&&e.remove(l.line+1,p-1),e.insert(l.line+1,v)}hn(e,"change",e,t)}function Ii(e,t,n){!function e(r,i,o){if(r.linked)for(var a=0;a<r.linked.length;++a){var l=r.linked[a];if(l.doc!=i){var s=o&&l.sharedHist;n&&!s||(t(l.doc,s),e(l.doc,r,s))}}}(e,null,!0)}function Ri(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,hr(e),Pi(e),Bi(e),e.options.direction=t.direction,e.options.lineWrapping||Yt(e),e.options.mode=t.modeOption,gr(e)}function Bi(e){("rtl"==e.doc.direction?E:L)(e.display.lineDiv,"CodeMirror-rtl")}function ji(e){this.done=[],this.undone=[],this.undoDepth=e?e.undoDepth:1/0,this.lastModTime=this.lastSelTime=0,this.lastOp=this.lastSelOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=e?e.maxGeneration:1}function qi(e,t){var n={from:st(t.from),to:Oi(t),text:Qe(e,t.from,t.to)};return Gi(e,n,t.from.line,t.to.line+1),Ii(e,function(e){return Gi(e,n,t.from.line,t.to.line+1)},!0),n}function Ui(e){for(;e.length&&J(e).ranges;)e.pop()}function Vi(e,t,n,r){var i=e.history;i.undone.length=0;var o,a,l=+new Date;if((i.lastOp==r||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&i.lastModTime>l-(e.cm?e.cm.options.historyEventDelay:500)||"*"==t.origin.charAt(0)))&&(o=function(e,t){return t?(Ui(e.done),J(e.done)):e.done.length&&!J(e.done).ranges?J(e.done):e.done.length>1&&!e.done[e.done.length-2].ranges?(e.done.pop(),J(e.done)):void 0}(i,i.lastOp==r)))a=J(o.changes),0==at(t.from,t.to)&&0==at(t.from,a.to)?a.to=Oi(t):o.changes.push(qi(e,t));else{var s=J(i.done);for(s&&s.ranges||$i(e.sel,i.done),o={changes:[qi(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,a||be(e,"historyAdded")}function Ki(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||function(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)}(e,o,J(i.done),t))?i.done[i.done.length-1]=t:$i(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=n,r&&!1!==r.clearRedo&&Ui(i.undone)}function $i(e,t){var n=J(t);n&&n.ranges&&n.equals(e)||t.push(e)}function Gi(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 Xi(e){if(!e)return null;for(var t,n=0;n<e.length;++n)e[n].marker.explicitlyCleared?t||(t=e.slice(0,n)):t&&t.push(e[n]);return t?t.length?t:null:e}function Yi(e,t){var n=function(e,t){var n=t["spans_"+e.id];if(!n)return null;for(var r=[],i=0;i<t.text.length;++i)r.push(Xi(n[i]));return r}(e,t),r=Ot(e,t);if(!n)return r;if(!r)return n;for(var i=0;i<n.length;++i){var o=n[i],a=r[i];if(o&&a)e:for(var l=0;l<a.length;++l){for(var s=a[l],c=0;c<o.length;++c)if(o[c].marker==s.marker)continue e;o.push(s)}else a&&(n[i]=a)}return n}function Zi(e,t,n){for(var r=[],i=0;i<e.length;++i){var o=e[i];if(o.ranges)r.push(n?Li.prototype.deepCopy.call(o):o);else{var a=o.changes,l=[];r.push({changes:l});for(var s=0;s<a.length;++s){var c=a[s],u=void 0;if(l.push({from:c.from,to:c.to,text:c.text}),t)for(var d in c)(u=d.match(/^spans_(\d+)$/))&&V(t,Number(u[1]))>-1&&(J(l)[d]=c[d],delete c[d])}}}return r}function Qi(e,t,n,r){if(r){var i=e.anchor;if(n){var o=at(t,i)<0;o!=at(n,i)<0?(i=t,t=n):o!=at(t,n)<0&&(t=n)}return new Mi(i,t)}return new Mi(n||t,t)}function Ji(e,t,n,r,i){null==i&&(i=e.cm&&(e.cm.display.shift||e.extend)),io(e,new Li([Qi(e.sel.primary(),t,n,i)],0),r)}function eo(e,t,n){for(var r=[],i=e.cm&&(e.cm.display.shift||e.extend),o=0;o<e.sel.ranges.length;o++)r[o]=Qi(e.sel.ranges[o],t[o],null,i);io(e,Ni(e.cm,r,e.sel.primIndex),n)}function to(e,t,n,r){var i=e.sel.ranges.slice(0);i[t]=n,io(e,Ni(e.cm,i,e.sel.primIndex),r)}function no(e,t,n,r){io(e,Ai(t,n),r)}function ro(e,t,n){var r=e.history.done,i=J(r);i&&i.ranges?(r[r.length-1]=t,oo(e,t,n)):io(e,t,n)}function io(e,t,n){oo(e,t,n),Ki(e,e.sel,e.cm?e.cm.curOp.id:NaN,n)}function oo(e,t,n){(ke(e,"beforeSelectionChange")||e.cm&&ke(e.cm,"beforeSelectionChange"))&&(t=function(e,t,n){var r={ranges:t.ranges,update:function(t){this.ranges=[];for(var n=0;n<t.length;n++)this.ranges[n]=new Mi(ft(e,t[n].anchor),ft(e,t[n].head))},origin:n&&n.origin};return be(e,"beforeSelectionChange",e,r),e.cm&&be(e.cm,"beforeSelectionChange",e.cm,r),r.ranges!=t.ranges?Ni(e.cm,r.ranges,r.ranges.length-1):t}(e,t,n));var r=n&&n.bias||(at(t.primary().head,e.sel.primary().head)<0?-1:1);ao(e,so(e,t,r,!0)),n&&!1===n.scroll||!e.cm||"nocursor"==e.cm.getOption("readOnly")||Wr(e.cm)}function ao(e,t){t.equals(e.sel)||(e.sel=t,e.cm&&(e.cm.curOp.updateInput=1,e.cm.curOp.selectionChanged=!0,xe(e.cm)),hn(e,"cursorActivity",e))}function lo(e){ao(e,so(e,e.sel,null,!1))}function so(e,t,n,r){for(var i,o=0;o<t.ranges.length;o++){var a=t.ranges[o],l=t.ranges.length==e.sel.ranges.length&&e.sel.ranges[o],s=uo(e,a.anchor,l&&l.anchor,n,r),c=a.head==a.anchor?s:uo(e,a.head,l&&l.head,n,r);(i||s!=a.anchor||c!=a.head)&&(i||(i=t.ranges.slice(0,o)),i[o]=new Mi(s,c))}return i?Ni(e.cm,i,t.primIndex):t}function co(e,t,n,r,i){var o=Ze(e,t.line);if(o.markedSpans)for(var a=0;a<o.markedSpans.length;++a){var l=o.markedSpans[a],s=l.marker,c="selectLeft"in s?!s.selectLeft:s.inclusiveLeft,u="selectRight"in s?!s.selectRight:s.inclusiveRight;if((null==l.from||(c?l.from<=t.ch:l.from<t.ch))&&(null==l.to||(u?l.to>=t.ch:l.to>t.ch))){if(i&&(be(s,"beforeCursorEnter"),s.explicitlyCleared)){if(o.markedSpans){--a;continue}break}if(!s.atomic)continue;if(n){var d=s.find(r<0?1:-1),f=void 0;if((r<0?u:c)&&(d=fo(e,d,-r,d&&d.line==t.line?o:null)),d&&d.line==t.line&&(f=at(d,n))&&(r<0?f<0:f>0))return co(e,d,t,r,i)}var h=s.find(r<0?-1:1);return(r<0?c:u)&&(h=fo(e,h,r,h.line==t.line?o:null)),h?co(e,h,t,r,i):null}}return t}function uo(e,t,n,r,i){var o=r||1;return co(e,t,n,o,i)||!i&&co(e,t,n,o,!0)||co(e,t,n,-o,i)||!i&&co(e,t,n,-o,!0)||(e.cantEdit=!0,ot(e.first,0))}function fo(e,t,n,r){return n<0&&0==t.ch?t.line>e.first?ft(e,ot(t.line-1)):null:n>0&&t.ch==(r||Ze(e,t.line)).text.length?t.line<e.first+e.size-1?ot(t.line+1,0):null:new ot(t.line,t.ch+n)}function ho(e){e.setSelection(ot(e.firstLine(),0),ot(e.lastLine()),$)}function po(e,t,n){var r={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){return r.canceled=!0}};return n&&(r.update=function(t,n,i,o){t&&(r.from=ft(e,t)),n&&(r.to=ft(e,n)),i&&(r.text=i),void 0!==o&&(r.origin=o)}),be(e,"beforeChange",e,r),e.cm&&be(e.cm,"beforeChange",e.cm,r),r.canceled?(e.cm&&(e.cm.curOp.updateInput=2),null):{from:r.from,to:r.to,text:r.text,origin:r.origin}}function mo(e,t,n){if(e.cm){if(!e.cm.curOp)return oi(e.cm,mo)(e,t,n);if(e.cm.state.suppressEdits)return}if(!(ke(e,"beforeChange")||e.cm&&ke(e.cm,"beforeChange"))||(t=po(e,t,!0))){var r=Tt&&!n&&function(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!=V(r,n)||(r||(r=[])).push(n)}}),!r)return null;for(var i=[{from:t,to:n}],o=0;o<r.length;++o)for(var a=r[o],l=a.find(0),s=0;s<i.length;++s){var c=i[s];if(!(at(c.to,l.from)<0||at(c.from,l.to)>0)){var u=[s,1],d=at(c.from,l.from),f=at(c.to,l.to);(d<0||!a.inclusiveLeft&&!d)&&u.push({from:c.from,to:l.from}),(f>0||!a.inclusiveRight&&!f)&&u.push({from:l.to,to:c.to}),i.splice.apply(i,u),s+=u.length-3}}return i}(e,t.from,t.to);if(r)for(var i=r.length-1;i>=0;--i)go(e,{from:r[i].from,to:r[i].to,text:i?[""]:t.text,origin:t.origin});else go(e,t)}}function go(e,t){if(1!=t.text.length||""!=t.text[0]||0!=at(t.from,t.to)){var n=Fi(e,t);Vi(e,t,n,e.cm?e.cm.curOp.id:NaN),bo(e,t,n,Ot(e,t));var r=[];Ii(e,function(e,n){n||-1!=V(r,e.history)||(Co(e.history,t),r.push(e.history)),bo(e,t,null,Ot(e,t))})}}function vo(e,t,n){var r=e.cm&&e.cm.state.suppressEdits;if(!r||n){for(var i,o=e.history,a=e.sel,l="undo"==t?o.done:o.undone,s="undo"==t?o.undone:o.done,c=0;c<l.length&&(i=l[c],n?!i.ranges||i.equals(e.sel):i.ranges);c++);if(c!=l.length){for(o.lastOrigin=o.lastSelOrigin=null;;){if(!(i=l.pop()).ranges){if(r)return void l.push(i);break}if($i(i,s),n&&!i.equals(e.sel))return void io(e,i,{clearRedo:!1});a=i}var u=[];$i(a,s),s.push({changes:u,generation:o.generation}),o.generation=i.generation||++o.maxGeneration;for(var d=ke(e,"beforeChange")||e.cm&&ke(e.cm,"beforeChange"),f=function(n){var r=i.changes[n];if(r.origin=t,d&&!po(e,r,!1))return l.length=0,{};u.push(qi(e,r));var o=n?Fi(e,r):J(l);bo(e,r,o,Yi(e,r)),!n&&e.cm&&e.cm.scrollIntoView({from:r.from,to:Oi(r)});var a=[];Ii(e,function(e,t){t||-1!=V(a,e.history)||(Co(e.history,r),a.push(e.history)),bo(e,r,null,Yi(e,r))})},h=i.changes.length-1;h>=0;--h){var p=f(h);if(p)return p.v}}}}function yo(e,t){if(0!=t&&(e.first+=t,e.sel=new Li(ee(e.sel.ranges,function(e){return new Mi(ot(e.anchor.line+t,e.anchor.ch),ot(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){gr(e.cm,e.first,e.first-t,t);for(var n=e.cm.display,r=n.viewFrom;r<n.viewTo;r++)vr(e.cm,r,"gutter")}}function bo(e,t,n,r){if(e.cm&&!e.cm.curOp)return oi(e.cm,bo)(e,t,n,r);if(t.to.line<e.first)yo(e,t.text.length-1-(t.to.line-t.from.line));else if(!(t.from.line>e.lastLine())){if(t.from.line<e.first){var i=t.text.length-1-(e.first-t.from.line);yo(e,i),t={from:ot(e.first,0),to:ot(t.to.line+i,t.to.ch),text:[J(t.text)],origin:t.origin}}var o=e.lastLine();t.to.line>o&&(t={from:t.from,to:ot(o,Ze(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=Qe(e,t.from,t.to),n||(n=Fi(e,t)),e.cm?function(e,t,n){var r=e.doc,i=e.display,o=t.from,a=t.to,l=!1,s=o.line;e.options.lineWrapping||(s=tt(qt(Ze(r,o.line))),r.iter(s,a.line+1,function(e){if(e==i.maxLine)return l=!0,!0})),r.sel.contains(t.from,t.to)>-1&&xe(e),Hi(r,t,n,fr(e)),e.options.lineWrapping||(r.iter(s,o.line+t.text.length,function(e){var t=Xt(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,l=!1)}),l&&(e.curOp.updateMaxLine=!0)),function(e,t){if(e.modeFrontier=Math.min(e.modeFrontier,t),!(e.highlightFrontier<t-10)){for(var n=e.first,r=t-1;r>n;r--){var i=Ze(e,r).stateAfter;if(i&&(!(i instanceof pt)||r+i.lookAhead<t)){n=r+1;break}}e.highlightFrontier=Math.min(e.highlightFrontier,n)}}(r,o.line),si(e,400);var c=t.text.length-(a.line-o.line)-1;t.full?gr(e):o.line!=a.line||1!=t.text.length||zi(e.doc,t)?gr(e,o.line,a.line+1,c):vr(e,o.line,"text");var u=ke(e,"changes"),d=ke(e,"change");if(d||u){var f={from:o,to:a,text:t.text,removed:t.removed,origin:t.origin};d&&hn(e,"change",e,f),u&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(f)}e.display.selForContextMenu=null}(e.cm,t,r):Hi(e,t,r),oo(e,n,$),e.cantEdit&&uo(e,ot(e.firstLine(),0))&&(e.cantEdit=!1)}}function wo(e,t,n,r,i){var o;r||(r=n),at(r,n)<0&&(n=(o=[r,n])[0],r=o[1]),"string"==typeof t&&(t=e.splitLines(t)),mo(e,{from:n,to:r,text:t,origin:i})}function xo(e,t,n,r){n<e.line?e.line+=r:t<e.line&&(e.line=t,e.ch=0)}function ko(e,t,n,r){for(var i=0;i<e.length;++i){var o=e[i],a=!0;if(o.ranges){o.copied||((o=e[i]=o.deepCopy()).copied=!0);for(var l=0;l<o.ranges.length;l++)xo(o.ranges[l].anchor,t,n,r),xo(o.ranges[l].head,t,n,r)}else{for(var s=0;s<o.changes.length;++s){var c=o.changes[s];if(n<c.from.line)c.from=ot(c.from.line+r,c.from.ch),c.to=ot(c.to.line+r,c.to.ch);else if(t<=c.to.line){a=!1;break}}a||(e.splice(0,i+1),i=0)}}}function Co(e,t){var n=t.from.line,r=t.to.line,i=t.text.length-(r-n)-1;ko(e.done,n,r,i),ko(e.undone,n,r,i)}function _o(e,t,n,r){var i=t,o=t;return"number"==typeof t?o=Ze(e,dt(e,t)):i=tt(t),null==i?null:(r(o,i)&&e.cm&&vr(e.cm,i,n),o)}function So(e){this.lines=e,this.parent=null;for(var t=0,n=0;n<e.length;++n)e[n].parent=this,t+=e[n].height;this.height=t}function To(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}Mi.prototype.from=function(){return ut(this.anchor,this.head)},Mi.prototype.to=function(){return ct(this.anchor,this.head)},Mi.prototype.empty=function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch},So.prototype={chunkSize:function(){return this.lines.length},removeInner:function(e,t){for(var n=e,r=e+t;n<r;++n){var i=this.lines[n];this.height-=i.height,Qt(i),hn(i,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,n){this.height+=n,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var r=0;r<t.length;++r)t[r].parent=this},iterN:function(e,t,n){for(var r=e+t;e<r;++e)if(n(this.lines[e]))return!0}},To.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var n=0;n<this.children.length;++n){var r=this.children[n],i=r.chunkSize();if(e<i){var o=Math.min(t,i-e),a=r.height;if(r.removeInner(e,o),this.height-=a-r.height,i==o&&(this.children.splice(n--,1),r.parent=null),0==(t-=o))break;e=0}else e-=i}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof So))){var l=[];this.collapse(l),this.children=[new So(l)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t<this.children.length;++t)this.children[t].collapse(e)},insertInner:function(e,t,n){this.size+=t.length,this.height+=n;for(var r=0;r<this.children.length;++r){var i=this.children[r],o=i.chunkSize();if(e<=o){if(i.insertInner(e,t,n),i.lines&&i.lines.length>50){for(var a=i.lines.length%25+25,l=a;l<i.lines.length;){var s=new So(i.lines.slice(l,l+=25));i.height-=s.height,this.children.splice(++r,0,s),s.parent=this}i.lines=i.lines.slice(0,a),this.maybeSpill()}break}e-=o}},maybeSpill:function(){if(!(this.children.length<=10)){var e=this;do{var t=new To(e.children.splice(e.children.length-5,5));if(e.parent){e.size-=t.size,e.height-=t.height;var n=V(e.parent.children,e);e.parent.children.splice(n+1,0,t)}else{var r=new To(e.children);r.parent=e,e.children=[r,t],e=r}t.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},iterN:function(e,t,n){for(var r=0;r<this.children.length;++r){var i=this.children[r],o=i.chunkSize();if(e<o){var a=Math.min(t,o-e);if(i.iterN(e,a,n))return!0;if(0==(t-=a))break;e=0}else e-=o}}};var Lo=function(e,t,n){if(n)for(var r in n)n.hasOwnProperty(r)&&(this[r]=n[r]);this.doc=e,this.node=t};function Mo(e,t,n){Gt(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Pr(e,n)}Lo.prototype.clear=function(){var e=this.doc.cm,t=this.line.widgets,n=this.line,r=tt(n);if(null!=r&&t){for(var i=0;i<t.length;++i)t[i]==this&&t.splice(i--,1);t.length||(n.widgets=null);var o=Tn(this);et(n,Math.max(0,n.height-o)),e&&(ii(e,function(){Mo(e,n,-o),vr(e,r,"widget")}),hn(e,"lineWidgetCleared",e,this,r))}},Lo.prototype.changed=function(){var e=this,t=this.height,n=this.doc.cm,r=this.line;this.height=null;var i=Tn(this)-t;i&&(Kt(this.doc,r)||et(r,r.height+i),n&&ii(n,function(){n.curOp.forceUpdate=!0,Mo(n,r,i),hn(n,"lineWidgetChanged",n,e,tt(r))}))},Ce(Lo);var No=0,Ao=function(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++No};function Oo(e,t,n,r,i){if(r&&r.shared)return function(e,t,n,r,i){(r=j(r)).shared=!1;var o=[Oo(e,t,n,r,i)],a=o[0],l=r.widgetNode;return Ii(e,function(e){l&&(r.widgetNode=l.cloneNode(!0)),o.push(Oo(e,ft(e,t),ft(e,n),r,i));for(var s=0;s<e.linked.length;++s)if(e.linked[s].isParent)return;a=J(o)}),new Do(o,a)}(e,t,n,r,i);if(e.cm&&!e.cm.curOp)return oi(e.cm,Oo)(e,t,n,r,i);var o=new Ao(e,i),a=at(t,n);if(r&&j(r,o,!1),a>0||0==a&&!1!==o.clearWhenEmpty)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(jt(e,t.line,t,n,o)||t.line!=n.line&&jt(e,n.line,t,n,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");Lt=!0}o.addToHistory&&Vi(e,{from:t,to:n,origin:"markText"},e.sel,NaN);var l,s=t.line,c=e.cm;if(e.iter(s,n.line+1,function(r){c&&o.collapsed&&!c.options.lineWrapping&&qt(r)==c.display.maxLine&&(l=!0),o.collapsed&&s!=t.line&&et(r,0),function(e,t,n){var r=n&&window.WeakSet&&(n.markedSpans||(n.markedSpans=new WeakSet));r&&e.markedSpans&&r.has(e.markedSpans)?e.markedSpans.push(t):(e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],r&&r.add(e.markedSpans)),t.marker.attachLine(e)}(r,new Mt(o,s==t.line?t.ch:null,s==n.line?n.ch:null),e.cm&&e.cm.curOp),++s}),o.collapsed&&e.iter(t.line,n.line+1,function(t){Kt(e,t)&&et(t,0)}),o.clearOnEnter&&ge(o,"beforeCursorEnter",function(){return o.clear()}),o.readOnly&&(Tt=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++No,o.atomic=!0),c){if(l&&(c.curOp.updateMaxLine=!0),o.collapsed)gr(c,t.line,n.line+1);else if(o.className||o.startStyle||o.endStyle||o.css||o.attributes||o.title)for(var u=t.line;u<=n.line;u++)vr(c,u,"text");o.atomic&&lo(c.doc),hn(c,"markerAdded",c,o)}return o}Ao.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&Zr(e),ke(this,"clear")){var n=this.find();n&&hn(this,"clear",n.from,n.to)}for(var r=null,i=null,o=0;o<this.lines.length;++o){var a=this.lines[o],l=Nt(a.markedSpans,this);e&&!this.collapsed?vr(e,tt(a),"text"):e&&(null!=l.to&&(i=tt(a)),null!=l.from&&(r=tt(a))),a.markedSpans=At(a.markedSpans,l),null==l.from&&this.collapsed&&!Kt(this.doc,a)&&e&&et(a,sr(e.display))}if(e&&this.collapsed&&!e.options.lineWrapping)for(var s=0;s<this.lines.length;++s){var c=qt(this.lines[s]),u=Xt(c);u>e.display.maxLineLength&&(e.display.maxLine=c,e.display.maxLineLength=u,e.display.maxLineChanged=!0)}null!=r&&e&&this.collapsed&&gr(e,r,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&lo(e.doc)),e&&hn(e,"markerCleared",e,this,r,i),t&&Qr(e),this.parent&&this.parent.clear()}},Ao.prototype.find=function(e,t){var n,r;null==e&&"bookmark"==this.type&&(e=1);for(var i=0;i<this.lines.length;++i){var o=this.lines[i],a=Nt(o.markedSpans,this);if(null!=a.from&&(n=ot(t?o:tt(o),a.from),-1==e))return n;if(null!=a.to&&(r=ot(t?o:tt(o),a.to),1==e))return r}return n&&{from:n,to:r}},Ao.prototype.changed=function(){var e=this,t=this.find(-1,!0),n=this,r=this.doc.cm;t&&r&&ii(r,function(){var i=t.line,o=tt(t.line),a=Wn(r,o);if(a&&(qn(a),r.curOp.selectionChanged=r.curOp.forceUpdate=!0),r.curOp.updateMaxLine=!0,!Kt(n.doc,i)&&null!=n.height){var l=n.height;n.height=null;var s=Tn(n)-l;s&&et(i,i.height+s)}hn(r,"markerChanged",r,e)})},Ao.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;t.maybeHiddenMarkers&&-1!=V(t.maybeHiddenMarkers,this)||(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)},Ao.prototype.detachLine=function(e){if(this.lines.splice(V(this.lines,e),1),!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}},Ce(Ao);var Do=function(e,t){this.markers=e,this.primary=t;for(var n=0;n<e.length;++n)e[n].parent=this};function Fo(e){return e.findMarks(ot(e.first,0),e.clipPos(ot(e.lastLine())),function(e){return e.parent})}function Eo(e){for(var t=function(t){var n=e[t],r=[n.primary.doc];Ii(n.primary.doc,function(e){return r.push(e)});for(var i=0;i<n.markers.length;i++){var o=n.markers[i];-1==V(r,o.doc)&&(o.parent=null,n.markers.splice(i--,1))}},n=0;n<e.length;n++)t(n)}Do.prototype.clear=function(){if(!this.explicitlyCleared){this.explicitlyCleared=!0;for(var e=0;e<this.markers.length;++e)this.markers[e].clear();hn(this,"clear")}},Do.prototype.find=function(e,t){return this.primary.find(e,t)},Ce(Do);var Po=0,Wo=function(e,t,n,r,i){if(!(this instanceof Wo))return new Wo(e,t,n,r,i);null==n&&(n=0),To.call(this,[new So([new Zt("",null)])]),this.first=n,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.modeFrontier=this.highlightFrontier=n;var o=ot(n,0);this.sel=Ai(o),this.history=new ji(null),this.id=++Po,this.modeOption=t,this.lineSep=r,this.direction="rtl"==i?"rtl":"ltr",this.extend=!1,"string"==typeof e&&(e=this.splitLines(e)),Hi(this,{from:o,to:o,text:e}),io(this,Ai(o),$)};Wo.prototype=ne(To.prototype,{constructor:Wo,iter:function(e,t,n){n?this.iterN(e-this.first,t-e,n):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var n=0,r=0;r<t.length;++r)n+=t[r].height;this.insertInner(e-this.first,t,n)},remove:function(e,t){this.removeInner(e-this.first,t)},getValue:function(e){var t=Je(this,this.first,this.first+this.size);return!1===e?t:t.join(e||this.lineSeparator())},setValue:li(function(e){var t=ot(this.first,0),n=this.first+this.size-1;mo(this,{from:t,to:ot(n,Ze(this,n).text.length),text:this.splitLines(e),origin:"setValue",full:!0},!0),this.cm&&zr(this.cm,0,0),io(this,Ai(t),$)}),replaceRange:function(e,t,n,r){wo(this,e,t=ft(this,t),n=n?ft(this,n):t,r)},getRange:function(e,t,n){var r=Qe(this,ft(this,e),ft(this,t));return!1===n?r:""===n?r.join(""):r.join(n||this.lineSeparator())},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},getLineHandle:function(e){if(rt(this,e))return Ze(this,e)},getLineNumber:function(e){return tt(e)},getLineHandleVisualStart:function(e){return"number"==typeof e&&(e=Ze(this,e)),qt(e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return ft(this,e)},getCursor:function(e){var t=this.sel.primary();return null==e||"head"==e?t.head:"anchor"==e?t.anchor:"end"==e||"to"==e||!1===e?t.to():t.from()},listSelections:function(){return this.sel.ranges},somethingSelected:function(){return this.sel.somethingSelected()},setCursor:li(function(e,t,n){no(this,ft(this,"number"==typeof e?ot(e,t||0):e),null,n)}),setSelection:li(function(e,t,n){no(this,ft(this,e),ft(this,t||e),n)}),extendSelection:li(function(e,t,n){Ji(this,ft(this,e),t&&ft(this,t),n)}),extendSelections:li(function(e,t){eo(this,ht(this,e),t)}),extendSelectionsBy:li(function(e,t){eo(this,ht(this,ee(this.sel.ranges,e)),t)}),setSelections:li(function(e,t,n){if(e.length){for(var r=[],i=0;i<e.length;i++)r[i]=new Mi(ft(this,e[i].anchor),ft(this,e[i].head||e[i].anchor));null==t&&(t=Math.min(e.length-1,this.sel.primIndex)),io(this,Ni(this.cm,r,t),n)}}),addSelection:li(function(e,t,n){var r=this.sel.ranges.slice(0);r.push(new Mi(ft(this,e),ft(this,t||e))),io(this,Ni(this.cm,r,r.length-1),n)}),getSelection:function(e){for(var t,n=this.sel.ranges,r=0;r<n.length;r++){var i=Qe(this,n[r].from(),n[r].to());t=t?t.concat(i):i}return!1===e?t:t.join(e||this.lineSeparator())},getSelections:function(e){for(var t=[],n=this.sel.ranges,r=0;r<n.length;r++){var i=Qe(this,n[r].from(),n[r].to());!1!==e&&(i=i.join(e||this.lineSeparator())),t[r]=i}return t},replaceSelection:function(e,t,n){for(var r=[],i=0;i<this.sel.ranges.length;i++)r[i]=e;this.replaceSelections(r,t,n||"+input")},replaceSelections:li(function(e,t,n){for(var r=[],i=this.sel,o=0;o<i.ranges.length;o++){var a=i.ranges[o];r[o]={from:a.from(),to:a.to(),text:this.splitLines(e[o]),origin:n}}for(var l=t&&"end"!=t&&function(e,t,n){for(var r=[],i=ot(e.first,0),o=i,a=0;a<t.length;a++){var l=t[a],s=Ei(l.from,i,o),c=Ei(Oi(l),i,o);if(i=l.to,o=c,"around"==n){var u=e.sel.ranges[a],d=at(u.head,u.anchor)<0;r[a]=new Mi(d?c:s,d?s:c)}else r[a]=new Mi(s,s)}return new Li(r,e.sel.primIndex)}(this,r,t),s=r.length-1;s>=0;s--)mo(this,r[s]);l?ro(this,l):this.cm&&Wr(this.cm)}),undo:li(function(){vo(this,"undo")}),redo:li(function(){vo(this,"redo")}),undoSelection:li(function(){vo(this,"undo",!0)}),redoSelection:li(function(){vo(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,n=0,r=0;r<e.done.length;r++)e.done[r].ranges||++t;for(var i=0;i<e.undone.length;i++)e.undone[i].ranges||++n;return{undo:t,redo:n}},clearHistory:function(){var e=this;this.history=new ji(this.history),Ii(this,function(t){return t.history=e.history},!0)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(e){return e&&(this.history.lastOp=this.history.lastSelOp=this.history.lastOrigin=null),this.history.generation},isClean:function(e){return this.history.generation==(e||this.cleanGeneration)},getHistory:function(){return{done:Zi(this.history.done),undone:Zi(this.history.undone)}},setHistory:function(e){var t=this.history=new ji(this.history);t.done=Zi(e.done.slice(0),null,!0),t.undone=Zi(e.undone.slice(0),null,!0)},setGutterMarker:li(function(e,t,n){return _o(this,e,"gutter",function(e){var r=e.gutterMarkers||(e.gutterMarkers={});return r[t]=n,!n&&ae(r)&&(e.gutterMarkers=null),!0})}),clearGutter:li(function(e){var t=this;this.iter(function(n){n.gutterMarkers&&n.gutterMarkers[e]&&_o(t,n,"gutter",function(){return n.gutterMarkers[e]=null,ae(n.gutterMarkers)&&(n.gutterMarkers=null),!0})})}),lineInfo:function(e){var t;if("number"==typeof e){if(!rt(this,e))return null;if(t=e,!(e=Ze(this,e)))return null}else if(null==(t=tt(e)))return null;return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},addLineClass:li(function(e,t,n){return _o(this,e,"gutter"==t?"gutter":"class",function(e){var r="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass";if(e[r]){if(S(n).test(e[r]))return!1;e[r]+=" "+n}else e[r]=n;return!0})}),removeLineClass:li(function(e,t,n){return _o(this,e,"gutter"==t?"gutter":"class",function(e){var r="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass",i=e[r];if(!i)return!1;if(null==n)e[r]=null;else{var o=i.match(S(n));if(!o)return!1;var a=o.index+o[0].length;e[r]=i.slice(0,o.index)+(o.index&&a!=i.length?" ":"")+i.slice(a)||null}return!0})}),addLineWidget:li(function(e,t,n){return function(e,t,n,r){var i=new Lo(e,n,r),o=e.cm;return o&&i.noHScroll&&(o.display.alignWidgets=!0),_o(e,t,"widget",function(t){var n=t.widgets||(t.widgets=[]);if(null==i.insertAt?n.push(i):n.splice(Math.min(n.length,Math.max(0,i.insertAt)),0,i),i.line=t,o&&!Kt(e,t)){var r=Gt(t)<e.scrollTop;et(t,t.height+Tn(i)),r&&Pr(o,i.height),o.curOp.forceUpdate=!0}return!0}),o&&hn(o,"lineWidgetAdded",o,i,"number"==typeof t?t:tt(t)),i}(this,e,t,n)}),removeLineWidget:function(e){e.clear()},markText:function(e,t,n){return Oo(this,ft(this,e),ft(this,t),n,n&&n.type||"range")},setBookmark:function(e,t){var n={replacedWith:t&&(null==t.nodeType?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1,shared:t&&t.shared,handleMouseEvents:t&&t.handleMouseEvents};return Oo(this,e=ft(this,e),e,n,"bookmark")},findMarksAt:function(e){var t=[],n=Ze(this,(e=ft(this,e)).line).markedSpans;if(n)for(var r=0;r<n.length;++r){var i=n[r];(null==i.from||i.from<=e.ch)&&(null==i.to||i.to>=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t,n){e=ft(this,e),t=ft(this,t);var r=[],i=e.line;return this.iter(e.line,t.line+1,function(o){var a=o.markedSpans;if(a)for(var l=0;l<a.length;l++){var s=a[l];null!=s.to&&i==e.line&&e.ch>=s.to||null==s.from&&i!=e.line||null!=s.from&&i==t.line&&s.from>=t.ch||n&&!n(s.marker)||r.push(s.marker.parent||s.marker)}++i}),r},getAllMarks:function(){var e=[];return this.iter(function(t){var n=t.markedSpans;if(n)for(var r=0;r<n.length;++r)null!=n[r].from&&e.push(n[r].marker)}),e},posFromIndex:function(e){var t,n=this.first,r=this.lineSeparator().length;return this.iter(function(i){var o=i.text.length+r;if(o>e)return t=e,!0;e-=o,++n}),ft(this,ot(n,t))},indexFromPos:function(e){var t=(e=ft(this,e)).ch;if(e.line<this.first||e.ch<0)return 0;var n=this.lineSeparator().length;return this.iter(this.first,e.line,function(e){t+=e.text.length+n}),t},copy:function(e){var t=new Wo(Je(this,this.first,this.first+this.size),this.modeOption,this.first,this.lineSep,this.direction);return t.scrollTop=this.scrollTop,t.scrollLeft=this.scrollLeft,t.sel=this.sel,t.extend=!1,e&&(t.history.undoDepth=this.history.undoDepth,t.setHistory(this.getHistory())),t},linkedDoc:function(e){e||(e={});var t=this.first,n=this.first+this.size;null!=e.from&&e.from>t&&(t=e.from),null!=e.to&&e.to<n&&(n=e.to);var r=new Wo(Je(this,t,n),e.mode||this.modeOption,t,this.lineSep,this.direction);return e.sharedHist&&(r.history=this.history),(this.linked||(this.linked=[])).push({doc:r,sharedHist:e.sharedHist}),r.linked=[{doc:this,isParent:!0,sharedHist:e.sharedHist}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n],i=r.find(),o=e.clipPos(i.from),a=e.clipPos(i.to);if(at(o,a)){var l=Oo(e,o,a,r.primary,r.primary.type);r.markers.push(l),l.parent=r}}}(r,Fo(this)),r},unlinkDoc:function(e){if(e instanceof Da&&(e=e.doc),this.linked)for(var t=0;t<this.linked.length;++t)if(this.linked[t].doc==e){this.linked.splice(t,1),e.unlinkDoc(this),Eo(Fo(this));break}if(e.history==this.history){var n=[e.id];Ii(e,function(e){return n.push(e.id)},!0),e.history=new ji(null),e.history.done=Zi(this.history.done,n),e.history.undone=Zi(this.history.undone,n)}},iterLinkedDocs:function(e){Ii(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm},splitLines:function(e){return this.lineSep?e.split(this.lineSep):We(e)},lineSeparator:function(){return this.lineSep||"\n"},setDirection:li(function(e){var t;"rtl"!=e&&(e="ltr"),e!=this.direction&&(this.direction=e,this.iter(function(e){return e.order=null}),this.cm&&ii(t=this.cm,function(){Bi(t),gr(t)}))})}),Wo.prototype.eachLine=Wo.prototype.iter;var zo=0;function Ho(e){var t=this;if(Io(t),!we(t,e)&&!Ln(t.display,e)){_e(e),a&&(zo=+new Date);var n=pr(t,e,!0),r=e.dataTransfer.files;if(n&&!t.isReadOnly())if(r&&r.length&&window.FileReader&&window.File)for(var i=r.length,o=Array(i),l=0,s=function(){++l==i&&oi(t,function(){var e={from:n=ft(t.doc,n),to:n,text:t.doc.splitLines(o.filter(function(e){return null!=e}).join(t.doc.lineSeparator())),origin:"paste"};mo(t.doc,e),ro(t.doc,Ai(ft(t.doc,n),ft(t.doc,Oi(e))))})()},c=function(e,n){if(t.options.allowDropFileTypes&&-1==V(t.options.allowDropFileTypes,e.type))s();else{var r=new FileReader;r.onerror=function(){return s()},r.onload=function(){var e=r.result;/[\x00-\x08\x0e-\x1f]{2}/.test(e)||(o[n]=e),s()},r.readAsText(e)}},u=0;u<r.length;u++)c(r[u],u);else{if(t.state.draggingText&&t.doc.sel.contains(n)>-1)return t.state.draggingText(e),void setTimeout(function(){return t.display.input.focus()},20);try{var d=e.dataTransfer.getData("Text");if(d){var f;if(t.state.draggingText&&!t.state.draggingText.copy&&(f=t.listSelections()),oo(t.doc,Ai(n,n)),f)for(var h=0;h<f.length;++h)wo(t.doc,"",f[h].anchor,f[h].head,"drag");t.replaceSelection(d,"around","paste"),t.display.input.focus()}}catch(e){}}}}function Io(e){e.display.dragCursor&&(e.display.lineSpace.removeChild(e.display.dragCursor),e.display.dragCursor=null)}function Ro(e){if(document.getElementsByClassName){for(var t=document.getElementsByClassName("CodeMirror"),n=[],r=0;r<t.length;r++){var i=t[r].CodeMirror;i&&n.push(i)}n.length&&n[0].operation(function(){for(var t=0;t<n.length;t++)e(n[t])})}}var Bo=!1;function jo(){var e;Bo||(ge(window,"resize",function(){null==e&&(e=setTimeout(function(){e=null,Ro(qo)},100))}),ge(window,"blur",function(){return Ro(Ar)}),Bo=!0)}function qo(e){var t=e.display;t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize()}for(var Uo={3:"Pause",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",61:"=",91:"Mod",92:"Mod",93:"Mod",106:"*",107:"=",109:"-",110:".",111:"/",145:"ScrollLock",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",224:"Mod",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"},Vo=0;Vo<10;Vo++)Uo[Vo+48]=Uo[Vo+96]=String(Vo);for(var Ko=65;Ko<=90;Ko++)Uo[Ko]=String.fromCharCode(Ko);for(var $o=1;$o<=12;$o++)Uo[$o+111]=Uo[$o+63235]="F"+$o;var Go={};function Xo(e){var t,n,r,i,o=e.split(/-(?!$)/);e=o[o.length-1];for(var a=0;a<o.length-1;a++){var l=o[a];if(/^(cmd|meta|m)$/i.test(l))i=!0;else if(/^a(lt)?$/i.test(l))t=!0;else if(/^(c|ctrl|control)$/i.test(l))n=!0;else{if(!/^s(hift)?$/i.test(l))throw new Error("Unrecognized modifier name: "+l);r=!0}}return t&&(e="Alt-"+e),n&&(e="Ctrl-"+e),i&&(e="Cmd-"+e),r&&(e="Shift-"+e),e}function Yo(e){var t={};for(var n in e)if(e.hasOwnProperty(n)){var r=e[n];if(/^(name|fallthrough|(de|at)tach)$/.test(n))continue;if("..."==r){delete e[n];continue}for(var i=ee(n.split(" "),Xo),o=0;o<i.length;o++){var a=void 0,l=void 0;o==i.length-1?(l=i.join(" "),a=r):(l=i.slice(0,o+1).join(" "),a="...");var s=t[l];if(s){if(s!=a)throw new Error("Inconsistent bindings for "+l)}else t[l]=a}delete e[n]}for(var c in t)e[c]=t[c];return e}function Zo(e,t,n,r){var i=(t=ta(t)).call?t.call(e,r):t[e];if(!1===i)return"nothing";if("..."===i)return"multi";if(null!=i&&n(i))return"handled";if(t.fallthrough){if("[object Array]"!=Object.prototype.toString.call(t.fallthrough))return Zo(e,t.fallthrough,n,r);for(var o=0;o<t.fallthrough.length;o++){var a=Zo(e,t.fallthrough[o],n,r);if(a)return a}}}function Qo(e){var t="string"==typeof e?e:Uo[e.keyCode];return"Ctrl"==t||"Alt"==t||"Shift"==t||"Mod"==t}function Jo(e,t,n){var r=e;return t.altKey&&"Alt"!=r&&(e="Alt-"+e),(C?t.metaKey:t.ctrlKey)&&"Ctrl"!=r&&(e="Ctrl-"+e),(C?t.ctrlKey:t.metaKey)&&"Mod"!=r&&(e="Cmd-"+e),!n&&t.shiftKey&&"Shift"!=r&&(e="Shift-"+e),e}function ea(e,t){if(f&&34==e.keyCode&&e.char)return!1;var n=Uo[e.keyCode];return null!=n&&!e.altGraphKey&&(3==e.keyCode&&e.code&&(n=e.code),Jo(n,e,t))}function ta(e){return"string"==typeof e?Go[e]:e}function na(e,t){for(var n=e.doc.sel.ranges,r=[],i=0;i<n.length;i++){for(var o=t(n[i]);r.length&&at(o.from,J(r).to)<=0;){var a=r.pop();if(at(a.from,o.from)<0){o.from=a.from;break}}r.push(o)}ii(e,function(){for(var t=r.length-1;t>=0;t--)wo(e.doc,"",r[t].from,r[t].to,"+delete");Wr(e)})}function ra(e,t,n){var r=ce(e.text,t+n,n);return r<0||r>e.text.length?null:r}function ia(e,t,n){var r=ra(e,t.ch,n);return null==r?null:new ot(t.line,r,n<0?"after":"before")}function oa(e,t,n,r,i){if(e){"rtl"==t.doc.direction&&(i=-i);var o=pe(n,t.doc.direction);if(o){var a,l=i<0?J(o):o[0],s=i<0==(1==l.level)?"after":"before";if(l.level>0||"rtl"==t.doc.direction){var c=zn(t,n);a=i<0?n.text.length-1:0;var u=Hn(t,c,a).top;a=ue(function(e){return Hn(t,c,e).top==u},i<0==(1==l.level)?l.from:l.to-1,a),"before"==s&&(a=ra(n,a,1))}else a=i<0?l.to:l.from;return new ot(r,a,s)}}return new ot(r,i<0?n.text.length:0,i<0?"before":"after")}Go.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},Go.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},Go.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Go.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},Go.default=b?Go.macDefault:Go.pcDefault;var aa={selectAll:ho,singleSelection:function(e){return e.setSelection(e.getCursor("anchor"),e.getCursor("head"),$)},killLine:function(e){return na(e,function(t){if(t.empty()){var n=Ze(e.doc,t.head.line).text.length;return t.head.ch==n&&t.head.line<e.lastLine()?{from:t.head,to:ot(t.head.line+1,0)}:{from:t.head,to:ot(t.head.line,n)}}return{from:t.from(),to:t.to()}})},deleteLine:function(e){return na(e,function(t){return{from:ot(t.from().line,0),to:ft(e.doc,ot(t.to().line+1,0))}})},delLineLeft:function(e){return na(e,function(e){return{from:ot(e.from().line,0),to:e.from()}})},delWrappedLineLeft:function(e){return na(e,function(t){var n=e.charCoords(t.head,"div").top+5;return{from:e.coordsChar({left:0,top:n},"div"),to:t.from()}})},delWrappedLineRight:function(e){return na(e,function(t){var n=e.charCoords(t.head,"div").top+5,r=e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div");return{from:t.from(),to:r}})},undo:function(e){return e.undo()},redo:function(e){return e.redo()},undoSelection:function(e){return e.undoSelection()},redoSelection:function(e){return e.redoSelection()},goDocStart:function(e){return e.extendSelection(ot(e.firstLine(),0))},goDocEnd:function(e){return e.extendSelection(ot(e.lastLine()))},goLineStart:function(e){return e.extendSelectionsBy(function(t){return la(e,t.head.line)},{origin:"+move",bias:1})},goLineStartSmart:function(e){return e.extendSelectionsBy(function(t){return sa(e,t.head)},{origin:"+move",bias:1})},goLineEnd:function(e){return e.extendSelectionsBy(function(t){return function(e,t){var n=Ze(e.doc,t),r=function(e){for(var t;t=Rt(e);)e=t.find(1,!0).line;return e}(n);return r!=n&&(t=tt(r)),oa(!0,e,n,t,-1)}(e,t.head.line)},{origin:"+move",bias:-1})},goLineRight:function(e){return e.extendSelectionsBy(function(t){var n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:n},"div")},X)},goLineLeft:function(e){return e.extendSelectionsBy(function(t){var n=e.cursorCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:n},"div")},X)},goLineLeftSmart:function(e){return e.extendSelectionsBy(function(t){var n=e.cursorCoords(t.head,"div").top+5,r=e.coordsChar({left:0,top:n},"div");return r.ch<e.getLine(r.line).search(/\S/)?sa(e,t.head):r},X)},goLineUp:function(e){return e.moveV(-1,"line")},goLineDown:function(e){return e.moveV(1,"line")},goPageUp:function(e){return e.moveV(-1,"page")},goPageDown:function(e){return e.moveV(1,"page")},goCharLeft:function(e){return e.moveH(-1,"char")},goCharRight:function(e){return e.moveH(1,"char")},goColumnLeft:function(e){return e.moveH(-1,"column")},goColumnRight:function(e){return e.moveH(1,"column")},goWordLeft:function(e){return e.moveH(-1,"word")},goGroupRight:function(e){return e.moveH(1,"group")},goGroupLeft:function(e){return e.moveH(-1,"group")},goWordRight:function(e){return e.moveH(1,"word")},delCharBefore:function(e){return e.deleteH(-1,"codepoint")},delCharAfter:function(e){return e.deleteH(1,"char")},delWordBefore:function(e){return e.deleteH(-1,"word")},delWordAfter:function(e){return e.deleteH(1,"word")},delGroupBefore:function(e){return e.deleteH(-1,"group")},delGroupAfter:function(e){return e.deleteH(1,"group")},indentAuto:function(e){return e.indentSelection("smart")},indentMore:function(e){return e.indentSelection("add")},indentLess:function(e){return e.indentSelection("subtract")},insertTab:function(e){return e.replaceSelection("\t")},insertSoftTab:function(e){for(var t=[],n=e.listSelections(),r=e.options.tabSize,i=0;i<n.length;i++){var o=n[i].from(),a=q(e.getLine(o.line),o.ch,r);t.push(Q(r-a%r))}e.replaceSelections(t)},defaultTab:function(e){e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:function(e){return ii(e,function(){for(var t=e.listSelections(),n=[],r=0;r<t.length;r++)if(t[r].empty()){var i=t[r].head,o=Ze(e.doc,i.line).text;if(o)if(i.ch==o.length&&(i=new ot(i.line,i.ch-1)),i.ch>0)i=new ot(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),ot(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var a=Ze(e.doc,i.line-1).text;a&&(i=new ot(i.line,1),e.replaceRange(o.charAt(0)+e.doc.lineSeparator()+a.charAt(a.length-1),ot(i.line-1,a.length-1),i,"+transpose"))}n.push(new Mi(i,i))}e.setSelections(n)})},newlineAndIndent:function(e){return ii(e,function(){for(var t=e.listSelections(),n=t.length-1;n>=0;n--)e.replaceRange(e.doc.lineSeparator(),t[n].anchor,t[n].head,"+input");t=e.listSelections();for(var r=0;r<t.length;r++)e.indentLine(t[r].from().line,null,!0);Wr(e)})},openLine:function(e){return e.replaceSelection("\n","start")},toggleOverwrite:function(e){return e.toggleOverwrite()}};function la(e,t){var n=Ze(e.doc,t),r=qt(n);return r!=n&&(t=tt(r)),oa(!0,e,r,t,1)}function sa(e,t){var n=la(e,t.line),r=Ze(e.doc,n.line),i=pe(r,e.doc.direction);if(!i||0==i[0].level){var o=Math.max(n.ch,r.text.search(/\S/)),a=t.line==n.line&&t.ch<=o&&t.ch;return ot(n.line,a?0:o,n.sticky)}return n}function ca(e,t,n){if("string"==typeof t&&!(t=aa[t]))return!1;e.display.input.ensurePolled();var r=e.display.shift,i=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),n&&(e.display.shift=!1),i=t(e)!=K}finally{e.display.shift=r,e.state.suppressEdits=!1}return i}var ua=new U;function da(e,t,n,r){var i=e.state.keySeq;if(i){if(Qo(t))return"handled";if(/\'$/.test(t)?e.state.keySeq=null:ua.set(50,function(){e.state.keySeq==i&&(e.state.keySeq=null,e.display.input.reset())}),fa(e,i+" "+t,n,r))return!0}return fa(e,t,n,r)}function fa(e,t,n,r){var i=function(e,t,n){for(var r=0;r<e.state.keyMaps.length;r++){var i=Zo(t,e.state.keyMaps[r],n,e);if(i)return i}return e.options.extraKeys&&Zo(t,e.options.extraKeys,n,e)||Zo(t,e.options.keyMap,n,e)}(e,t,r);return"multi"==i&&(e.state.keySeq=t),"handled"==i&&hn(e,"keyHandled",e,t,n),"handled"!=i&&"multi"!=i||(_e(n),Tr(e)),!!i}function ha(e,t){var n=ea(t,!0);return!!n&&(t.shiftKey&&!e.state.keySeq?da(e,"Shift-"+n,t,function(t){return ca(e,t,!0)})||da(e,n,t,function(t){if("string"==typeof t?/^go[A-Z]/.test(t):t.motion)return ca(e,t)}):da(e,n,t,function(t){return ca(e,t)}))}var pa=null;function ma(e){var t=this;if(!(e.target&&e.target!=t.display.input.getField()||(t.curOp.focus=F(H(t)),we(t,e)))){a&&l<11&&27==e.keyCode&&(e.returnValue=!1);var r=e.keyCode;t.display.shift=16==r||e.shiftKey;var i=ha(t,e);f&&(pa=i?r:null,i||88!=r||He||!(b?e.metaKey:e.ctrlKey)||t.replaceSelection("",null,"cut")),n&&!b&&!i&&46==r&&e.shiftKey&&!e.ctrlKey&&document.execCommand&&document.execCommand("cut"),18!=r||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||function(e){var t=e.display.lineDiv;function n(e){18!=e.keyCode&&e.altKey||(L(t,"CodeMirror-crosshair"),ye(document,"keyup",n),ye(document,"mouseover",n))}E(t,"CodeMirror-crosshair"),ge(document,"keyup",n),ge(document,"mouseover",n)}(t)}}function ga(e){16==e.keyCode&&(this.doc.sel.shift=!1),we(this,e)}function va(e){var t=this;if(!(e.target&&e.target!=t.display.input.getField()||Ln(t.display,e)||we(t,e)||e.ctrlKey&&!e.altKey||b&&e.metaKey)){var n=e.keyCode,r=e.charCode;if(f&&n==pa)return pa=null,void _e(e);if(!f||e.which&&!(e.which<10)||!ha(t,e)){var i=String.fromCharCode(null==r?n:r);"\b"!=i&&(function(e,t,n){return da(e,"'"+n+"'",t,function(t){return ca(e,t,!0)})}(t,e,i)||t.display.input.onKeyPress(e))}}}var ya,ba,wa=function(e,t,n){this.time=e,this.pos=t,this.button=n};function xa(e){var t=this,n=t.display;if(!(we(t,e)||n.activeTouch&&n.input.supportsTouch()))if(n.input.ensurePolled(),n.shift=e.shiftKey,Ln(n,e))s||(n.scroller.draggable=!1,setTimeout(function(){return n.scroller.draggable=!0},100));else if(!_a(t,e)){var r=pr(t,e),i=Ne(e),o=r?function(e,t){var n=+new Date;return ba&&ba.compare(n,e,t)?(ya=ba=null,"triple"):ya&&ya.compare(n,e,t)?(ba=new wa(n,e,t),ya=null,"double"):(ya=new wa(n,e,t),ba=null,"single")}(r,i):"single";R(t).focus(),1==i&&t.state.selectingText&&t.state.selectingText(e),r&&function(e,t,n,r,i){var o="Click";return"double"==r?o="Double"+o:"triple"==r&&(o="Triple"+o),da(e,Jo(o=(1==t?"Left":2==t?"Middle":"Right")+o,i),i,function(t){if("string"==typeof t&&(t=aa[t]),!t)return!1;var r=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),r=t(e,n)!=K}finally{e.state.suppressEdits=!1}return r})}(t,i,r,o,e)||(1==i?r?function(e,t,n,r){a?setTimeout(B(Lr,e),0):e.curOp.focus=F(H(e));var i,o=function(e,t,n){var r=e.getOption("configureMouse"),i=r?r(e,t,n):{};if(null==i.unit){var o=w?n.shiftKey&&n.metaKey:n.altKey;i.unit=o?"rectangle":"single"==t?"char":"double"==t?"word":"line"}return(null==i.extend||e.doc.extend)&&(i.extend=e.doc.extend||n.shiftKey),null==i.addNew&&(i.addNew=b?n.metaKey:n.ctrlKey),null==i.moveOnDrag&&(i.moveOnDrag=!(b?n.altKey:n.ctrlKey)),i}(e,n,r),c=e.doc.sel;e.options.dragDrop&&De&&!e.isReadOnly()&&"single"==n&&(i=c.contains(t))>-1&&(at((i=c.ranges[i]).from(),t)<0||t.xRel>0)&&(at(i.to(),t)>0||t.xRel<0)?function(e,t,n,r){var i=e.display,o=!1,c=oi(e,function(t){s&&(i.scroller.draggable=!1),e.state.draggingText=!1,e.state.delayingBlurEvent&&(e.hasFocus()?e.state.delayingBlurEvent=!1:Mr(e)),ye(i.wrapper.ownerDocument,"mouseup",c),ye(i.wrapper.ownerDocument,"mousemove",u),ye(i.scroller,"dragstart",d),ye(i.scroller,"drop",c),o||(_e(t),r.addNew||Ji(e.doc,n,null,null,r.extend),s&&!h||a&&9==l?setTimeout(function(){i.wrapper.ownerDocument.body.focus({preventScroll:!0}),i.input.focus()},20):i.input.focus())}),u=function(e){o=o||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},d=function(){return o=!0};s&&(i.scroller.draggable=!0),e.state.draggingText=c,c.copy=!r.moveOnDrag,ge(i.wrapper.ownerDocument,"mouseup",c),ge(i.wrapper.ownerDocument,"mousemove",u),ge(i.scroller,"dragstart",d),ge(i.scroller,"drop",c),e.state.delayingBlurEvent=!0,setTimeout(function(){return i.input.focus()},20),i.scroller.dragDrop&&i.scroller.dragDrop()}(e,r,t,o):function(e,t,n,r){a&&Mr(e);var i=e.display,o=e.doc;_e(t);var l,s,c=o.sel,u=c.ranges;if(r.addNew&&!r.extend?(s=o.sel.contains(n),l=s>-1?u[s]:new Mi(n,n)):(l=o.sel.primary(),s=o.sel.primIndex),"rectangle"==r.unit)r.addNew||(l=new Mi(n,n)),n=pr(e,t,!0,!0),s=-1;else{var d=ka(e,n,r.unit);l=r.extend?Qi(l,d.anchor,d.head,r.extend):d}r.addNew?-1==s?(s=u.length,io(o,Ni(e,u.concat([l]),s),{scroll:!1,origin:"*mouse"})):u.length>1&&u[s].empty()&&"char"==r.unit&&!r.extend?(io(o,Ni(e,u.slice(0,s).concat(u.slice(s+1)),0),{scroll:!1,origin:"*mouse"}),c=o.sel):to(o,s,l,G):(s=0,io(o,new Li([l],0),G),c=o.sel);var f=n;function h(t){if(0!=at(f,t))if(f=t,"rectangle"==r.unit){for(var i=[],a=e.options.tabSize,u=q(Ze(o,n.line).text,n.ch,a),d=q(Ze(o,t.line).text,t.ch,a),h=Math.min(u,d),p=Math.max(u,d),m=Math.min(n.line,t.line),g=Math.min(e.lastLine(),Math.max(n.line,t.line));m<=g;m++){var v=Ze(o,m).text,y=Y(v,h,a);h==p?i.push(new Mi(ot(m,y),ot(m,y))):v.length>y&&i.push(new Mi(ot(m,y),ot(m,Y(v,p,a))))}i.length||i.push(new Mi(n,n)),io(o,Ni(e,c.ranges.slice(0,s).concat(i),s),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var b,w=l,x=ka(e,t,r.unit),k=w.anchor;at(x.anchor,k)>0?(b=x.head,k=ut(w.from(),x.anchor)):(b=x.anchor,k=ct(w.to(),x.head));var C=c.ranges.slice(0);C[s]=function(e,t){var n=t.anchor,r=t.head,i=Ze(e.doc,n.line);if(0==at(n,r)&&n.sticky==r.sticky)return t;var o=pe(i);if(!o)return t;var a=fe(o,n.ch,n.sticky),l=o[a];if(l.from!=n.ch&&l.to!=n.ch)return t;var s,c=a+(l.from==n.ch==(1!=l.level)?0:1);if(0==c||c==o.length)return t;if(r.line!=n.line)s=(r.line-n.line)*("ltr"==e.doc.direction?1:-1)>0;else{var u=fe(o,r.ch,r.sticky),d=u-a||(r.ch-n.ch)*(1==l.level?-1:1);s=u==c-1||u==c?d<0:d>0}var f=o[c+(s?-1:0)],h=s==(1==f.level),p=h?f.from:f.to,m=h?"after":"before";return n.ch==p&&n.sticky==m?t:new Mi(new ot(n.line,p,m),r)}(e,new Mi(ft(o,k),b)),io(o,Ni(e,C,s),G)}}var p=i.wrapper.getBoundingClientRect(),m=0;function g(t){var n=++m,a=pr(e,t,!0,"rectangle"==r.unit);if(a)if(0!=at(a,f)){e.curOp.focus=F(H(e)),h(a);var l=Fr(i,o);(a.line>=l.to||a.line<l.from)&&setTimeout(oi(e,function(){m==n&&g(t)}),150)}else{var s=t.clientY<p.top?-20:t.clientY>p.bottom?20:0;s&&setTimeout(oi(e,function(){m==n&&(i.scroller.scrollTop+=s,g(t))}),50)}}function v(t){e.state.selectingText=!1,m=1/0,t&&(_e(t),i.input.focus()),ye(i.wrapper.ownerDocument,"mousemove",y),ye(i.wrapper.ownerDocument,"mouseup",b),o.history.lastSelOrigin=null}var y=oi(e,function(e){0!==e.buttons&&Ne(e)?g(e):v(e)}),b=oi(e,v);e.state.selectingText=b,ge(i.wrapper.ownerDocument,"mousemove",y),ge(i.wrapper.ownerDocument,"mouseup",b)}(e,r,t,o)}(t,r,o,e):Me(e)==n.scroller&&_e(e):2==i?(r&&Ji(t.doc,r),setTimeout(function(){return n.input.focus()},20)):3==i&&(_?t.display.input.onContextMenu(e):Mr(t)))}}function ka(e,t,n){if("char"==n)return new Mi(t,t);if("word"==n)return e.findWordAt(t);if("line"==n)return new Mi(ot(t.line,0),ft(e.doc,ot(t.line+1,0)));var r=n(e,t);return new Mi(r.from,r.to)}function Ca(e,t,n,r){var i,o;if(t.touches)i=t.touches[0].clientX,o=t.touches[0].clientY;else try{i=t.clientX,o=t.clientY}catch(e){return!1}if(i>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;r&&_e(t);var a=e.display,l=a.lineDiv.getBoundingClientRect();if(o>l.bottom||!ke(e,n))return Te(t);o-=l.top-a.viewOffset;for(var s=0;s<e.display.gutterSpecs.length;++s){var c=a.gutters.childNodes[s];if(c&&c.getBoundingClientRect().right>=i)return be(e,n,e,nt(e.doc,o),e.display.gutterSpecs[s].className,t),Te(t)}}function _a(e,t){return Ca(e,t,"gutterClick",!0)}function Sa(e,t){Ln(e.display,t)||function(e,t){return!!ke(e,"gutterContextMenu")&&Ca(e,t,"gutterContextMenu",!1)}(e,t)||we(e,t,"contextmenu")||_||e.display.input.onContextMenu(t)}function Ta(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),Vn(e)}wa.prototype.compare=function(e,t,n){return this.time+400>e&&0==at(t,this.pos)&&n==this.button};var La={toString:function(){return"CodeMirror.Init"}},Ma={},Na={};function Aa(e,t,n){if(!t!=!(n&&n!=La)){var r=e.display.dragFunctions,i=t?ge:ye;i(e.display.scroller,"dragstart",r.start),i(e.display.scroller,"dragenter",r.enter),i(e.display.scroller,"dragover",r.over),i(e.display.scroller,"dragleave",r.leave),i(e.display.scroller,"drop",r.drop)}}function Oa(e){e.options.lineWrapping?(E(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(L(e.display.wrapper,"CodeMirror-wrap"),Yt(e)),hr(e),gr(e),Vn(e),setTimeout(function(){return Kr(e)},100)}function Da(e,t){var n=this;if(!(this instanceof Da))return new Da(e,t);this.options=t=t?j(t):{},j(Ma,t,!1);var r=t.value;"string"==typeof r?r=new Wo(r,t.mode,null,t.lineSeparator,t.direction):t.mode&&(r.modeOption=t.mode),this.doc=r;var i=new Da.inputStyles[t.inputStyle](this),o=this.display=new xi(e,r,i,t);for(var c in o.wrapper.CodeMirror=this,Ta(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),Xr(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:-1,cutIncoming:-1,selectingText:!1,draggingText:!1,highlight:new U,keySeq:null,specialChars:null},t.autofocus&&!y&&o.input.focus(),a&&l<11&&setTimeout(function(){return n.display.input.reset(!0)},20),function(e){var t=e.display;ge(t.scroller,"mousedown",oi(e,xa)),ge(t.scroller,"dblclick",a&&l<11?oi(e,function(t){if(!we(e,t)){var n=pr(e,t);if(n&&!_a(e,t)&&!Ln(e.display,t)){_e(t);var r=e.findWordAt(n);Ji(e.doc,r.anchor,r.head)}}}):function(t){return we(e,t)||_e(t)}),ge(t.scroller,"contextmenu",function(t){return Sa(e,t)}),ge(t.input.getField(),"contextmenu",function(n){t.scroller.contains(n.target)||Sa(e,n)});var n,r={end:0};function i(){t.activeTouch&&(n=setTimeout(function(){return t.activeTouch=null},1e3),(r=t.activeTouch).end=+new Date)}function o(e){if(1!=e.touches.length)return!1;var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}function s(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}ge(t.scroller,"touchstart",function(i){if(!we(e,i)&&!o(i)&&!_a(e,i)){t.input.ensurePolled(),clearTimeout(n);var a=+new Date;t.activeTouch={start:a,moved:!1,prev:a-r.end<=300?r:null},1==i.touches.length&&(t.activeTouch.left=i.touches[0].pageX,t.activeTouch.top=i.touches[0].pageY)}}),ge(t.scroller,"touchmove",function(){t.activeTouch&&(t.activeTouch.moved=!0)}),ge(t.scroller,"touchend",function(n){var r=t.activeTouch;if(r&&!Ln(t,n)&&null!=r.left&&!r.moved&&new Date-r.start<300){var o,a=e.coordsChar(t.activeTouch,"page");o=!r.prev||s(r,r.prev)?new Mi(a,a):!r.prev.prev||s(r,r.prev.prev)?e.findWordAt(a):new Mi(ot(a.line,0),ft(e.doc,ot(a.line+1,0))),e.setSelection(o.anchor,o.head),e.focus(),_e(n)}i()}),ge(t.scroller,"touchcancel",i),ge(t.scroller,"scroll",function(){t.scroller.clientHeight&&(Rr(e,t.scroller.scrollTop),jr(e,t.scroller.scrollLeft,!0),be(e,"scroll",e))}),ge(t.scroller,"mousewheel",function(t){return Ti(e,t)}),ge(t.scroller,"DOMMouseScroll",function(t){return Ti(e,t)}),ge(t.wrapper,"scroll",function(){return t.wrapper.scrollTop=t.wrapper.scrollLeft=0}),t.dragFunctions={enter:function(t){we(e,t)||Le(t)},over:function(t){we(e,t)||(function(e,t){var n=pr(e,t);if(n){var r=document.createDocumentFragment();Cr(e,n,r),e.display.dragCursor||(e.display.dragCursor=A("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),e.display.lineSpace.insertBefore(e.display.dragCursor,e.display.cursorDiv)),N(e.display.dragCursor,r)}}(e,t),Le(t))},start:function(t){return function(e,t){if(a&&(!e.state.draggingText||+new Date-zo<100))Le(t);else if(!we(e,t)&&!Ln(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.effectAllowed="copyMove",t.dataTransfer.setDragImage&&!h)){var n=A("img",null,null,"position: fixed; left: 0; top: 0;");n.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",f&&(n.width=n.height=1,e.display.wrapper.appendChild(n),n._top=n.offsetTop),t.dataTransfer.setDragImage(n,0,0),f&&n.parentNode.removeChild(n)}}(e,t)},drop:oi(e,Ho),leave:function(t){we(e,t)||Io(e)}};var c=t.input.getField();ge(c,"keyup",function(t){return ga.call(e,t)}),ge(c,"keydown",oi(e,ma)),ge(c,"keypress",oi(e,va)),ge(c,"focus",function(t){return Nr(e,t)}),ge(c,"blur",function(t){return Ar(e,t)})}(this),jo(),Zr(this),this.curOp.forceUpdate=!0,Ri(this,r),t.autofocus&&!y||this.hasFocus()?setTimeout(function(){n.hasFocus()&&!n.state.focused&&Nr(n)},20):Ar(this),Na)Na.hasOwnProperty(c)&&Na[c](this,t[c],La);vi(this),t.finishInit&&t.finishInit(this);for(var u=0;u<Fa.length;++u)Fa[u](this);Qr(this),s&&t.lineWrapping&&"optimizelegibility"==getComputedStyle(o.lineDiv).textRendering&&(o.lineDiv.style.textRendering="auto")}Da.defaults=Ma,Da.optionHandlers=Na;var Fa=[];function Ea(e,t,n,r){var i,o=e.doc;null==n&&(n="add"),"smart"==n&&(o.mode.indent?i=yt(e,t).state:n="prev");var a=e.options.tabSize,l=Ze(o,t),s=q(l.text,null,a);l.stateAfter&&(l.stateAfter=null);var c,u=l.text.match(/^\s*/)[0];if(r||/\S/.test(l.text)){if("smart"==n&&((c=o.mode.indent(i,l.text.slice(u.length),l.text))==K||c>150)){if(!r)return;n="prev"}}else c=0,n="not";"prev"==n?c=t>o.first?q(Ze(o,t-1).text,null,a):0:"add"==n?c=s+e.options.indentUnit:"subtract"==n?c=s-e.options.indentUnit:"number"==typeof n&&(c=s+n),c=Math.max(0,c);var d="",f=0;if(e.options.indentWithTabs)for(var h=Math.floor(c/a);h;--h)f+=a,d+="\t";if(f<c&&(d+=Q(c-f)),d!=u)return wo(o,d,ot(t,0),ot(t,u.length),"+input"),l.stateAfter=null,!0;for(var p=0;p<o.sel.ranges.length;p++){var m=o.sel.ranges[p];if(m.head.line==t&&m.head.ch<u.length){var g=ot(t,u.length);to(o,p,new Mi(g,g));break}}}Da.defineInitHook=function(e){return Fa.push(e)};var Pa=null;function Wa(e){Pa=e}function za(e,t,n,r,i){var o=e.doc;e.display.shift=!1,r||(r=o.sel);var a=+new Date-200,l="paste"==i||e.state.pasteIncoming>a,s=We(t),c=null;if(l&&r.ranges.length>1)if(Pa&&Pa.text.join("\n")==t){if(r.ranges.length%Pa.text.length==0){c=[];for(var u=0;u<Pa.text.length;u++)c.push(o.splitLines(Pa.text[u]))}}else s.length==r.ranges.length&&e.options.pasteLinesPerSelection&&(c=ee(s,function(e){return[e]}));for(var d=e.curOp.updateInput,f=r.ranges.length-1;f>=0;f--){var h=r.ranges[f],p=h.from(),m=h.to();h.empty()&&(n&&n>0?p=ot(p.line,p.ch-n):e.state.overwrite&&!l?m=ot(m.line,Math.min(Ze(o,m.line).text.length,m.ch+J(s).length)):l&&Pa&&Pa.lineWise&&Pa.text.join("\n")==s.join("\n")&&(p=m=ot(p.line,0)));var g={from:p,to:m,text:c?c[f%c.length]:s,origin:i||(l?"paste":e.state.cutIncoming>a?"cut":"+input")};mo(e.doc,g),hn(e,"inputRead",e,g)}t&&!l&&Ia(e,t),Wr(e),e.curOp.updateInput<2&&(e.curOp.updateInput=d),e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=-1}function Ha(e,t){var n=e.clipboardData&&e.clipboardData.getData("Text");if(n)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||!t.hasFocus()||ii(t,function(){return za(t,n,0,null,"paste")}),!0}function Ia(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var n=e.doc.sel,r=n.ranges.length-1;r>=0;r--){var i=n.ranges[r];if(!(i.head.ch>100||r&&n.ranges[r-1].head.line==i.head.line)){var o=e.getModeAt(i.head),a=!1;if(o.electricChars){for(var l=0;l<o.electricChars.length;l++)if(t.indexOf(o.electricChars.charAt(l))>-1){a=Ea(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Ze(e.doc,i.head.line).text.slice(0,i.head.ch))&&(a=Ea(e,i.head.line,"smart"));a&&hn(e,"electricInput",e,i.head.line)}}}function Ra(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:ot(i,0),head:ot(i+1,0)};n.push(o),t.push(e.getRange(o.anchor,o.head))}return{text:t,ranges:n}}function Ba(e,t,n,r){e.setAttribute("autocorrect",n?"on":"off"),e.setAttribute("autocapitalize",r?"on":"off"),e.setAttribute("spellcheck",!!t)}function ja(){var e=A("textarea",null,null,"position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; min-height: 1em; outline: none"),t=A("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");return s?e.style.width="1000px":e.setAttribute("wrap","off"),g&&(e.style.border="1px solid black"),t}function qa(e,t,n,r,i){var o=t,a=n,l=Ze(e,t.line),s=i&&"rtl"==e.direction?-n:n;function c(o){var a,c;if("codepoint"==r){var u=l.text.charCodeAt(t.ch+(n>0?0:-1));if(isNaN(u))a=null;else{var d=n>0?u>=55296&&u<56320:u>=56320&&u<57343;a=new ot(t.line,Math.max(0,Math.min(l.text.length,t.ch+n*(d?2:1))),-n)}}else a=i?function(e,t,n,r){var i=pe(t,e.doc.direction);if(!i)return ia(t,n,r);n.ch>=t.text.length?(n.ch=t.text.length,n.sticky="before"):n.ch<=0&&(n.ch=0,n.sticky="after");var o=fe(i,n.ch,n.sticky),a=i[o];if("ltr"==e.doc.direction&&a.level%2==0&&(r>0?a.to>n.ch:a.from<n.ch))return ia(t,n,r);var l,s=function(e,n){return ra(t,e instanceof ot?e.ch:e,n)},c=function(n){return e.options.lineWrapping?(l=l||zn(e,t),rr(e,t,l,n)):{begin:0,end:t.text.length}},u=c("before"==n.sticky?s(n,-1):n.ch);if("rtl"==e.doc.direction||1==a.level){var d=1==a.level==r<0,f=s(n,d?1:-1);if(null!=f&&(d?f<=a.to&&f<=u.end:f>=a.from&&f>=u.begin)){var h=d?"before":"after";return new ot(n.line,f,h)}}var p=function(e,t,r){for(var o=function(e,t){return t?new ot(n.line,s(e,1),"before"):new ot(n.line,e,"after")};e>=0&&e<i.length;e+=t){var a=i[e],l=t>0==(1!=a.level),c=l?r.begin:s(r.end,-1);if(a.from<=c&&c<a.to)return o(c,l);if(c=l?a.from:s(a.to,-1),r.begin<=c&&c<r.end)return o(c,l)}},m=p(o+r,r,u);if(m)return m;var g=r>0?u.end:s(u.begin,-1);return null==g||r>0&&g==t.text.length||!(m=p(r>0?0:i.length-1,r,c(g)))?null:m}(e.cm,l,t,n):ia(l,t,n);if(null==a){if(o||((c=t.line+s)<e.first||c>=e.first+e.size||(t=new ot(c,t.ch,t.sticky),!(l=Ze(e,c)))))return!1;t=oa(i,e.cm,l,t.line,s)}else t=a;return!0}if("char"==r||"codepoint"==r)c();else if("column"==r)c(!0);else if("word"==r||"group"==r)for(var u=null,d="group"==r,f=e.cm&&e.cm.getHelper(t,"wordChars"),h=!0;!(n<0)||c(!h);h=!1){var p=l.text.charAt(t.ch)||"\n",m=oe(p,f)?"w":d&&"\n"==p?"n":!d||/\s/.test(p)?null:"p";if(!d||h||m||(m="s"),u&&u!=m){n<0&&(n=1,c(),t.sticky="after");break}if(m&&(u=m),n>0&&!c(!h))break}var g=uo(e,t,o,a,!0);return lt(o,g)&&(g.hitSide=!0),g}function Ua(e,t,n,r){var i,o,a=e.doc,l=t.left;if("page"==r){var s=Math.min(e.display.wrapper.clientHeight,R(e).innerHeight||a(e).documentElement.clientHeight),c=Math.max(s-.5*sr(e.display),3);i=(n>0?t.bottom:t.top)+n*c}else"line"==r&&(i=n>0?t.bottom+3:t.top-3);for(;(o=tr(e,l,i)).outside;){if(n<0?i<=0:i>=a.height){o.hitSide=!0;break}i+=5*n}return o}var Va=function(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new U,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};function Ka(e,t){var n=Wn(e,t.line);if(!n||n.hidden)return null;var r=Ze(e.doc,t.line),i=En(n,r,t.line),o=pe(r,e.doc.direction),a="left";o&&(a=fe(o,t.ch)%2?"right":"left");var l=Bn(i.map,t.ch,a);return l.offset="right"==l.collapse?l.end:l.start,l}function $a(e,t){return t&&(e.bad=!0),e}function Ga(e,t,n){var r;if(t==e.display.lineDiv){if(!(r=e.display.lineDiv.childNodes[n]))return $a(e.clipPos(ot(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 Xa(o,t,n)}}function Xa(e,t,n){var r=e.text.firstChild,i=!1;if(!t||!D(r,t))return $a(ot(tt(e.line),0),!0);if(t==r&&(i=!0,t=r.childNodes[n],n=0,!t)){var o=e.rest?J(e.rest):e.line;return $a(ot(tt(o),o.text.length),i)}var a=3==t.nodeType?t:null,l=t;for(a||1!=t.childNodes.length||3!=t.firstChild.nodeType||(a=t.firstChild,n&&(n=a.nodeValue.length));l.parentNode!=r;)l=l.parentNode;var s=e.measure,c=s.maps;function u(t,n,r){for(var i=-1;i<(c?c.length:0);i++)for(var o=i<0?s.map:c[i],a=0;a<o.length;a+=3){var l=o[a+2];if(l==t||l==n){var u=tt(i<0?e.line:e.rest[i]),d=o[a]+r;return(r<0||l!=t)&&(d=o[a+(r?1:0)]),ot(u,d)}}}var d=u(a,l,n);if(d)return $a(d,i);for(var f=l.nextSibling,h=a?a.nodeValue.length-n:0;f;f=f.nextSibling){if(d=u(f,f.firstChild,0))return $a(ot(d.line,d.ch-h),i);h+=f.textContent.length}for(var p=l.previousSibling,m=n;p;p=p.previousSibling){if(d=u(p,p.firstChild,-1))return $a(ot(d.line,d.ch+m),i);m+=p.textContent.length}}Va.prototype.init=function(e){var t=this,n=this,r=n.cm,i=n.div=e.lineDiv;function o(e){for(var t=e.target;t;t=t.parentNode){if(t==i)return!0;if(/\bCodeMirror-(?:line)?widget\b/.test(t.className))break}return!1}function a(e){if(o(e)&&!we(r,e)){if(r.somethingSelected())Wa({lineWise:!1,text:r.getSelections()}),"cut"==e.type&&r.replaceSelection("",null,"cut");else{if(!r.options.lineWiseCopyCut)return;var t=Ra(r);Wa({lineWise:!0,text:t.text}),"cut"==e.type&&r.operation(function(){r.setSelections(t.ranges,0,$),r.replaceSelection("",null,"cut")})}if(e.clipboardData){e.clipboardData.clearData();var a=Pa.text.join("\n");if(e.clipboardData.setData("Text",a),e.clipboardData.getData("Text")==a)return void e.preventDefault()}var l=ja(),s=l.firstChild;Ba(s),r.display.lineSpace.insertBefore(l,r.display.lineSpace.firstChild),s.value=Pa.text.join("\n");var c=F(I(i));W(s),setTimeout(function(){r.display.lineSpace.removeChild(l),c.focus(),c==i&&n.showPrimarySelection()},50)}}i.contentEditable=!0,Ba(i,r.options.spellcheck,r.options.autocorrect,r.options.autocapitalize),ge(i,"paste",function(e){!o(e)||we(r,e)||Ha(e,r)||l<=11&&setTimeout(oi(r,function(){return t.updateFromDOM()}),20)}),ge(i,"compositionstart",function(e){t.composing={data:e.data,done:!1}}),ge(i,"compositionupdate",function(e){t.composing||(t.composing={data:e.data,done:!1})}),ge(i,"compositionend",function(e){t.composing&&(e.data!=t.composing.data&&t.readFromDOMSoon(),t.composing.done=!0)}),ge(i,"touchstart",function(){return n.forceCompositionEnd()}),ge(i,"input",function(){t.composing||t.readFromDOMSoon()}),ge(i,"copy",a),ge(i,"cut",a)},Va.prototype.screenReaderLabelChanged=function(e){e?this.div.setAttribute("aria-label",e):this.div.removeAttribute("aria-label")},Va.prototype.prepareSelection=function(){var e=kr(this.cm,!1);return e.focus=F(I(this.div))==this.div,e},Va.prototype.showSelection=function(e,t){e&&this.cm.display.view.length&&((e.focus||t)&&this.showPrimarySelection(),this.showMultipleSelections(e))},Va.prototype.getSelection=function(){return this.cm.display.wrapper.ownerDocument.getSelection()},Va.prototype.showPrimarySelection=function(){var e=this.getSelection(),t=this.cm,r=t.doc.sel.primary(),i=r.from(),o=r.to();if(t.display.viewTo==t.display.viewFrom||i.line>=t.display.viewTo||o.line<t.display.viewFrom)e.removeAllRanges();else{var a=Ga(t,e.anchorNode,e.anchorOffset),l=Ga(t,e.focusNode,e.focusOffset);if(!a||a.bad||!l||l.bad||0!=at(ut(a,l),i)||0!=at(ct(a,l),o)){var s=t.display.view,c=i.line>=t.display.viewFrom&&Ka(t,i)||{node:s[0].measure.map[2],offset:0},u=o.line<t.display.viewTo&&Ka(t,o);if(!u){var d=s[s.length-1].measure,f=d.maps?d.maps[d.maps.length-1]:d.map;u={node:f[f.length-1],offset:f[f.length-2]-f[f.length-3]}}if(c&&u){var h,p=e.rangeCount&&e.getRangeAt(0);try{h=T(c.node,c.offset,u.offset,u.node)}catch(e){}h&&(!n&&t.state.focused?(e.collapse(c.node,c.offset),h.collapsed||(e.removeAllRanges(),e.addRange(h))):(e.removeAllRanges(),e.addRange(h)),p&&null==e.anchorNode?e.addRange(p):n&&this.startGracePeriod()),this.rememberSelection()}else e.removeAllRanges()}}},Va.prototype.startGracePeriod=function(){var e=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout(function(){e.gracePeriod=!1,e.selectionChanged()&&e.cm.operation(function(){return e.cm.curOp.selectionChanged=!0})},20)},Va.prototype.showMultipleSelections=function(e){N(this.cm.display.cursorDiv,e.cursors),N(this.cm.display.selectionDiv,e.selection)},Va.prototype.rememberSelection=function(){var e=this.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset},Va.prototype.selectionInEditor=function(){var e=this.getSelection();if(!e.rangeCount)return!1;var t=e.getRangeAt(0).commonAncestorContainer;return D(this.div,t)},Va.prototype.focus=function(){"nocursor"!=this.cm.options.readOnly&&(this.selectionInEditor()&&F(I(this.div))==this.div||this.showSelection(this.prepareSelection(),!0),this.div.focus())},Va.prototype.blur=function(){this.div.blur()},Va.prototype.getField=function(){return this.div},Va.prototype.supportsTouch=function(){return!0},Va.prototype.receivedFocus=function(){var e=this,t=this;this.selectionInEditor()?setTimeout(function(){return e.pollSelection()},20):ii(this.cm,function(){return t.cm.curOp.selectionChanged=!0}),this.polling.set(this.cm.options.pollInterval,function e(){t.cm.state.focused&&(t.pollSelection(),t.polling.set(t.cm.options.pollInterval,e))})},Va.prototype.selectionChanged=function(){var e=this.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset},Va.prototype.pollSelection=function(){if(null==this.readDOMTimeout&&!this.gracePeriod&&this.selectionChanged()){var e=this.getSelection(),t=this.cm;if(v&&u&&this.cm.display.gutterSpecs.length&&function(e){for(var t=e;t;t=t.parentNode)if(/CodeMirror-gutter-wrapper/.test(t.className))return!0;return!1}(e.anchorNode))return this.cm.triggerOnKeyDown({type:"keydown",keyCode:8,preventDefault:Math.abs}),this.blur(),void this.focus();if(!this.composing){this.rememberSelection();var n=Ga(t,e.anchorNode,e.anchorOffset),r=Ga(t,e.focusNode,e.focusOffset);n&&r&&ii(t,function(){io(t.doc,Ai(n,r),$),(n.bad||r.bad)&&(t.curOp.selectionChanged=!0)})}}},Va.prototype.pollContent=function(){null!=this.readDOMTimeout&&(clearTimeout(this.readDOMTimeout),this.readDOMTimeout=null);var e,t,n,r=this.cm,i=r.display,o=r.doc.sel.primary(),a=o.from(),l=o.to();if(0==a.ch&&a.line>r.firstLine()&&(a=ot(a.line-1,Ze(r.doc,a.line-1).length)),l.ch==Ze(r.doc,l.line).text.length&&l.line<r.lastLine()&&(l=ot(l.line+1,0)),a.line<i.viewFrom||l.line>i.viewTo-1)return!1;a.line==i.viewFrom||0==(e=mr(r,a.line))?(t=tt(i.view[0].line),n=i.view[0].node):(t=tt(i.view[e].line),n=i.view[e-1].node.nextSibling);var s,c,u=mr(r,l.line);if(u==i.view.length-1?(s=i.viewTo-1,c=i.lineDiv.lastChild):(s=tt(i.view[u+1].line)-1,c=i.view[u+1].node.previousSibling),!n)return!1;for(var d=r.doc.splitLines(function(e,t,n,r,i){var o="",a=!1,l=e.doc.lineSeparator(),s=!1;function c(){a&&(o+=l,s&&(o+=l),a=s=!1)}function u(e){e&&(c(),o+=e)}function d(t){if(1==t.nodeType){var n=t.getAttribute("cm-text");if(n)return void u(n);var o,f=t.getAttribute("cm-marker");if(f){var h=e.findMarks(ot(r,0),ot(i+1,0),(g=+f,function(e){return e.id==g}));return void(h.length&&(o=h[0].find(0))&&u(Qe(e.doc,o.from,o.to).join(l)))}if("false"==t.getAttribute("contenteditable"))return;var p=/^(pre|div|p|li|table|br)$/i.test(t.nodeName);if(!/^br$/i.test(t.nodeName)&&0==t.textContent.length)return;p&&c();for(var m=0;m<t.childNodes.length;m++)d(t.childNodes[m]);/^(pre|p)$/i.test(t.nodeName)&&(s=!0),p&&(a=!0)}else 3==t.nodeType&&u(t.nodeValue.replace(/\u200b/g,"").replace(/\u00a0/g," "));var g}for(;d(t),t!=n;)t=t.nextSibling,s=!1;return o}(r,n,c,t,s)),f=Qe(r.doc,ot(t,0),ot(s,Ze(r.doc,s).text.length));d.length>1&&f.length>1;)if(J(d)==J(f))d.pop(),f.pop(),s--;else{if(d[0]!=f[0])break;d.shift(),f.shift(),t++}for(var h=0,p=0,m=d[0],g=f[0],v=Math.min(m.length,g.length);h<v&&m.charCodeAt(h)==g.charCodeAt(h);)++h;for(var y=J(d),b=J(f),w=Math.min(y.length-(1==d.length?h:0),b.length-(1==f.length?h:0));p<w&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)++p;if(1==d.length&&1==f.length&&t==a.line)for(;h&&h>a.ch&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)h--,p++;d[d.length-1]=y.slice(0,y.length-p).replace(/^\u200b+/,""),d[0]=d[0].slice(h).replace(/\u200b+$/,"");var x=ot(t,h),k=ot(s,f.length?J(f).length-p:0);return d.length>1||d[0]||at(x,k)?(wo(r.doc,d,x,k,"+input"),!0):void 0},Va.prototype.ensurePolled=function(){this.forceCompositionEnd()},Va.prototype.reset=function(){this.forceCompositionEnd()},Va.prototype.forceCompositionEnd=function(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())},Va.prototype.readFromDOMSoon=function(){var e=this;null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout(function(){if(e.readDOMTimeout=null,e.composing){if(!e.composing.done)return;e.composing=null}e.updateFromDOM()},80))},Va.prototype.updateFromDOM=function(){var e=this;!this.cm.isReadOnly()&&this.pollContent()||ii(this.cm,function(){return gr(e.cm)})},Va.prototype.setUneditable=function(e){e.contentEditable="false"},Va.prototype.onKeyPress=function(e){0==e.charCode||this.composing||(e.preventDefault(),this.cm.isReadOnly()||oi(this.cm,za)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0))},Va.prototype.readOnlyChanged=function(e){this.div.contentEditable=String("nocursor"!=e)},Va.prototype.onContextMenu=function(){},Va.prototype.resetPosition=function(){},Va.prototype.needsContentAttribute=!0;var Ya=function(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new U,this.hasSelection=!1,this.composing=null,this.resetting=!1};Ya.prototype.init=function(e){var t=this,n=this,r=this.cm;this.createField(e);var i=this.textarea;function o(e){if(!we(r,e)){if(r.somethingSelected())Wa({lineWise:!1,text:r.getSelections()});else{if(!r.options.lineWiseCopyCut)return;var t=Ra(r);Wa({lineWise:!0,text:t.text}),"cut"==e.type?r.setSelections(t.ranges,null,$):(n.prevInput="",i.value=t.text.join("\n"),W(i))}"cut"==e.type&&(r.state.cutIncoming=+new Date)}}e.wrapper.insertBefore(this.wrapper,e.wrapper.firstChild),g&&(i.style.width="0px"),ge(i,"input",function(){a&&l>=9&&t.hasSelection&&(t.hasSelection=null),n.poll()}),ge(i,"paste",function(e){we(r,e)||Ha(e,r)||(r.state.pasteIncoming=+new Date,n.fastPoll())}),ge(i,"cut",o),ge(i,"copy",o),ge(e.scroller,"paste",function(t){if(!Ln(e,t)&&!we(r,t)){if(!i.dispatchEvent)return r.state.pasteIncoming=+new Date,void n.focus();var o=new Event("paste");o.clipboardData=t.clipboardData,i.dispatchEvent(o)}}),ge(e.lineSpace,"selectstart",function(t){Ln(e,t)||_e(t)}),ge(i,"compositionstart",function(){var e=r.getCursor("from");n.composing&&n.composing.range.clear(),n.composing={start:e,range:r.markText(e,r.getCursor("to"),{className:"CodeMirror-composing"})}}),ge(i,"compositionend",function(){n.composing&&(n.poll(),n.composing.range.clear(),n.composing=null)})},Ya.prototype.createField=function(e){this.wrapper=ja(),this.textarea=this.wrapper.firstChild;var t=this.cm.options;Ba(this.textarea,t.spellcheck,t.autocorrect,t.autocapitalize)},Ya.prototype.screenReaderLabelChanged=function(e){e?this.textarea.setAttribute("aria-label",e):this.textarea.removeAttribute("aria-label")},Ya.prototype.prepareSelection=function(){var e=this.cm,t=e.display,n=e.doc,r=kr(e);if(e.options.moveInputWithCursor){var i=Qn(e,n.sel.primary().head,"div"),o=t.wrapper.getBoundingClientRect(),a=t.lineDiv.getBoundingClientRect();r.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,i.top+a.top-o.top)),r.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,i.left+a.left-o.left))}return r},Ya.prototype.showSelection=function(e){var t=this.cm.display;N(t.cursorDiv,e.cursors),N(t.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},Ya.prototype.reset=function(e){if(!(this.contextMenuPending||this.composing&&e)){var t=this.cm;if(this.resetting=!0,t.somethingSelected()){this.prevInput="";var n=t.getSelection();this.textarea.value=n,t.state.focused&&W(this.textarea),a&&l>=9&&(this.hasSelection=n)}else e||(this.prevInput=this.textarea.value="",a&&l>=9&&(this.hasSelection=null));this.resetting=!1}},Ya.prototype.getField=function(){return this.textarea},Ya.prototype.supportsTouch=function(){return!1},Ya.prototype.focus=function(){if("nocursor"!=this.cm.options.readOnly&&(!y||F(I(this.textarea))!=this.textarea))try{this.textarea.focus()}catch(e){}},Ya.prototype.blur=function(){this.textarea.blur()},Ya.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0},Ya.prototype.receivedFocus=function(){this.slowPoll()},Ya.prototype.slowPoll=function(){var e=this;this.pollingFast||this.polling.set(this.cm.options.pollInterval,function(){e.poll(),e.cm.state.focused&&e.slowPoll()})},Ya.prototype.fastPoll=function(){var e=!1,t=this;t.pollingFast=!0,t.polling.set(20,function n(){t.poll()||e?(t.pollingFast=!1,t.slowPoll()):(e=!0,t.polling.set(60,n))})},Ya.prototype.poll=function(){var e=this,t=this.cm,n=this.textarea,r=this.prevInput;if(this.contextMenuPending||this.resetting||!t.state.focused||ze(n)&&!r&&!this.composing||t.isReadOnly()||t.options.disableInput||t.state.keySeq)return!1;var i=n.value;if(i==r&&!t.somethingSelected())return!1;if(a&&l>=9&&this.hasSelection===i||b&&/[\uf700-\uf7ff]/.test(i))return t.display.input.reset(),!1;if(t.doc.sel==t.display.selForContextMenu){var o=i.charCodeAt(0);if(8203!=o||r||(r=""),8666==o)return this.reset(),this.cm.execCommand("undo")}for(var s=0,c=Math.min(r.length,i.length);s<c&&r.charCodeAt(s)==i.charCodeAt(s);)++s;return ii(t,function(){za(t,i.slice(s),r.length-s,null,e.composing?"*compose":null),i.length>1e3||i.indexOf("\n")>-1?n.value=e.prevInput="":e.prevInput=i,e.composing&&(e.composing.range.clear(),e.composing.range=t.markText(e.composing.start,t.getCursor("to"),{className:"CodeMirror-composing"}))}),!0},Ya.prototype.ensurePolled=function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},Ya.prototype.onKeyPress=function(){a&&l>=9&&(this.hasSelection=null),this.fastPoll()},Ya.prototype.onContextMenu=function(e){var t=this,n=t.cm,r=n.display,i=t.textarea;t.contextMenuPending&&t.contextMenuPending();var o=pr(n,e),c=r.scroller.scrollTop;if(o&&!f){n.options.resetSelectionOnContextMenu&&-1==n.doc.sel.contains(o)&&oi(n,io)(n.doc,Ai(o),$);var u,d=i.style.cssText,h=t.wrapper.style.cssText,p=t.wrapper.offsetParent.getBoundingClientRect();if(t.wrapper.style.cssText="position: static",i.style.cssText="position: absolute; width: 30px; height: 30px;\n top: "+(e.clientY-p.top-5)+"px; left: "+(e.clientX-p.left-5)+"px;\n z-index: 1000; background: "+(a?"rgba(255, 255, 255, .05)":"transparent")+";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",s&&(u=i.ownerDocument.defaultView.scrollY),r.input.focus(),s&&i.ownerDocument.defaultView.scrollTo(null,u),r.input.reset(),n.somethingSelected()||(i.value=t.prevInput=" "),t.contextMenuPending=v,r.selForContextMenu=n.doc.sel,clearTimeout(r.detectingSelectAll),a&&l>=9&&g(),_){Le(e);var m=function(){ye(window,"mouseup",m),setTimeout(v,20)};ge(window,"mouseup",m)}else setTimeout(v,50)}function g(){if(null!=i.selectionStart){var e=n.somethingSelected(),o=""+(e?i.value:"");i.value="⇚",i.value=o,t.prevInput=e?"":"",i.selectionStart=1,i.selectionEnd=o.length,r.selForContextMenu=n.doc.sel}}function v(){if(t.contextMenuPending==v&&(t.contextMenuPending=!1,t.wrapper.style.cssText=h,i.style.cssText=d,a&&l<9&&r.scrollbars.setScrollTop(r.scroller.scrollTop=c),null!=i.selectionStart)){(!a||a&&l<9)&&g();var e=0,o=function(){r.selForContextMenu==n.doc.sel&&0==i.selectionStart&&i.selectionEnd>0&&""==t.prevInput?oi(n,ho)(n):e++<10?r.detectingSelectAll=setTimeout(o,500):(r.selForContextMenu=null,r.input.reset())};r.detectingSelectAll=setTimeout(o,200)}}},Ya.prototype.readOnlyChanged=function(e){e||this.reset(),this.textarea.disabled="nocursor"==e,this.textarea.readOnly=!!e},Ya.prototype.setUneditable=function(){},Ya.prototype.needsContentAttribute=!1,function(e){var t=e.optionHandlers;function n(n,r,i,o){e.defaults[n]=r,i&&(t[n]=o?function(e,t,n){n!=La&&i(e,t,n)}:i)}e.defineOption=n,e.Init=La,n("value","",function(e,t){return e.setValue(t)},!0),n("mode",null,function(e,t){e.doc.modeOption=t,Pi(e)},!0),n("indentUnit",2,Pi,!0),n("indentWithTabs",!1),n("smartIndent",!0),n("tabSize",4,function(e){Wi(e),Vn(e),gr(e)},!0),n("lineSeparator",null,function(e,t){if(e.doc.lineSep=t,t){var n=[],r=e.doc.first;e.doc.iter(function(e){for(var i=0;;){var o=e.text.indexOf(t,i);if(-1==o)break;i=o+t.length,n.push(ot(r,o))}r++});for(var i=n.length-1;i>=0;i--)wo(e.doc,t,n[i],ot(n[i].line,n[i].ch+t.length))}}),n("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\u202d\u202e\u2066\u2067\u2069\ufeff\ufff9-\ufffc]/g,function(e,t,n){e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),n!=La&&e.refresh()}),n("specialCharPlaceholder",rn,function(e){return e.refresh()},!0),n("electricChars",!0),n("inputStyle",y?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),n("spellcheck",!1,function(e,t){return e.getInputField().spellcheck=t},!0),n("autocorrect",!1,function(e,t){return e.getInputField().autocorrect=t},!0),n("autocapitalize",!1,function(e,t){return e.getInputField().autocapitalize=t},!0),n("rtlMoveVisually",!x),n("wholeLineUpdateBefore",!0),n("theme","default",function(e){Ta(e),wi(e)},!0),n("keyMap","default",function(e,t,n){var r=ta(t),i=n!=La&&ta(n);i&&i.detach&&i.detach(e,r),r.attach&&r.attach(e,i||null)}),n("extraKeys",null),n("configureMouse",null),n("lineWrapping",!1,Oa,!0),n("gutters",[],function(e,t){e.display.gutterSpecs=yi(t,e.options.lineNumbers),wi(e)},!0),n("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?dr(e.display)+"px":"0",e.refresh()},!0),n("coverGutterNextToScrollbar",!1,function(e){return Kr(e)},!0),n("scrollbarStyle","native",function(e){Xr(e),Kr(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),n("lineNumbers",!1,function(e,t){e.display.gutterSpecs=yi(e.options.gutters,t),wi(e)},!0),n("firstLineNumber",1,wi,!0),n("lineNumberFormatter",function(e){return e},wi,!0),n("showCursorWhenSelecting",!1,xr,!0),n("resetSelectionOnContextMenu",!0),n("lineWiseCopyCut",!0),n("pasteLinesPerSelection",!0),n("selectionsMayTouch",!1),n("readOnly",!1,function(e,t){"nocursor"==t&&(Ar(e),e.display.input.blur()),e.display.input.readOnlyChanged(t)}),n("screenReaderLabel",null,function(e,t){t=""===t?null:t,e.display.input.screenReaderLabelChanged(t)}),n("disableInput",!1,function(e,t){t||e.display.input.reset()},!0),n("dragDrop",!0,Aa),n("allowDropFileTypes",null),n("cursorBlinkRate",530),n("cursorScrollMargin",0),n("cursorHeight",1,xr,!0),n("singleCursorHeightPerLine",!0,xr,!0),n("workTime",100),n("workDelay",100),n("flattenSpans",!0,Wi,!0),n("addModeClass",!1,Wi,!0),n("pollInterval",100),n("undoDepth",200,function(e,t){return e.doc.history.undoDepth=t}),n("historyEventDelay",1250),n("viewportMargin",10,function(e){return e.refresh()},!0),n("maxHighlightLength",1e4,Wi,!0),n("moveInputWithCursor",!0,function(e,t){t||e.display.input.resetPosition()}),n("tabindex",null,function(e,t){return e.display.input.getField().tabIndex=t||""}),n("autofocus",null),n("direction","ltr",function(e,t){return e.doc.setDirection(t)},!0),n("phrases",null)}(Da),function(e){var t=e.optionHandlers,n=e.helpers={};e.prototype={constructor:e,focus:function(){R(this).focus(),this.display.input.focus()},setOption:function(e,n){var r=this.options,i=r[e];r[e]==n&&"mode"!=e||(r[e]=n,t.hasOwnProperty(e)&&oi(this,t[e])(this,n,i),be(this,"optionChange",this,e))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](ta(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,n=0;n<t.length;++n)if(t[n]==e||t[n].name==e)return t.splice(n,1),!0},addOverlay:ai(function(t,n){var r=t.token?t:e.getMode(this.options,t);if(r.startState)throw new Error("Overlays may not be stateful.");(function(e,t,n){for(var r=0,i=n(t);r<e.length&&n(e[r])<=i;)r++;e.splice(r,0,t)})(this.state.overlays,{mode:r,modeSpec:t,opaque:n&&n.opaque,priority:n&&n.priority||0},function(e){return e.priority}),this.state.modeGen++,gr(this)}),removeOverlay:ai(function(e){for(var t=this.state.overlays,n=0;n<t.length;++n){var r=t[n].modeSpec;if(r==e||"string"==typeof e&&r.name==e)return t.splice(n,1),this.state.modeGen++,void gr(this)}}),indentLine:ai(function(e,t,n){"string"!=typeof t&&"number"!=typeof t&&(t=null==t?this.options.smartIndent?"smart":"prev":t?"add":"subtract"),rt(this.doc,e)&&Ea(this,e,t,n)}),indentSelection:ai(function(e){for(var t=this.doc.sel.ranges,n=-1,r=0;r<t.length;r++){var i=t[r];if(i.empty())i.head.line>n&&(Ea(this,i.head.line,e,!0),n=i.head.line,r==this.doc.sel.primIndex&&Wr(this));else{var o=i.from(),a=i.to(),l=Math.max(n,o.line);n=Math.min(this.lastLine(),a.line-(a.ch?0:1))+1;for(var s=l;s<n;++s)Ea(this,s,e);var c=this.doc.sel.ranges;0==o.ch&&t.length==c.length&&c[r].from().ch>0&&to(this.doc,r,new Mi(o,c[r].to()),$)}}}),getTokenAt:function(e,t){return Ct(this,e,t)},getLineTokens:function(e,t){return Ct(this,ot(e),t,!0)},getTokenTypeAt:function(e){e=ft(this.doc,e);var t,n=vt(this,Ze(this.doc,e.line)),r=0,i=(n.length-1)/2,o=e.ch;if(0==o)t=n[2];else for(;;){var a=r+i>>1;if((a?n[2*a-1]:0)>=o)i=a;else{if(!(n[2*a+1]<o)){t=n[2*a+2];break}r=a+1}}var l=t?t.indexOf("overlay "):-1;return l<0?t:0==l?null:t.slice(0,l-1)},getModeAt:function(t){var n=this.doc.mode;return n.innerMode?e.innerMode(n,this.getTokenAt(t).state).mode:n},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var r=[];if(!n.hasOwnProperty(t))return r;var i=n[t],o=this.getModeAt(e);if("string"==typeof o[t])i[o[t]]&&r.push(i[o[t]]);else if(o[t])for(var a=0;a<o[t].length;a++){var l=i[o[t][a]];l&&r.push(l)}else o.helperType&&i[o.helperType]?r.push(i[o.helperType]):i[o.name]&&r.push(i[o.name]);for(var s=0;s<i._global.length;s++){var c=i._global[s];c.pred(o,this)&&-1==V(r,c.val)&&r.push(c.val)}return r},getStateAfter:function(e,t){var n=this.doc;return yt(this,(e=dt(n,null==e?n.first+n.size-1:e))+1,t).state},cursorCoords:function(e,t){var n=this.doc.sel.primary();return Qn(this,null==e?n.head:"object"==typeof e?ft(this.doc,e):e?n.from():n.to(),t||"page")},charCoords:function(e,t){return Zn(this,ft(this.doc,e),t||"page")},coordsChar:function(e,t){return tr(this,(e=Yn(this,e,t||"page")).left,e.top)},lineAtHeight:function(e,t){return e=Yn(this,{top:e,left:0},t||"page").top,nt(this.doc,e+this.display.viewOffset)},heightAtLine:function(e,t,n){var r,i=!1;if("number"==typeof e){var o=this.doc.first+this.doc.size-1;e<this.doc.first?e=this.doc.first:e>o&&(e=o,i=!0),r=Ze(this.doc,e)}else r=e;return Xn(this,r,{top:0,left:0},t||"page",n||i).top+(i?this.doc.height-Gt(r):0)},defaultTextHeight:function(){return sr(this.display)},defaultCharWidth:function(){return cr(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,n,r,i){var o,a,l,s=this.display,c=(e=Qn(this,ft(this.doc,e))).bottom,u=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),s.sizer.appendChild(t),"over"==r)c=e.top;else if("above"==r||"near"==r){var d=Math.max(s.wrapper.clientHeight,this.doc.height),f=Math.max(s.sizer.clientWidth,s.lineSpace.clientWidth);("above"==r||e.bottom+t.offsetHeight>d)&&e.top>t.offsetHeight?c=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=d&&(c=e.bottom),u+t.offsetWidth>f&&(u=f-t.offsetWidth)}t.style.top=c+"px",t.style.left=t.style.right="","right"==i?(u=s.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?u=0:"middle"==i&&(u=(s.sizer.clientWidth-t.offsetWidth)/2),t.style.left=u+"px"),n&&(o=this,a={left:u,top:c,right:u+t.offsetWidth,bottom:c+t.offsetHeight},null!=(l=Er(o,a)).scrollTop&&Rr(o,l.scrollTop),null!=l.scrollLeft&&jr(o,l.scrollLeft))},triggerOnKeyDown:ai(ma),triggerOnKeyPress:ai(va),triggerOnKeyUp:ga,triggerOnMouseDown:ai(xa),execCommand:function(e){if(aa.hasOwnProperty(e))return aa[e].call(null,this)},triggerElectric:ai(function(e){Ia(this,e)}),findPosH:function(e,t,n,r){var i=1;t<0&&(i=-1,t=-t);for(var o=ft(this.doc,e),a=0;a<t&&!(o=qa(this.doc,o,i,n,r)).hitSide;++a);return o},moveH:ai(function(e,t){var n=this;this.extendSelectionsBy(function(r){return n.display.shift||n.doc.extend||r.empty()?qa(n.doc,r.head,e,t,n.options.rtlMoveVisually):e<0?r.from():r.to()},X)}),deleteH:ai(function(e,t){var n=this.doc.sel,r=this.doc;n.somethingSelected()?r.replaceSelection("",null,"+delete"):na(this,function(n){var i=qa(r,n.head,e,t,!1);return e<0?{from:i,to:n.head}:{from:n.head,to:i}})}),findPosV:function(e,t,n,r){var i=1,o=r;t<0&&(i=-1,t=-t);for(var a=ft(this.doc,e),l=0;l<t;++l){var s=Qn(this,a,"div");if(null==o?o=s.left:s.left=o,(a=Ua(this,s,i,n)).hitSide)break}return a},moveV:ai(function(e,t){var n=this,r=this.doc,i=[],o=!this.display.shift&&!r.extend&&r.sel.somethingSelected();if(r.extendSelectionsBy(function(a){if(o)return e<0?a.from():a.to();var l=Qn(n,a.head,"div");null!=a.goalColumn&&(l.left=a.goalColumn),i.push(l.left);var s=Ua(n,l,e,t);return"page"==t&&a==r.sel.primary()&&Pr(n,Zn(n,s,"div").top-l.top),s},X),i.length)for(var a=0;a<r.sel.ranges.length;a++)r.sel.ranges[a].goalColumn=i[a]}),findWordAt:function(e){var t=Ze(this.doc,e.line).text,n=e.ch,r=e.ch;if(t){var i=this.getHelper(e,"wordChars");"before"!=e.sticky&&r!=t.length||!n?++r:--n;for(var o=t.charAt(n),a=oe(o,i)?function(e){return oe(e,i)}:/\s/.test(o)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!oe(e)};n>0&&a(t.charAt(n-1));)--n;for(;r<t.length&&a(t.charAt(r));)++r}return new Mi(ot(e.line,n),ot(e.line,r))},toggleOverwrite:function(e){null!=e&&e==this.state.overwrite||((this.state.overwrite=!this.state.overwrite)?E(this.display.cursorDiv,"CodeMirror-overwrite"):L(this.display.cursorDiv,"CodeMirror-overwrite"),be(this,"overwriteToggle",this,this.state.overwrite))},hasFocus:function(){return this.display.input.getField()==F(H(this))},isReadOnly:function(){return!(!this.options.readOnly&&!this.doc.cantEdit)},scrollTo:ai(function(e,t){zr(this,e,t)}),getScrollInfo:function(){var e=this.display.scroller;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-On(this)-this.display.barHeight,width:e.scrollWidth-On(this)-this.display.barWidth,clientHeight:Fn(this),clientWidth:Dn(this)}},scrollIntoView:ai(function(e,t){null==e?(e={from:this.doc.sel.primary().head,to:null},null==t&&(t=this.options.cursorScrollMargin)):"number"==typeof e?e={from:ot(e,0),to:null}:null==e.from&&(e={from:e,to:null}),e.to||(e.to=e.from),e.margin=t||0,null!=e.from.line?function(e,t){Hr(e),e.curOp.scrollToPos=t}(this,e):Ir(this,e.from,e.to,e.margin)}),setSize:ai(function(e,t){var n=this,r=function(e){return"number"==typeof e||/^\d+$/.test(String(e))?e+"px":e};null!=e&&(this.display.wrapper.style.width=r(e)),null!=t&&(this.display.wrapper.style.height=r(t)),this.options.lineWrapping&&Un(this);var i=this.display.viewFrom;this.doc.iter(i,this.display.viewTo,function(e){if(e.widgets)for(var t=0;t<e.widgets.length;t++)if(e.widgets[t].noHScroll){vr(n,i,"widget");break}++i}),this.curOp.forceUpdate=!0,be(this,"refresh",this)}),operation:function(e){return ii(this,e)},startOperation:function(){return Zr(this)},endOperation:function(){return Qr(this)},refresh:ai(function(){var e=this.display.cachedTextHeight;gr(this),this.curOp.forceUpdate=!0,Vn(this),zr(this,this.doc.scrollLeft,this.doc.scrollTop),pi(this.display),(null==e||Math.abs(e-sr(this.display))>.5||this.options.lineWrapping)&&hr(this),be(this,"refresh",this)}),swapDoc:ai(function(e){var t=this.doc;return t.cm=null,this.state.selectingText&&this.state.selectingText(),Ri(this,e),Vn(this),this.display.input.reset(),zr(this,e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,hn(this,"swapDoc",this,t),t}),phrase:function(e){var t=this.options.phrases;return t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:e},getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},Ce(e),e.registerHelper=function(t,r,i){n.hasOwnProperty(t)||(n[t]=e[t]={_global:[]}),n[t][r]=i},e.registerGlobalHelper=function(t,r,i,o){e.registerHelper(t,r,o),n[t]._global.push({pred:i,val:o})}}(Da);var Za="iter insert remove copy getEditor constructor".split(" ");for(var Qa in Wo.prototype)Wo.prototype.hasOwnProperty(Qa)&&V(Za,Qa)<0&&(Da.prototype[Qa]=function(e){return function(){return e.apply(this.doc,arguments)}}(Wo.prototype[Qa]));return Ce(Wo),Da.inputStyles={textarea:Ya,contenteditable:Va},Da.defineMode=function(e){Da.defaults.mode||"null"==e||(Da.defaults.mode=e),je.apply(this,arguments)},Da.defineMIME=function(e,t){Be[e]=t},Da.defineMode("null",function(){return{token:function(e){return e.skipToEnd()}}}),Da.defineMIME("text/plain","null"),Da.defineExtension=function(e,t){Da.prototype[e]=t},Da.defineDocExtension=function(e,t){Wo.prototype[e]=t},Da.fromTextArea=function(e,t){if((t=t?j(t):{}).value=e.value,!t.tabindex&&e.tabIndex&&(t.tabindex=e.tabIndex),!t.placeholder&&e.placeholder&&(t.placeholder=e.placeholder),null==t.autofocus){var n=F(I(e));t.autofocus=n==e||null!=e.getAttribute("autofocus")&&n==document.body}function r(){e.value=l.getValue()}var i;if(e.form&&(ge(e.form,"submit",r),!t.leaveSubmitMethodAlone)){var o=e.form;i=o.submit;try{var a=o.submit=function(){r(),o.submit=i,o.submit(),o.submit=a}}catch(e){}}t.finishInit=function(n){n.save=r,n.getTextArea=function(){return e},n.toTextArea=function(){n.toTextArea=isNaN,r(),e.parentNode.removeChild(n.getWrapperElement()),e.style.display="",e.form&&(ye(e.form,"submit",r),t.leaveSubmitMethodAlone||"function"!=typeof e.form.submit||(e.form.submit=i))}},e.style.display="none";var l=Da(function(t){return e.parentNode.insertBefore(t,e.nextSibling)},t);return l},function(e){e.off=ye,e.on=ge,e.wheelEventPixels=Si,e.Doc=Wo,e.splitLines=We,e.countColumn=q,e.findColumn=Y,e.isWordChar=ie,e.Pass=K,e.signal=be,e.Line=Zt,e.changeEnd=Oi,e.scrollbarModel=Gr,e.Pos=ot,e.cmpPos=at,e.modes=Re,e.mimeModes=Be,e.resolveMode=qe,e.getMode=Ue,e.modeExtensions=Ve,e.extendMode=Ke,e.copyState=$e,e.startState=Xe,e.innerMode=Ge,e.commands=aa,e.keyMap=Go,e.keyName=ea,e.isModifierKey=Qo,e.lookupKey=Zo,e.normalizeKeyMap=Yo,e.StringStream=Ye,e.SharedTextMarker=Do,e.TextMarker=Ao,e.LineWidget=Lo,e.e_preventDefault=_e,e.e_stopPropagation=Se,e.e_stop=Le,e.addClass=E,e.contains=D,e.rmClass=L,e.keyNames=Uo}(Da),Da.version="5.65.21",Da}()},656(e,t,n){!function(e){"use strict";function t(e){for(var t={},n=0;n<e.length;++n)t[e[n].toLowerCase()]=!0;return t}e.defineMode("css",function(t,n){var r=n.inline;n.propertyKeywords||(n=e.resolveMode("text/css"));var i,o,a=t.indentUnit,l=n.tokenHooks,s=n.documentTypes||{},c=n.mediaTypes||{},u=n.mediaFeatures||{},d=n.mediaValueKeywords||{},f=n.propertyKeywords||{},h=n.nonStandardPropertyKeywords||{},p=n.fontProperties||{},m=n.counterDescriptors||{},g=n.colorKeywords||{},v=n.valueKeywords||{},y=n.allowNested,b=n.lineComment,w=!0===n.supportsAtComponent,x=!1!==t.highlightNonStandardPropertyKeywords;function k(e,t){return i=t,e}function C(e,t){var n=e.next();if(l[n]){var r=l[n](e,t);if(!1!==r)return r}return"@"==n?(e.eatWhile(/[\w\\\-]/),k("def",e.current())):"="==n||("~"==n||"|"==n)&&e.eat("=")?k(null,"compare"):'"'==n||"'"==n?(t.tokenize=_(n),t.tokenize(e,t)):"#"==n?(e.eatWhile(/[\w\\\-]/),k("atom","hash")):"!"==n?(e.match(/^\s*\w*/),k("keyword","important")):/\d/.test(n)||"."==n&&e.eat(/\d/)?(e.eatWhile(/[\w.%]/),k("number","unit")):"-"!==n?/[,+>*\/]/.test(n)?k(null,"select-op"):"."==n&&e.match(/^-?[_a-z][_a-z0-9-]*/i)?k("qualifier","qualifier"):/[:;{}\[\]\(\)]/.test(n)?k(null,n):e.match(/^[\w-.]+(?=\()/)?(/^(url(-prefix)?|domain|regexp)$/i.test(e.current())&&(t.tokenize=S),k("variable callee","variable")):/[\w\\\-]/.test(n)?(e.eatWhile(/[\w\\\-]/),k("property","word")):k(null,null):/[\d.]/.test(e.peek())?(e.eatWhile(/[\w.%]/),k("number","unit")):e.match(/^-[\w\\\-]*/)?(e.eatWhile(/[\w\\\-]/),e.match(/^\s*:/,!1)?k("variable-2","variable-definition"):k("variable-2","variable")):e.match(/^\w+-/)?k("meta","meta"):void 0}function _(e){return function(t,n){for(var r,i=!1;null!=(r=t.next());){if(r==e&&!i){")"==e&&t.backUp(1);break}i=!i&&"\\"==r}return(r==e||!i&&")"!=e)&&(n.tokenize=null),k("string","string")}}function S(e,t){return e.next(),e.match(/^\s*[\"\')]/,!1)?t.tokenize=null:t.tokenize=_(")"),k(null,"(")}function T(e,t,n){this.type=e,this.indent=t,this.prev=n}function L(e,t,n,r){return e.context=new T(n,t.indentation()+(!1===r?0:a),e.context),n}function M(e){return e.context.prev&&(e.context=e.context.prev),e.context.type}function N(e,t,n){return D[n.context.type](e,t,n)}function A(e,t,n,r){for(var i=r||1;i>0;i--)n.context=n.context.prev;return N(e,t,n)}function O(e){var t=e.current().toLowerCase();o=v.hasOwnProperty(t)?"atom":g.hasOwnProperty(t)?"keyword":"variable"}var D={top:function(e,t,n){if("{"==e)return L(n,t,"block");if("}"==e&&n.context.prev)return M(n);if(w&&/@component/i.test(e))return L(n,t,"atComponentBlock");if(/^@(-moz-)?document$/i.test(e))return L(n,t,"documentTypes");if(/^@(media|supports|(-moz-)?document|import)$/i.test(e))return L(n,t,"atBlock");if(/^@(font-face|counter-style)/i.test(e))return n.stateArg=e,"restricted_atBlock_before";if(/^@(-(moz|ms|o|webkit)-)?keyframes$/i.test(e))return"keyframes";if(e&&"@"==e.charAt(0))return L(n,t,"at");if("hash"==e)o="builtin";else if("word"==e)o="tag";else{if("variable-definition"==e)return"maybeprop";if("interpolation"==e)return L(n,t,"interpolation");if(":"==e)return"pseudo";if(y&&"("==e)return L(n,t,"parens")}return n.context.type},block:function(e,t,n){if("word"==e){var r=t.current().toLowerCase();return f.hasOwnProperty(r)?(o="property","maybeprop"):h.hasOwnProperty(r)?(o=x?"string-2":"property","maybeprop"):y?(o=t.match(/^\s*:(?:\s|$)/,!1)?"property":"tag","block"):(o+=" error","maybeprop")}return"meta"==e?"block":y||"hash"!=e&&"qualifier"!=e?D.top(e,t,n):(o="error","block")},maybeprop:function(e,t,n){return":"==e?L(n,t,"prop"):N(e,t,n)},prop:function(e,t,n){if(";"==e)return M(n);if("{"==e&&y)return L(n,t,"propBlock");if("}"==e||"{"==e)return A(e,t,n);if("("==e)return L(n,t,"parens");if("hash"!=e||/^#([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(t.current())){if("word"==e)O(t);else if("interpolation"==e)return L(n,t,"interpolation")}else o+=" error";return"prop"},propBlock:function(e,t,n){return"}"==e?M(n):"word"==e?(o="property","maybeprop"):n.context.type},parens:function(e,t,n){return"{"==e||"}"==e?A(e,t,n):")"==e?M(n):"("==e?L(n,t,"parens"):"interpolation"==e?L(n,t,"interpolation"):("word"==e&&O(t),"parens")},pseudo:function(e,t,n){return"meta"==e?"pseudo":"word"==e?(o="variable-3",n.context.type):N(e,t,n)},documentTypes:function(e,t,n){return"word"==e&&s.hasOwnProperty(t.current())?(o="tag",n.context.type):D.atBlock(e,t,n)},atBlock:function(e,t,n){if("("==e)return L(n,t,"atBlock_parens");if("}"==e||";"==e)return A(e,t,n);if("{"==e)return M(n)&&L(n,t,y?"block":"top");if("interpolation"==e)return L(n,t,"interpolation");if("word"==e){var r=t.current().toLowerCase();o="only"==r||"not"==r||"and"==r||"or"==r?"keyword":c.hasOwnProperty(r)?"attribute":u.hasOwnProperty(r)?"property":d.hasOwnProperty(r)?"keyword":f.hasOwnProperty(r)?"property":h.hasOwnProperty(r)?x?"string-2":"property":v.hasOwnProperty(r)?"atom":g.hasOwnProperty(r)?"keyword":"error"}return n.context.type},atComponentBlock:function(e,t,n){return"}"==e?A(e,t,n):"{"==e?M(n)&&L(n,t,y?"block":"top",!1):("word"==e&&(o="error"),n.context.type)},atBlock_parens:function(e,t,n){return")"==e?M(n):"{"==e||"}"==e?A(e,t,n,2):D.atBlock(e,t,n)},restricted_atBlock_before:function(e,t,n){return"{"==e?L(n,t,"restricted_atBlock"):"word"==e&&"@counter-style"==n.stateArg?(o="variable","restricted_atBlock_before"):N(e,t,n)},restricted_atBlock:function(e,t,n){return"}"==e?(n.stateArg=null,M(n)):"word"==e?(o="@font-face"==n.stateArg&&!p.hasOwnProperty(t.current().toLowerCase())||"@counter-style"==n.stateArg&&!m.hasOwnProperty(t.current().toLowerCase())?"error":"property","maybeprop"):"restricted_atBlock"},keyframes:function(e,t,n){return"word"==e?(o="variable","keyframes"):"{"==e?L(n,t,"top"):N(e,t,n)},at:function(e,t,n){return";"==e?M(n):"{"==e||"}"==e?A(e,t,n):("word"==e?o="tag":"hash"==e&&(o="builtin"),"at")},interpolation:function(e,t,n){return"}"==e?M(n):"{"==e||";"==e?A(e,t,n):("word"==e?o="variable":"variable"!=e&&"("!=e&&")"!=e&&(o="error"),"interpolation")}};return{startState:function(e){return{tokenize:null,state:r?"block":"top",stateArg:null,context:new T(r?"block":"top",e||0,null)}},token:function(e,t){if(!t.tokenize&&e.eatSpace())return null;var n=(t.tokenize||C)(e,t);return n&&"object"==typeof n&&(i=n[1],n=n[0]),o=n,"comment"!=i&&(t.state=D[t.state](i,e,t)),o},indent:function(e,t){var n=e.context,r=t&&t.charAt(0),i=n.indent;return"prop"!=n.type||"}"!=r&&")"!=r||(n=n.prev),n.prev&&("}"!=r||"block"!=n.type&&"top"!=n.type&&"interpolation"!=n.type&&"restricted_atBlock"!=n.type?(")"!=r||"parens"!=n.type&&"atBlock_parens"!=n.type)&&("{"!=r||"at"!=n.type&&"atBlock"!=n.type)||(i=Math.max(0,n.indent-a)):i=(n=n.prev).indent),i},electricChars:"}",blockCommentStart:"/*",blockCommentEnd:"*/",blockCommentContinue:" * ",lineComment:b,fold:"brace"}});var n=["domain","regexp","url","url-prefix"],r=t(n),i=["all","aural","braille","handheld","print","projection","screen","tty","tv","embossed"],o=t(i),a=["width","min-width","max-width","height","min-height","max-height","device-width","min-device-width","max-device-width","device-height","min-device-height","max-device-height","aspect-ratio","min-aspect-ratio","max-aspect-ratio","device-aspect-ratio","min-device-aspect-ratio","max-device-aspect-ratio","color","min-color","max-color","color-index","min-color-index","max-color-index","monochrome","min-monochrome","max-monochrome","resolution","min-resolution","max-resolution","scan","grid","orientation","device-pixel-ratio","min-device-pixel-ratio","max-device-pixel-ratio","pointer","any-pointer","hover","any-hover","prefers-color-scheme","dynamic-range","video-dynamic-range"],l=t(a),s=["landscape","portrait","none","coarse","fine","on-demand","hover","interlace","progressive","dark","light","standard","high"],c=t(s),u=["align-content","align-items","align-self","alignment-adjust","alignment-baseline","all","anchor-point","animation","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-timing-function","appearance","azimuth","backdrop-filter","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-position-x","background-position-y","background-repeat","background-size","baseline-shift","binding","bleed","block-size","bookmark-label","bookmark-level","bookmark-state","bookmark-target","border","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-decoration-break","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","caret-color","clear","clip","color","color-profile","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","content","counter-increment","counter-reset","crop","cue","cue-after","cue-before","cursor","direction","display","dominant-baseline","drop-initial-after-adjust","drop-initial-after-align","drop-initial-before-adjust","drop-initial-before-align","drop-initial-size","drop-initial-value","elevation","empty-cells","fit","fit-content","fit-position","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","float-offset","flow-from","flow-into","font","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-size","font-size-adjust","font-stretch","font-style","font-synthesis","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","font-weight","gap","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-gap","grid-column-start","grid-gap","grid-row","grid-row-end","grid-row-gap","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphens","icon","image-orientation","image-rendering","image-resolution","inline-box-align","inset","inset-block","inset-block-end","inset-block-start","inset-inline","inset-inline-end","inset-inline-start","isolation","justify-content","justify-items","justify-self","left","letter-spacing","line-break","line-height","line-height-step","line-stacking","line-stacking-ruby","line-stacking-shift","line-stacking-strategy","list-style","list-style-image","list-style-position","list-style-type","margin","margin-bottom","margin-left","margin-right","margin-top","marks","marquee-direction","marquee-loop","marquee-play-count","marquee-speed","marquee-style","mask-clip","mask-composite","mask-image","mask-mode","mask-origin","mask-position","mask-repeat","mask-size","mask-type","max-block-size","max-height","max-inline-size","max-width","min-block-size","min-height","min-inline-size","min-width","mix-blend-mode","move-to","nav-down","nav-index","nav-left","nav-right","nav-up","object-fit","object-position","offset","offset-anchor","offset-distance","offset-path","offset-position","offset-rotate","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-style","overflow-wrap","overflow-x","overflow-y","padding","padding-bottom","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","page-policy","pause","pause-after","pause-before","perspective","perspective-origin","pitch","pitch-range","place-content","place-items","place-self","play-during","position","presentation-level","punctuation-trim","quotes","region-break-after","region-break-before","region-break-inside","region-fragment","rendering-intent","resize","rest","rest-after","rest-before","richness","right","rotate","rotation","rotation-point","row-gap","ruby-align","ruby-overhang","ruby-position","ruby-span","scale","scroll-behavior","scroll-margin","scroll-margin-block","scroll-margin-block-end","scroll-margin-block-start","scroll-margin-bottom","scroll-margin-inline","scroll-margin-inline-end","scroll-margin-inline-start","scroll-margin-left","scroll-margin-right","scroll-margin-top","scroll-padding","scroll-padding-block","scroll-padding-block-end","scroll-padding-block-start","scroll-padding-bottom","scroll-padding-inline","scroll-padding-inline-end","scroll-padding-inline-start","scroll-padding-left","scroll-padding-right","scroll-padding-top","scroll-snap-align","scroll-snap-type","shape-image-threshold","shape-inside","shape-margin","shape-outside","size","speak","speak-as","speak-header","speak-numeral","speak-punctuation","speech-rate","stress","string-set","tab-size","table-layout","target","target-name","target-new","target-position","text-align","text-align-last","text-combine-upright","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-height","text-indent","text-justify","text-orientation","text-outline","text-overflow","text-rendering","text-shadow","text-size-adjust","text-space-collapse","text-transform","text-underline-position","text-wrap","top","touch-action","transform","transform-origin","transform-style","transition","transition-delay","transition-duration","transition-property","transition-timing-function","translate","unicode-bidi","user-select","vertical-align","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","volume","white-space","widows","width","will-change","word-break","word-spacing","word-wrap","writing-mode","z-index","clip-path","clip-rule","mask","enable-background","filter","flood-color","flood-opacity","lighting-color","stop-color","stop-opacity","pointer-events","color-interpolation","color-interpolation-filters","color-rendering","fill","fill-opacity","fill-rule","image-rendering","marker","marker-end","marker-mid","marker-start","paint-order","shape-rendering","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","text-rendering","baseline-shift","dominant-baseline","glyph-orientation-horizontal","glyph-orientation-vertical","text-anchor","writing-mode"],d=t(u),f=["accent-color","aspect-ratio","border-block","border-block-color","border-block-end","border-block-end-color","border-block-end-style","border-block-end-width","border-block-start","border-block-start-color","border-block-start-style","border-block-start-width","border-block-style","border-block-width","border-inline","border-inline-color","border-inline-end","border-inline-end-color","border-inline-end-style","border-inline-end-width","border-inline-start","border-inline-start-color","border-inline-start-style","border-inline-start-width","border-inline-style","border-inline-width","content-visibility","margin-block","margin-block-end","margin-block-start","margin-inline","margin-inline-end","margin-inline-start","overflow-anchor","overscroll-behavior","padding-block","padding-block-end","padding-block-start","padding-inline","padding-inline-end","padding-inline-start","scroll-snap-stop","scrollbar-3d-light-color","scrollbar-arrow-color","scrollbar-base-color","scrollbar-dark-shadow-color","scrollbar-face-color","scrollbar-highlight-color","scrollbar-shadow-color","scrollbar-track-color","searchfield-cancel-button","searchfield-decoration","searchfield-results-button","searchfield-results-decoration","shape-inside","zoom"],h=t(f),p=t(["font-display","font-family","src","unicode-range","font-variant","font-feature-settings","font-stretch","font-weight","font-style"]),m=t(["additive-symbols","fallback","negative","pad","prefix","range","speak-as","suffix","symbols","system"]),g=["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","grey","green","greenyellow","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"],v=t(g),y=["above","absolute","activeborder","additive","activecaption","afar","after-white-space","ahead","alias","all","all-scroll","alphabetic","alternate","always","amharic","amharic-abegede","antialiased","appworkspace","arabic-indic","armenian","asterisks","attr","auto","auto-flow","avoid","avoid-column","avoid-page","avoid-region","axis-pan","background","backwards","baseline","below","bidi-override","binary","bengali","blink","block","block-axis","blur","bold","bolder","border","border-box","both","bottom","break","break-all","break-word","brightness","bullets","button","buttonface","buttonhighlight","buttonshadow","buttontext","calc","cambodian","capitalize","caps-lock-indicator","caption","captiontext","caret","cell","center","checkbox","circle","cjk-decimal","cjk-earthly-branch","cjk-heavenly-stem","cjk-ideographic","clear","clip","close-quote","col-resize","collapse","color","color-burn","color-dodge","column","column-reverse","compact","condensed","conic-gradient","contain","content","contents","content-box","context-menu","continuous","contrast","copy","counter","counters","cover","crop","cross","crosshair","cubic-bezier","currentcolor","cursive","cyclic","darken","dashed","decimal","decimal-leading-zero","default","default-button","dense","destination-atop","destination-in","destination-out","destination-over","devanagari","difference","disc","discard","disclosure-closed","disclosure-open","document","dot-dash","dot-dot-dash","dotted","double","down","drop-shadow","e-resize","ease","ease-in","ease-in-out","ease-out","element","ellipse","ellipsis","embed","end","ethiopic","ethiopic-abegede","ethiopic-abegede-am-et","ethiopic-abegede-gez","ethiopic-abegede-ti-er","ethiopic-abegede-ti-et","ethiopic-halehame-aa-er","ethiopic-halehame-aa-et","ethiopic-halehame-am-et","ethiopic-halehame-gez","ethiopic-halehame-om-et","ethiopic-halehame-sid-et","ethiopic-halehame-so-et","ethiopic-halehame-ti-er","ethiopic-halehame-ti-et","ethiopic-halehame-tig","ethiopic-numeric","ew-resize","exclusion","expanded","extends","extra-condensed","extra-expanded","fantasy","fast","fill","fill-box","fixed","flat","flex","flex-end","flex-start","footnotes","forwards","from","geometricPrecision","georgian","grayscale","graytext","grid","groove","gujarati","gurmukhi","hand","hangul","hangul-consonant","hard-light","hebrew","help","hidden","hide","higher","highlight","highlighttext","hiragana","hiragana-iroha","horizontal","hsl","hsla","hue","hue-rotate","icon","ignore","inactiveborder","inactivecaption","inactivecaptiontext","infinite","infobackground","infotext","inherit","initial","inline","inline-axis","inline-block","inline-flex","inline-grid","inline-table","inset","inside","intrinsic","invert","italic","japanese-formal","japanese-informal","justify","kannada","katakana","katakana-iroha","keep-all","khmer","korean-hangul-formal","korean-hanja-formal","korean-hanja-informal","landscape","lao","large","larger","left","level","lighter","lighten","line-through","linear","linear-gradient","lines","list-item","listbox","listitem","local","logical","loud","lower","lower-alpha","lower-armenian","lower-greek","lower-hexadecimal","lower-latin","lower-norwegian","lower-roman","lowercase","ltr","luminosity","malayalam","manipulation","match","matrix","matrix3d","media-play-button","media-slider","media-sliderthumb","media-volume-slider","media-volume-sliderthumb","medium","menu","menulist","menulist-button","menutext","message-box","middle","min-intrinsic","mix","mongolian","monospace","move","multiple","multiple_mask_images","multiply","myanmar","n-resize","narrower","ne-resize","nesw-resize","no-close-quote","no-drop","no-open-quote","no-repeat","none","normal","not-allowed","nowrap","ns-resize","numbers","numeric","nw-resize","nwse-resize","oblique","octal","opacity","open-quote","optimizeLegibility","optimizeSpeed","oriya","oromo","outset","outside","outside-shape","overlay","overline","padding","padding-box","painted","page","paused","persian","perspective","pinch-zoom","plus-darker","plus-lighter","pointer","polygon","portrait","pre","pre-line","pre-wrap","preserve-3d","progress","push-button","radial-gradient","radio","read-only","read-write","read-write-plaintext-only","rectangle","region","relative","repeat","repeating-linear-gradient","repeating-radial-gradient","repeating-conic-gradient","repeat-x","repeat-y","reset","reverse","rgb","rgba","ridge","right","rotate","rotate3d","rotateX","rotateY","rotateZ","round","row","row-resize","row-reverse","rtl","run-in","running","s-resize","sans-serif","saturate","saturation","scale","scale3d","scaleX","scaleY","scaleZ","screen","scroll","scrollbar","scroll-position","se-resize","searchfield","searchfield-cancel-button","searchfield-decoration","searchfield-results-button","searchfield-results-decoration","self-start","self-end","semi-condensed","semi-expanded","separate","sepia","serif","show","sidama","simp-chinese-formal","simp-chinese-informal","single","skew","skewX","skewY","skip-white-space","slide","slider-horizontal","slider-vertical","sliderthumb-horizontal","sliderthumb-vertical","slow","small","small-caps","small-caption","smaller","soft-light","solid","somali","source-atop","source-in","source-out","source-over","space","space-around","space-between","space-evenly","spell-out","square","square-button","start","static","status-bar","stretch","stroke","stroke-box","sub","subpixel-antialiased","svg_masks","super","sw-resize","symbolic","symbols","system-ui","table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row","table-row-group","tamil","telugu","text","text-bottom","text-top","textarea","textfield","thai","thick","thin","threeddarkshadow","threedface","threedhighlight","threedlightshadow","threedshadow","tibetan","tigre","tigrinya-er","tigrinya-er-abegede","tigrinya-et","tigrinya-et-abegede","to","top","trad-chinese-formal","trad-chinese-informal","transform","translate","translate3d","translateX","translateY","translateZ","transparent","ultra-condensed","ultra-expanded","underline","unidirectional-pan","unset","up","upper-alpha","upper-armenian","upper-greek","upper-hexadecimal","upper-latin","upper-norwegian","upper-roman","uppercase","urdu","url","var","vertical","vertical-text","view-box","visible","visibleFill","visiblePainted","visibleStroke","visual","w-resize","wait","wave","wider","window","windowframe","windowtext","words","wrap","wrap-reverse","x-large","x-small","xor","xx-large","xx-small"],b=t(y),w=n.concat(i).concat(a).concat(s).concat(u).concat(f).concat(g).concat(y);function x(e,t){for(var n,r=!1;null!=(n=e.next());){if(r&&"/"==n){t.tokenize=null;break}r="*"==n}return["comment","comment"]}e.registerHelper("hintWords","css",w),e.defineMIME("text/css",{documentTypes:r,mediaTypes:o,mediaFeatures:l,mediaValueKeywords:c,propertyKeywords:d,nonStandardPropertyKeywords:h,fontProperties:p,counterDescriptors:m,colorKeywords:v,valueKeywords:b,tokenHooks:{"/":function(e,t){return!!e.eat("*")&&(t.tokenize=x,x(e,t))}},name:"css"}),e.defineMIME("text/x-scss",{mediaTypes:o,mediaFeatures:l,mediaValueKeywords:c,propertyKeywords:d,nonStandardPropertyKeywords:h,colorKeywords:v,valueKeywords:b,fontProperties:p,allowNested:!0,lineComment:"//",tokenHooks:{"/":function(e,t){return e.eat("/")?(e.skipToEnd(),["comment","comment"]):e.eat("*")?(t.tokenize=x,x(e,t)):["operator","operator"]},":":function(e){return!!e.match(/^\s*\{/,!1)&&[null,null]},$:function(e){return e.match(/^[\w-]+/),e.match(/^\s*:/,!1)?["variable-2","variable-definition"]:["variable-2","variable"]},"#":function(e){return!!e.eat("{")&&[null,"interpolation"]}},name:"css",helperType:"scss"}),e.defineMIME("text/x-less",{mediaTypes:o,mediaFeatures:l,mediaValueKeywords:c,propertyKeywords:d,nonStandardPropertyKeywords:h,colorKeywords:v,valueKeywords:b,fontProperties:p,allowNested:!0,lineComment:"//",tokenHooks:{"/":function(e,t){return e.eat("/")?(e.skipToEnd(),["comment","comment"]):e.eat("*")?(t.tokenize=x,x(e,t)):["operator","operator"]},"@":function(e){return e.eat("{")?[null,"interpolation"]:!e.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/i,!1)&&(e.eatWhile(/[\w\\\-]/),e.match(/^\s*:/,!1)?["variable-2","variable-definition"]:["variable-2","variable"])},"&":function(){return["atom","atom"]}},name:"css",helperType:"less"}),e.defineMIME("text/x-gss",{documentTypes:r,mediaTypes:o,mediaFeatures:l,propertyKeywords:d,nonStandardPropertyKeywords:h,fontProperties:p,counterDescriptors:m,colorKeywords:v,valueKeywords:b,supportsAtComponent:!0,tokenHooks:{"/":function(e,t){return!!e.eat("*")&&(t.tokenize=x,x(e,t))}},name:"css",helperType:"gss"})}(n(237))},520(e,t,n){!function(e){"use strict";var t={script:[["lang",/(javascript|babel)/i,"javascript"],["type",/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i,"javascript"],["type",/./,"text/plain"],[null,null,"javascript"]],style:[["lang",/^css$/i,"css"],["type",/^(text\/)?(x-)?(stylesheet|css)$/i,"css"],["type",/./,"text/plain"],[null,null,"css"]]};var n={};function r(e,t){var r=e.match(function(e){return n[e]||(n[e]=new RegExp("\\s+"+e+"\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*"))}(t));return r?/^\s*(.*?)\s*$/.exec(r[2])[1]:""}function i(e,t){return new RegExp((t?"^":"")+"</\\s*"+e+"\\s*>","i")}function o(e,t){for(var n in e)for(var r=t[n]||(t[n]=[]),i=e[n],o=i.length-1;o>=0;o--)r.unshift(i[o])}e.defineMode("htmlmixed",function(n,a){var l=e.getMode(n,{name:"xml",htmlMode:!0,multilineTagIndentFactor:a.multilineTagIndentFactor,multilineTagIndentPastTag:a.multilineTagIndentPastTag,allowMissingTagName:a.allowMissingTagName}),s={},c=a&&a.tags,u=a&&a.scriptTypes;if(o(t,s),c&&o(c,s),u)for(var d=u.length-1;d>=0;d--)s.script.unshift(["type",u[d].matches,u[d].mode]);function f(t,o){var a,c=l.token(t,o.htmlState),u=/\btag\b/.test(c);if(u&&!/[<>\s\/]/.test(t.current())&&(a=o.htmlState.tagName&&o.htmlState.tagName.toLowerCase())&&s.hasOwnProperty(a))o.inTag=a+" ";else if(o.inTag&&u&&/>$/.test(t.current())){var d=/^([\S]+) (.*)/.exec(o.inTag);o.inTag=null;var h=">"==t.current()&&function(e,t){for(var n=0;n<e.length;n++){var i=e[n];if(!i[0]||i[1].test(r(t,i[0])))return i[2]}}(s[d[1]],d[2]),p=e.getMode(n,h),m=i(d[1],!0),g=i(d[1],!1);o.token=function(e,t){return e.match(m,!1)?(t.token=f,t.localState=t.localMode=null,null):function(e,t,n){var r=e.current(),i=r.search(t);return i>-1?e.backUp(r.length-i):r.match(/<\/?$/)&&(e.backUp(r.length),e.match(t,!1)||e.match(r)),n}(e,g,t.localMode.token(e,t.localState))},o.localMode=p,o.localState=e.startState(p,l.indent(o.htmlState,"",""))}else o.inTag&&(o.inTag+=t.current(),t.eol()&&(o.inTag+=" "));return c}return{startState:function(){return{token:f,inTag:null,localMode:null,localState:null,htmlState:e.startState(l)}},copyState:function(t){var n;return t.localState&&(n=e.copyState(t.localMode,t.localState)),{token:t.token,inTag:t.inTag,localMode:t.localMode,localState:n,htmlState:e.copyState(l,t.htmlState)}},token:function(e,t){return t.token(e,t)},indent:function(t,n,r){return!t.localMode||/^\s*<\//.test(n)?l.indent(t.htmlState,n,r):t.localMode.indent?t.localMode.indent(t.localState,n,r):e.Pass},innerMode:function(e){return{state:e.localState||e.htmlState,mode:e.localMode||l}}}},"xml","javascript","css"),e.defineMIME("text/html","htmlmixed")}(n(237),n(576),n(792),n(656))},792(e,t,n){!function(e){"use strict";e.defineMode("javascript",function(t,n){var r,i,o=t.indentUnit,a=n.statementIndent,l=n.jsonld,s=n.json||l,c=!1!==n.trackScope,u=n.typescript,d=n.wordCharacters||/[\w$\xa1-\uffff]/,f=function(){function e(e){return{type:e,style:"keyword"}}var t=e("keyword a"),n=e("keyword b"),r=e("keyword c"),i=e("keyword d"),o=e("operator"),a={type:"atom",style:"atom"};return{if:e("if"),while:t,with:t,else:n,do:n,try:n,finally:n,return:i,break:i,continue:i,new:e("new"),delete:r,void:r,throw:r,debugger:e("debugger"),var:e("var"),const:e("var"),let:e("var"),function:e("function"),catch:e("catch"),for:e("for"),switch:e("switch"),case:e("case"),default:e("default"),in:o,typeof:o,instanceof:o,true:a,false:a,null:a,undefined:a,NaN:a,Infinity:a,this:e("this"),class:e("class"),super:e("atom"),yield:r,export:e("export"),import:e("import"),extends:r,await:r}}(),h=/[+\-*&%=<>!?|~^@]/,p=/^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;function m(e,t,n){return r=e,i=n,t}function g(e,t){var n,r=e.next();if('"'==r||"'"==r)return t.tokenize=(n=r,function(e,t){var r,i=!1;if(l&&"@"==e.peek()&&e.match(p))return t.tokenize=g,m("jsonld-keyword","meta");for(;null!=(r=e.next())&&(r!=n||i);)i=!i&&"\\"==r;return i||(t.tokenize=g),m("string","string")}),t.tokenize(e,t);if("."==r&&e.match(/^\d[\d_]*(?:[eE][+\-]?[\d_]+)?/))return m("number","number");if("."==r&&e.match(".."))return m("spread","meta");if(/[\[\]{}\(\),;\:\.]/.test(r))return m(r);if("="==r&&e.eat(">"))return m("=>","operator");if("0"==r&&e.match(/^(?:x[\dA-Fa-f_]+|o[0-7_]+|b[01_]+)n?/))return m("number","number");if(/\d/.test(r))return e.match(/^[\d_]*(?:n|(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)?/),m("number","number");if("/"==r)return e.eat("*")?(t.tokenize=v,v(e,t)):e.eat("/")?(e.skipToEnd(),m("comment","comment")):Je(e,t,1)?(function(e){for(var t,n=!1,r=!1;null!=(t=e.next());){if(!n){if("/"==t&&!r)return;"["==t?r=!0:r&&"]"==t&&(r=!1)}n=!n&&"\\"==t}}(e),e.match(/^\b(([gimyus])(?![gimyus]*\2))+\b/),m("regexp","string-2")):(e.eat("="),m("operator","operator",e.current()));if("`"==r)return t.tokenize=y,y(e,t);if("#"==r&&"!"==e.peek())return e.skipToEnd(),m("meta","meta");if("#"==r&&e.eatWhile(d))return m("variable","property");if("<"==r&&e.match("!--")||"-"==r&&e.match("->")&&!/\S/.test(e.string.slice(0,e.start)))return e.skipToEnd(),m("comment","comment");if(h.test(r))return">"==r&&t.lexical&&">"==t.lexical.type||(e.eat("=")?"!"!=r&&"="!=r||e.eat("="):/[<>*+\-|&?]/.test(r)&&(e.eat(r),">"==r&&e.eat(r))),"?"==r&&e.eat(".")?m("."):m("operator","operator",e.current());if(d.test(r)){e.eatWhile(d);var i=e.current();if("."!=t.lastType){if(f.propertyIsEnumerable(i)){var o=f[i];return m(o.type,o.style,i)}if("async"==i&&e.match(/^(\s|\/\*([^*]|\*(?!\/))*?\*\/)*[\[\(\w]/,!1))return m("async","keyword",i)}return m("variable","variable",i)}}function v(e,t){for(var n,r=!1;n=e.next();){if("/"==n&&r){t.tokenize=g;break}r="*"==n}return m("comment","comment")}function y(e,t){for(var n,r=!1;null!=(n=e.next());){if(!r&&("`"==n||"$"==n&&e.eat("{"))){t.tokenize=g;break}r=!r&&"\\"==n}return m("quasi","string-2",e.current())}function b(e,t){t.fatArrowAt&&(t.fatArrowAt=null);var n=e.string.indexOf("=>",e.start);if(!(n<0)){if(u){var r=/:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(e.string.slice(e.start,n));r&&(n=r.index)}for(var i=0,o=!1,a=n-1;a>=0;--a){var l=e.string.charAt(a),s="([{}])".indexOf(l);if(s>=0&&s<3){if(!i){++a;break}if(0==--i){"("==l&&(o=!0);break}}else if(s>=3&&s<6)++i;else if(d.test(l))o=!0;else if(/["'\/`]/.test(l))for(;;--a){if(0==a)return;if(e.string.charAt(a-1)==l&&"\\"!=e.string.charAt(a-2)){a--;break}}else if(o&&!i){++a;break}}o&&!i&&(t.fatArrowAt=a)}}var w={atom:!0,number:!0,variable:!0,string:!0,regexp:!0,this:!0,import:!0,"jsonld-keyword":!0};function x(e,t,n,r,i,o){this.indented=e,this.column=t,this.type=n,this.prev=i,this.info=o,null!=r&&(this.align=r)}function k(e,t){if(!c)return!1;for(var n=e.localVars;n;n=n.next)if(n.name==t)return!0;for(var r=e.context;r;r=r.prev)for(n=r.vars;n;n=n.next)if(n.name==t)return!0}function C(e,t,n,r,i){var o=e.cc;for(_.state=e,_.stream=i,_.marked=null,_.cc=o,_.style=t,e.lexical.hasOwnProperty("align")||(e.lexical.align=!0);;)if((o.length?o.pop():s?j:R)(n,r)){for(;o.length&&o[o.length-1].lex;)o.pop()();return _.marked?_.marked:"variable"==n&&k(e,r)?"variable-2":t}}var _={state:null,column:null,marked:null,cc:null};function S(){for(var e=arguments.length-1;e>=0;e--)_.cc.push(arguments[e])}function T(){return S.apply(null,arguments),!0}function L(e,t){for(var n=t;n;n=n.next)if(n.name==e)return!0;return!1}function M(e){var t=_.state;if(_.marked="def",c){if(t.context)if("var"==t.lexical.info&&t.context&&t.context.block){var r=N(e,t.context);if(null!=r)return void(t.context=r)}else if(!L(e,t.localVars))return void(t.localVars=new D(e,t.localVars));n.globalVars&&!L(e,t.globalVars)&&(t.globalVars=new D(e,t.globalVars))}}function N(e,t){if(t){if(t.block){var n=N(e,t.prev);return n?n==t.prev?t:new O(n,t.vars,!0):null}return L(e,t.vars)?t:new O(t.prev,new D(e,t.vars),!1)}return null}function A(e){return"public"==e||"private"==e||"protected"==e||"abstract"==e||"readonly"==e}function O(e,t,n){this.prev=e,this.vars=t,this.block=n}function D(e,t){this.name=e,this.next=t}var F=new D("this",new D("arguments",null));function E(){_.state.context=new O(_.state.context,_.state.localVars,!1),_.state.localVars=F}function P(){_.state.context=new O(_.state.context,_.state.localVars,!0),_.state.localVars=null}function W(){_.state.localVars=_.state.context.vars,_.state.context=_.state.context.prev}function z(e,t){var n=function(){var n=_.state,r=n.indented;if("stat"==n.lexical.type)r=n.lexical.indented;else for(var i=n.lexical;i&&")"==i.type&&i.align;i=i.prev)r=i.indented;n.lexical=new x(r,_.stream.column(),e,null,n.lexical,t)};return n.lex=!0,n}function H(){var e=_.state;e.lexical.prev&&(")"==e.lexical.type&&(e.indented=e.lexical.indented),e.lexical=e.lexical.prev)}function I(e){return function t(n){return n==e?T():";"==e||"}"==n||")"==n||"]"==n?S():T(t)}}function R(e,t){return"var"==e?T(z("vardef",t),_e,I(";"),H):"keyword a"==e?T(z("form"),U,R,H):"keyword b"==e?T(z("form"),R,H):"keyword d"==e?_.stream.match(/^\s*$/,!1)?T():T(z("stat"),K,I(";"),H):"debugger"==e?T(I(";")):"{"==e?T(z("}"),P,se,H,W):";"==e?T():"if"==e?("else"==_.state.lexical.info&&_.state.cc[_.state.cc.length-1]==H&&_.state.cc.pop()(),T(z("form"),U,R,H,Ae)):"function"==e?T(Ee):"for"==e?T(z("form"),P,Oe,R,W,H):"class"==e||u&&"interface"==t?(_.marked="keyword",T(z("form","class"==e?e:t),Ie,H)):"variable"==e?u&&"declare"==t?(_.marked="keyword",T(R)):u&&("module"==t||"enum"==t||"type"==t)&&_.stream.match(/^\s*\w/,!1)?(_.marked="keyword","enum"==t?T(Ze):"type"==t?T(We,I("operator"),he,I(";")):T(z("form"),Se,I("{"),z("}"),se,H,H)):u&&"namespace"==t?(_.marked="keyword",T(z("form"),j,R,H)):u&&"abstract"==t?(_.marked="keyword",T(R)):T(z("stat"),te):"switch"==e?T(z("form"),U,I("{"),z("}","switch"),P,se,H,H,W):"case"==e?T(j,I(":")):"default"==e?T(I(":")):"catch"==e?T(z("form"),E,B,R,H,W):"export"==e?T(z("stat"),qe,H):"import"==e?T(z("stat"),Ve,H):"async"==e?T(R):"@"==t?T(j,R):S(z("stat"),j,I(";"),H)}function B(e){if("("==e)return T(ze,I(")"))}function j(e,t){return V(e,t,!1)}function q(e,t){return V(e,t,!0)}function U(e){return"("!=e?S():T(z(")"),K,I(")"),H)}function V(e,t,n){if(_.state.fatArrowAt==_.stream.start){var r=n?Q:Z;if("("==e)return T(E,z(")"),ae(ze,")"),H,I("=>"),r,W);if("variable"==e)return S(E,Se,I("=>"),r,W)}var i=n?G:$;return w.hasOwnProperty(e)?T(i):"function"==e?T(Ee,i):"class"==e||u&&"interface"==t?(_.marked="keyword",T(z("form"),He,H)):"keyword c"==e||"async"==e?T(n?q:j):"("==e?T(z(")"),K,I(")"),H,i):"operator"==e||"spread"==e?T(n?q:j):"["==e?T(z("]"),Ye,H,i):"{"==e?le(re,"}",null,i):"quasi"==e?S(X,i):"new"==e?T(function(e){return function(t){return"."==t?T(e?ee:J):"variable"==t&&u?T(xe,e?G:$):S(e?q:j)}}(n)):T()}function K(e){return e.match(/[;\}\)\],]/)?S():S(j)}function $(e,t){return","==e?T(K):G(e,t,!1)}function G(e,t,n){var r=0==n?$:G,i=0==n?j:q;return"=>"==e?T(E,n?Q:Z,W):"operator"==e?/\+\+|--/.test(t)||u&&"!"==t?T(r):u&&"<"==t&&_.stream.match(/^([^<>]|<[^<>]*>)*>\s*\(/,!1)?T(z(">"),ae(he,">"),H,r):"?"==t?T(j,I(":"),i):T(i):"quasi"==e?S(X,r):";"!=e?"("==e?le(q,")","call",r):"."==e?T(ne,r):"["==e?T(z("]"),K,I("]"),H,r):u&&"as"==t?(_.marked="keyword",T(he,r)):"regexp"==e?(_.state.lastType=_.marked="operator",_.stream.backUp(_.stream.pos-_.stream.start-1),T(i)):void 0:void 0}function X(e,t){return"quasi"!=e?S():"${"!=t.slice(t.length-2)?T(X):T(K,Y)}function Y(e){if("}"==e)return _.marked="string-2",_.state.tokenize=y,T(X)}function Z(e){return b(_.stream,_.state),S("{"==e?R:j)}function Q(e){return b(_.stream,_.state),S("{"==e?R:q)}function J(e,t){if("target"==t)return _.marked="keyword",T($)}function ee(e,t){if("target"==t)return _.marked="keyword",T(G)}function te(e){return":"==e?T(H,R):S($,I(";"),H)}function ne(e){if("variable"==e)return _.marked="property",T()}function re(e,t){return"async"==e?(_.marked="property",T(re)):"variable"==e||"keyword"==_.style?(_.marked="property","get"==t||"set"==t?T(ie):(u&&_.state.fatArrowAt==_.stream.start&&(n=_.stream.match(/^\s*:\s*/,!1))&&(_.state.fatArrowAt=_.stream.pos+n[0].length),T(oe))):"number"==e||"string"==e?(_.marked=l?"property":_.style+" property",T(oe)):"jsonld-keyword"==e?T(oe):u&&A(t)?(_.marked="keyword",T(re)):"["==e?T(j,ce,I("]"),oe):"spread"==e?T(q,oe):"*"==t?(_.marked="keyword",T(re)):":"==e?S(oe):void 0;var n}function ie(e){return"variable"!=e?S(oe):(_.marked="property",T(Ee))}function oe(e){return":"==e?T(q):"("==e?S(Ee):void 0}function ae(e,t,n){function r(i,o){if(n?n.indexOf(i)>-1:","==i){var a=_.state.lexical;return"call"==a.info&&(a.pos=(a.pos||0)+1),T(function(n,r){return n==t||r==t?S():S(e)},r)}return i==t||o==t?T():n&&n.indexOf(";")>-1?S(e):T(I(t))}return function(n,i){return n==t||i==t?T():S(e,r)}}function le(e,t,n){for(var r=3;r<arguments.length;r++)_.cc.push(arguments[r]);return T(z(t,n),ae(e,t),H)}function se(e){return"}"==e?T():S(R,se)}function ce(e,t){if(u){if(":"==e)return T(he);if("?"==t)return T(ce)}}function ue(e,t){if(u&&(":"==e||"in"==t))return T(he)}function de(e){if(u&&":"==e)return _.stream.match(/^\s*\w+\s+is\b/,!1)?T(j,fe,he):T(he)}function fe(e,t){if("is"==t)return _.marked="keyword",T()}function he(e,t){return"keyof"==t||"typeof"==t||"infer"==t||"readonly"==t?(_.marked="keyword",T("typeof"==t?q:he)):"variable"==e||"void"==t?(_.marked="type",T(we)):"|"==t||"&"==t?T(he):"string"==e||"number"==e||"atom"==e?T(we):"["==e?T(z("]"),ae(he,"]",","),H,we):"{"==e?T(z("}"),me,H,we):"("==e?T(ae(be,")"),pe,we):"<"==e?T(ae(he,">"),he):"quasi"==e?S(ve,we):void 0}function pe(e){if("=>"==e)return T(he)}function me(e){return e.match(/[\}\)\]]/)?T():","==e||";"==e?T(me):S(ge,me)}function ge(e,t){return"variable"==e||"keyword"==_.style?(_.marked="property",T(ge)):"?"==t||"number"==e||"string"==e?T(ge):":"==e?T(he):"["==e?T(I("variable"),ue,I("]"),ge):"("==e?S(Pe,ge):e.match(/[;\}\)\],]/)?void 0:T()}function ve(e,t){return"quasi"!=e?S():"${"!=t.slice(t.length-2)?T(ve):T(he,ye)}function ye(e){if("}"==e)return _.marked="string-2",_.state.tokenize=y,T(ve)}function be(e,t){return"variable"==e&&_.stream.match(/^\s*[?:]/,!1)||"?"==t?T(be):":"==e?T(he):"spread"==e?T(be):S(he)}function we(e,t){return"<"==t?T(z(">"),ae(he,">"),H,we):"|"==t||"."==e||"&"==t?T(he):"["==e?T(he,I("]"),we):"extends"==t||"implements"==t?(_.marked="keyword",T(he)):"?"==t?T(he,I(":"),he):void 0}function xe(e,t){if("<"==t)return T(z(">"),ae(he,">"),H,we)}function ke(){return S(he,Ce)}function Ce(e,t){if("="==t)return T(he)}function _e(e,t){return"enum"==t?(_.marked="keyword",T(Ze)):S(Se,ce,Me,Ne)}function Se(e,t){return u&&A(t)?(_.marked="keyword",T(Se)):"variable"==e?(M(t),T()):"spread"==e?T(Se):"["==e?le(Le,"]"):"{"==e?le(Te,"}"):void 0}function Te(e,t){return"variable"!=e||_.stream.match(/^\s*:/,!1)?("variable"==e&&(_.marked="property"),"spread"==e?T(Se):"}"==e?S():"["==e?T(j,I("]"),I(":"),Te):T(I(":"),Se,Me)):(M(t),T(Me))}function Le(){return S(Se,Me)}function Me(e,t){if("="==t)return T(q)}function Ne(e){if(","==e)return T(_e)}function Ae(e,t){if("keyword b"==e&&"else"==t)return T(z("form","else"),R,H)}function Oe(e,t){return"await"==t?T(Oe):"("==e?T(z(")"),De,H):void 0}function De(e){return"var"==e?T(_e,Fe):"variable"==e?T(Fe):S(Fe)}function Fe(e,t){return")"==e?T():";"==e?T(Fe):"in"==t||"of"==t?(_.marked="keyword",T(j,Fe)):S(j,Fe)}function Ee(e,t){return"*"==t?(_.marked="keyword",T(Ee)):"variable"==e?(M(t),T(Ee)):"("==e?T(E,z(")"),ae(ze,")"),H,de,R,W):u&&"<"==t?T(z(">"),ae(ke,">"),H,Ee):void 0}function Pe(e,t){return"*"==t?(_.marked="keyword",T(Pe)):"variable"==e?(M(t),T(Pe)):"("==e?T(E,z(")"),ae(ze,")"),H,de,W):u&&"<"==t?T(z(">"),ae(ke,">"),H,Pe):void 0}function We(e,t){return"keyword"==e||"variable"==e?(_.marked="type",T(We)):"<"==t?T(z(">"),ae(ke,">"),H):void 0}function ze(e,t){return"@"==t&&T(j,ze),"spread"==e?T(ze):u&&A(t)?(_.marked="keyword",T(ze)):u&&"this"==e?T(ce,Me):S(Se,ce,Me)}function He(e,t){return"variable"==e?Ie(e,t):Re(e,t)}function Ie(e,t){if("variable"==e)return M(t),T(Re)}function Re(e,t){return"<"==t?T(z(">"),ae(ke,">"),H,Re):"extends"==t||"implements"==t||u&&","==e?("implements"==t&&(_.marked="keyword"),T(u?he:j,Re)):"{"==e?T(z("}"),Be,H):void 0}function Be(e,t){return"async"==e||"variable"==e&&("static"==t||"get"==t||"set"==t||u&&A(t))&&_.stream.match(/^\s+#?[\w$\xa1-\uffff]/,!1)?(_.marked="keyword",T(Be)):"variable"==e||"keyword"==_.style?(_.marked="property",T(je,Be)):"number"==e||"string"==e?T(je,Be):"["==e?T(j,ce,I("]"),je,Be):"*"==t?(_.marked="keyword",T(Be)):u&&"("==e?S(Pe,Be):";"==e||","==e?T(Be):"}"==e?T():"@"==t?T(j,Be):void 0}function je(e,t){if("!"==t)return T(je);if("?"==t)return T(je);if(":"==e)return T(he,Me);if("="==t)return T(q);var n=_.state.lexical.prev;return S(n&&"interface"==n.info?Pe:Ee)}function qe(e,t){return"*"==t?(_.marked="keyword",T(Xe,I(";"))):"default"==t?(_.marked="keyword",T(j,I(";"))):"{"==e?T(ae(Ue,"}"),Xe,I(";")):S(R)}function Ue(e,t){return"as"==t?(_.marked="keyword",T(I("variable"))):"variable"==e?S(q,Ue):void 0}function Ve(e){return"string"==e?T():"("==e?S(j):"."==e?S($):S(Ke,$e,Xe)}function Ke(e,t){return"{"==e?le(Ke,"}"):("variable"==e&&M(t),"*"==t&&(_.marked="keyword"),T(Ge))}function $e(e){if(","==e)return T(Ke,$e)}function Ge(e,t){if("as"==t)return _.marked="keyword",T(Ke)}function Xe(e,t){if("from"==t)return _.marked="keyword",T(j)}function Ye(e){return"]"==e?T():S(ae(q,"]"))}function Ze(){return S(z("form"),Se,I("{"),z("}"),ae(Qe,"}"),H,H)}function Qe(){return S(Se,Me)}function Je(e,t,n){return t.tokenize==g&&/^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(t.lastType)||"quasi"==t.lastType&&/\{\s*$/.test(e.string.slice(0,e.pos-(n||0)))}return E.lex=P.lex=!0,W.lex=!0,H.lex=!0,{startState:function(e){var t={tokenize:g,lastType:"sof",cc:[],lexical:new x((e||0)-o,0,"block",!1),localVars:n.localVars,context:n.localVars&&new O(null,null,!1),indented:e||0};return n.globalVars&&"object"==typeof n.globalVars&&(t.globalVars=n.globalVars),t},token:function(e,t){if(e.sol()&&(t.lexical.hasOwnProperty("align")||(t.lexical.align=!1),t.indented=e.indentation(),b(e,t)),t.tokenize!=v&&e.eatSpace())return null;var n=t.tokenize(e,t);return"comment"==r?n:(t.lastType="operator"!=r||"++"!=i&&"--"!=i?r:"incdec",C(t,n,r,i,e))},indent:function(t,r){if(t.tokenize==v||t.tokenize==y)return e.Pass;if(t.tokenize!=g)return 0;var i,l=r&&r.charAt(0),s=t.lexical;if(!/^\s*else\b/.test(r))for(var c=t.cc.length-1;c>=0;--c){var u=t.cc[c];if(u==H)s=s.prev;else if(u!=Ae&&u!=W)break}for(;("stat"==s.type||"form"==s.type)&&("}"==l||(i=t.cc[t.cc.length-1])&&(i==$||i==G)&&!/^[,\.=+\-*:?[\(]/.test(r));)s=s.prev;a&&")"==s.type&&"stat"==s.prev.type&&(s=s.prev);var d=s.type,f=l==d;return"vardef"==d?s.indented+("operator"==t.lastType||","==t.lastType?s.info.length+1:0):"form"==d&&"{"==l?s.indented:"form"==d?s.indented+o:"stat"==d?s.indented+(function(e,t){return"operator"==e.lastType||","==e.lastType||h.test(t.charAt(0))||/[,.]/.test(t.charAt(0))}(t,r)?a||o:0):"switch"!=s.info||f||0==n.doubleIndentSwitch?s.align?s.column+(f?0:1):s.indented+(f?0:o):s.indented+(/^(?:case|default)\b/.test(r)?o:2*o)},electricInput:/^\s*(?:case .*?:|default:|\{|\})$/,blockCommentStart:s?null:"/*",blockCommentEnd:s?null:"*/",blockCommentContinue:s?null:" * ",lineComment:s?null:"//",fold:"brace",closeBrackets:"()[]{}''\"\"``",helperType:s?"json":"javascript",jsonldMode:l,jsonMode:s,expressionAllowed:Je,skipExpression:function(t){C(t,"atom","atom","true",new e.StringStream("",2,null))}}}),e.registerHelper("wordChars","javascript",/[\w$]/),e.defineMIME("text/javascript","javascript"),e.defineMIME("text/ecmascript","javascript"),e.defineMIME("application/javascript","javascript"),e.defineMIME("application/x-javascript","javascript"),e.defineMIME("application/ecmascript","javascript"),e.defineMIME("application/json",{name:"javascript",json:!0}),e.defineMIME("application/x-json",{name:"javascript",json:!0}),e.defineMIME("application/manifest+json",{name:"javascript",json:!0}),e.defineMIME("application/ld+json",{name:"javascript",jsonld:!0}),e.defineMIME("text/typescript",{name:"javascript",typescript:!0}),e.defineMIME("application/typescript",{name:"javascript",typescript:!0})}(n(237))},576(e,t,n){!function(e){"use strict";var t={autoSelfClosers:{area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,frame:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,menuitem:!0},implicitlyClosed:{dd:!0,li:!0,optgroup:!0,option:!0,p:!0,rp:!0,rt:!0,tbody:!0,td:!0,tfoot:!0,th:!0,tr:!0},contextGrabbers:{dd:{dd:!0,dt:!0},dt:{dd:!0,dt:!0},li:{li:!0},option:{option:!0,optgroup:!0},optgroup:{optgroup:!0},p:{address:!0,article:!0,aside:!0,blockquote:!0,dir:!0,div:!0,dl:!0,fieldset:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,menu:!0,nav:!0,ol:!0,p:!0,pre:!0,section:!0,table:!0,ul:!0},rp:{rp:!0,rt:!0},rt:{rp:!0,rt:!0},tbody:{tbody:!0,tfoot:!0},td:{td:!0,th:!0},tfoot:{tbody:!0},th:{td:!0,th:!0},thead:{tbody:!0,tfoot:!0},tr:{tr:!0}},doNotIndent:{pre:!0},allowUnquoted:!0,allowMissing:!0,caseFold:!0},n={autoSelfClosers:{},implicitlyClosed:{},contextGrabbers:{},doNotIndent:{},allowUnquoted:!1,allowMissing:!1,allowMissingTagName:!1,caseFold:!1};e.defineMode("xml",function(r,i){var o,a,l=r.indentUnit,s={},c=i.htmlMode?t:n;for(var u in c)s[u]=c[u];for(var u in i)s[u]=i[u];function d(e,t){function n(n){return t.tokenize=n,n(e,t)}var r=e.next();return"<"==r?e.eat("!")?e.eat("[")?e.match("CDATA[")?n(h("atom","]]>")):null:e.match("--")?n(h("comment","--\x3e")):e.match("DOCTYPE",!0,!0)?(e.eatWhile(/[\w\._\-]/),n(p(1))):null:e.eat("?")?(e.eatWhile(/[\w\._\-]/),t.tokenize=h("meta","?>"),"meta"):(o=e.eat("/")?"closeTag":"openTag",t.tokenize=f,"tag bracket"):"&"==r?(e.eat("#")?e.eat("x")?e.eatWhile(/[a-fA-F\d]/)&&e.eat(";"):e.eatWhile(/[\d]/)&&e.eat(";"):e.eatWhile(/[\w\.\-:]/)&&e.eat(";"))?"atom":"error":(e.eatWhile(/[^&<]/),null)}function f(e,t){var n,r,i=e.next();if(">"==i||"/"==i&&e.eat(">"))return t.tokenize=d,o=">"==i?"endTag":"selfcloseTag","tag bracket";if("="==i)return o="equals",null;if("<"==i){t.tokenize=d,t.state=b,t.tagName=t.tagStart=null;var a=t.tokenize(e,t);return a?a+" tag error":"tag error"}return/[\'\"]/.test(i)?(t.tokenize=(n=i,r=function(e,t){for(;!e.eol();)if(e.next()==n){t.tokenize=f;break}return"string"},r.isInAttribute=!0,r),t.stringStartCol=e.column(),t.tokenize(e,t)):(e.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/),"word")}function h(e,t){return function(n,r){for(;!n.eol();){if(n.match(t)){r.tokenize=d;break}n.next()}return e}}function p(e){return function(t,n){for(var r;null!=(r=t.next());){if("<"==r)return n.tokenize=p(e+1),n.tokenize(t,n);if(">"==r){if(1==e){n.tokenize=d;break}return n.tokenize=p(e-1),n.tokenize(t,n)}}return"meta"}}function m(e){return e&&e.toLowerCase()}function g(e,t,n){this.prev=e.context,this.tagName=t||"",this.indent=e.indented,this.startOfLine=n,(s.doNotIndent.hasOwnProperty(t)||e.context&&e.context.noIndent)&&(this.noIndent=!0)}function v(e){e.context&&(e.context=e.context.prev)}function y(e,t){for(var n;;){if(!e.context)return;if(n=e.context.tagName,!s.contextGrabbers.hasOwnProperty(m(n))||!s.contextGrabbers[m(n)].hasOwnProperty(m(t)))return;v(e)}}function b(e,t,n){return"openTag"==e?(n.tagStart=t.column(),w):"closeTag"==e?x:b}function w(e,t,n){return"word"==e?(n.tagName=t.current(),a="tag",_):s.allowMissingTagName&&"endTag"==e?(a="tag bracket",_(e,0,n)):(a="error",w)}function x(e,t,n){if("word"==e){var r=t.current();return n.context&&n.context.tagName!=r&&s.implicitlyClosed.hasOwnProperty(m(n.context.tagName))&&v(n),n.context&&n.context.tagName==r||!1===s.matchClosing?(a="tag",k):(a="tag error",C)}return s.allowMissingTagName&&"endTag"==e?(a="tag bracket",k(e,0,n)):(a="error",C)}function k(e,t,n){return"endTag"!=e?(a="error",k):(v(n),b)}function C(e,t,n){return a="error",k(e,0,n)}function _(e,t,n){if("word"==e)return a="attribute",S;if("endTag"==e||"selfcloseTag"==e){var r=n.tagName,i=n.tagStart;return n.tagName=n.tagStart=null,"selfcloseTag"==e||s.autoSelfClosers.hasOwnProperty(m(r))?y(n,r):(y(n,r),n.context=new g(n,r,i==n.indented)),b}return a="error",_}function S(e,t,n){return"equals"==e?T:(s.allowMissing||(a="error"),_(e,0,n))}function T(e,t,n){return"string"==e?L:"word"==e&&s.allowUnquoted?(a="string",_):(a="error",_(e,0,n))}function L(e,t,n){return"string"==e?L:_(e,0,n)}return d.isInText=!0,{startState:function(e){var t={tokenize:d,state:b,indented:e||0,tagName:null,tagStart:null,context:null};return null!=e&&(t.baseIndent=e),t},token:function(e,t){if(!t.tagName&&e.sol()&&(t.indented=e.indentation()),e.eatSpace())return null;o=null;var n=t.tokenize(e,t);return(n||o)&&"comment"!=n&&(a=null,t.state=t.state(o||n,e,t),a&&(n="error"==a?n+" error":a)),n},indent:function(t,n,r){var i=t.context;if(t.tokenize.isInAttribute)return t.tagStart==t.indented?t.stringStartCol+1:t.indented+l;if(i&&i.noIndent)return e.Pass;if(t.tokenize!=f&&t.tokenize!=d)return r?r.match(/^(\s*)/)[0].length:0;if(t.tagName)return!1!==s.multilineTagIndentPastTag?t.tagStart+t.tagName.length+2:t.tagStart+l*(s.multilineTagIndentFactor||1);if(s.alignCDATA&&/<!\[CDATA\[/.test(n))return 0;var o=n&&/^<(\/)?([\w_:\.-]*)/.exec(n);if(o&&o[1])for(;i;){if(i.tagName==o[2]){i=i.prev;break}if(!s.implicitlyClosed.hasOwnProperty(m(i.tagName)))break;i=i.prev}else if(o)for(;i;){var a=s.contextGrabbers[m(i.tagName)];if(!a||!a.hasOwnProperty(m(o[2])))break;i=i.prev}for(;i&&i.prev&&!i.startOfLine;)i=i.prev;return i?i.indent+l:t.baseIndent||0},electricInput:/<\/[\s\w:]+>$/,blockCommentStart:"\x3c!--",blockCommentEnd:"--\x3e",configuration:s.htmlMode?"html":"xml",helperType:s.htmlMode?"html":"xml",skipAttribute:function(e){e.state==T&&(e.state=_)},xmlCurrentTag:function(e){return e.tagName?{name:e.tagName,close:"closeTag"==e.type}:null},xmlCurrentContext:function(e){for(var t=[],n=e.context;n;n=n.prev)t.push(n.tagName);return t.reverse()}}}),e.defineMIME("text/xml","xml"),e.defineMIME("application/xml","xml"),e.mimeModes.hasOwnProperty("text/html")||e.defineMIME("text/html",{name:"xml",htmlMode:!0})}(n(237))}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}(()=>{"use strict";n(688),n(665);const e=n(237);let t,r,i,o,a,l,s;n(576),n(792),n(656),n(520),n(753),n(115),n(819);const c=/\{\{ *(\w+)(?:\.([\w.]+))? *(?:\|\| *(\w+))? *\}\}/g;function u(){const e=l.contentDocument||l.contentWindow.document;s=e.querySelector(".hf-fields-wrap"),s&&h()}function d(e){return e.name.replace("[]","").replace(/\[(\w+)\]/g,".$1")}function f(){const e=i.querySelectorAll("input[name], select[name], textarea[name], button[name]"),t=function(e){const t={};return e.filter(e=>Object.hasOwn(t,e)?null:(t[e]=!0,e))}([].map.call(e,e=>`[${d(e)}]`)),n=t.concat(["[HF_TIMESTAMP]","[HF_USER_AGENT]","[HF_IP_ADDRESS]","[HF_REFERRER_URL]"]),r=document.getElementById("wpbody-content"),o=["[hcaptcha-widget-id]","[html_forms_form_nonce]","[_wp_http_referer]"],a=n.filter(e=>!o.includes(e));[].forEach.call(document.querySelectorAll(".hf-field-names"),e=>{for(;e.firstChild;)e.removeChild(e.firstChild);const t=a.map(e=>{const t=document.createElement("span");t.style.visibility="hidden",t.innerText=e,r.appendChild(t);const n=t.offsetWidth;r.removeChild(t);const i=document.createElement("input");return i.type="text",i.style.maxWidth=`${Math.ceil(1.1*n+24)}px`,i.value=e,i.setAttribute("readonly","readonly"),i.addEventListener("focus",()=>{i.select()}),i});t.forEach(t=>{e.appendChild(t)})})}function h(){let e=t.getValue();e=e.replace(c,function(){return arguments[3]?arguments[3]:""}),s.innerHTML=e,s.dispatchEvent(new Event("hf-refresh"))}function p(){i.innerHTML=t.getValue()}function m(e){return e.replace(/\s/g,"_")}const g={init:function(){l=document.getElementById("hf-form-preview"),r=document.getElementById("hf-form-editor"),i=document.createElement("form"),o=document.getElementById("hf-required-fields"),a=document.getElementById("hf-email-fields"),i.innerHTML=r.value,t=e.fromTextArea(r,{selectionPointer:!0,matchTags:{bothTags:!0},mode:"htmlmixed",htmlMode:!0,autoCloseTags:!0,autoRefresh:!0,styleActiveLine:!0,matchBrackets:!0}),t.on("changes",function(e){let t;return function(){t&&window.clearTimeout(t),t=window.setTimeout(e,600)}}(()=>{p(),h()})),t.on("blur",()=>{p(),h(),f(),function(){const e=i.querySelectorAll("input[required], select[required], textarea[required]"),t=[].map.call(e,d).map(m);o.value=t.join(",")}(),function(){const e=i.querySelectorAll('input[type="email"]'),t=[].map.call(e,d).map(m);a.value=t.join(",")}()}),l.addEventListener("load",u),u(),f(),document.getElementById("hf-tabs-nav").addEventListener("click",()=>{t.refresh()}),window.addEventListener("load",f)},replaceSelection:function(e){t.replaceSelection(e),t.focus()},updateFieldVariables:f};let v,y,b;function w(e,t){const n=document.createElement("div");n.className="hf-accordion expanded ";const r=document.createElement("h4");r.className="hf-accordion-heading",r.innerHTML=e,n.appendChild(r);const i=document.createElement("div");i.className="hf-accordion-content",i.innerHTML=t,n.appendChild(i);const o=document.createElement("p");o.style.textAlign="right";const a=document.createElement("a");return a.href="",a.className="danger",a.innerText="Delete Action",o.appendChild(a),i.appendChild(o),r.addEventListener("click",function(e,t){return function(){const n=null===t.offsetParent;e.className=e.className.replace("expanded","")+(n?" expanded":""),t.style.display=n?"block":"none"}}(n,i)),a.addEventListener("click",function(e){return function(t){t.preventDefault(),b.removeChild(e),1===b.childElementCount&&(b.querySelector("#hf-form-actions-empty").style.display="")}}(n)),n}function x(e){const t=e.target;if("INPUT"!==t.tagName)return;const n=t.getAttribute("data-action-type"),r=y.querySelector(`#hf-action-type-${n}-template`),i=b.querySelectorAll("div").length-1,o=w(t.value,r.innerHTML.replace(/\$index/g,i));b.appendChild(o),b.querySelector("#hf-form-actions-empty").style.display="none",window.html_forms.Editor.updateFieldVariables()}const k=function(){b=document.getElementById("hf-form-actions"),v=document.getElementById("hf-available-form-actions"),y=document.getElementById("hf-form-action-templates"),[].forEach.call(b.querySelectorAll(".hf-action-settings"),e=>{e.parentNode.removeChild(e);let t=e.getAttribute("data-title");const n=e.querySelector(".hf-action-summary");n&&(t+=` — <span class="hf-muted">${n.innerHTML}</span>`);const r=w(t,e.innerHTML);b.appendChild(r),b.querySelector("#hf-form-actions-empty").style.display="none"}),v.addEventListener("click",x,!0)};var C,_,S,T,L,M,N,A,O,D,F,E={},P=[],W=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,z=Array.isArray;function H(e,t){for(var n in t)e[n]=t[n];return e}function I(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function R(e,t,n){var r,i,o,a={};for(o in t)"key"==o?r=t[o]:"ref"==o?i=t[o]:a[o]=t[o];if(arguments.length>2&&(a.children=arguments.length>3?C.call(arguments,2):n),"function"==typeof e&&null!=e.defaultProps)for(o in e.defaultProps)void 0===a[o]&&(a[o]=e.defaultProps[o]);return B(e,a,r,i,null)}function B(e,t,n,r,i){var o={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==i?++S:i,__i:-1,__u:0};return null==i&&null!=_.vnode&&_.vnode(o),o}function j(e){return e.children}function q(e,t){this.props=e,this.context=t}function U(e,t){if(null==t)return e.__?U(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e)return n.__e;return"function"==typeof e.type?U(e):null}function V(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],i=[],o=H({},t);o.__v=t.__v+1,_.vnode&&_.vnode(o),ne(e.__P,o,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,r,null==n?U(t):n,!!(32&t.__u),i),o.__v=t.__v,o.__.__k[o.__i]=o,ie(r,o,i),t.__e=t.__=null,o.__e!=n&&K(o)}}function K(e){if(null!=(e=e.__)&&null!=e.__c)return e.__e=e.__c.base=null,e.__k.some(function(t){if(null!=t&&null!=t.__e)return e.__e=e.__c.base=t.__e}),K(e)}function $(e){(!e.__d&&(e.__d=!0)&&T.push(e)&&!G.__r++||L!=_.debounceRendering)&&((L=_.debounceRendering)||M)(G)}function G(){try{for(var e,t=1;T.length;)T.length>t&&T.sort(N),e=T.shift(),t=T.length,V(e)}finally{T.length=G.__r=0}}function X(e,t,n,r,i,o,a,l,s,c,u){var d,f,h,p,m,g,v,y=r&&r.__k||P,b=t.length;for(s=Y(n,t,y,s,b),d=0;d<b;d++)null!=(h=n.__k[d])&&(f=-1!=h.__i&&y[h.__i]||E,h.__i=d,g=ne(e,h,f,i,o,a,l,s,c,u),p=h.__e,h.ref&&f.ref!=h.ref&&(f.ref&&le(f.ref,null,h),u.push(h.ref,h.__c||p,h)),null==m&&null!=p&&(m=p),(v=!!(4&h.__u))||f.__k===h.__k?s=Z(h,s,e,v):"function"==typeof h.type&&void 0!==g?s=g:p&&(s=p.nextSibling),h.__u&=-7);return n.__e=m,s}function Y(e,t,n,r,i){var o,a,l,s,c,u=n.length,d=u,f=0;for(e.__k=new Array(i),o=0;o<i;o++)null!=(a=t[o])&&"boolean"!=typeof a&&"function"!=typeof a?("string"==typeof a||"number"==typeof a||"bigint"==typeof a||a.constructor==String?a=e.__k[o]=B(null,a,null,null,null):z(a)?a=e.__k[o]=B(j,{children:a},null,null,null):void 0===a.constructor&&a.__b>0?a=e.__k[o]=B(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):e.__k[o]=a,s=o+f,a.__=e,a.__b=e.__b+1,l=null,-1!=(c=a.__i=Q(a,n,s,d))&&(d--,(l=n[c])&&(l.__u|=2)),null==l||null==l.__v?(-1==c&&(i>u?f--:i<u&&f++),"function"!=typeof a.type&&(a.__u|=4)):c!=s&&(c==s-1?f--:c==s+1?f++:(c>s?f--:f++,a.__u|=4))):e.__k[o]=null;if(d)for(o=0;o<u;o++)null!=(l=n[o])&&!(2&l.__u)&&(l.__e==r&&(r=U(l)),se(l,l));return r}function Z(e,t,n,r){var i,o;if("function"==typeof e.type){for(i=e.__k,o=0;i&&o<i.length;o++)i[o]&&(i[o].__=e,t=Z(i[o],t,n,r));return t}e.__e!=t&&(r&&(t&&e.type&&!t.parentNode&&(t=U(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do{t=t&&t.nextSibling}while(null!=t&&8==t.nodeType);return t}function Q(e,t,n,r){var i,o,a,l=e.key,s=e.type,c=t[n],u=null!=c&&!(2&c.__u);if(null===c&&null==l||u&&l==c.key&&s==c.type)return n;if(r>(u?1:0))for(i=n-1,o=n+1;i>=0||o<t.length;)if(null!=(c=t[a=i>=0?i--:o++])&&!(2&c.__u)&&l==c.key&&s==c.type)return a;return-1}function J(e,t,n){"-"==t[0]?e.setProperty(t,null==n?"":n):e[t]=null==n?"":"number"!=typeof n||W.test(t)?n:n+"px"}function ee(e,t,n,r,i){var o,a;e:if("style"==t)if("string"==typeof n)e.style.cssText=n;else{if("string"==typeof r&&(e.style.cssText=r=""),r)for(t in r)n&&t in n||J(e.style,t,"");if(n)for(t in n)r&&n[t]==r[t]||J(e.style,t,n[t])}else if("o"==t[0]&&"n"==t[1])o=t!=(t=t.replace(A,"$1")),a=t.toLowerCase(),t=a in e||"onFocusOut"==t||"onFocusIn"==t?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+o]=n,n?r?n.u=r.u:(n.u=O,e.addEventListener(t,o?F:D,o)):e.removeEventListener(t,o?F:D,o);else{if("http://www.w3.org/2000/svg"==i)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=t&&"height"!=t&&"href"!=t&&"list"!=t&&"form"!=t&&"tabIndex"!=t&&"download"!=t&&"rowSpan"!=t&&"colSpan"!=t&&"role"!=t&&"popover"!=t&&t in e)try{e[t]=null==n?"":n;break e}catch(e){}"function"==typeof n||(null==n||!1===n&&"-"!=t[4]?e.removeAttribute(t):e.setAttribute(t,"popover"==t&&1==n?"":n))}}function te(e){return function(t){if(this.l){var n=this.l[t.type+e];if(null==t.t)t.t=O++;else if(t.t<n.u)return;return n(_.event?_.event(t):t)}}}function ne(e,t,n,r,i,o,a,l,s,c){var u,d,f,h,p,m,g,v,y,b,w,x,k,C,S,T=t.type;if(void 0!==t.constructor)return null;128&n.__u&&(s=!!(32&n.__u),o=[l=t.__e=n.__e]),(u=_.__b)&&u(t);e:if("function"==typeof T)try{if(v=t.props,y=T.prototype&&T.prototype.render,b=(u=T.contextType)&&r[u.__c],w=u?b?b.props.value:u.__:r,n.__c?g=(d=t.__c=n.__c).__=d.__E:(y?t.__c=d=new T(v,w):(t.__c=d=new q(v,w),d.constructor=T,d.render=ce),b&&b.sub(d),d.state||(d.state={}),d.__n=r,f=d.__d=!0,d.__h=[],d._sb=[]),y&&null==d.__s&&(d.__s=d.state),y&&null!=T.getDerivedStateFromProps&&(d.__s==d.state&&(d.__s=H({},d.__s)),H(d.__s,T.getDerivedStateFromProps(v,d.__s))),h=d.props,p=d.state,d.__v=t,f)y&&null==T.getDerivedStateFromProps&&null!=d.componentWillMount&&d.componentWillMount(),y&&null!=d.componentDidMount&&d.__h.push(d.componentDidMount);else{if(y&&null==T.getDerivedStateFromProps&&v!==h&&null!=d.componentWillReceiveProps&&d.componentWillReceiveProps(v,w),t.__v==n.__v||!d.__e&&null!=d.shouldComponentUpdate&&!1===d.shouldComponentUpdate(v,d.__s,w)){t.__v!=n.__v&&(d.props=v,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),P.push.apply(d.__h,d._sb),d._sb=[],d.__h.length&&a.push(d);break e}null!=d.componentWillUpdate&&d.componentWillUpdate(v,d.__s,w),y&&null!=d.componentDidUpdate&&d.__h.push(function(){d.componentDidUpdate(h,p,m)})}if(d.context=w,d.props=v,d.__P=e,d.__e=!1,x=_.__r,k=0,y)d.state=d.__s,d.__d=!1,x&&x(t),u=d.render(d.props,d.state,d.context),P.push.apply(d.__h,d._sb),d._sb=[];else do{d.__d=!1,x&&x(t),u=d.render(d.props,d.state,d.context),d.state=d.__s}while(d.__d&&++k<25);d.state=d.__s,null!=d.getChildContext&&(r=H(H({},r),d.getChildContext())),y&&!f&&null!=d.getSnapshotBeforeUpdate&&(m=d.getSnapshotBeforeUpdate(h,p)),C=null!=u&&u.type===j&&null==u.key?oe(u.props.children):u,l=X(e,z(C)?C:[C],t,n,r,i,o,a,l,s,c),d.base=t.__e,t.__u&=-161,d.__h.length&&a.push(d),g&&(d.__E=d.__=null)}catch(e){if(t.__v=null,s||null!=o)if(e.then){for(t.__u|=s?160:128;l&&8==l.nodeType&&l.nextSibling;)l=l.nextSibling;o[o.indexOf(l)]=null,t.__e=l}else{for(S=o.length;S--;)I(o[S]);re(t)}else t.__e=n.__e,t.__k=n.__k,e.then||re(t);_.__e(e,t,n)}else null==o&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):l=t.__e=ae(n.__e,t,n,r,i,o,a,s,c);return(u=_.diffed)&&u(t),128&t.__u?void 0:l}function re(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(re))}function ie(e,t,n){for(var r=0;r<n.length;r++)le(n[r],n[++r],n[++r]);_.__c&&_.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){_.__e(e,t.__v)}})}function oe(e){return"object"!=typeof e||null==e||e.__b>0?e:z(e)?e.map(oe):H({},e)}function ae(e,t,n,r,i,o,a,l,s){var c,u,d,f,h,p,m,g=n.props||E,v=t.props,y=t.type;if("svg"==y?i="http://www.w3.org/2000/svg":"math"==y?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),null!=o)for(c=0;c<o.length;c++)if((h=o[c])&&"setAttribute"in h==!!y&&(y?h.localName==y:3==h.nodeType)){e=h,o[c]=null;break}if(null==e){if(null==y)return document.createTextNode(v);e=document.createElementNS(i,y,v.is&&v),l&&(_.__m&&_.__m(t,o),l=!1),o=null}if(null==y)g===v||l&&e.data==v||(e.data=v);else{if(o=o&&C.call(e.childNodes),!l&&null!=o)for(g={},c=0;c<e.attributes.length;c++)g[(h=e.attributes[c]).name]=h.value;for(c in g)h=g[c],"dangerouslySetInnerHTML"==c?d=h:"children"==c||c in v||"value"==c&&"defaultValue"in v||"checked"==c&&"defaultChecked"in v||ee(e,c,null,h,i);for(c in v)h=v[c],"children"==c?f=h:"dangerouslySetInnerHTML"==c?u=h:"value"==c?p=h:"checked"==c?m=h:l&&"function"!=typeof h||g[c]===h||ee(e,c,h,g[c],i);if(u)l||d&&(u.__html==d.__html||u.__html==e.innerHTML)||(e.innerHTML=u.__html),t.__k=[];else if(d&&(e.innerHTML=""),X("template"==t.type?e.content:e,z(f)?f:[f],t,n,r,"foreignObject"==y?"http://www.w3.org/1999/xhtml":i,o,a,o?o[0]:n.__k&&U(n,0),l,s),null!=o)for(c=o.length;c--;)I(o[c]);l||(c="value","progress"==y&&null==p?e.removeAttribute("value"):null!=p&&(p!==e[c]||"progress"==y&&!p||"option"==y&&p!=g[c])&&ee(e,c,p,g[c],i),c="checked",null!=m&&m!=e[c]&&ee(e,c,m,g[c],i))}return e}function le(e,t,n){try{if("function"==typeof e){var r="function"==typeof e.__u;r&&e.__u(),r&&null==t||(e.__u=e(t))}else e.current=t}catch(e){_.__e(e,n)}}function se(e,t,n){var r,i;if(_.unmount&&_.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||le(r,null,t)),null!=(r=e.__c)){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){_.__e(e,t)}r.base=r.__P=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&se(r[i],t,n||"function"!=typeof e.type);n||I(e.__e),e.__c=e.__=e.__e=void 0}function ce(e,t,n){return this.constructor(e,n)}C=P.slice,_={__e:function(e,t,n,r){for(var i,o,a;t=t.__;)if((i=t.__c)&&!i.__)try{if((o=i.constructor)&&null!=o.getDerivedStateFromError&&(i.setState(o.getDerivedStateFromError(e)),a=i.__d),null!=i.componentDidCatch&&(i.componentDidCatch(e,r||{}),a=i.__d),a)return i.__E=i}catch(t){e=t}throw e}},S=0,q.prototype.setState=function(e,t){var n;n=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=H({},this.state),"function"==typeof e&&(e=e(H({},n),this.props)),e&&H(n,e),null!=e&&this.__v&&(t&&this._sb.push(t),$(this))},q.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),$(this))},q.prototype.render=j,T=[],M="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,N=function(e,t){return e.__v.__b-t.__v.__b},G.__r=0,A=/(PointerCapture)$|Capture$/i,O=0,D=te(!1),F=te(!0);const ue=function(e,t,n){var r=t.split("."),i=e.__lsc||(e.__lsc={});return i[t+n]||(i[t+n]=function(t){for(var i=t&&t.target||this,o={},a=o,l="string"==typeof n?function(e,t,n,r){for(r=0,t=t.split?t.split("."):t;e&&r<t.length;)e=e[t[r++]];return void 0===e?void 0:e}(t,n):i.nodeName?i.type.match(/^che|rad/)?i.checked:i.value:t,s=0;s<r.length-1;s++)a=a[r[s]]||(a[r[s]]=!s&&e.state[r[s]]||{});a[r[s]]=l,e.setState(o)})};var de=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i,fe=/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/,he=/[\s\n\\/='"\0<>]/,pe=/^xlink:?./,me=/["&<]/;function ge(e){if(!1===me.test(e+=""))return e;for(var t=0,n=0,r="",i="";n<e.length;n++){switch(e.charCodeAt(n)){case 34:i=""";break;case 38:i="&";break;case 60:i="<";break;default:continue}n!==t&&(r+=e.slice(t,n)),r+=i,t=n+1}return n!==t&&(r+=e.slice(t,n)),r}var ve=function(e,t){return String(e).replace(/(\n+)/g,"$1"+(t||"\t"))},ye=function(e,t,n){return String(e).length>(t||40)||!n&&-1!==String(e).indexOf("\n")||-1!==String(e).indexOf("<")},be={},we=/([A-Z])/g;function xe(e){var t="";for(var n in e){var r=e[n];null!=r&&""!==r&&(t&&(t+=" "),t+="-"==n[0]?n:be[n]||(be[n]=n.replace(we,"-$1").toLowerCase()),t="number"==typeof r&&!1===de.test(n)?t+": "+r+"px;":t+": "+r+";")}return t||void 0}function ke(e,t){return Array.isArray(t)?t.reduce(ke,e):null!=t&&!1!==t&&e.push(t),e}function Ce(){this.__d=!0}function _e(e,t){return{__v:e,context:t,props:e.props,setState:Ce,forceUpdate:Ce,__d:!0,__h:[]}}function Se(e,t){var n=e.contextType,r=n&&t[n.__c];return null!=n?r?r.props.value:n.__:t}var Te=[];function Le(e,t,n,r,i,o){if(null==e||"boolean"==typeof e)return"";if("object"!=typeof e)return"function"==typeof e?"":ge(e);var a=n.pretty,l=a&&"string"==typeof a?a:"\t";if(Array.isArray(e)){for(var s="",c=0;c<e.length;c++)a&&c>0&&(s+="\n"),s+=Le(e[c],t,n,r,i,o);return s}if(void 0!==e.constructor)return"";var u,d=e.type,f=e.props,h=!1;if("function"==typeof d){if(h=!0,!n.shallow||!r&&!1!==n.renderRootComponent){if(d===j){var p=[];return ke(p,e.props.children),Le(p,t,n,!1!==n.shallowHighOrder,i,o)}var m,g=e.__c=_e(e,t);_.__b&&_.__b(e);var v=_.__r;if(d.prototype&&"function"==typeof d.prototype.render){var y=Se(d,t);(g=e.__c=new d(f,y)).__v=e,g._dirty=g.__d=!0,g.props=f,null==g.state&&(g.state={}),null==g._nextState&&null==g.__s&&(g._nextState=g.__s=g.state),g.context=y,d.getDerivedStateFromProps?g.state=Object.assign({},g.state,d.getDerivedStateFromProps(g.props,g.state)):g.componentWillMount&&(g.componentWillMount(),g.state=g._nextState!==g.state?g._nextState:g.__s!==g.state?g.__s:g.state),v&&v(e),m=g.render(g.props,g.state,g.context)}else for(var b=Se(d,t),w=0;g.__d&&w++<25;)g.__d=!1,v&&v(e),m=d.call(e.__c,f,b);return g.getChildContext&&(t=Object.assign({},t,g.getChildContext())),_.diffed&&_.diffed(e),Le(m,t,n,!1!==n.shallowHighOrder,i,o)}d=(u=d).displayName||u!==Function&&u.name||function(e){var t=(Function.prototype.toString.call(e).match(/^\s*function\s+([^( ]+)/)||"")[1];if(!t){for(var n=-1,r=Te.length;r--;)if(Te[r]===e){n=r;break}n<0&&(n=Te.push(e)-1),t="UnnamedComponent"+n}return t}(u)}var x,k,C="<"+d;if(f){var S=Object.keys(f);n&&!0===n.sortAttributes&&S.sort();for(var T=0;T<S.length;T++){var L=S[T],M=f[L];if("children"!==L){if(!he.test(L)&&(n&&n.allAttributes||"key"!==L&&"ref"!==L&&"__self"!==L&&"__source"!==L)){if("defaultValue"===L)L="value";else if("defaultChecked"===L)L="checked";else if("defaultSelected"===L)L="selected";else if("className"===L){if(void 0!==f.class)continue;L="class"}else i&&pe.test(L)&&(L=L.toLowerCase().replace(/^xlink:?/,"xlink:"));if("htmlFor"===L){if(f.for)continue;L="for"}"style"===L&&M&&"object"==typeof M&&(M=xe(M)),"a"===L[0]&&"r"===L[1]&&"boolean"==typeof M&&(M=String(M));var N=n.attributeHook&&n.attributeHook(L,M,t,n,h);if(N||""===N)C+=N;else if("dangerouslySetInnerHTML"===L)k=M&&M.__html;else if("textarea"===d&&"value"===L)x=M;else if((M||0===M||""===M)&&"function"!=typeof M){if(!(!0!==M&&""!==M||(M=L,n&&n.xml))){C=C+" "+L;continue}if("value"===L){if("select"===d){o=M;continue}"option"===d&&o==M&&void 0===f.selected&&(C+=" selected")}C=C+" "+L+'="'+ge(M)+'"'}}}else x=M}}if(a){var A=C.replace(/\n\s*/," ");A===C||~A.indexOf("\n")?a&&~C.indexOf("\n")&&(C+="\n"):C=A}if(C+=">",he.test(d))throw new Error(d+" is not a valid HTML tag name in "+C);var O,D=fe.test(d)||n.voidElements&&n.voidElements.test(d),F=[];if(k)a&&ye(k)&&(k="\n"+l+ve(k,l)),C+=k;else if(null!=x&&ke(O=[],x).length){for(var E=a&&~C.indexOf("\n"),P=!1,W=0;W<O.length;W++){var z=O[W];if(null!=z&&!1!==z){var H=Le(z,t,n,!0,"svg"===d||"foreignObject"!==d&&i,o);if(a&&!E&&ye(H)&&(E=!0),H)if(a){var I=H.length>0&&"<"!=H[0];P&&I?F[F.length-1]+=H:F.push(H),P=I}else F.push(H)}}if(a&&E)for(var R=F.length;R--;)F[R]="\n"+l+ve(F[R],l)}if(F.length||k)C+=F.join("");else if(n&&n.xml)return C.substring(0,C.length-1)+" />";return!D||O||k?(a&&~C.indexOf("\n")&&(C+="\n"),C=C+"</"+d+">"):C=C.replace(/>$/," />"),C}var Me={shallow:!0};Ae.render=Ae;var Ne=[];function Ae(e,t,n){t=t||{};var r=_.__s;_.__s=!0;var i,o=R(j,null);return o.__k=[e],i=n&&(n.pretty||n.voidElements||n.sortAttributes||n.shallow||n.allAttributes||n.xml||n.attributeHook)?Le(e,t,n):We(e,t,!1,void 0,o),_.__c&&_.__c(e,Ne),_.__s=r,Ne.length=0,i}function Oe(e){return null==e||"boolean"==typeof e?null:"string"==typeof e||"number"==typeof e||"bigint"==typeof e?R(null,null,e):e}function De(e,t){return"className"===e?"class":"htmlFor"===e?"for":"defaultValue"===e?"value":"defaultChecked"===e?"checked":"defaultSelected"===e?"selected":t&&pe.test(e)?e.toLowerCase().replace(/^xlink:?/,"xlink:"):e}function Fe(e,t){return"style"===e&&null!=t&&"object"==typeof t?xe(t):"a"===e[0]&&"r"===e[1]&&"boolean"==typeof t?String(t):t}var Ee=Array.isArray,Pe=Object.assign;function We(e,t,n,r,i){if(null==e||!0===e||!1===e||""===e)return"";if("object"!=typeof e)return"function"==typeof e?"":ge(e);if(Ee(e)){var o="";i.__k=e;for(var a=0;a<e.length;a++)o+=We(e[a],t,n,r,i),e[a]=Oe(e[a]);return o}if(void 0!==e.constructor)return"";e.__=i,_.__b&&_.__b(e);var l=e.type,s=e.props;if("function"==typeof l){var c;if(l===j)c=s.children;else{c=l.prototype&&"function"==typeof l.prototype.render?function(e,t){var n=e.type,r=Se(n,t),i=new n(e.props,r);e.__c=i,i.__v=e,i.__d=!0,i.props=e.props,null==i.state&&(i.state={}),null==i.__s&&(i.__s=i.state),i.context=r,n.getDerivedStateFromProps?i.state=Pe({},i.state,n.getDerivedStateFromProps(i.props,i.state)):i.componentWillMount&&(i.componentWillMount(),i.state=i.__s!==i.state?i.__s:i.state);var o=_.__r;return o&&o(e),i.render(i.props,i.state,i.context)}(e,t):function(e,t){var n,r=_e(e,t),i=Se(e.type,t);e.__c=r;for(var o=_.__r,a=0;r.__d&&a++<25;)r.__d=!1,o&&o(e),n=e.type.call(r,e.props,i);return n}(e,t);var u=e.__c;u.getChildContext&&(t=Pe({},t,u.getChildContext()))}var d=We(c=null!=c&&c.type===j&&null==c.key?c.props.children:c,t,n,r,e);return _.diffed&&_.diffed(e),e.__=void 0,_.unmount&&_.unmount(e),d}var f,h,p="<";if(p+=l,s)for(var m in f=s.children,s){var g=s[m];if(!("key"===m||"ref"===m||"__self"===m||"__source"===m||"children"===m||"className"===m&&"class"in s||"htmlFor"===m&&"for"in s||he.test(m)))if(g=Fe(m=De(m,n),g),"dangerouslySetInnerHTML"===m)h=g&&g.__html;else if("textarea"===l&&"value"===m)f=g;else if((g||0===g||""===g)&&"function"!=typeof g){if(!0===g||""===g){g=m,p=p+" "+m;continue}if("value"===m){if("select"===l){r=g;continue}"option"!==l||r!=g||"selected"in s||(p+=" selected")}p=p+" "+m+'="'+ge(g)+'"'}}var v=p;if(p+=">",he.test(l))throw new Error(l+" is not a valid HTML tag name in "+p);var y="",b=!1;if(h)y+=h,b=!0;else if("string"==typeof f)y+=ge(f),b=!0;else if(Ee(f)){e.__k=f;for(var w=0;w<f.length;w++){var x=f[w];if(f[w]=Oe(x),null!=x&&!1!==x){var k=We(x,t,"svg"===l||"foreignObject"!==l&&n,r,e);k&&(y+=k,b=!0)}}}else if(null!=f&&!1!==f&&!0!==f){e.__k=[Oe(f)];var C=We(f,t,"svg"===l||"foreignObject"!==l&&n,r,e);C&&(y+=C,b=!0)}if(_.diffed&&_.diffed(e),e.__=void 0,_.unmount&&_.unmount(e),b)p+=y;else if(fe.test(l))return v+" />";return p+"</"+l+">"}Ae.shallowRender=function(e,t){return Ae(e,t,Me)};const ze=Ae;function He(e){return ze(e,{pretty:!0})}function Ie(e,t,n){return R(e,t=function(e){const t={};return Object.keys(e).forEach(n=>{!1!==e[n]&&""!==e[n]&&(t[n]=e[n])}),t}(t),n)}const Re=function(e){const t=function(e){return e.replace(/ /g,"_").replace(/[^\w[\]_]*/g,"").toUpperCase()}(e.fieldLabel),n=`${e.formSlug}-${t}`,r=e.fieldLabel.length&&"submit"!==e.fieldType?R("label",{for:n},e.fieldLabel):"";let i,o;switch(e.fieldType){case"textarea":i={name:t,placeholder:e.placeholder,required:e.required,id:n},o=Ie("textarea",i,e.value);break;case"dropdown":i={name:t+(e.multiple?"[]":""),required:e.required,multiple:e.multiple,id:n},o=Ie("select",i,e.choices.map(e=>Ie("option",{selected:e.checked},e.label)));break;case"radio":o=e.choices.map(e=>Ie("label",{},[Ie("input",{type:"radio",name:t,value:e.label,selected:e.checked})," ",Ie("span",{},e.label)]));break;case"checkbox":o=e.choices.map(e=>Ie("label",{},[Ie("input",{type:"checkbox",name:`${t}[]`,value:e.label,checked:e.checked})," ",Ie("span",{},e.label)]));break;case"file":i={type:"file",name:t,required:e.required,id:n},e.accept&&(i.accept=e.accept),o=Ie("input",i);break;case"submit":i={type:"submit",value:e.value},o=Ie("input",i);break;default:i={type:e.fieldType,name:t,value:e.value,placeholder:e.placeholder,required:e.required,id:n},o=Ie("input",i)}let a="";if(e.wrap){const e=""!==r?["\n\t",r,"\n\t",o,"\n"]:["\n\t",o,"\n"];a=He(R(hf_options.wrapper_tag,{},e))}else a=He(""!==r?[r,"\n",o]:[o]);return a};function Be(e){return R("div",{className:"hf-small-margin"},R("button",{className:"button",type:"button",onClick:e.onSubmit},"Add Field to Form")," ",R("a",{href:"#",className:"hf-small",style:"vertical-align: middle;",onClick:e.onCancel},"Cancel"))}function je(e){return R("div",{className:"hf-small-margin"},R("label",{htmlFor:"hf-fg-field-label"},"Field Label ",R("span",{className:"hf-required"},"*")),R("input",{id:"hf-fg-field-label",type:"text",value:e.value,onChange:e.onChange}))}function qe(e){return R("div",{className:"hf-small-margin"},R("label",{htmlFor:"hf-fg-placeholder"},"Placeholder ",R("span",{className:"hf-italic hf-pull-right"},"Optional")),R("input",{id:"hf-fg-placeholder",type:"text",value:e.value,onChange:e.onChange}),R("p",{className:"description"},"Text to show when field has no value."))}function Ue(e){return R("div",{className:"hf-small-margin"},R("label",{htmlFor:"hf-fg-default-value"},"Button Text ",R("span",{className:"hf-required"},"*")),R("input",{id:"hf-fg-default-value",type:"text",value:e.value,onChange:e.onChange}),R("p",{className:"description"},"Text to show on the button."))}function Ve(e){return R("div",{className:"hf-small-margin"},R("label",{htmlFor:"hf-fg-default-value"},"Default Value ",R("span",{className:"hf-italic hf-pull-right"},"Optional")),R("input",{id:"hf-fg-default-value",type:"text",value:e.value,onChange:e.onChange}),R("p",{className:"description"},"Text to pre-fill this field with."))}function Ke(e){return R("div",{className:"hf-small-margin"},R("label",{className:"inline"},R("input",{type:"checkbox",value:"1",defaultChecked:e.checked,onChange:e.onChange}),"Accept multiple values."))}function $e(e){return R("div",{className:"hf-small-margin"},R("label",{className:"inline"},R("input",{type:"checkbox",value:"1",defaultChecked:e.checked,onChange:e.onChange}),"Wrap this field in a <",hf_options.wrapper_tag,"> tag."))}function Ge(e){return R("div",{className:"hf-small-margin"},R("label",{className:"inline"},R("input",{type:"checkbox",value:"1",defaultChecked:e.checked,onChange:e.onChange}),"This field is required."))}function Xe(e){const t=e.choices.map((t,n)=>R("div",{"data-key":n,key:n},R("input",{type:e.multiple?"checkbox":"radio",name:"selected",defaultChecked:t.checked,onChange:e.handlers.toggleChecked,title:"Pre-select this choice?"}),R("input",{type:"text",value:t.label,placeholder:"Choice Label",style:"width: 80%;",onChange:e.handlers.changeLabel}),R("a",{href:"#",onClick:e.handlers.delete,style:"text-decoration: none;",title:"Delete Choice"},"✕")));return R("div",{className:"hf-small-margin"},R("label",null,"Choices"),t,R("input",{type:e.multiple?"checkbox":"radio",style:"visibility: hidden;"}),R("a",{href:"#",onClick:e.handlers.add},"Add Choice"))}function Ye(e){return R("div",{className:"hf-small-margin"},R("label",null,"Accepted File Types"),R("input",{type:"text",value:e.value,onChange:e.onChange}),R("p",{className:"description"},"Use a comma-separated list of accepted file extensions, eg ",R("code",null,".pdf"),". ",R("br",null),"Leave empty to accept any file type."))}class Ze extends q{constructor(e){super(e),this.state=this.getInitialState(),this.choiceHandlers={add:this.addChoice.bind(this),delete:this.deleteChoice.bind(this),changeLabel:this.changeChoiceLabel.bind(this),toggleChecked:this.toggleChoiceChecked.bind(this)},this.addToForm=this.addToForm.bind(this),this.handleCancel=this.handleCancel.bind(this)}getInitialState(){return{formId:document.querySelector('input[name="form_id"]').value,formSlug:document.querySelector('input[name="form[slug]"]').value,fieldType:"",fieldLabel:"",placeholder:"",value:"",multiple:!1,wrap:!0,required:!1,choices:[{checked:!1,label:"One"},{checked:!1,label:"Two"}],accept:""}}componentWillReceiveProps(e){const t={fieldType:e.fieldType};"checkbox"===this.state.fieldType&&"checkbox"!==e.fieldType&&(t.choices=this.state.choices.map(e=>(e.checked=!1,e))),this.setState(t)}addToForm(){const e=Re(this.state);window.html_forms.Editor.replaceSelection(e)}addChoice(){const e=this.state.choices;e.push({checked:!1,label:"..."}),this.setState({choices:e})}deleteChoice(e){const t=this.state.choices,n=e.target.parentElement.getAttribute("data-key");t.splice(n,1),this.setState({choices:t})}changeChoiceLabel(e){const t=this.state.choices;t[e.target.parentElement.getAttribute("data-key")].label=e.target.value,this.setState({choices:t})}toggleChoiceChecked(e){const t=this.state.choices,n=e.target.parentElement.getAttribute("data-key");t[n].checked=!t[n].checked,this.setState({choices:t})}static handleKeyPress(e){13===e.keyCode&&e.preventDefault()}handleCancel(){this.setState(this.getInitialState()),this.props.onCancel()}render(e,t){if(0===e.rows.length)return"";const n=[];for(let r=0;r<e.rows.length;r++)switch(e.rows[r]){case"label":n.push(R(je,{value:t.fieldLabel,onChange:ue(this,"fieldLabel")}));break;case"placeholder":n.push(R(qe,{value:t.placeholder,onChange:ue(this,"placeholder")}));break;case"default-value":n.push(R(Ve,{value:t.value,onChange:ue(this,"value")}));break;case"multiple":n.push(R(Ke,{checked:t.multiple,onChange:ue(this,"multiple")}));break;case"required":n.push(R(Ge,{checked:t.required,onChange:ue(this,"required")}));break;case"wrap":n.push(R($e,{checked:t.wrap,onChange:ue(this,"wrap")}));break;case"add-to-form":n.push(R(Be,{onSubmit:this.addToForm,onCancel:this.handleCancel}));break;case"choices":n.push(R(Xe,{multiple:"checkbox"===t.fieldType,choices:t.choices,handlers:this.choiceHandlers}));break;case"button-text":n.push(R(Ue,{value:t.value,onChange:ue(this,"value")}));break;case"accept":n.push(R(Ye,{value:t.accept,onChange:ue(this,"accept")}))}return R("div",{className:"field-config",onKeyPress:Ze.handleKeyPress},n)}}const Qe=Ze,Je=class extends q{constructor(e){super(e),this.state={activeField:null},this.handleCancel=this.handleCancel.bind(this),this.openFieldConfig=this.openFieldConfig.bind(this)}handleCancel(){this.setState({activeField:null})}openFieldConfig(e){const t=this.props.fields[e.target.value];this.state.activeField===t?this.setState({activeField:null}):this.setState({activeField:t})}render(e,t){const n=e.fields.map((e,n)=>R("button",{type:"button",key:n,value:n,className:"button "+(t.activeField===e?"active":""),onClick:this.openFieldConfig},e.label)),r=t.activeField?t.activeField.key:"",i=t.activeField?t.activeField.configRows:[];return R("div",{className:"hf-field-builder"},R("h4",null,"Add Field"),R("div",{className:"available-fields"},n),R("div",{style:"max-width: 480px;"},R(Qe,{fieldType:r,rows:i,onCancel:this.handleCancel})),null===t.activeField?R("p",{className:"help",style:"margin-bottom: 0;"},"Use the buttons above to generate your field HTML, or manually modify your form below."):"")}};function et(e,t,n){this.key=e,this.label=t,this.configRows=n||[]}const tt=[new et("text","Text",["label","placeholder","default-value","required","wrap","add-to-form"]),new et("email","Email",["label","placeholder","default-value","required","wrap","add-to-form"]),new et("url","URL",["label","placeholder","default-value","required","wrap","add-to-form"]),new et("number","Number",["label","placeholder","default-value","required","wrap","add-to-form"]),new et("date","Date",["label","default-value","required","wrap","add-to-form"]),new et("textarea","Textarea",["label","placeholder","default-value","required","wrap","add-to-form"]),new et("dropdown","Dropdown",["label","choices","multiple","required","wrap","add-to-form"]),new et("checkbox","Checkboxes",["label","choices","wrap","add-to-form"]),new et("radio","Radio Buttons",["label","choices","wrap","add-to-form"]),new et("submit","Submit Button",["button-text","wrap","add-to-form"])],nt={init(){!function(e,t,n){var r,i,o,a;t==document&&(t=document.documentElement),_.__&&_.__(e,t),i=(r="function"==typeof n)?null:n&&n.__k||t.__k,o=[],a=[],ne(t,e=(!r&&n||t).__k=R(j,null,[e]),i||E,E,t.namespaceURI,!r&&n?[n]:i?null:t.firstChild?C.call(t.childNodes):null,o,!r&&n?n:i?i.__e:t.firstChild,r,a),ie(o,e,a)}(R(Je,{fields:tt}),document.getElementById("hf-field-builder"))},registerField(e,t,n){tt.push(new et(e,t,n))}};var rt,it,ot;window.html_forms={},document.addEventListener("DOMContentLoaded",()=>{document.getElementById("hf-form-editor")&&(g.init(),k(),nt.init())}),window.html_forms.FieldBuilder=nt,window.html_forms.Editor=g,"edit"===window.hf_options.view&&window.columns.useCheckboxesForHidden(),document.querySelector("#hf-form-preview-container")&&(rt=document.querySelector("#hf-form-preview-container"),it=document.querySelector("a#hf-show-form-preview"),ot=document.querySelector("a#hf-hide-form-preview"),it.addEventListener("click",function(e){e.preventDefault(),rt.style.display="block",it.style.display="none"}),ot.addEventListener("click",function(e){e.preventDefault(),rt.style.display="none",it.style.display="block"})),document.querySelector(".wrap.hf").addEventListener("click",function(e){"A"===e.target.tagName&&e.target.getAttribute("href").startsWith("#")&&e.preventDefault()})})()})(); | |
| 1 | +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | |
| 2 | +"use strict"; | |
| 3 | + | |
| 4 | +Object.defineProperty(exports, "__esModule", { | |
| 5 | + value: true | |
| 6 | +}); | |
| 7 | +exports["default"] = void 0; | |
| 8 | + | |
| 9 | +function init() { | |
| 10 | + document.body.addEventListener('click', handleClickEvent, true); | |
| 11 | +} | |
| 12 | + | |
| 13 | +function handleClickEvent(e) { | |
| 14 | + if (e.target.tagName !== 'A') { | |
| 15 | + return; | |
| 16 | + } | |
| 17 | + | |
| 18 | + if (e.target.hasAttribute('data-hf-confirm')) { | |
| 19 | + var sure = confirm(e.target.getAttribute('data-hf-confirm')); | |
| 20 | + | |
| 21 | + if (!sure) { | |
| 22 | + e.preventDefault(); | |
| 23 | + } | |
| 24 | + } | |
| 25 | +} | |
| 26 | + | |
| 27 | +var _default = { | |
| 28 | + init: init | |
| 29 | +}; | |
| 30 | +exports["default"] = _default; | |
| 31 | + | |
| 32 | +},{}],2:[function(require,module,exports){ | |
| 33 | +"use strict"; | |
| 34 | + | |
| 35 | +var _tabs = _interopRequireDefault(require("./tabs.js")); | |
| 36 | + | |
| 37 | +var _formEditor = _interopRequireDefault(require("./form-editor.js")); | |
| 38 | + | |
| 39 | +var _formActions = _interopRequireDefault(require("./form-actions.js")); | |
| 40 | + | |
| 41 | +var _fieldBuilder = _interopRequireDefault(require("./field-builder.js")); | |
| 42 | + | |
| 43 | +var _actionConfirmations = _interopRequireDefault(require("./action-confirmations.js")); | |
| 44 | + | |
| 45 | +var _tlite = _interopRequireDefault(require("tlite")); | |
| 46 | + | |
| 47 | +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
| 48 | + | |
| 49 | +window.html_forms = {}; // init the various components | |
| 50 | + | |
| 51 | +_tabs["default"].init(); | |
| 52 | + | |
| 53 | +_actionConfirmations["default"].init(); | |
| 54 | + | |
| 55 | +if (document.getElementById('hf-form-editor')) { | |
| 56 | + _formEditor["default"].init(); | |
| 57 | + | |
| 58 | + _formActions["default"].init(); | |
| 59 | + | |
| 60 | + _fieldBuilder["default"].init(_formEditor["default"]); | |
| 61 | +} | |
| 62 | + | |
| 63 | +(0, _tlite["default"])(function (el) { | |
| 64 | + return el.className.indexOf('hf-tooltip') > -1; | |
| 65 | +}); | |
| 66 | +window.html_forms.FieldBuilder = _fieldBuilder["default"]; | |
| 67 | +window.html_forms.Editor = _formEditor["default"]; // tell WP common.js to override the method used for determining hidden columns (screen options) | |
| 68 | + | |
| 69 | +if (window.hf_options.view === 'edit') { | |
| 70 | + window.columns.useCheckboxesForHidden(); | |
| 71 | +} | |
| 72 | + | |
| 73 | +},{"./action-confirmations.js":1,"./field-builder.js":6,"./form-actions.js":8,"./form-editor.js":9,"./tabs.js":10,"tlite":23}],3:[function(require,module,exports){ | |
| 74 | +"use strict"; | |
| 75 | + | |
| 76 | +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | |
| 77 | + | |
| 78 | +Object.defineProperty(exports, "__esModule", { | |
| 79 | + value: true | |
| 80 | +}); | |
| 81 | +exports.FieldBuilder = void 0; | |
| 82 | + | |
| 83 | +var _preact = require("preact"); | |
| 84 | + | |
| 85 | +var _fieldConfigurator = require("./field-configurator.js"); | |
| 86 | + | |
| 87 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
| 88 | + | |
| 89 | +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | |
| 90 | + | |
| 91 | +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | |
| 92 | + | |
| 93 | +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | |
| 94 | + | |
| 95 | +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | |
| 96 | + | |
| 97 | +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | |
| 98 | + | |
| 99 | +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | |
| 100 | + | |
| 101 | +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | |
| 102 | + | |
| 103 | +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | |
| 104 | + | |
| 105 | +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | |
| 106 | + | |
| 107 | +var FieldBuilder = /*#__PURE__*/function (_Component) { | |
| 108 | + _inherits(FieldBuilder, _Component); | |
| 109 | + | |
| 110 | + var _super = _createSuper(FieldBuilder); | |
| 111 | + | |
| 112 | + function FieldBuilder(props) { | |
| 113 | + var _this; | |
| 114 | + | |
| 115 | + _classCallCheck(this, FieldBuilder); | |
| 116 | + | |
| 117 | + _this = _super.call(this, props); | |
| 118 | + _this.state = { | |
| 119 | + activeField: null | |
| 120 | + }; | |
| 121 | + _this.handleCancel = _this.handleCancel.bind(_assertThisInitialized(_this)); | |
| 122 | + _this.openFieldConfig = _this.openFieldConfig.bind(_assertThisInitialized(_this)); | |
| 123 | + return _this; | |
| 124 | + } | |
| 125 | + | |
| 126 | + _createClass(FieldBuilder, [{ | |
| 127 | + key: "handleCancel", | |
| 128 | + value: function handleCancel() { | |
| 129 | + this.setState({ | |
| 130 | + activeField: null | |
| 131 | + }); | |
| 132 | + } | |
| 133 | + }, { | |
| 134 | + key: "openFieldConfig", | |
| 135 | + value: function openFieldConfig(e) { | |
| 136 | + var field = this.props.fields[e.target.value]; | |
| 137 | + | |
| 138 | + if (this.state.activeField === field) { | |
| 139 | + this.setState({ | |
| 140 | + activeField: null | |
| 141 | + }); | |
| 142 | + } else { | |
| 143 | + this.setState({ | |
| 144 | + activeField: field | |
| 145 | + }); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + }, { | |
| 149 | + key: "render", | |
| 150 | + value: function render(props, state) { | |
| 151 | + var _this2 = this; | |
| 152 | + | |
| 153 | + var fieldButtons = props.fields.map(function (f, i) { | |
| 154 | + return (0, _preact.h)("button", { | |
| 155 | + type: "button", | |
| 156 | + value: i, | |
| 157 | + className: 'button ' + (state.activeField === f ? 'active' : ''), | |
| 158 | + onClick: _this2.openFieldConfig | |
| 159 | + }, f.label); | |
| 160 | + }); | |
| 161 | + var fieldType = state.activeField ? state.activeField.key : ''; | |
| 162 | + var rows = state.activeField ? state.activeField.configRows : []; | |
| 163 | + return (0, _preact.h)("div", { | |
| 164 | + "class": "hf-field-builder" | |
| 165 | + }, (0, _preact.h)("h4", null, "Add field"), (0, _preact.h)("div", { | |
| 166 | + "class": "available-fields" | |
| 167 | + }, fieldButtons), (0, _preact.h)("div", { | |
| 168 | + style: "max-width: 480px;" | |
| 169 | + }, (0, _preact.h)(_fieldConfigurator.FieldConfigurator, { | |
| 170 | + fieldType: fieldType, | |
| 171 | + rows: rows, | |
| 172 | + onCancel: this.handleCancel | |
| 173 | + })), state.activeField === null ? (0, _preact.h)("p", { | |
| 174 | + "class": "help", | |
| 175 | + style: "margin-bottom: 0;" | |
| 176 | + }, "Use the buttons above to generate your field HTML, or manually modify your form below.") : ''); | |
| 177 | + } | |
| 178 | + }]); | |
| 179 | + | |
| 180 | + return FieldBuilder; | |
| 181 | +}(_preact.Component); | |
| 182 | + | |
| 183 | +exports.FieldBuilder = FieldBuilder; | |
| 184 | + | |
| 185 | +},{"./field-configurator.js":4,"preact":22}],4:[function(require,module,exports){ | |
| 186 | +"use strict"; | |
| 187 | + | |
| 188 | +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | |
| 189 | + | |
| 190 | +Object.defineProperty(exports, "__esModule", { | |
| 191 | + value: true | |
| 192 | +}); | |
| 193 | +exports.FieldConfigurator = void 0; | |
| 194 | + | |
| 195 | +var _preact = require("preact"); | |
| 196 | + | |
| 197 | +var _html = require("../field-builder/html.js"); | |
| 198 | + | |
| 199 | +var FS = _interopRequireWildcard(require("./field-settings.js")); | |
| 200 | + | |
| 201 | +var _linkstate = _interopRequireDefault(require("linkstate")); | |
| 202 | + | |
| 203 | +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
| 204 | + | |
| 205 | +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | |
| 206 | + | |
| 207 | +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | |
| 208 | + | |
| 209 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
| 210 | + | |
| 211 | +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | |
| 212 | + | |
| 213 | +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | |
| 214 | + | |
| 215 | +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | |
| 216 | + | |
| 217 | +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | |
| 218 | + | |
| 219 | +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | |
| 220 | + | |
| 221 | +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | |
| 222 | + | |
| 223 | +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | |
| 224 | + | |
| 225 | +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | |
| 226 | + | |
| 227 | +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | |
| 228 | + | |
| 229 | +var FieldConfigurator = /*#__PURE__*/function (_Component) { | |
| 230 | + _inherits(FieldConfigurator, _Component); | |
| 231 | + | |
| 232 | + var _super = _createSuper(FieldConfigurator); | |
| 233 | + | |
| 234 | + function FieldConfigurator(props) { | |
| 235 | + var _this; | |
| 236 | + | |
| 237 | + _classCallCheck(this, FieldConfigurator); | |
| 238 | + | |
| 239 | + _this = _super.call(this, props); | |
| 240 | + _this.state = _this.getInitialState(); | |
| 241 | + _this.choiceHandlers = { | |
| 242 | + add: _this.addChoice.bind(_assertThisInitialized(_this)), | |
| 243 | + "delete": _this.deleteChoice.bind(_assertThisInitialized(_this)), | |
| 244 | + changeLabel: _this.changeChoiceLabel.bind(_assertThisInitialized(_this)), | |
| 245 | + toggleChecked: _this.toggleChoiceChecked.bind(_assertThisInitialized(_this)) | |
| 246 | + }; | |
| 247 | + _this.addToForm = _this.addToForm.bind(_assertThisInitialized(_this)); | |
| 248 | + _this.handleCancel = _this.handleCancel.bind(_assertThisInitialized(_this)); | |
| 249 | + return _this; | |
| 250 | + } | |
| 251 | + | |
| 252 | + _createClass(FieldConfigurator, [{ | |
| 253 | + key: "getInitialState", | |
| 254 | + value: function getInitialState() { | |
| 255 | + return { | |
| 256 | + formId: document.querySelector('input[name="form_id"]').value, | |
| 257 | + formSlug: document.querySelector('input[name="form[slug]"]').value, | |
| 258 | + fieldType: '', | |
| 259 | + fieldLabel: '', | |
| 260 | + placeholder: '', | |
| 261 | + value: '', | |
| 262 | + multiple: false, | |
| 263 | + wrap: true, | |
| 264 | + required: false, | |
| 265 | + choices: [{ | |
| 266 | + checked: false, | |
| 267 | + label: 'One' | |
| 268 | + }, { | |
| 269 | + checked: false, | |
| 270 | + label: 'Two' | |
| 271 | + }], | |
| 272 | + accept: '' | |
| 273 | + }; | |
| 274 | + } | |
| 275 | + }, { | |
| 276 | + key: "componentWillReceiveProps", | |
| 277 | + value: function componentWillReceiveProps(props) { | |
| 278 | + var newState = { | |
| 279 | + fieldType: props.fieldType | |
| 280 | + }; // when changing from field that accepts multiple values to single-value field, reset all pre-selections | |
| 281 | + | |
| 282 | + if (this.state.fieldType === 'checkbox' && props.fieldType !== 'checkbox') { | |
| 283 | + newState.choices = this.state.choices.map(function (c, i) { | |
| 284 | + c.checked = false; | |
| 285 | + return c; | |
| 286 | + }); | |
| 287 | + } | |
| 288 | + | |
| 289 | + this.setState(newState); | |
| 290 | + } | |
| 291 | + }, { | |
| 292 | + key: "addToForm", | |
| 293 | + value: function addToForm() { | |
| 294 | + var html = (0, _html.htmlgenerate)(this.state); | |
| 295 | + window.html_forms.Editor.replaceSelection(html); | |
| 296 | + } | |
| 297 | + }, { | |
| 298 | + key: "addChoice", | |
| 299 | + value: function addChoice() { | |
| 300 | + var arr = this.state.choices; | |
| 301 | + arr.push({ | |
| 302 | + checked: false, | |
| 303 | + label: '...' | |
| 304 | + }); | |
| 305 | + this.setState({ | |
| 306 | + choices: arr | |
| 307 | + }); | |
| 308 | + } | |
| 309 | + }, { | |
| 310 | + key: "deleteChoice", | |
| 311 | + value: function deleteChoice(e) { | |
| 312 | + var arr = this.state.choices; | |
| 313 | + var index = e.target.parentElement.getAttribute('data-key'); | |
| 314 | + arr.splice(index, 1); | |
| 315 | + this.setState({ | |
| 316 | + choices: arr | |
| 317 | + }); | |
| 318 | + } | |
| 319 | + }, { | |
| 320 | + key: "changeChoiceLabel", | |
| 321 | + value: function changeChoiceLabel(e) { | |
| 322 | + var arr = this.state.choices; | |
| 323 | + var index = e.target.parentElement.getAttribute('data-key'); | |
| 324 | + arr[index].label = e.target.value; | |
| 325 | + this.setState({ | |
| 326 | + choices: arr | |
| 327 | + }); | |
| 328 | + } | |
| 329 | + }, { | |
| 330 | + key: "toggleChoiceChecked", | |
| 331 | + value: function toggleChoiceChecked(e) { | |
| 332 | + var arr = this.state.choices; | |
| 333 | + var index = e.target.parentElement.getAttribute('data-key'); | |
| 334 | + arr[index].checked = !arr[index].checked; | |
| 335 | + this.setState({ | |
| 336 | + choices: arr | |
| 337 | + }); | |
| 338 | + } | |
| 339 | + }, { | |
| 340 | + key: "handleCancel", | |
| 341 | + value: function handleCancel() { | |
| 342 | + // revert back to initial state | |
| 343 | + this.setState(this.getInitialState()); | |
| 344 | + this.props.onCancel(); | |
| 345 | + } | |
| 346 | + }, { | |
| 347 | + key: "render", | |
| 348 | + value: function render(props, state) { | |
| 349 | + if (props.rows.length === 0) { | |
| 350 | + return ''; | |
| 351 | + } | |
| 352 | + | |
| 353 | + var formFields = []; | |
| 354 | + | |
| 355 | + for (var i = 0; i < props.rows.length; i++) { | |
| 356 | + switch (props.rows[i]) { | |
| 357 | + case 'label': | |
| 358 | + formFields.push((0, _preact.h)(FS.Label, { | |
| 359 | + value: state.fieldLabel, | |
| 360 | + onChange: (0, _linkstate["default"])(this, 'fieldLabel') | |
| 361 | + })); | |
| 362 | + break; | |
| 363 | + | |
| 364 | + case 'placeholder': | |
| 365 | + formFields.push((0, _preact.h)(FS.Placeholder, { | |
| 366 | + value: state.placeholder, | |
| 367 | + onChange: (0, _linkstate["default"])(this, 'placeholder') | |
| 368 | + })); | |
| 369 | + break; | |
| 370 | + | |
| 371 | + case 'default-value': | |
| 372 | + formFields.push((0, _preact.h)(FS.DefaultValue, { | |
| 373 | + value: state.value, | |
| 374 | + onChange: (0, _linkstate["default"])(this, 'value') | |
| 375 | + })); | |
| 376 | + break; | |
| 377 | + | |
| 378 | + case 'multiple': | |
| 379 | + formFields.push((0, _preact.h)(FS.Multiple, { | |
| 380 | + checked: state.multiple, | |
| 381 | + onChange: (0, _linkstate["default"])(this, 'multiple') | |
| 382 | + })); | |
| 383 | + break; | |
| 384 | + | |
| 385 | + case 'required': | |
| 386 | + formFields.push((0, _preact.h)(FS.Required, { | |
| 387 | + checked: state.required, | |
| 388 | + onChange: (0, _linkstate["default"])(this, 'required') | |
| 389 | + })); | |
| 390 | + break; | |
| 391 | + | |
| 392 | + case 'wrap': | |
| 393 | + formFields.push((0, _preact.h)(FS.Wrap, { | |
| 394 | + checked: state.wrap, | |
| 395 | + onChange: (0, _linkstate["default"])(this, 'wrap') | |
| 396 | + })); | |
| 397 | + break; | |
| 398 | + | |
| 399 | + case 'add-to-form': | |
| 400 | + formFields.push((0, _preact.h)(FS.AddToForm, { | |
| 401 | + onSubmit: this.addToForm, | |
| 402 | + onCancel: this.handleCancel | |
| 403 | + })); | |
| 404 | + break; | |
| 405 | + | |
| 406 | + case 'choices': | |
| 407 | + formFields.push((0, _preact.h)(FS.Choices, { | |
| 408 | + multiple: state.fieldType === 'checkbox', | |
| 409 | + choices: state.choices, | |
| 410 | + handlers: this.choiceHandlers | |
| 411 | + })); | |
| 412 | + break; | |
| 413 | + | |
| 414 | + case 'button-text': | |
| 415 | + formFields.push((0, _preact.h)(FS.ButtonText, { | |
| 416 | + value: state.value, | |
| 417 | + onChange: (0, _linkstate["default"])(this, 'value') | |
| 418 | + })); | |
| 419 | + break; | |
| 420 | + | |
| 421 | + case 'accept': | |
| 422 | + formFields.push((0, _preact.h)(FS.Accept, { | |
| 423 | + value: state.accept, | |
| 424 | + onChange: (0, _linkstate["default"])(this, 'accept') | |
| 425 | + })); | |
| 426 | + break; | |
| 427 | + } | |
| 428 | + } | |
| 429 | + | |
| 430 | + return (0, _preact.h)("div", { | |
| 431 | + "class": "field-config", | |
| 432 | + onKeyPress: FieldConfigurator.handleKeyPress | |
| 433 | + }, formFields); | |
| 434 | + } | |
| 435 | + }], [{ | |
| 436 | + key: "handleKeyPress", | |
| 437 | + value: function handleKeyPress(e) { | |
| 438 | + // stop RETURN from submitting the parent form. | |
| 439 | + if (e.keyCode === 13) { | |
| 440 | + e.preventDefault(); | |
| 441 | + } | |
| 442 | + } | |
| 443 | + }]); | |
| 444 | + | |
| 445 | + return FieldConfigurator; | |
| 446 | +}(_preact.Component); | |
| 447 | + | |
| 448 | +exports.FieldConfigurator = FieldConfigurator; | |
| 449 | + | |
| 450 | +},{"../field-builder/html.js":7,"./field-settings.js":5,"linkstate":19,"preact":22}],5:[function(require,module,exports){ | |
| 451 | +"use strict"; | |
| 452 | + | |
| 453 | +Object.defineProperty(exports, "__esModule", { | |
| 454 | + value: true | |
| 455 | +}); | |
| 456 | +exports.AddToForm = AddToForm; | |
| 457 | +exports.Label = Label; | |
| 458 | +exports.Placeholder = Placeholder; | |
| 459 | +exports.DefaultValue = DefaultValue; | |
| 460 | +exports.Wrap = Wrap; | |
| 461 | +exports.Required = Required; | |
| 462 | +exports.Choices = Choices; | |
| 463 | +exports.ButtonText = ButtonText; | |
| 464 | +exports.Accept = Accept; | |
| 465 | +exports.Multiple = Multiple; | |
| 466 | + | |
| 467 | +var _preact = require("preact"); | |
| 468 | + | |
| 469 | +function AddToForm(props) { | |
| 470 | + return (0, _preact.h)("div", { | |
| 471 | + "class": "hf-small-margin" | |
| 472 | + }, (0, _preact.h)("button", { | |
| 473 | + "class": "button", | |
| 474 | + type: "button", | |
| 475 | + onClick: props.onSubmit | |
| 476 | + }, "Add field to form"), " \xA0 ", (0, _preact.h)("a", { | |
| 477 | + href: "javascript:void(0);", | |
| 478 | + "class": "hf-small", | |
| 479 | + style: "vertical-align: middle;", | |
| 480 | + onClick: props.onCancel | |
| 481 | + }, "or close field helper")); | |
| 482 | +} | |
| 483 | + | |
| 484 | +function Label(props) { | |
| 485 | + return (0, _preact.h)("div", { | |
| 486 | + "class": "hf-small-margin" | |
| 487 | + }, (0, _preact.h)("label", { | |
| 488 | + "for": "hf-fg-field-label" | |
| 489 | + }, "Field label ", (0, _preact.h)("span", { | |
| 490 | + "class": "hf-required" | |
| 491 | + }, "*")), (0, _preact.h)("input", { | |
| 492 | + id: "hf-fg-field-label", | |
| 493 | + type: "text", | |
| 494 | + value: props.value, | |
| 495 | + onChange: props.onChange | |
| 496 | + })); | |
| 497 | +} | |
| 498 | + | |
| 499 | +function Placeholder(props) { | |
| 500 | + return (0, _preact.h)("div", { | |
| 501 | + "class": "hf-small-margin" | |
| 502 | + }, (0, _preact.h)("label", { | |
| 503 | + "for": "hf-fg-placeholder" | |
| 504 | + }, "Placeholder ", (0, _preact.h)("span", { | |
| 505 | + "class": "hf-italic hf-pull-right" | |
| 506 | + }, "Optional")), (0, _preact.h)("input", { | |
| 507 | + id: "hf-fg-placeholder", | |
| 508 | + type: "text", | |
| 509 | + value: props.value, | |
| 510 | + onChange: props.onChange | |
| 511 | + }), (0, _preact.h)("p", { | |
| 512 | + "class": "description" | |
| 513 | + }, "Text to show when field has no value.")); | |
| 514 | +} | |
| 515 | + | |
| 516 | +function ButtonText(props) { | |
| 517 | + return (0, _preact.h)("div", { | |
| 518 | + "class": "hf-small-margin" | |
| 519 | + }, (0, _preact.h)("label", { | |
| 520 | + "for": "hf-fg-default-value" | |
| 521 | + }, "Button text ", (0, _preact.h)("span", { | |
| 522 | + "class": "hf-required" | |
| 523 | + }, "*")), (0, _preact.h)("input", { | |
| 524 | + id: "hf-fg-default-value", | |
| 525 | + type: "text", | |
| 526 | + value: props.value, | |
| 527 | + onChange: props.onChange | |
| 528 | + }), (0, _preact.h)("p", { | |
| 529 | + "class": "description" | |
| 530 | + }, "Text to show on the button.")); | |
| 531 | +} | |
| 532 | + | |
| 533 | +function DefaultValue(props) { | |
| 534 | + return (0, _preact.h)("div", { | |
| 535 | + "class": "hf-small-margin" | |
| 536 | + }, (0, _preact.h)("label", { | |
| 537 | + "for": "hf-fg-default-value" | |
| 538 | + }, "Default value ", (0, _preact.h)("span", { | |
| 539 | + "class": "hf-italic hf-pull-right" | |
| 540 | + }, "Optional")), (0, _preact.h)("input", { | |
| 541 | + id: "hf-fg-default-value", | |
| 542 | + type: "text", | |
| 543 | + value: props.value, | |
| 544 | + onChange: props.onChange | |
| 545 | + }), (0, _preact.h)("p", { | |
| 546 | + "class": "description" | |
| 547 | + }, "Text to pre-fill this field with.")); | |
| 548 | +} | |
| 549 | + | |
| 550 | +function Multiple(props) { | |
| 551 | + return (0, _preact.h)("div", { | |
| 552 | + "class": "hf-small-margin" | |
| 553 | + }, (0, _preact.h)("label", { | |
| 554 | + "class": "inline" | |
| 555 | + }, (0, _preact.h)("input", { | |
| 556 | + type: "checkbox", | |
| 557 | + value: "1", | |
| 558 | + defaultChecked: props.checked, | |
| 559 | + onChange: props.onChange | |
| 560 | + }), "Accept multiple values.")); | |
| 561 | +} | |
| 562 | + | |
| 563 | +function Wrap(props) { | |
| 564 | + return (0, _preact.h)("div", { | |
| 565 | + "class": "hf-small-margin" | |
| 566 | + }, (0, _preact.h)("label", { | |
| 567 | + "class": "inline" | |
| 568 | + }, (0, _preact.h)("input", { | |
| 569 | + type: "checkbox", | |
| 570 | + value: "1", | |
| 571 | + defaultChecked: props.checked, | |
| 572 | + onChange: props.onChange | |
| 573 | + }), "Wrap this field in paragraph tags.")); | |
| 574 | +} | |
| 575 | + | |
| 576 | +function Required(props) { | |
| 577 | + return (0, _preact.h)("div", { | |
| 578 | + "class": "hf-small-margin" | |
| 579 | + }, (0, _preact.h)("label", { | |
| 580 | + "class": "inline" | |
| 581 | + }, (0, _preact.h)("input", { | |
| 582 | + type: "checkbox", | |
| 583 | + value: "1", | |
| 584 | + defaultChecked: props.checked, | |
| 585 | + onChange: props.onChange | |
| 586 | + }), "This field is required.")); | |
| 587 | +} | |
| 588 | + | |
| 589 | +function Choices(props) { | |
| 590 | + var choiceFields = props.choices.map(function (choice, k) { | |
| 591 | + return (0, _preact.h)("div", { | |
| 592 | + "data-key": k | |
| 593 | + }, (0, _preact.h)("input", { | |
| 594 | + type: props.multiple ? 'checkbox' : 'radio', | |
| 595 | + name: "selected", | |
| 596 | + defaultChecked: choice.checked, | |
| 597 | + onChange: props.handlers.toggleChecked, | |
| 598 | + title: "Pre-select this choice?" | |
| 599 | + }), (0, _preact.h)("input", { | |
| 600 | + type: "text", | |
| 601 | + value: choice.label, | |
| 602 | + placeholder: "Choice label", | |
| 603 | + style: "width: 80%;", | |
| 604 | + onChange: props.handlers.changeLabel | |
| 605 | + }), (0, _preact.h)("a", { | |
| 606 | + href: "javascript:void(0);", | |
| 607 | + onClick: props.handlers["delete"], | |
| 608 | + style: "text-decoration: none;", | |
| 609 | + title: "Delete choice" | |
| 610 | + }, "\u2715")); | |
| 611 | + }); | |
| 612 | + return (0, _preact.h)("div", { | |
| 613 | + "class": "hf-small-margin" | |
| 614 | + }, (0, _preact.h)("label", null, "Choices"), choiceFields, (0, _preact.h)("input", { | |
| 615 | + type: props.multiple ? 'checkbox' : 'radio', | |
| 616 | + style: "visibility: hidden;" | |
| 617 | + }), (0, _preact.h)("a", { | |
| 618 | + href: "javascript:void(0);", | |
| 619 | + onClick: props.handlers.add | |
| 620 | + }, "Add choice")); | |
| 621 | +} | |
| 622 | + | |
| 623 | +function Accept(props) { | |
| 624 | + return (0, _preact.h)("div", { | |
| 625 | + "class": "hf-small-margin" | |
| 626 | + }, (0, _preact.h)("label", null, "Accepted file types"), (0, _preact.h)("input", { | |
| 627 | + type: "text", | |
| 628 | + value: props.value, | |
| 629 | + onChange: props.onChange | |
| 630 | + }), (0, _preact.h)("p", { | |
| 631 | + "class": "description" | |
| 632 | + }, "Use a comma-separated list of accepted file extensions, eg ", (0, _preact.h)("code", null, ".pdf"), ". ", (0, _preact.h)("br", null), "Leave empty to accept any file type.")); | |
| 633 | +} | |
| 634 | + | |
| 635 | +},{"preact":22}],6:[function(require,module,exports){ | |
| 636 | +"use strict"; | |
| 637 | + | |
| 638 | +Object.defineProperty(exports, "__esModule", { | |
| 639 | + value: true | |
| 640 | +}); | |
| 641 | +exports["default"] = void 0; | |
| 642 | + | |
| 643 | +var _preact = require("preact"); | |
| 644 | + | |
| 645 | +var _fieldBuilder = require("./components/field-builder.js"); | |
| 646 | + | |
| 647 | +// imports | |
| 648 | +// vars | |
| 649 | +var rootElement; // functions | |
| 650 | + | |
| 651 | +function Field(key, label, configRows) { | |
| 652 | + this.key = key; | |
| 653 | + this.label = label; | |
| 654 | + this.configRows = configRows || []; | |
| 655 | +} | |
| 656 | + | |
| 657 | +function mount() { | |
| 658 | + rootElement = (0, _preact.render)((0, _preact.h)(_fieldBuilder.FieldBuilder, { | |
| 659 | + fields: fields | |
| 660 | + }), document.getElementById('hf-field-builder'), rootElement); | |
| 661 | +} // bootstrap | |
| 662 | + | |
| 663 | + | |
| 664 | +var fields = [new Field('text', 'Text', ['label', 'placeholder', 'default-value', 'required', 'wrap', 'add-to-form']), new Field('email', 'Email', ['label', 'placeholder', 'default-value', 'required', 'wrap', 'add-to-form']), new Field('url', 'URL', ['label', 'placeholder', 'default-value', 'required', 'wrap', 'add-to-form']), new Field('number', 'Number', ['label', 'placeholder', 'default-value', 'required', 'wrap', 'add-to-form']), new Field('date', 'Date', ['label', 'default-value', 'required', 'wrap', 'add-to-form']), new Field('textarea', 'Textarea', ['label', 'placeholder', 'default-value', 'required', 'wrap', 'add-to-form']), new Field('dropdown', 'Dropdown', ['label', 'choices', 'multiple', 'required', 'wrap', 'add-to-form']), new Field('checkbox', 'Checkboxes', ['label', 'choices', 'wrap', 'add-to-form']), new Field('radio', 'Radio buttons', ['label', 'choices', 'wrap', 'add-to-form']), new Field('submit', 'Submit button', ['button-text', 'wrap', 'add-to-form'])]; | |
| 665 | +var _default = { | |
| 666 | + init: function init() { | |
| 667 | + mount(); | |
| 668 | + }, | |
| 669 | + registerField: function registerField(key, label, configRows) { | |
| 670 | + fields.push(new Field(key, label, configRows)); | |
| 671 | + mount(); | |
| 672 | + } | |
| 673 | +}; | |
| 674 | +exports["default"] = _default; | |
| 675 | + | |
| 676 | +},{"./components/field-builder.js":3,"preact":22}],7:[function(require,module,exports){ | |
| 677 | +'use strict'; | |
| 678 | + | |
| 679 | +Object.defineProperty(exports, "__esModule", { | |
| 680 | + value: true | |
| 681 | +}); | |
| 682 | +exports.htmlgenerate = htmlgenerate; | |
| 683 | + | |
| 684 | +var _preact = require("preact"); | |
| 685 | + | |
| 686 | +var _preactRenderToString = _interopRequireDefault(require("preact-render-to-string")); | |
| 687 | + | |
| 688 | +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | |
| 689 | + | |
| 690 | +function htmlgenerate(conf) { | |
| 691 | + var fieldName = namify(conf.fieldLabel); | |
| 692 | + var fieldId = conf.formSlug + '-' + fieldName; | |
| 693 | + var label = conf.fieldLabel.length && conf.fieldType !== 'submit' ? (0, _preact.h)('label', { | |
| 694 | + "for": fieldId | |
| 695 | + }, conf.fieldLabel) : ''; | |
| 696 | + var fieldAttr, field; | |
| 697 | + | |
| 698 | + switch (conf.fieldType) { | |
| 699 | + case 'text': | |
| 700 | + default: | |
| 701 | + fieldAttr = { | |
| 702 | + type: conf.fieldType, | |
| 703 | + name: fieldName, | |
| 704 | + value: conf.value, | |
| 705 | + placeholder: conf.placeholder, | |
| 706 | + required: conf.required, | |
| 707 | + id: fieldId | |
| 708 | + }; | |
| 709 | + field = html('input', fieldAttr); | |
| 710 | + break; | |
| 711 | + | |
| 712 | + case 'textarea': | |
| 713 | + fieldAttr = { | |
| 714 | + name: fieldName, | |
| 715 | + placeholder: conf.placeholder, | |
| 716 | + required: conf.required, | |
| 717 | + id: fieldId | |
| 718 | + }; | |
| 719 | + field = html('textarea', fieldAttr, conf.value); | |
| 720 | + break; | |
| 721 | + | |
| 722 | + case 'dropdown': | |
| 723 | + fieldAttr = { | |
| 724 | + name: fieldName + (conf.multiple ? '[]' : ''), | |
| 725 | + required: conf.required, | |
| 726 | + multiple: conf.multiple, | |
| 727 | + id: fieldId | |
| 728 | + }; | |
| 729 | + field = html('select', fieldAttr, conf.choices.map(function (choice) { | |
| 730 | + return html('option', { | |
| 731 | + selected: choice.checked | |
| 732 | + }, choice.label); | |
| 733 | + })); | |
| 734 | + break; | |
| 735 | + | |
| 736 | + case 'radio': | |
| 737 | + field = conf.choices.map(function (choice) { | |
| 738 | + return html('label', {}, [html('input', { | |
| 739 | + type: 'radio', | |
| 740 | + name: fieldName, | |
| 741 | + value: choice.label, | |
| 742 | + selected: choice.checked | |
| 743 | + }), ' ', html('span', {}, choice.label)]); | |
| 744 | + }); | |
| 745 | + break; | |
| 746 | + | |
| 747 | + case 'checkbox': | |
| 748 | + field = conf.choices.map(function (choice) { | |
| 749 | + return html('label', {}, [html('input', { | |
| 750 | + type: 'checkbox', | |
| 751 | + name: fieldName + '[]', | |
| 752 | + value: choice.label, | |
| 753 | + checked: choice.checked | |
| 754 | + }), ' ', html('span', {}, choice.label)]); | |
| 755 | + }); | |
| 756 | + break; | |
| 757 | + | |
| 758 | + case 'file': | |
| 759 | + fieldAttr = { | |
| 760 | + type: 'file', | |
| 761 | + name: fieldName, | |
| 762 | + required: conf.required, | |
| 763 | + id: fieldId | |
| 764 | + }; | |
| 765 | + | |
| 766 | + if (conf.accept) { | |
| 767 | + fieldAttr.accept = conf.accept; | |
| 768 | + } | |
| 769 | + | |
| 770 | + field = html('input', fieldAttr); | |
| 771 | + break; | |
| 772 | + | |
| 773 | + case 'submit': | |
| 774 | + fieldAttr = { | |
| 775 | + type: 'submit', | |
| 776 | + value: conf.value | |
| 777 | + }; | |
| 778 | + field = html('input', fieldAttr); | |
| 779 | + break; | |
| 780 | + } | |
| 781 | + | |
| 782 | + var str = ''; | |
| 783 | + | |
| 784 | + if (conf.wrap) { | |
| 785 | + var children = label !== '' ? ['\n\t', label, '\n\t', field, '\n'] : ['\n\t', field, '\n']; | |
| 786 | + var tmpl = (0, _preact.h)('p', {}, children); | |
| 787 | + str = renderToString(tmpl); | |
| 788 | + } else { | |
| 789 | + var _children = label !== '' ? [label, '\n', field] : [field]; | |
| 790 | + | |
| 791 | + str = renderToString(_children); | |
| 792 | + } | |
| 793 | + | |
| 794 | + return str; | |
| 795 | +} | |
| 796 | + | |
| 797 | +function renderToString(vdom) { | |
| 798 | + return (0, _preactRenderToString["default"])(vdom, { | |
| 799 | + pretty: true | |
| 800 | + }); | |
| 801 | +} | |
| 802 | + | |
| 803 | +function html(tag, attr, children) { | |
| 804 | + attr = filterEmptyObjectValues(attr); | |
| 805 | + return (0, _preact.h)(tag, attr, children); | |
| 806 | +} | |
| 807 | + | |
| 808 | +function namify(str) { | |
| 809 | + return str.replace(/ /g, '_').replace(/[^\w[\]_]*/g, '').toUpperCase(); | |
| 810 | +} | |
| 811 | + | |
| 812 | +function filterEmptyObjectValues(obj) { | |
| 813 | + var newObj = {}; | |
| 814 | + | |
| 815 | + for (var propName in obj) { | |
| 816 | + if (obj[propName] !== false && obj[propName] !== '') { | |
| 817 | + newObj[propName] = obj[propName]; | |
| 818 | + } | |
| 819 | + } | |
| 820 | + | |
| 821 | + return newObj; | |
| 822 | +} | |
| 823 | + | |
| 824 | +},{"preact":22,"preact-render-to-string":21}],8:[function(require,module,exports){ | |
| 825 | +"use strict"; | |
| 826 | + | |
| 827 | +Object.defineProperty(exports, "__esModule", { | |
| 828 | + value: true | |
| 829 | +}); | |
| 830 | +exports["default"] = void 0; | |
| 831 | +var availableActions, actionTemplates, actions; | |
| 832 | + | |
| 833 | +function init() { | |
| 834 | + actions = document.getElementById('hf-form-actions'); | |
| 835 | + availableActions = document.getElementById('hf-available-form-actions'); | |
| 836 | + actionTemplates = document.getElementById('hf-form-action-templates'); // turn settings into accordions | |
| 837 | + | |
| 838 | + [].forEach.call(actions.querySelectorAll('.hf-action-settings'), function (el) { | |
| 839 | + el.parentNode.removeChild(el); | |
| 840 | + var heading = el.getAttribute('data-title'); | |
| 841 | + var summary = el.querySelector('.hf-action-summary'); | |
| 842 | + | |
| 843 | + if (summary) { | |
| 844 | + heading += ' — <span class="hf-muted">' + summary.innerHTML + '</span>'; | |
| 845 | + } | |
| 846 | + | |
| 847 | + var wrap = createAccordion(heading, el.innerHTML); | |
| 848 | + actions.appendChild(wrap); | |
| 849 | + actions.querySelector('#hf-form-actions-empty').style.display = 'none'; | |
| 850 | + }); | |
| 851 | + availableActions.addEventListener('click', addAction, true); | |
| 852 | +} | |
| 853 | + | |
| 854 | +function createAccordion(headingHTML, contentHTML) { | |
| 855 | + var wrap = document.createElement('div'); | |
| 856 | + wrap.className = 'hf-accordion expanded '; | |
| 857 | + var heading = document.createElement('h4'); | |
| 858 | + heading.className = 'hf-accordion-heading'; | |
| 859 | + heading.innerHTML = headingHTML; | |
| 860 | + wrap.appendChild(heading); | |
| 861 | + var content = document.createElement('div'); | |
| 862 | + content.className = 'hf-accordion-content'; | |
| 863 | + content.innerHTML = contentHTML; | |
| 864 | + wrap.appendChild(content); | |
| 865 | + var deleteWrap = document.createElement('p'); | |
| 866 | + deleteWrap.style.textAlign = 'right'; | |
| 867 | + var deleteLink = document.createElement('a'); | |
| 868 | + deleteLink.href = 'javascript:void(0);'; | |
| 869 | + deleteLink.className = 'danger'; | |
| 870 | + deleteLink.innerText = 'Delete this action'; | |
| 871 | + deleteWrap.appendChild(deleteLink); | |
| 872 | + content.appendChild(deleteWrap); // bind handlers | |
| 873 | + | |
| 874 | + heading.addEventListener('click', createToggleActionHandler(wrap, content)); | |
| 875 | + deleteLink.addEventListener('click', createDeleteActionHandler(wrap)); | |
| 876 | + return wrap; | |
| 877 | +} | |
| 878 | + | |
| 879 | +function addAction(e) { | |
| 880 | + var el = e.target || e.srcElement; | |
| 881 | + | |
| 882 | + if (el.tagName !== 'INPUT') { | |
| 883 | + return; | |
| 884 | + } | |
| 885 | + | |
| 886 | + var actionType = el.getAttribute('data-action-type'); | |
| 887 | + var actionTemplate = actionTemplates.querySelector("#hf-action-type-".concat(actionType, "-template")); // append HTML to actions wrapper | |
| 888 | + | |
| 889 | + var index = actions.querySelectorAll('div').length - 1; | |
| 890 | + var wrap = createAccordion(el.value, actionTemplate.innerHTML.replace(/\$index/g, index)); | |
| 891 | + actions.appendChild(wrap); // hide "no form actions" message | |
| 892 | + | |
| 893 | + actions.querySelector('#hf-form-actions-empty').style.display = 'none'; | |
| 894 | + window.html_forms.Editor.updateFieldVariables(); | |
| 895 | +} | |
| 896 | + | |
| 897 | +function createDeleteActionHandler(wrap) { | |
| 898 | + return function () { | |
| 899 | + actions.removeChild(wrap); | |
| 900 | + | |
| 901 | + if (actions.childElementCount === 1) { | |
| 902 | + actions.querySelector('#hf-form-actions-empty').style.display = ''; | |
| 903 | + } | |
| 904 | + }; | |
| 905 | +} | |
| 906 | + | |
| 907 | +function createToggleActionHandler(wrap, content) { | |
| 908 | + return function () { | |
| 909 | + var show = content.offsetParent === null; | |
| 910 | + wrap.className = wrap.className.replace('expanded', '') + (show ? ' expanded' : ''); | |
| 911 | + content.style.display = show ? 'block' : 'none'; | |
| 912 | + }; | |
| 913 | +} | |
| 914 | + | |
| 915 | +var _default = { | |
| 916 | + init: init | |
| 917 | +}; | |
| 918 | +exports["default"] = _default; | |
| 919 | + | |
| 920 | +},{}],9:[function(require,module,exports){ | |
| 921 | +"use strict"; | |
| 922 | + | |
| 923 | +Object.defineProperty(exports, "__esModule", { | |
| 924 | + value: true | |
| 925 | +}); | |
| 926 | +exports["default"] = void 0; | |
| 927 | + | |
| 928 | +// load CodeMirror & plugins | |
| 929 | +var CodeMirror = require('codemirror'); | |
| 930 | + | |
| 931 | +require('codemirror/mode/xml/xml'); | |
| 932 | + | |
| 933 | +require('codemirror/mode/javascript/javascript'); | |
| 934 | + | |
| 935 | +require('codemirror/mode/css/css'); | |
| 936 | + | |
| 937 | +require('codemirror/mode/htmlmixed/htmlmixed'); | |
| 938 | + | |
| 939 | +require('codemirror/addon/fold/xml-fold'); | |
| 940 | + | |
| 941 | +require('codemirror/addon/edit/matchtags'); | |
| 942 | + | |
| 943 | +require('codemirror/addon/edit/closetag.js'); | |
| 944 | + | |
| 945 | +var editor, element, dom, requiredFieldsInput, emailFieldsInput, previewFrame, previewDom; | |
| 946 | +var templateRegex = /\{\{ *(\w+)(?:\.([\w.]+))? *(?:\|\| *(\w+))? *\}\}/g; | |
| 947 | + | |
| 948 | +function init() { | |
| 949 | + previewFrame = document.getElementById('hf-form-preview'); | |
| 950 | + element = document.getElementById('hf-form-editor'); | |
| 951 | + dom = document.createElement('form'); | |
| 952 | + requiredFieldsInput = document.getElementById('hf-required-fields'); | |
| 953 | + emailFieldsInput = document.getElementById('hf-email-fields'); | |
| 954 | + dom.innerHTML = element.value; | |
| 955 | + editor = CodeMirror.fromTextArea(element, { | |
| 956 | + selectionPointer: true, | |
| 957 | + matchTags: { | |
| 958 | + bothTags: true | |
| 959 | + }, | |
| 960 | + mode: 'htmlmixed', | |
| 961 | + htmlMode: true, | |
| 962 | + autoCloseTags: true, | |
| 963 | + autoRefresh: true, | |
| 964 | + styleActiveLine: true, | |
| 965 | + matchBrackets: true | |
| 966 | + }); | |
| 967 | + editor.on('changes', debounce(updatePreview, 500)); | |
| 968 | + editor.on('changes', debounce(updateShadowDOM, 100)); | |
| 969 | + editor.on('changes', debounce(updateFieldVariables, 500)); | |
| 970 | + editor.on('blur', updatePreview); | |
| 971 | + editor.on('blur', updateShadowDOM); | |
| 972 | + editor.on('blur', updateFieldVariables); | |
| 973 | + editor.on('blur', updateRequiredFields); | |
| 974 | + editor.on('blur', updateEmailFields); | |
| 975 | + previewFrame.addEventListener('load', setPreviewDom); | |
| 976 | + setPreviewDom(); | |
| 977 | + updateFieldVariables(); | |
| 978 | + document.getElementById('hf-tabs-nav').addEventListener('click', function () { | |
| 979 | + editor.refresh(); | |
| 980 | + }); | |
| 981 | + window.addEventListener('load', updateFieldVariables); | |
| 982 | +} | |
| 983 | + | |
| 984 | +function setPreviewDom() { | |
| 985 | + var frameContent = previewFrame.contentDocument || previewFrame.contentWindow.document; | |
| 986 | + previewDom = frameContent.querySelector('.hf-fields-wrap'); | |
| 987 | + | |
| 988 | + if (previewDom) { | |
| 989 | + updatePreview(); | |
| 990 | + } | |
| 991 | +} | |
| 992 | + | |
| 993 | +function getFieldVariableName(f) { | |
| 994 | + return f.name.replace('[]', '').replace(/\[(\w+)\]/g, '.$1'); | |
| 995 | +} | |
| 996 | + | |
| 997 | +function updateFieldVariables() { | |
| 998 | + var fields = dom.querySelectorAll('input[name], select[name], textarea[name], button[name]'); | |
| 999 | + var fieldVariables = uniq([].map.call(fields, function (f) { | |
| 1000 | + return '[' + getFieldVariableName(f) + ']'; | |
| 1001 | + })); | |
| 1002 | + var wpbody = document.getElementById('wpbody-content'); | |
| 1003 | + [].forEach.call(document.querySelectorAll('.hf-field-names'), function (el) { | |
| 1004 | + // remove existing variables | |
| 1005 | + while (el.firstChild) { | |
| 1006 | + el.removeChild(el.firstChild); | |
| 1007 | + } | |
| 1008 | + | |
| 1009 | + var variableElements = fieldVariables.map(function (n) { | |
| 1010 | + // measure width of actual font size for prettiness | |
| 1011 | + var sizeEl = document.createElement('span'); | |
| 1012 | + sizeEl.style.visibility = 'hidden'; | |
| 1013 | + sizeEl.innerText = n; | |
| 1014 | + wpbody.appendChild(sizeEl); | |
| 1015 | + var width = sizeEl.offsetWidth; | |
| 1016 | + wpbody.removeChild(sizeEl); // add input el | |
| 1017 | + | |
| 1018 | + var el = document.createElement('input'); | |
| 1019 | + el.type = 'text'; | |
| 1020 | + el.style.maxWidth = Math.ceil(width * 1.1 + 14) + 'px'; | |
| 1021 | + el.value = n; | |
| 1022 | + el.readonly = true; | |
| 1023 | + | |
| 1024 | + el.onfocus = function () { | |
| 1025 | + return el.select(); | |
| 1026 | + }; | |
| 1027 | + | |
| 1028 | + return el; | |
| 1029 | + }); | |
| 1030 | + variableElements.forEach(function (vel, i, arr) { | |
| 1031 | + el.appendChild(vel); | |
| 1032 | + }); | |
| 1033 | + }); | |
| 1034 | +} | |
| 1035 | + | |
| 1036 | +function updatePreview() { | |
| 1037 | + var markup = editor.getValue(); // replace template tags | |
| 1038 | + | |
| 1039 | + markup = markup.replace(templateRegex, function (s, m) { | |
| 1040 | + // if a default value was provided, use that | |
| 1041 | + if (arguments[3]) { | |
| 1042 | + return arguments[3]; | |
| 1043 | + } | |
| 1044 | + | |
| 1045 | + return ''; | |
| 1046 | + }); // update dom | |
| 1047 | + | |
| 1048 | + previewDom.innerHTML = markup; | |
| 1049 | + previewDom.dispatchEvent(new Event('hf-refresh')); | |
| 1050 | +} | |
| 1051 | + | |
| 1052 | +function updateShadowDOM() { | |
| 1053 | + dom.innerHTML = editor.getValue(); | |
| 1054 | +} // PHP Does not allow spaces in the field name, yet HTML & HTTP spec does | |
| 1055 | +// So here we are preparing the field name so we can use it without issues in PHP | |
| 1056 | + | |
| 1057 | + | |
| 1058 | +function normalizeFieldName(name) { | |
| 1059 | + return name.replace(' ', '_'); | |
| 1060 | +} | |
| 1061 | + | |
| 1062 | +function updateRequiredFields() { | |
| 1063 | + var fields = dom.querySelectorAll('[required]'); | |
| 1064 | + var fieldNames = [].map.call(fields, getFieldVariableName).map(normalizeFieldName); | |
| 1065 | + requiredFieldsInput.value = fieldNames.join(','); | |
| 1066 | +} | |
| 1067 | + | |
| 1068 | +function updateEmailFields() { | |
| 1069 | + var fields = dom.querySelectorAll('input[type="email"]'); | |
| 1070 | + var fieldNames = [].map.call(fields, getFieldVariableName).map(normalizeFieldName); | |
| 1071 | + emailFieldsInput.value = fieldNames.join(','); | |
| 1072 | +} | |
| 1073 | + | |
| 1074 | +function replaceSelection(str) { | |
| 1075 | + editor.replaceSelection(str); | |
| 1076 | + editor.focus(); | |
| 1077 | +} | |
| 1078 | + | |
| 1079 | +function debounce(func, wait, immediate) { | |
| 1080 | + var timeout; | |
| 1081 | + return function () { | |
| 1082 | + var context = this; | |
| 1083 | + var args = arguments; | |
| 1084 | + | |
| 1085 | + var later = function later() { | |
| 1086 | + timeout = null; | |
| 1087 | + if (!immediate) func.apply(context, args); | |
| 1088 | + }; | |
| 1089 | + | |
| 1090 | + var callNow = immediate && !timeout; | |
| 1091 | + clearTimeout(timeout); | |
| 1092 | + timeout = setTimeout(later, wait); | |
| 1093 | + if (callNow) func.apply(context, args); | |
| 1094 | + }; | |
| 1095 | +} | |
| 1096 | + | |
| 1097 | +; | |
| 1098 | + | |
| 1099 | +function uniq(a) { | |
| 1100 | + var seen = {}; | |
| 1101 | + return a.filter(function (item) { | |
| 1102 | + return seen.hasOwnProperty(item) ? false : seen[item] = true; | |
| 1103 | + }); | |
| 1104 | +} | |
| 1105 | + | |
| 1106 | +var _default = { | |
| 1107 | + init: init, | |
| 1108 | + replaceSelection: replaceSelection, | |
| 1109 | + updateFieldVariables: updateFieldVariables | |
| 1110 | +}; | |
| 1111 | +exports["default"] = _default; | |
| 1112 | + | |
| 1113 | +},{"codemirror":14,"codemirror/addon/edit/closetag.js":11,"codemirror/addon/edit/matchtags":12,"codemirror/addon/fold/xml-fold":13,"codemirror/mode/css/css":15,"codemirror/mode/htmlmixed/htmlmixed":16,"codemirror/mode/javascript/javascript":17,"codemirror/mode/xml/xml":18}],10:[function(require,module,exports){ | |
| 1114 | +"use strict"; | |
| 1115 | + | |
| 1116 | +Object.defineProperty(exports, "__esModule", { | |
| 1117 | + value: true | |
| 1118 | +}); | |
| 1119 | +exports["default"] = void 0; | |
| 1120 | +var tabs, tabNavs; | |
| 1121 | + | |
| 1122 | +function init() { | |
| 1123 | + tabs = document.querySelectorAll('.hf-tab'); | |
| 1124 | + tabNavs = document.querySelectorAll('#hf-tabs-nav a'); | |
| 1125 | + | |
| 1126 | + for (var i = 0; i < tabNavs.length; i++) { | |
| 1127 | + tabNavs[i].addEventListener('click', open); | |
| 1128 | + } | |
| 1129 | +} | |
| 1130 | + | |
| 1131 | +function open(e) { | |
| 1132 | + var tabTarget = this.getAttribute('data-tab-target'); | |
| 1133 | + | |
| 1134 | + for (var i = 0; i < tabNavs.length; i++) { | |
| 1135 | + tabNavs[i].classList.toggle('nav-tab-active', tabNavs[i] === this); | |
| 1136 | + } | |
| 1137 | + | |
| 1138 | + this.blur(); | |
| 1139 | + | |
| 1140 | + for (var _i = 0; _i < tabs.length; _i++) { | |
| 1141 | + var tab = tabs[_i]; | |
| 1142 | + tab.classList.toggle('hf-tab-active', tab.getAttribute('data-tab') === tabTarget); | |
| 1143 | + } | |
| 1144 | + | |
| 1145 | + document.title = document.title.replace(document.title.split(' - ').shift(), this.innerText + ' '); | |
| 1146 | + | |
| 1147 | + if (window.history) { | |
| 1148 | + var newUrl = window.location.href; | |
| 1149 | + newUrl = newUrl.replace(/&tab=\w+/, ''); | |
| 1150 | + newUrl += '&tab=' + tabTarget; | |
| 1151 | + window.history.replaceState({ | |
| 1152 | + tab: tabTarget | |
| 1153 | + }, document.title, newUrl); | |
| 1154 | + } | |
| 1155 | + | |
| 1156 | + e.preventDefault(); | |
| 1157 | +} | |
| 1158 | + | |
| 1159 | +var _default = { | |
| 1160 | + init: init, | |
| 1161 | + open: open | |
| 1162 | +}; | |
| 1163 | +exports["default"] = _default; | |
| 1164 | + | |
| 1165 | +},{}],11:[function(require,module,exports){ | |
| 1166 | +// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
| 1167 | +// Distributed under an MIT license: https://codemirror.net/LICENSE | |
| 1168 | + | |
| 1169 | +/** | |
| 1170 | + * Tag-closer extension for CodeMirror. | |
| 1171 | + * | |
| 1172 | + * This extension adds an "autoCloseTags" option that can be set to | |
| 1173 | + * either true to get the default behavior, or an object to further | |
| 1174 | + * configure its behavior. | |
| 1175 | + * | |
| 1176 | + * These are supported options: | |
| 1177 | + * | |
| 1178 | + * `whenClosing` (default true) | |
| 1179 | + * Whether to autoclose when the '/' of a closing tag is typed. | |
| 1180 | + * `whenOpening` (default true) | |
| 1181 | + * Whether to autoclose the tag when the final '>' of an opening | |
| 1182 | + * tag is typed. | |
| 1183 | + * `dontCloseTags` (default is empty tags for HTML, none for XML) | |
| 1184 | + * An array of tag names that should not be autoclosed. | |
| 1185 | + * `indentTags` (default is block tags for HTML, none for XML) | |
| 1186 | + * An array of tag names that should, when opened, cause a | |
| 1187 | + * blank line to be added inside the tag, and the blank line and | |
| 1188 | + * closing line to be indented. | |
| 1189 | + * `emptyTags` (default is none) | |
| 1190 | + * An array of XML tag names that should be autoclosed with '/>'. | |
| 1191 | + * | |
| 1192 | + * See demos/closetag.html for a usage example. | |
| 1193 | + */ | |
| 1194 | + | |
| 1195 | +(function(mod) { | |
| 1196 | + if (typeof exports == "object" && typeof module == "object") // CommonJS | |
| 1197 | + mod(require("../../lib/codemirror"), require("../fold/xml-fold")); | |
| 1198 | + else if (typeof define == "function" && define.amd) // AMD | |
| 1199 | + define(["../../lib/codemirror", "../fold/xml-fold"], mod); | |
| 1200 | + else // Plain browser env | |
| 1201 | + mod(CodeMirror); | |
| 1202 | +})(function(CodeMirror) { | |
| 1203 | + CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) { | |
| 1204 | + if (old != CodeMirror.Init && old) | |
| 1205 | + cm.removeKeyMap("autoCloseTags"); | |
| 1206 | + if (!val) return; | |
| 1207 | + var map = {name: "autoCloseTags"}; | |
| 1208 | + if (typeof val != "object" || val.whenClosing !== false) | |
| 1209 | + map["'/'"] = function(cm) { return autoCloseSlash(cm); }; | |
| 1210 | + if (typeof val != "object" || val.whenOpening !== false) | |
| 1211 | + map["'>'"] = function(cm) { return autoCloseGT(cm); }; | |
| 1212 | + cm.addKeyMap(map); | |
| 1213 | + }); | |
| 1214 | + | |
| 1215 | + var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", | |
| 1216 | + "source", "track", "wbr"]; | |
| 1217 | + var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4", | |
| 1218 | + "h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"]; | |
| 1219 | + | |
| 1220 | + function autoCloseGT(cm) { | |
| 1221 | + if (cm.getOption("disableInput")) return CodeMirror.Pass; | |
| 1222 | + var ranges = cm.listSelections(), replacements = []; | |
| 1223 | + var opt = cm.getOption("autoCloseTags"); | |
| 1224 | + for (var i = 0; i < ranges.length; i++) { | |
| 1225 | + if (!ranges[i].empty()) return CodeMirror.Pass; | |
| 1226 | + var pos = ranges[i].head, tok = cm.getTokenAt(pos); | |
| 1227 | + var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state; | |
| 1228 | + var tagInfo = inner.mode.xmlCurrentTag && inner.mode.xmlCurrentTag(state) | |
| 1229 | + var tagName = tagInfo && tagInfo.name | |
| 1230 | + if (!tagName) return CodeMirror.Pass | |
| 1231 | + | |
| 1232 | + var html = inner.mode.configuration == "html"; | |
| 1233 | + var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose); | |
| 1234 | + var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent); | |
| 1235 | + | |
| 1236 | + if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch); | |
| 1237 | + var lowerTagName = tagName.toLowerCase(); | |
| 1238 | + // Don't process the '>' at the end of an end-tag or self-closing tag | |
| 1239 | + if (!tagName || | |
| 1240 | + tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) || | |
| 1241 | + tok.type == "tag" && tagInfo.close || | |
| 1242 | + tok.string.indexOf("/") == (pos.ch - tok.start - 1) || // match something like <someTagName /> | |
| 1243 | + dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 || | |
| 1244 | + closingTagExists(cm, inner.mode.xmlCurrentContext && inner.mode.xmlCurrentContext(state) || [], tagName, pos, true)) | |
| 1245 | + return CodeMirror.Pass; | |
| 1246 | + | |
| 1247 | + var emptyTags = typeof opt == "object" && opt.emptyTags; | |
| 1248 | + if (emptyTags && indexOf(emptyTags, tagName) > -1) { | |
| 1249 | + replacements[i] = { text: "/>", newPos: CodeMirror.Pos(pos.line, pos.ch + 2) }; | |
| 1250 | + continue; | |
| 1251 | + } | |
| 1252 | + | |
| 1253 | + var indent = indentTags && indexOf(indentTags, lowerTagName) > -1; | |
| 1254 | + replacements[i] = {indent: indent, | |
| 1255 | + text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">", | |
| 1256 | + newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1)}; | |
| 1257 | + } | |
| 1258 | + | |
| 1259 | + var dontIndentOnAutoClose = (typeof opt == "object" && opt.dontIndentOnAutoClose); | |
| 1260 | + for (var i = ranges.length - 1; i >= 0; i--) { | |
| 1261 | + var info = replacements[i]; | |
| 1262 | + cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert"); | |
| 1263 | + var sel = cm.listSelections().slice(0); | |
| 1264 | + sel[i] = {head: info.newPos, anchor: info.newPos}; | |
| 1265 | + cm.setSelections(sel); | |
| 1266 | + if (!dontIndentOnAutoClose && info.indent) { | |
| 1267 | + cm.indentLine(info.newPos.line, null, true); | |
| 1268 | + cm.indentLine(info.newPos.line + 1, null, true); | |
| 1269 | + } | |
| 1270 | + } | |
| 1271 | + } | |
| 1272 | + | |
| 1273 | + function autoCloseCurrent(cm, typingSlash) { | |
| 1274 | + var ranges = cm.listSelections(), replacements = []; | |
| 1275 | + var head = typingSlash ? "/" : "</"; | |
| 1276 | + var opt = cm.getOption("autoCloseTags"); | |
| 1277 | + var dontIndentOnAutoClose = (typeof opt == "object" && opt.dontIndentOnSlash); | |
| 1278 | + for (var i = 0; i < ranges.length; i++) { | |
| 1279 | + if (!ranges[i].empty()) return CodeMirror.Pass; | |
| 1280 | + var pos = ranges[i].head, tok = cm.getTokenAt(pos); | |
| 1281 | + var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state; | |
| 1282 | + if (typingSlash && (tok.type == "string" || tok.string.charAt(0) != "<" || | |
| 1283 | + tok.start != pos.ch - 1)) | |
| 1284 | + return CodeMirror.Pass; | |
| 1285 | + // Kludge to get around the fact that we are not in XML mode | |
| 1286 | + // when completing in JS/CSS snippet in htmlmixed mode. Does not | |
| 1287 | + // work for other XML embedded languages (there is no general | |
| 1288 | + // way to go from a mixed mode to its current XML state). | |
| 1289 | + var replacement, mixed = inner.mode.name != "xml" && cm.getMode().name == "htmlmixed" | |
| 1290 | + if (mixed && inner.mode.name == "javascript") { | |
| 1291 | + replacement = head + "script"; | |
| 1292 | + } else if (mixed && inner.mode.name == "css") { | |
| 1293 | + replacement = head + "style"; | |
| 1294 | + } else { | |
| 1295 | + var context = inner.mode.xmlCurrentContext && inner.mode.xmlCurrentContext(state) | |
| 1296 | + var top = context.length ? context[context.length - 1] : "" | |
| 1297 | + if (!context || (context.length && closingTagExists(cm, context, top, pos))) | |
| 1298 | + return CodeMirror.Pass; | |
| 1299 | + replacement = head + top | |
| 1300 | + } | |
| 1301 | + if (cm.getLine(pos.line).charAt(tok.end) != ">") replacement += ">"; | |
| 1302 | + replacements[i] = replacement; | |
| 1303 | + } | |
| 1304 | + cm.replaceSelections(replacements); | |
| 1305 | + ranges = cm.listSelections(); | |
| 1306 | + if (!dontIndentOnAutoClose) { | |
| 1307 | + for (var i = 0; i < ranges.length; i++) | |
| 1308 | + if (i == ranges.length - 1 || ranges[i].head.line < ranges[i + 1].head.line) | |
| 1309 | + cm.indentLine(ranges[i].head.line); | |
| 1310 | + } | |
| 1311 | + } | |
| 1312 | + | |
| 1313 | + function autoCloseSlash(cm) { | |
| 1314 | + if (cm.getOption("disableInput")) return CodeMirror.Pass; | |
| 1315 | + return autoCloseCurrent(cm, true); | |
| 1316 | + } | |
| 1317 | + | |
| 1318 | + CodeMirror.commands.closeTag = function(cm) { return autoCloseCurrent(cm); }; | |
| 1319 | + | |
| 1320 | + function indexOf(collection, elt) { | |
| 1321 | + if (collection.indexOf) return collection.indexOf(elt); | |
| 1322 | + for (var i = 0, e = collection.length; i < e; ++i) | |
| 1323 | + if (collection[i] == elt) return i; | |
| 1324 | + return -1; | |
| 1325 | + } | |
| 1326 | + | |
| 1327 | + // If xml-fold is loaded, we use its functionality to try and verify | |
| 1328 | + // whether a given tag is actually unclosed. | |
| 1329 | + function closingTagExists(cm, context, tagName, pos, newTag) { | |
| 1330 | + if (!CodeMirror.scanForClosingTag) return false; | |
| 1331 | + var end = Math.min(cm.lastLine() + 1, pos.line + 500); | |
| 1332 | + var nextClose = CodeMirror.scanForClosingTag(cm, pos, null, end); | |
| 1333 | + if (!nextClose || nextClose.tag != tagName) return false; | |
| 1334 | + // If the immediate wrapping context contains onCx instances of | |
| 1335 | + // the same tag, a closing tag only exists if there are at least | |
| 1336 | + // that many closing tags of that type following. | |
| 1337 | + var onCx = newTag ? 1 : 0 | |
| 1338 | + for (var i = context.length - 1; i >= 0; i--) { | |
| 1339 | + if (context[i] == tagName) ++onCx | |
| 1340 | + else break | |
| 1341 | + } | |
| 1342 | + pos = nextClose.to; | |
| 1343 | + for (var i = 1; i < onCx; i++) { | |
| 1344 | + var next = CodeMirror.scanForClosingTag(cm, pos, null, end); | |
| 1345 | + if (!next || next.tag != tagName) return false; | |
| 1346 | + pos = next.to; | |
| 1347 | + } | |
| 1348 | + return true; | |
| 1349 | + } | |
| 1350 | +}); | |
| 1351 | + | |
| 1352 | +},{"../../lib/codemirror":14,"../fold/xml-fold":13}],12:[function(require,module,exports){ | |
| 1353 | +// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
| 1354 | +// Distributed under an MIT license: https://codemirror.net/LICENSE | |
| 1355 | + | |
| 1356 | +(function(mod) { | |
| 1357 | + if (typeof exports == "object" && typeof module == "object") // CommonJS | |
| 1358 | + mod(require("../../lib/codemirror"), require("../fold/xml-fold")); | |
| 1359 | + else if (typeof define == "function" && define.amd) // AMD | |
| 1360 | + define(["../../lib/codemirror", "../fold/xml-fold"], mod); | |
| 1361 | + else // Plain browser env | |
| 1362 | + mod(CodeMirror); | |
| 1363 | +})(function(CodeMirror) { | |
| 1364 | + "use strict"; | |
| 1365 | + | |
| 1366 | + CodeMirror.defineOption("matchTags", false, function(cm, val, old) { | |
| 1367 | + if (old && old != CodeMirror.Init) { | |
| 1368 | + cm.off("cursorActivity", doMatchTags); | |
| 1369 | + cm.off("viewportChange", maybeUpdateMatch); | |
| 1370 | + clear(cm); | |
| 1371 | + } | |
| 1372 | + if (val) { | |
| 1373 | + cm.state.matchBothTags = typeof val == "object" && val.bothTags; | |
| 1374 | + cm.on("cursorActivity", doMatchTags); | |
| 1375 | + cm.on("viewportChange", maybeUpdateMatch); | |
| 1376 | + doMatchTags(cm); | |
| 1377 | + } | |
| 1378 | + }); | |
| 1379 | + | |
| 1380 | + function clear(cm) { | |
| 1381 | + if (cm.state.tagHit) cm.state.tagHit.clear(); | |
| 1382 | + if (cm.state.tagOther) cm.state.tagOther.clear(); | |
| 1383 | + cm.state.tagHit = cm.state.tagOther = null; | |
| 1384 | + } | |
| 1385 | + | |
| 1386 | + function doMatchTags(cm) { | |
| 1387 | + cm.state.failedTagMatch = false; | |
| 1388 | + cm.operation(function() { | |
| 1389 | + clear(cm); | |
| 1390 | + if (cm.somethingSelected()) return; | |
| 1391 | + var cur = cm.getCursor(), range = cm.getViewport(); | |
| 1392 | + range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to); | |
| 1393 | + var match = CodeMirror.findMatchingTag(cm, cur, range); | |
| 1394 | + if (!match) return; | |
| 1395 | + if (cm.state.matchBothTags) { | |
| 1396 | + var hit = match.at == "open" ? match.open : match.close; | |
| 1397 | + if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, {className: "CodeMirror-matchingtag"}); | |
| 1398 | + } | |
| 1399 | + var other = match.at == "close" ? match.open : match.close; | |
| 1400 | + if (other) | |
| 1401 | + cm.state.tagOther = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"}); | |
| 1402 | + else | |
| 1403 | + cm.state.failedTagMatch = true; | |
| 1404 | + }); | |
| 1405 | + } | |
| 1406 | + | |
| 1407 | + function maybeUpdateMatch(cm) { | |
| 1408 | + if (cm.state.failedTagMatch) doMatchTags(cm); | |
| 1409 | + } | |
| 1410 | + | |
| 1411 | + CodeMirror.commands.toMatchingTag = function(cm) { | |
| 1412 | + var found = CodeMirror.findMatchingTag(cm, cm.getCursor()); | |
| 1413 | + if (found) { | |
| 1414 | + var other = found.at == "close" ? found.open : found.close; | |
| 1415 | + if (other) cm.extendSelection(other.to, other.from); | |
| 1416 | + } | |
| 1417 | + }; | |
| 1418 | +}); | |
| 1419 | + | |
| 1420 | +},{"../../lib/codemirror":14,"../fold/xml-fold":13}],13:[function(require,module,exports){ | |
| 1421 | +// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
| 1422 | +// Distributed under an MIT license: https://codemirror.net/LICENSE | |
| 1423 | + | |
| 1424 | +(function(mod) { | |
| 1425 | + if (typeof exports == "object" && typeof module == "object") // CommonJS | |
| 1426 | + mod(require("../../lib/codemirror")); | |
| 1427 | + else if (typeof define == "function" && define.amd) // AMD | |
| 1428 | + define(["../../lib/codemirror"], mod); | |
| 1429 | + else // Plain browser env | |
| 1430 | + mod(CodeMirror); | |
| 1431 | +})(function(CodeMirror) { | |
| 1432 | + "use strict"; | |
| 1433 | + | |
| 1434 | + var Pos = CodeMirror.Pos; | |
| 1435 | + function cmp(a, b) { return a.line - b.line || a.ch - b.ch; } | |
| 1436 | + | |
| 1437 | + var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD"; | |
| 1438 | + var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040"; | |
| 1439 | + var xmlTagStart = new RegExp("<(/?)([" + nameStartChar + "][" + nameChar + "]*)", "g"); | |
| 1440 | + | |
| 1441 | + function Iter(cm, line, ch, range) { | |
| 1442 | + this.line = line; this.ch = ch; | |
| 1443 | + this.cm = cm; this.text = cm.getLine(line); | |
| 1444 | + this.min = range ? Math.max(range.from, cm.firstLine()) : cm.firstLine(); | |
| 1445 | + this.max = range ? Math.min(range.to - 1, cm.lastLine()) : cm.lastLine(); | |
| 1446 | + } | |
| 1447 | + | |
| 1448 | + function tagAt(iter, ch) { | |
| 1449 | + var type = iter.cm.getTokenTypeAt(Pos(iter.line, ch)); | |
| 1450 | + return type && /\btag\b/.test(type); | |
| 1451 | + } | |
| 1452 | + | |
| 1453 | + function nextLine(iter) { | |
| 1454 | + if (iter.line >= iter.max) return; | |
| 1455 | + iter.ch = 0; | |
| 1456 | + iter.text = iter.cm.getLine(++iter.line); | |
| 1457 | + return true; | |
| 1458 | + } | |
| 1459 | + function prevLine(iter) { | |
| 1460 | + if (iter.line <= iter.min) return; | |
| 1461 | + iter.text = iter.cm.getLine(--iter.line); | |
| 1462 | + iter.ch = iter.text.length; | |
| 1463 | + return true; | |
| 1464 | + } | |
| 1465 | + | |
| 1466 | + function toTagEnd(iter) { | |
| 1467 | + for (;;) { | |
| 1468 | + var gt = iter.text.indexOf(">", iter.ch); | |
| 1469 | + if (gt == -1) { if (nextLine(iter)) continue; else return; } | |
| 1470 | + if (!tagAt(iter, gt + 1)) { iter.ch = gt + 1; continue; } | |
| 1471 | + var lastSlash = iter.text.lastIndexOf("/", gt); | |
| 1472 | + var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt)); | |
| 1473 | + iter.ch = gt + 1; | |
| 1474 | + return selfClose ? "selfClose" : "regular"; | |
| 1475 | + } | |
| 1476 | + } | |
| 1477 | + function toTagStart(iter) { | |
| 1478 | + for (;;) { | |
| 1479 | + var lt = iter.ch ? iter.text.lastIndexOf("<", iter.ch - 1) : -1; | |
| 1480 | + if (lt == -1) { if (prevLine(iter)) continue; else return; } | |
| 1481 | + if (!tagAt(iter, lt + 1)) { iter.ch = lt; continue; } | |
| 1482 | + xmlTagStart.lastIndex = lt; | |
| 1483 | + iter.ch = lt; | |
| 1484 | + var match = xmlTagStart.exec(iter.text); | |
| 1485 | + if (match && match.index == lt) return match; | |
| 1486 | + } | |
| 1487 | + } | |
| 1488 | + | |
| 1489 | + function toNextTag(iter) { | |
| 1490 | + for (;;) { | |
| 1491 | + xmlTagStart.lastIndex = iter.ch; | |
| 1492 | + var found = xmlTagStart.exec(iter.text); | |
| 1493 | + if (!found) { if (nextLine(iter)) continue; else return; } | |
| 1494 | + if (!tagAt(iter, found.index + 1)) { iter.ch = found.index + 1; continue; } | |
| 1495 | + iter.ch = found.index + found[0].length; | |
| 1496 | + return found; | |
| 1497 | + } | |
| 1498 | + } | |
| 1499 | + function toPrevTag(iter) { | |
| 1500 | + for (;;) { | |
| 1501 | + var gt = iter.ch ? iter.text.lastIndexOf(">", iter.ch - 1) : -1; | |
| 1502 | + if (gt == -1) { if (prevLine(iter)) continue; else return; } | |
| 1503 | + if (!tagAt(iter, gt + 1)) { iter.ch = gt; continue; } | |
| 1504 | + var lastSlash = iter.text.lastIndexOf("/", gt); | |
| 1505 | + var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt)); | |
| 1506 | + iter.ch = gt + 1; | |
| 1507 | + return selfClose ? "selfClose" : "regular"; | |
| 1508 | + } | |
| 1509 | + } | |
| 1510 | + | |
| 1511 | + function findMatchingClose(iter, tag) { | |
| 1512 | + var stack = []; | |
| 1513 | + for (;;) { | |
| 1514 | + var next = toNextTag(iter), end, startLine = iter.line, startCh = iter.ch - (next ? next[0].length : 0); | |
| 1515 | + if (!next || !(end = toTagEnd(iter))) return; | |
| 1516 | + if (end == "selfClose") continue; | |
| 1517 | + if (next[1]) { // closing tag | |
| 1518 | + for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == next[2]) { | |
| 1519 | + stack.length = i; | |
| 1520 | + break; | |
| 1521 | + } | |
| 1522 | + if (i < 0 && (!tag || tag == next[2])) return { | |
| 1523 | + tag: next[2], | |
| 1524 | + from: Pos(startLine, startCh), | |
| 1525 | + to: Pos(iter.line, iter.ch) | |
| 1526 | + }; | |
| 1527 | + } else { // opening tag | |
| 1528 | + stack.push(next[2]); | |
| 1529 | + } | |
| 1530 | + } | |
| 1531 | + } | |
| 1532 | + function findMatchingOpen(iter, tag) { | |
| 1533 | + var stack = []; | |
| 1534 | + for (;;) { | |
| 1535 | + var prev = toPrevTag(iter); | |
| 1536 | + if (!prev) return; | |
| 1537 | + if (prev == "selfClose") { toTagStart(iter); continue; } | |
| 1538 | + var endLine = iter.line, endCh = iter.ch; | |
| 1539 | + var start = toTagStart(iter); | |
| 1540 | + if (!start) return; | |
| 1541 | + if (start[1]) { // closing tag | |
| 1542 | + stack.push(start[2]); | |
| 1543 | + } else { // opening tag | |
| 1544 | + for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == start[2]) { | |
| 1545 | + stack.length = i; | |
| 1546 | + break; | |
| 1547 | + } | |
| 1548 | + if (i < 0 && (!tag || tag == start[2])) return { | |
| 1549 | + tag: start[2], | |
| 1550 | + from: Pos(iter.line, iter.ch), | |
| 1551 | + to: Pos(endLine, endCh) | |
| 1552 | + }; | |
| 1553 | + } | |
| 1554 | + } | |
| 1555 | + } | |
| 1556 | + | |
| 1557 | + CodeMirror.registerHelper("fold", "xml", function(cm, start) { | |
| 1558 | + var iter = new Iter(cm, start.line, 0); | |
| 1559 | + for (;;) { | |
| 1560 | + var openTag = toNextTag(iter) | |
| 1561 | + if (!openTag || iter.line != start.line) return | |
| 1562 | + var end = toTagEnd(iter) | |
| 1563 | + if (!end) return | |
| 1564 | + if (!openTag[1] && end != "selfClose") { | |
| 1565 | + var startPos = Pos(iter.line, iter.ch); | |
| 1566 | + var endPos = findMatchingClose(iter, openTag[2]); | |
| 1567 | + return endPos && cmp(endPos.from, startPos) > 0 ? {from: startPos, to: endPos.from} : null | |
| 1568 | + } | |
| 1569 | + } | |
| 1570 | + }); | |
| 1571 | + CodeMirror.findMatchingTag = function(cm, pos, range) { | |
| 1572 | + var iter = new Iter(cm, pos.line, pos.ch, range); | |
| 1573 | + if (iter.text.indexOf(">") == -1 && iter.text.indexOf("<") == -1) return; | |
| 1574 | + var end = toTagEnd(iter), to = end && Pos(iter.line, iter.ch); | |
| 1575 | + var start = end && toTagStart(iter); | |
| 1576 | + if (!end || !start || cmp(iter, pos) > 0) return; | |
| 1577 | + var here = {from: Pos(iter.line, iter.ch), to: to, tag: start[2]}; | |
| 1578 | + if (end == "selfClose") return {open: here, close: null, at: "open"}; | |
| 1579 | + | |
| 1580 | + if (start[1]) { // closing tag | |
| 1581 | + return {open: findMatchingOpen(iter, start[2]), close: here, at: "close"}; | |
| 1582 | + } else { // opening tag | |
| 1583 | + iter = new Iter(cm, to.line, to.ch, range); | |
| 1584 | + return {open: here, close: findMatchingClose(iter, start[2]), at: "open"}; | |
| 1585 | + } | |
| 1586 | + }; | |
| 1587 | + | |
| 1588 | + CodeMirror.findEnclosingTag = function(cm, pos, range, tag) { | |
| 1589 | + var iter = new Iter(cm, pos.line, pos.ch, range); | |
| 1590 | + for (;;) { | |
| 1591 | + var open = findMatchingOpen(iter, tag); | |
| 1592 | + if (!open) break; | |
| 1593 | + var forward = new Iter(cm, pos.line, pos.ch, range); | |
| 1594 | + var close = findMatchingClose(forward, open.tag); | |
| 1595 | + if (close) return {open: open, close: close}; | |
| 1596 | + } | |
| 1597 | + }; | |
| 1598 | + | |
| 1599 | + // Used by addon/edit/closetag.js | |
| 1600 | + CodeMirror.scanForClosingTag = function(cm, pos, name, end) { | |
| 1601 | + var iter = new Iter(cm, pos.line, pos.ch, end ? {from: 0, to: end} : null); | |
| 1602 | + return findMatchingClose(iter, name); | |
| 1603 | + }; | |
| 1604 | +}); | |
| 1605 | + | |
| 1606 | +},{"../../lib/codemirror":14}],14:[function(require,module,exports){ | |
| 1607 | +// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
| 1608 | +// Distributed under an MIT license: https://codemirror.net/LICENSE | |
| 1609 | + | |
| 1610 | +// This is CodeMirror (https://codemirror.net), a code editor | |
| 1611 | +// implemented in JavaScript on top of the browser's DOM. | |
| 1612 | +// | |
| 1613 | +// You can find some technical background for some of the code below | |
| 1614 | +// at http://marijnhaverbeke.nl/blog/#cm-internals . | |
| 1615 | + | |
| 1616 | +(function (global, factory) { | |
| 1617 | + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | |
| 1618 | + typeof define === 'function' && define.amd ? define(factory) : | |
| 1619 | + (global = global || self, global.CodeMirror = factory()); | |
| 1620 | +}(this, (function () { 'use strict'; | |
| 1621 | + | |
| 1622 | + // Kludges for bugs and behavior differences that can't be feature | |
| 1623 | + // detected are enabled based on userAgent etc sniffing. | |
| 1624 | + var userAgent = navigator.userAgent; | |
| 1625 | + var platform = navigator.platform; | |
| 1626 | + | |
| 1627 | + var gecko = /gecko\/\d/i.test(userAgent); | |
| 1628 | + var ie_upto10 = /MSIE \d/.test(userAgent); | |
| 1629 | + var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent); | |
| 1630 | + var edge = /Edge\/(\d+)/.exec(userAgent); | |
| 1631 | + var ie = ie_upto10 || ie_11up || edge; | |
| 1632 | + var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]); | |
| 1633 | + var webkit = !edge && /WebKit\//.test(userAgent); | |
| 1634 | + var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent); | |
| 1635 | + var chrome = !edge && /Chrome\//.test(userAgent); | |
| 1636 | + var presto = /Opera\//.test(userAgent); | |
| 1637 | + var safari = /Apple Computer/.test(navigator.vendor); | |
| 1638 | + var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent); | |
| 1639 | + var phantom = /PhantomJS/.test(userAgent); | |
| 1640 | + | |
| 1641 | + var ios = safari && (/Mobile\/\w+/.test(userAgent) || navigator.maxTouchPoints > 2); | |
| 1642 | + var android = /Android/.test(userAgent); | |
| 1643 | + // This is woefully incomplete. Suggestions for alternative methods welcome. | |
| 1644 | + var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent); | |
| 1645 | + var mac = ios || /Mac/.test(platform); | |
| 1646 | + var chromeOS = /\bCrOS\b/.test(userAgent); | |
| 1647 | + var windows = /win/i.test(platform); | |
| 1648 | + | |
| 1649 | + var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/); | |
| 1650 | + if (presto_version) { presto_version = Number(presto_version[1]); } | |
| 1651 | + if (presto_version && presto_version >= 15) { presto = false; webkit = true; } | |
| 1652 | + // Some browsers use the wrong event properties to signal cmd/ctrl on OS X | |
| 1653 | + var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11)); | |
| 1654 | + var captureRightClick = gecko || (ie && ie_version >= 9); | |
| 1655 | + | |
| 1656 | + function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") } | |
| 1657 | + | |
| 1658 | + var rmClass = function(node, cls) { | |
| 1659 | + var current = node.className; | |
| 1660 | + var match = classTest(cls).exec(current); | |
| 1661 | + if (match) { | |
| 1662 | + var after = current.slice(match.index + match[0].length); | |
| 1663 | + node.className = current.slice(0, match.index) + (after ? match[1] + after : ""); | |
| 1664 | + } | |
| 1665 | + }; | |
| 1666 | + | |
| 1667 | + function removeChildren(e) { | |
| 1668 | + for (var count = e.childNodes.length; count > 0; --count) | |
| 1669 | + { e.removeChild(e.firstChild); } | |
| 1670 | + return e | |
| 1671 | + } | |
| 1672 | + | |
| 1673 | + function removeChildrenAndAdd(parent, e) { | |
| 1674 | + return removeChildren(parent).appendChild(e) | |
| 1675 | + } | |
| 1676 | + | |
| 1677 | + function elt(tag, content, className, style) { | |
| 1678 | + var e = document.createElement(tag); | |
| 1679 | + if (className) { e.className = className; } | |
| 1680 | + if (style) { e.style.cssText = style; } | |
| 1681 | + if (typeof content == "string") { e.appendChild(document.createTextNode(content)); } | |
| 1682 | + else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]); } } | |
| 1683 | + return e | |
| 1684 | + } | |
| 1685 | + // wrapper for elt, which removes the elt from the accessibility tree | |
| 1686 | + function eltP(tag, content, className, style) { | |
| 1687 | + var e = elt(tag, content, className, style); | |
| 1688 | + e.setAttribute("role", "presentation"); | |
| 1689 | + return e | |
| 1690 | + } | |
| 1691 | + | |
| 1692 | + var range; | |
| 1693 | + if (document.createRange) { range = function(node, start, end, endNode) { | |
| 1694 | + var r = document.createRange(); | |
| 1695 | + r.setEnd(endNode || node, end); | |
| 1696 | + r.setStart(node, start); | |
| 1697 | + return r | |
| 1698 | + }; } | |
| 1699 | + else { range = function(node, start, end) { | |
| 1700 | + var r = document.body.createTextRange(); | |
| 1701 | + try { r.moveToElementText(node.parentNode); } | |
| 1702 | + catch(e) { return r } | |
| 1703 | + r.collapse(true); | |
| 1704 | + r.moveEnd("character", end); | |
| 1705 | + r.moveStart("character", start); | |
| 1706 | + return r | |
| 1707 | + }; } | |
| 1708 | + | |
| 1709 | + function contains(parent, child) { | |
| 1710 | + if (child.nodeType == 3) // Android browser always returns false when child is a textnode | |
| 1711 | + { child = child.parentNode; } | |
| 1712 | + if (parent.contains) | |
| 1713 | + { return parent.contains(child) } | |
| 1714 | + do { | |
| 1715 | + if (child.nodeType == 11) { child = child.host; } | |
| 1716 | + if (child == parent) { return true } | |
| 1717 | + } while (child = child.parentNode) | |
| 1718 | + } | |
| 1719 | + | |
| 1720 | + function activeElt() { | |
| 1721 | + // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement. | |
| 1722 | + // IE < 10 will throw when accessed while the page is loading or in an iframe. | |
| 1723 | + // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable. | |
| 1724 | + var activeElement; | |
| 1725 | + try { | |
| 1726 | + activeElement = document.activeElement; | |
| 1727 | + } catch(e) { | |
| 1728 | + activeElement = document.body || null; | |
| 1729 | + } | |
| 1730 | + while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) | |
| 1731 | + { activeElement = activeElement.shadowRoot.activeElement; } | |
| 1732 | + return activeElement | |
| 1733 | + } | |
| 1734 | + | |
| 1735 | + function addClass(node, cls) { | |
| 1736 | + var current = node.className; | |
| 1737 | + if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls; } | |
| 1738 | + } | |
| 1739 | + function joinClasses(a, b) { | |
| 1740 | + var as = a.split(" "); | |
| 1741 | + for (var i = 0; i < as.length; i++) | |
| 1742 | + { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i]; } } | |
| 1743 | + return b | |
| 1744 | + } | |
| 1745 | + | |
| 1746 | + var selectInput = function(node) { node.select(); }; | |
| 1747 | + if (ios) // Mobile Safari apparently has a bug where select() is broken. | |
| 1748 | + { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; } | |
| 1749 | + else if (ie) // Suppress mysterious IE10 errors | |
| 1750 | + { selectInput = function(node) { try { node.select(); } catch(_e) {} }; } | |
| 1751 | + | |
| 1752 | + function bind(f) { | |
| 1753 | + var args = Array.prototype.slice.call(arguments, 1); | |
| 1754 | + return function(){return f.apply(null, args)} | |
| 1755 | + } | |
| 1756 | + | |
| 1757 | + function copyObj(obj, target, overwrite) { | |
| 1758 | + if (!target) { target = {}; } | |
| 1759 | + for (var prop in obj) | |
| 1760 | + { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop))) | |
| 1761 | + { target[prop] = obj[prop]; } } | |
| 1762 | + return target | |
| 1763 | + } | |
| 1764 | + | |
| 1765 | + // Counts the column offset in a string, taking tabs into account. | |
| 1766 | + // Used mostly to find indentation. | |
| 1767 | + function countColumn(string, end, tabSize, startIndex, startValue) { | |
| 1768 | + if (end == null) { | |
| 1769 | + end = string.search(/[^\s\u00a0]/); | |
| 1770 | + if (end == -1) { end = string.length; } | |
| 1771 | + } | |
| 1772 | + for (var i = startIndex || 0, n = startValue || 0;;) { | |
| 1773 | + var nextTab = string.indexOf("\t", i); | |
| 1774 | + if (nextTab < 0 || nextTab >= end) | |
| 1775 | + { return n + (end - i) } | |
| 1776 | + n += nextTab - i; | |
| 1777 | + n += tabSize - (n % tabSize); | |
| 1778 | + i = nextTab + 1; | |
| 1779 | + } | |
| 1780 | + } | |
| 1781 | + | |
| 1782 | + var Delayed = function() { | |
| 1783 | + this.id = null; | |
| 1784 | + this.f = null; | |
| 1785 | + this.time = 0; | |
| 1786 | + this.handler = bind(this.onTimeout, this); | |
| 1787 | + }; | |
| 1788 | + Delayed.prototype.onTimeout = function (self) { | |
| 1789 | + self.id = 0; | |
| 1790 | + if (self.time <= +new Date) { | |
| 1791 | + self.f(); | |
| 1792 | + } else { | |
| 1793 | + setTimeout(self.handler, self.time - +new Date); | |
| 1794 | + } | |
| 1795 | + }; | |
| 1796 | + Delayed.prototype.set = function (ms, f) { | |
| 1797 | + this.f = f; | |
| 1798 | + var time = +new Date + ms; | |
| 1799 | + if (!this.id || time < this.time) { | |
| 1800 | + clearTimeout(this.id); | |
| 1801 | + this.id = setTimeout(this.handler, ms); | |
| 1802 | + this.time = time; | |
| 1803 | + } | |
| 1804 | + }; | |
| 1805 | + | |
| 1806 | + function indexOf(array, elt) { | |
| 1807 | + for (var i = 0; i < array.length; ++i) | |
| 1808 | + { if (array[i] == elt) { return i } } | |
| 1809 | + return -1 | |
| 1810 | + } | |
| 1811 | + | |
| 1812 | + // Number of pixels added to scroller and sizer to hide scrollbar | |
| 1813 | + var scrollerGap = 50; | |
| 1814 | + | |
| 1815 | + // Returned or thrown by various protocols to signal 'I'm not | |
| 1816 | + // handling this'. | |
| 1817 | + var Pass = {toString: function(){return "CodeMirror.Pass"}}; | |
| 1818 | + | |
| 1819 | + // Reused option objects for setSelection & friends | |
| 1820 | + var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"}; | |
| 1821 | + | |
| 1822 | + // The inverse of countColumn -- find the offset that corresponds to | |
| 1823 | + // a particular column. | |
| 1824 | + function findColumn(string, goal, tabSize) { | |
| 1825 | + for (var pos = 0, col = 0;;) { | |
| 1826 | + var nextTab = string.indexOf("\t", pos); | |
| 1827 | + if (nextTab == -1) { nextTab = string.length; } | |
| 1828 | + var skipped = nextTab - pos; | |
| 1829 | + if (nextTab == string.length || col + skipped >= goal) | |
| 1830 | + { return pos + Math.min(skipped, goal - col) } | |
| 1831 | + col += nextTab - pos; | |
| 1832 | + col += tabSize - (col % tabSize); | |
| 1833 | + pos = nextTab + 1; | |
| 1834 | + if (col >= goal) { return pos } | |
| 1835 | + } | |
| 1836 | + } | |
| 1837 | + | |
| 1838 | + var spaceStrs = [""]; | |
| 1839 | + function spaceStr(n) { | |
| 1840 | + while (spaceStrs.length <= n) | |
| 1841 | + { spaceStrs.push(lst(spaceStrs) + " "); } | |
| 1842 | + return spaceStrs[n] | |
| 1843 | + } | |
| 1844 | + | |
| 1845 | + function lst(arr) { return arr[arr.length-1] } | |
| 1846 | + | |
| 1847 | + function map(array, f) { | |
| 1848 | + var out = []; | |
| 1849 | + for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i); } | |
| 1850 | + return out | |
| 1851 | + } | |
| 1852 | + | |
| 1853 | + function insertSorted(array, value, score) { | |
| 1854 | + var pos = 0, priority = score(value); | |
| 1855 | + while (pos < array.length && score(array[pos]) <= priority) { pos++; } | |
| 1856 | + array.splice(pos, 0, value); | |
| 1857 | + } | |
| 1858 | + | |
| 1859 | + function nothing() {} | |
| 1860 | + | |
| 1861 | + function createObj(base, props) { | |
| 1862 | + var inst; | |
| 1863 | + if (Object.create) { | |
| 1864 | + inst = Object.create(base); | |
| 1865 | + } else { | |
| 1866 | + nothing.prototype = base; | |
| 1867 | + inst = new nothing(); | |
| 1868 | + } | |
| 1869 | + if (props) { copyObj(props, inst); } | |
| 1870 | + return inst | |
| 1871 | + } | |
| 1872 | + | |
| 1873 | + var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/; | |
| 1874 | + function isWordCharBasic(ch) { | |
| 1875 | + return /\w/.test(ch) || ch > "\x80" && | |
| 1876 | + (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)) | |
| 1877 | + } | |
| 1878 | + function isWordChar(ch, helper) { | |
| 1879 | + if (!helper) { return isWordCharBasic(ch) } | |
| 1880 | + if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true } | |
| 1881 | + return helper.test(ch) | |
| 1882 | + } | |
| 1883 | + | |
| 1884 | + function isEmpty(obj) { | |
| 1885 | + for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } } | |
| 1886 | + return true | |
| 1887 | + } | |
| 1888 | + | |
| 1889 | + // Extending unicode characters. A series of a non-extending char + | |
| 1890 | + // any number of extending chars is treated as a single unit as far | |
| 1891 | + // as editing and measuring is concerned. This is not fully correct, | |
| 1892 | + // since some scripts/fonts/browsers also treat other configurations | |
| 1893 | + // of code points as a group. | |
| 1894 | + var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/; | |
| 1895 | + function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) } | |
| 1896 | + | |
| 1897 | + // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range. | |
| 1898 | + function skipExtendingChars(str, pos, dir) { | |
| 1899 | + while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir; } | |
| 1900 | + return pos | |
| 1901 | + } | |
| 1902 | + | |
| 1903 | + // Returns the value from the range [`from`; `to`] that satisfies | |
| 1904 | + // `pred` and is closest to `from`. Assumes that at least `to` | |
| 1905 | + // satisfies `pred`. Supports `from` being greater than `to`. | |
| 1906 | + function findFirst(pred, from, to) { | |
| 1907 | + // At any point we are certain `to` satisfies `pred`, don't know | |
| 1908 | + // whether `from` does. | |
| 1909 | + var dir = from > to ? -1 : 1; | |
| 1910 | + for (;;) { | |
| 1911 | + if (from == to) { return from } | |
| 1912 | + var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF); | |
| 1913 | + if (mid == from) { return pred(mid) ? from : to } | |
| 1914 | + if (pred(mid)) { to = mid; } | |
| 1915 | + else { from = mid + dir; } | |
| 1916 | + } | |
| 1917 | + } | |
| 1918 | + | |
| 1919 | + // BIDI HELPERS | |
| 1920 | + | |
| 1921 | + function iterateBidiSections(order, from, to, f) { | |
| 1922 | + if (!order) { return f(from, to, "ltr", 0) } | |
| 1923 | + var found = false; | |
| 1924 | + for (var i = 0; i < order.length; ++i) { | |
| 1925 | + var part = order[i]; | |
| 1926 | + if (part.from < to && part.to > from || from == to && part.to == from) { | |
| 1927 | + f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i); | |
| 1928 | + found = true; | |
| 1929 | + } | |
| 1930 | + } | |
| 1931 | + if (!found) { f(from, to, "ltr"); } | |
| 1932 | + } | |
| 1933 | + | |
| 1934 | + var bidiOther = null; | |
| 1935 | + function getBidiPartAt(order, ch, sticky) { | |
| 1936 | + var found; | |
| 1937 | + bidiOther = null; | |
| 1938 | + for (var i = 0; i < order.length; ++i) { | |
| 1939 | + var cur = order[i]; | |
| 1940 | + if (cur.from < ch && cur.to > ch) { return i } | |
| 1941 | + if (cur.to == ch) { | |
| 1942 | + if (cur.from != cur.to && sticky == "before") { found = i; } | |
| 1943 | + else { bidiOther = i; } | |
| 1944 | + } | |
| 1945 | + if (cur.from == ch) { | |
| 1946 | + if (cur.from != cur.to && sticky != "before") { found = i; } | |
| 1947 | + else { bidiOther = i; } | |
| 1948 | + } | |
| 1949 | + } | |
| 1950 | + return found != null ? found : bidiOther | |
| 1951 | + } | |
| 1952 | + | |
| 1953 | + // Bidirectional ordering algorithm | |
| 1954 | + // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm | |
| 1955 | + // that this (partially) implements. | |
| 1956 | + | |
| 1957 | + // One-char codes used for character types: | |
| 1958 | + // L (L): Left-to-Right | |
| 1959 | + // R (R): Right-to-Left | |
| 1960 | + // r (AL): Right-to-Left Arabic | |
| 1961 | + // 1 (EN): European Number | |
| 1962 | + // + (ES): European Number Separator | |
| 1963 | + // % (ET): European Number Terminator | |
| 1964 | + // n (AN): Arabic Number | |
| 1965 | + // , (CS): Common Number Separator | |
| 1966 | + // m (NSM): Non-Spacing Mark | |
| 1967 | + // b (BN): Boundary Neutral | |
| 1968 | + // s (B): Paragraph Separator | |
| 1969 | + // t (S): Segment Separator | |
| 1970 | + // w (WS): Whitespace | |
| 1971 | + // N (ON): Other Neutrals | |
| 1972 | + | |
| 1973 | + // Returns null if characters are ordered as they appear | |
| 1974 | + // (left-to-right), or an array of sections ({from, to, level} | |
| 1975 | + // objects) in the order in which they occur visually. | |
| 1976 | + var bidiOrdering = (function() { | |
| 1977 | + // Character types for codepoints 0 to 0xff | |
| 1978 | + var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN"; | |
| 1979 | + // Character types for codepoints 0x600 to 0x6f9 | |
| 1980 | + var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111"; | |
| 1981 | + function charType(code) { | |
| 1982 | + if (code <= 0xf7) { return lowTypes.charAt(code) } | |
| 1983 | + else if (0x590 <= code && code <= 0x5f4) { return "R" } | |
| 1984 | + else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) } | |
| 1985 | + else if (0x6ee <= code && code <= 0x8ac) { return "r" } | |
| 1986 | + else if (0x2000 <= code && code <= 0x200b) { return "w" } | |
| 1987 | + else if (code == 0x200c) { return "b" } | |
| 1988 | + else { return "L" } | |
| 1989 | + } | |
| 1990 | + | |
| 1991 | + var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/; | |
| 1992 | + var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/; | |
| 1993 | + | |
| 1994 | + function BidiSpan(level, from, to) { | |
| 1995 | + this.level = level; | |
| 1996 | + this.from = from; this.to = to; | |
| 1997 | + } | |
| 1998 | + | |
| 1999 | + return function(str, direction) { | |
| 2000 | + var outerType = direction == "ltr" ? "L" : "R"; | |
| 2001 | + | |
| 2002 | + if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false } | |
| 2003 | + var len = str.length, types = []; | |
| 2004 | + for (var i = 0; i < len; ++i) | |
| 2005 | + { types.push(charType(str.charCodeAt(i))); } | |
| 2006 | + | |
| 2007 | + // W1. Examine each non-spacing mark (NSM) in the level run, and | |
| 2008 | + // change the type of the NSM to the type of the previous | |
| 2009 | + // character. If the NSM is at the start of the level run, it will | |
| 2010 | + // get the type of sor. | |
| 2011 | + for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) { | |
| 2012 | + var type = types[i$1]; | |
| 2013 | + if (type == "m") { types[i$1] = prev; } | |
| 2014 | + else { prev = type; } | |
| 2015 | + } | |
| 2016 | + | |
| 2017 | + // W2. Search backwards from each instance of a European number | |
| 2018 | + // until the first strong type (R, L, AL, or sor) is found. If an | |
| 2019 | + // AL is found, change the type of the European number to Arabic | |
| 2020 | + // number. | |
| 2021 | + // W3. Change all ALs to R. | |
| 2022 | + for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) { | |
| 2023 | + var type$1 = types[i$2]; | |
| 2024 | + if (type$1 == "1" && cur == "r") { types[i$2] = "n"; } | |
| 2025 | + else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R"; } } | |
| 2026 | + } | |
| 2027 | + | |
| 2028 | + // W4. A single European separator between two European numbers | |
| 2029 | + // changes to a European number. A single common separator between | |
| 2030 | + // two numbers of the same type changes to that type. | |
| 2031 | + for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) { | |
| 2032 | + var type$2 = types[i$3]; | |
| 2033 | + if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1"; } | |
| 2034 | + else if (type$2 == "," && prev$1 == types[i$3+1] && | |
| 2035 | + (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1; } | |
| 2036 | + prev$1 = type$2; | |
| 2037 | + } | |
| 2038 | + | |
| 2039 | + // W5. A sequence of European terminators adjacent to European | |
| 2040 | + // numbers changes to all European numbers. | |
| 2041 | + // W6. Otherwise, separators and terminators change to Other | |
| 2042 | + // Neutral. | |
| 2043 | + for (var i$4 = 0; i$4 < len; ++i$4) { | |
| 2044 | + var type$3 = types[i$4]; | |
| 2045 | + if (type$3 == ",") { types[i$4] = "N"; } | |
| 2046 | + else if (type$3 == "%") { | |
| 2047 | + var end = (void 0); | |
| 2048 | + for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {} | |
| 2049 | + var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N"; | |
| 2050 | + for (var j = i$4; j < end; ++j) { types[j] = replace; } | |
| 2051 | + i$4 = end - 1; | |
| 2052 | + } | |
| 2053 | + } | |
| 2054 | + | |
| 2055 | + // W7. Search backwards from each instance of a European number | |
| 2056 | + // until the first strong type (R, L, or sor) is found. If an L is | |
| 2057 | + // found, then change the type of the European number to L. | |
| 2058 | + for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) { | |
| 2059 | + var type$4 = types[i$5]; | |
| 2060 | + if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L"; } | |
| 2061 | + else if (isStrong.test(type$4)) { cur$1 = type$4; } | |
| 2062 | + } | |
| 2063 | + | |
| 2064 | + // N1. A sequence of neutrals takes the direction of the | |
| 2065 | + // surrounding strong text if the text on both sides has the same | |
| 2066 | + // direction. European and Arabic numbers act as if they were R in | |
| 2067 | + // terms of their influence on neutrals. Start-of-level-run (sor) | |
| 2068 | + // and end-of-level-run (eor) are used at level run boundaries. | |
| 2069 | + // N2. Any remaining neutrals take the embedding direction. | |
| 2070 | + for (var i$6 = 0; i$6 < len; ++i$6) { | |
| 2071 | + if (isNeutral.test(types[i$6])) { | |
| 2072 | + var end$1 = (void 0); | |
| 2073 | + for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {} | |
| 2074 | + var before = (i$6 ? types[i$6-1] : outerType) == "L"; | |
| 2075 | + var after = (end$1 < len ? types[end$1] : outerType) == "L"; | |
| 2076 | + var replace$1 = before == after ? (before ? "L" : "R") : outerType; | |
| 2077 | + for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1; } | |
| 2078 | + i$6 = end$1 - 1; | |
| 2079 | + } | |
| 2080 | + } | |
| 2081 | + | |
| 2082 | + // Here we depart from the documented algorithm, in order to avoid | |
| 2083 | + // building up an actual levels array. Since there are only three | |
| 2084 | + // levels (0, 1, 2) in an implementation that doesn't take | |
| 2085 | + // explicit embedding into account, we can build up the order on | |
| 2086 | + // the fly, without following the level-based algorithm. | |
| 2087 | + var order = [], m; | |
| 2088 | + for (var i$7 = 0; i$7 < len;) { | |
| 2089 | + if (countsAsLeft.test(types[i$7])) { | |
| 2090 | + var start = i$7; | |
| 2091 | + for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {} | |
| 2092 | + order.push(new BidiSpan(0, start, i$7)); | |
| 2093 | + } else { | |
| 2094 | + var pos = i$7, at = order.length, isRTL = direction == "rtl" ? 1 : 0; | |
| 2095 | + for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {} | |
| 2096 | + for (var j$2 = pos; j$2 < i$7;) { | |
| 2097 | + if (countsAsNum.test(types[j$2])) { | |
| 2098 | + if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)); at += isRTL; } | |
| 2099 | + var nstart = j$2; | |
| 2100 | + for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {} | |
| 2101 | + order.splice(at, 0, new BidiSpan(2, nstart, j$2)); | |
| 2102 | + at += isRTL; | |
| 2103 | + pos = j$2; | |
| 2104 | + } else { ++j$2; } | |
| 2105 | + } | |
| 2106 | + if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)); } | |
| 2107 | + } | |
| 2108 | + } | |
| 2109 | + if (direction == "ltr") { | |
| 2110 | + if (order[0].level == 1 && (m = str.match(/^\s+/))) { | |
| 2111 | + order[0].from = m[0].length; | |
| 2112 | + order.unshift(new BidiSpan(0, 0, m[0].length)); | |
| 2113 | + } | |
| 2114 | + if (lst(order).level == 1 && (m = str.match(/\s+$/))) { | |
| 2115 | + lst(order).to -= m[0].length; | |
| 2116 | + order.push(new BidiSpan(0, len - m[0].length, len)); | |
| 2117 | + } | |
| 2118 | + } | |
| 2119 | + | |
| 2120 | + return direction == "rtl" ? order.reverse() : order | |
| 2121 | + } | |
| 2122 | + })(); | |
| 2123 | + | |
| 2124 | + // Get the bidi ordering for the given line (and cache it). Returns | |
| 2125 | + // false for lines that are fully left-to-right, and an array of | |
| 2126 | + // BidiSpan objects otherwise. | |
| 2127 | + function getOrder(line, direction) { | |
| 2128 | + var order = line.order; | |
| 2129 | + if (order == null) { order = line.order = bidiOrdering(line.text, direction); } | |
| 2130 | + return order | |
| 2131 | + } | |
| 2132 | + | |
| 2133 | + // EVENT HANDLING | |
| 2134 | + | |
| 2135 | + // Lightweight event framework. on/off also work on DOM nodes, | |
| 2136 | + // registering native DOM handlers. | |
| 2137 | + | |
| 2138 | + var noHandlers = []; | |
| 2139 | + | |
| 2140 | + var on = function(emitter, type, f) { | |
| 2141 | + if (emitter.addEventListener) { | |
| 2142 | + emitter.addEventListener(type, f, false); | |
| 2143 | + } else if (emitter.attachEvent) { | |
| 2144 | + emitter.attachEvent("on" + type, f); | |
| 2145 | + } else { | |
| 2146 | + var map = emitter._handlers || (emitter._handlers = {}); | |
| 2147 | + map[type] = (map[type] || noHandlers).concat(f); | |
| 2148 | + } | |
| 2149 | + }; | |
| 2150 | + | |
| 2151 | + function getHandlers(emitter, type) { | |
| 2152 | + return emitter._handlers && emitter._handlers[type] || noHandlers | |
| 2153 | + } | |
| 2154 | + | |
| 2155 | + function off(emitter, type, f) { | |
| 2156 | + if (emitter.removeEventListener) { | |
| 2157 | + emitter.removeEventListener(type, f, false); | |
| 2158 | + } else if (emitter.detachEvent) { | |
| 2159 | + emitter.detachEvent("on" + type, f); | |
| 2160 | + } else { | |
| 2161 | + var map = emitter._handlers, arr = map && map[type]; | |
| 2162 | + if (arr) { | |
| 2163 | + var index = indexOf(arr, f); | |
| 2164 | + if (index > -1) | |
| 2165 | + { map[type] = arr.slice(0, index).concat(arr.slice(index + 1)); } | |
| 2166 | + } | |
| 2167 | + } | |
| 2168 | + } | |
| 2169 | + | |
| 2170 | + function signal(emitter, type /*, values...*/) { | |
| 2171 | + var handlers = getHandlers(emitter, type); | |
| 2172 | + if (!handlers.length) { return } | |
| 2173 | + var args = Array.prototype.slice.call(arguments, 2); | |
| 2174 | + for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args); } | |
| 2175 | + } | |
| 2176 | + | |
| 2177 | + // The DOM events that CodeMirror handles can be overridden by | |
| 2178 | + // registering a (non-DOM) handler on the editor for the event name, | |
| 2179 | + // and preventDefault-ing the event in that handler. | |
| 2180 | + function signalDOMEvent(cm, e, override) { | |
| 2181 | + if (typeof e == "string") | |
| 2182 | + { e = {type: e, preventDefault: function() { this.defaultPrevented = true; }}; } | |
| 2183 | + signal(cm, override || e.type, cm, e); | |
| 2184 | + return e_defaultPrevented(e) || e.codemirrorIgnore | |
| 2185 | + } | |
| 2186 | + | |
| 2187 | + function signalCursorActivity(cm) { | |
| 2188 | + var arr = cm._handlers && cm._handlers.cursorActivity; | |
| 2189 | + if (!arr) { return } | |
| 2190 | + var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []); | |
| 2191 | + for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1) | |
| 2192 | + { set.push(arr[i]); } } | |
| 2193 | + } | |
| 2194 | + | |
| 2195 | + function hasHandler(emitter, type) { | |
| 2196 | + return getHandlers(emitter, type).length > 0 | |
| 2197 | + } | |
| 2198 | + | |
| 2199 | + // Add on and off methods to a constructor's prototype, to make | |
| 2200 | + // registering events on such objects more convenient. | |
| 2201 | + function eventMixin(ctor) { | |
| 2202 | + ctor.prototype.on = function(type, f) {on(this, type, f);}; | |
| 2203 | + ctor.prototype.off = function(type, f) {off(this, type, f);}; | |
| 2204 | + } | |
| 2205 | + | |
| 2206 | + // Due to the fact that we still support jurassic IE versions, some | |
| 2207 | + // compatibility wrappers are needed. | |
| 2208 | + | |
| 2209 | + function e_preventDefault(e) { | |
| 2210 | + if (e.preventDefault) { e.preventDefault(); } | |
| 2211 | + else { e.returnValue = false; } | |
| 2212 | + } | |
| 2213 | + function e_stopPropagation(e) { | |
| 2214 | + if (e.stopPropagation) { e.stopPropagation(); } | |
| 2215 | + else { e.cancelBubble = true; } | |
| 2216 | + } | |
| 2217 | + function e_defaultPrevented(e) { | |
| 2218 | + return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false | |
| 2219 | + } | |
| 2220 | + function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);} | |
| 2221 | + | |
| 2222 | + function e_target(e) {return e.target || e.srcElement} | |
| 2223 | + function e_button(e) { | |
| 2224 | + var b = e.which; | |
| 2225 | + if (b == null) { | |
| 2226 | + if (e.button & 1) { b = 1; } | |
| 2227 | + else if (e.button & 2) { b = 3; } | |
| 2228 | + else if (e.button & 4) { b = 2; } | |
| 2229 | + } | |
| 2230 | + if (mac && e.ctrlKey && b == 1) { b = 3; } | |
| 2231 | + return b | |
| 2232 | + } | |
| 2233 | + | |
| 2234 | + // Detect drag-and-drop | |
| 2235 | + var dragAndDrop = function() { | |
| 2236 | + // There is *some* kind of drag-and-drop support in IE6-8, but I | |
| 2237 | + // couldn't get it to work yet. | |
| 2238 | + if (ie && ie_version < 9) { return false } | |
| 2239 | + var div = elt('div'); | |
| 2240 | + return "draggable" in div || "dragDrop" in div | |
| 2241 | + }(); | |
| 2242 | + | |
| 2243 | + var zwspSupported; | |
| 2244 | + function zeroWidthElement(measure) { | |
| 2245 | + if (zwspSupported == null) { | |
| 2246 | + var test = elt("span", "\u200b"); | |
| 2247 | + removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")])); | |
| 2248 | + if (measure.firstChild.offsetHeight != 0) | |
| 2249 | + { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8); } | |
| 2250 | + } | |
| 2251 | + var node = zwspSupported ? elt("span", "\u200b") : | |
| 2252 | + elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px"); | |
| 2253 | + node.setAttribute("cm-text", ""); | |
| 2254 | + return node | |
| 2255 | + } | |
| 2256 | + | |
| 2257 | + // Feature-detect IE's crummy client rect reporting for bidi text | |
| 2258 | + var badBidiRects; | |
| 2259 | + function hasBadBidiRects(measure) { | |
| 2260 | + if (badBidiRects != null) { return badBidiRects } | |
| 2261 | + var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA")); | |
| 2262 | + var r0 = range(txt, 0, 1).getBoundingClientRect(); | |
| 2263 | + var r1 = range(txt, 1, 2).getBoundingClientRect(); | |
| 2264 | + removeChildren(measure); | |
| 2265 | + if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780) | |
| 2266 | + return badBidiRects = (r1.right - r0.right < 3) | |
| 2267 | + } | |
| 2268 | + | |
| 2269 | + // See if "".split is the broken IE version, if so, provide an | |
| 2270 | + // alternative way to split lines. | |
| 2271 | + var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) { | |
| 2272 | + var pos = 0, result = [], l = string.length; | |
| 2273 | + while (pos <= l) { | |
| 2274 | + var nl = string.indexOf("\n", pos); | |
| 2275 | + if (nl == -1) { nl = string.length; } | |
| 2276 | + var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl); | |
| 2277 | + var rt = line.indexOf("\r"); | |
| 2278 | + if (rt != -1) { | |
| 2279 | + result.push(line.slice(0, rt)); | |
| 2280 | + pos += rt + 1; | |
| 2281 | + } else { | |
| 2282 | + result.push(line); | |
| 2283 | + pos = nl + 1; | |
| 2284 | + } | |
| 2285 | + } | |
| 2286 | + return result | |
| 2287 | + } : function (string) { return string.split(/\r\n?|\n/); }; | |
| 2288 | + | |
| 2289 | + var hasSelection = window.getSelection ? function (te) { | |
| 2290 | + try { return te.selectionStart != te.selectionEnd } | |
| 2291 | + catch(e) { return false } | |
| 2292 | + } : function (te) { | |
| 2293 | + var range; | |
| 2294 | + try {range = te.ownerDocument.selection.createRange();} | |
| 2295 | + catch(e) {} | |
| 2296 | + if (!range || range.parentElement() != te) { return false } | |
| 2297 | + return range.compareEndPoints("StartToEnd", range) != 0 | |
| 2298 | + }; | |
| 2299 | + | |
| 2300 | + var hasCopyEvent = (function () { | |
| 2301 | + var e = elt("div"); | |
| 2302 | + if ("oncopy" in e) { return true } | |
| 2303 | + e.setAttribute("oncopy", "return;"); | |
| 2304 | + return typeof e.oncopy == "function" | |
| 2305 | + })(); | |
| 2306 | + | |
| 2307 | + var badZoomedRects = null; | |
| 2308 | + function hasBadZoomedRects(measure) { | |
| 2309 | + if (badZoomedRects != null) { return badZoomedRects } | |
| 2310 | + var node = removeChildrenAndAdd(measure, elt("span", "x")); | |
| 2311 | + var normal = node.getBoundingClientRect(); | |
| 2312 | + var fromRange = range(node, 0, 1).getBoundingClientRect(); | |
| 2313 | + return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1 | |
| 2314 | + } | |
| 2315 | + | |
| 2316 | + // Known modes, by name and by MIME | |
| 2317 | + var modes = {}, mimeModes = {}; | |
| 2318 | + | |
| 2319 | + // Extra arguments are stored as the mode's dependencies, which is | |
| 2320 | + // used by (legacy) mechanisms like loadmode.js to automatically | |
| 2321 | + // load a mode. (Preferred mechanism is the require/define calls.) | |
| 2322 | + function defineMode(name, mode) { | |
| 2323 | + if (arguments.length > 2) | |
| 2324 | + { mode.dependencies = Array.prototype.slice.call(arguments, 2); } | |
| 2325 | + modes[name] = mode; | |
| 2326 | + } | |
| 2327 | + | |
| 2328 | + function defineMIME(mime, spec) { | |
| 2329 | + mimeModes[mime] = spec; | |
| 2330 | + } | |
| 2331 | + | |
| 2332 | + // Given a MIME type, a {name, ...options} config object, or a name | |
| 2333 | + // string, return a mode config object. | |
| 2334 | + function resolveMode(spec) { | |
| 2335 | + if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) { | |
| 2336 | + spec = mimeModes[spec]; | |
| 2337 | + } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) { | |
| 2338 | + var found = mimeModes[spec.name]; | |
| 2339 | + if (typeof found == "string") { found = {name: found}; } | |
| 2340 | + spec = createObj(found, spec); | |
| 2341 | + spec.name = found.name; | |
| 2342 | + } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) { | |
| 2343 | + return resolveMode("application/xml") | |
| 2344 | + } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) { | |
| 2345 | + return resolveMode("application/json") | |
| 2346 | + } | |
| 2347 | + if (typeof spec == "string") { return {name: spec} } | |
| 2348 | + else { return spec || {name: "null"} } | |
| 2349 | + } | |
| 2350 | + | |
| 2351 | + // Given a mode spec (anything that resolveMode accepts), find and | |
| 2352 | + // initialize an actual mode object. | |
| 2353 | + function getMode(options, spec) { | |
| 2354 | + spec = resolveMode(spec); | |
| 2355 | + var mfactory = modes[spec.name]; | |
| 2356 | + if (!mfactory) { return getMode(options, "text/plain") } | |
| 2357 | + var modeObj = mfactory(options, spec); | |
| 2358 | + if (modeExtensions.hasOwnProperty(spec.name)) { | |
| 2359 | + var exts = modeExtensions[spec.name]; | |
| 2360 | + for (var prop in exts) { | |
| 2361 | + if (!exts.hasOwnProperty(prop)) { continue } | |
| 2362 | + if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; } | |
| 2363 | + modeObj[prop] = exts[prop]; | |
| 2364 | + } | |
| 2365 | + } | |
| 2366 | + modeObj.name = spec.name; | |
| 2367 | + if (spec.helperType) { modeObj.helperType = spec.helperType; } | |
| 2368 | + if (spec.modeProps) { for (var prop$1 in spec.modeProps) | |
| 2369 | + { modeObj[prop$1] = spec.modeProps[prop$1]; } } | |
| 2370 | + | |
| 2371 | + return modeObj | |
| 2372 | + } | |
| 2373 | + | |
| 2374 | + // This can be used to attach properties to mode objects from | |
| 2375 | + // outside the actual mode definition. | |
| 2376 | + var modeExtensions = {}; | |
| 2377 | + function extendMode(mode, properties) { | |
| 2378 | + var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {}); | |
| 2379 | + copyObj(properties, exts); | |
| 2380 | + } | |
| 2381 | + | |
| 2382 | + function copyState(mode, state) { | |
| 2383 | + if (state === true) { return state } | |
| 2384 | + if (mode.copyState) { return mode.copyState(state) } | |
| 2385 | + var nstate = {}; | |
| 2386 | + for (var n in state) { | |
| 2387 | + var val = state[n]; | |
| 2388 | + if (val instanceof Array) { val = val.concat([]); } | |
| 2389 | + nstate[n] = val; | |
| 2390 | + } | |
| 2391 | + return nstate | |
| 2392 | + } | |
| 2393 | + | |
| 2394 | + // Given a mode and a state (for that mode), find the inner mode and | |
| 2395 | + // state at the position that the state refers to. | |
| 2396 | + function innerMode(mode, state) { | |
| 2397 | + var info; | |
| 2398 | + while (mode.innerMode) { | |
| 2399 | + info = mode.innerMode(state); | |
| 2400 | + if (!info || info.mode == mode) { break } | |
| 2401 | + state = info.state; | |
| 2402 | + mode = info.mode; | |
| 2403 | + } | |
| 2404 | + return info || {mode: mode, state: state} | |
| 2405 | + } | |
| 2406 | + | |
| 2407 | + function startState(mode, a1, a2) { | |
| 2408 | + return mode.startState ? mode.startState(a1, a2) : true | |
| 2409 | + } | |
| 2410 | + | |
| 2411 | + // STRING STREAM | |
| 2412 | + | |
| 2413 | + // Fed to the mode parsers, provides helper functions to make | |
| 2414 | + // parsers more succinct. | |
| 2415 | + | |
| 2416 | + var StringStream = function(string, tabSize, lineOracle) { | |
| 2417 | + this.pos = this.start = 0; | |
| 2418 | + this.string = string; | |
| 2419 | + this.tabSize = tabSize || 8; | |
| 2420 | + this.lastColumnPos = this.lastColumnValue = 0; | |
| 2421 | + this.lineStart = 0; | |
| 2422 | + this.lineOracle = lineOracle; | |
| 2423 | + }; | |
| 2424 | + | |
| 2425 | + StringStream.prototype.eol = function () {return this.pos >= this.string.length}; | |
| 2426 | + StringStream.prototype.sol = function () {return this.pos == this.lineStart}; | |
| 2427 | + StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined}; | |
| 2428 | + StringStream.prototype.next = function () { | |
| 2429 | + if (this.pos < this.string.length) | |
| 2430 | + { return this.string.charAt(this.pos++) } | |
| 2431 | + }; | |
| 2432 | + StringStream.prototype.eat = function (match) { | |
| 2433 | + var ch = this.string.charAt(this.pos); | |
| 2434 | + var ok; | |
| 2435 | + if (typeof match == "string") { ok = ch == match; } | |
| 2436 | + else { ok = ch && (match.test ? match.test(ch) : match(ch)); } | |
| 2437 | + if (ok) {++this.pos; return ch} | |
| 2438 | + }; | |
| 2439 | + StringStream.prototype.eatWhile = function (match) { | |
| 2440 | + var start = this.pos; | |
| 2441 | + while (this.eat(match)){} | |
| 2442 | + return this.pos > start | |
| 2443 | + }; | |
| 2444 | + StringStream.prototype.eatSpace = function () { | |
| 2445 | + var start = this.pos; | |
| 2446 | + while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this.pos; } | |
| 2447 | + return this.pos > start | |
| 2448 | + }; | |
| 2449 | + StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;}; | |
| 2450 | + StringStream.prototype.skipTo = function (ch) { | |
| 2451 | + var found = this.string.indexOf(ch, this.pos); | |
| 2452 | + if (found > -1) {this.pos = found; return true} | |
| 2453 | + }; | |
| 2454 | + StringStream.prototype.backUp = function (n) {this.pos -= n;}; | |
| 2455 | + StringStream.prototype.column = function () { | |
| 2456 | + if (this.lastColumnPos < this.start) { | |
| 2457 | + this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue); | |
| 2458 | + this.lastColumnPos = this.start; | |
| 2459 | + } | |
| 2460 | + return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0) | |
| 2461 | + }; | |
| 2462 | + StringStream.prototype.indentation = function () { | |
| 2463 | + return countColumn(this.string, null, this.tabSize) - | |
| 2464 | + (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0) | |
| 2465 | + }; | |
| 2466 | + StringStream.prototype.match = function (pattern, consume, caseInsensitive) { | |
| 2467 | + if (typeof pattern == "string") { | |
| 2468 | + var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; }; | |
| 2469 | + var substr = this.string.substr(this.pos, pattern.length); | |
| 2470 | + if (cased(substr) == cased(pattern)) { | |
| 2471 | + if (consume !== false) { this.pos += pattern.length; } | |
| 2472 | + return true | |
| 2473 | + } | |
| 2474 | + } else { | |
| 2475 | + var match = this.string.slice(this.pos).match(pattern); | |
| 2476 | + if (match && match.index > 0) { return null } | |
| 2477 | + if (match && consume !== false) { this.pos += match[0].length; } | |
| 2478 | + return match | |
| 2479 | + } | |
| 2480 | + }; | |
| 2481 | + StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)}; | |
| 2482 | + StringStream.prototype.hideFirstChars = function (n, inner) { | |
| 2483 | + this.lineStart += n; | |
| 2484 | + try { return inner() } | |
| 2485 | + finally { this.lineStart -= n; } | |
| 2486 | + }; | |
| 2487 | + StringStream.prototype.lookAhead = function (n) { | |
| 2488 | + var oracle = this.lineOracle; | |
| 2489 | + return oracle && oracle.lookAhead(n) | |
| 2490 | + }; | |
| 2491 | + StringStream.prototype.baseToken = function () { | |
| 2492 | + var oracle = this.lineOracle; | |
| 2493 | + return oracle && oracle.baseToken(this.pos) | |
| 2494 | + }; | |
| 2495 | + | |
| 2496 | + // Find the line object corresponding to the given line number. | |
| 2497 | + function getLine(doc, n) { | |
| 2498 | + n -= doc.first; | |
| 2499 | + if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") } | |
| 2500 | + var chunk = doc; | |
| 2501 | + while (!chunk.lines) { | |
| 2502 | + for (var i = 0;; ++i) { | |
| 2503 | + var child = chunk.children[i], sz = child.chunkSize(); | |
| 2504 | + if (n < sz) { chunk = child; break } | |
| 2505 | + n -= sz; | |
| 2506 | + } | |
| 2507 | + } | |
| 2508 | + return chunk.lines[n] | |
| 2509 | + } | |
| 2510 | + | |
| 2511 | + // Get the part of a document between two positions, as an array of | |
| 2512 | + // strings. | |
| 2513 | + function getBetween(doc, start, end) { | |
| 2514 | + var out = [], n = start.line; | |
| 2515 | + doc.iter(start.line, end.line + 1, function (line) { | |
| 2516 | + var text = line.text; | |
| 2517 | + if (n == end.line) { text = text.slice(0, end.ch); } | |
| 2518 | + if (n == start.line) { text = text.slice(start.ch); } | |
| 2519 | + out.push(text); | |
| 2520 | + ++n; | |
| 2521 | + }); | |
| 2522 | + return out | |
| 2523 | + } | |
| 2524 | + // Get the lines between from and to, as array of strings. | |
| 2525 | + function getLines(doc, from, to) { | |
| 2526 | + var out = []; | |
| 2527 | + doc.iter(from, to, function (line) { out.push(line.text); }); // iter aborts when callback returns truthy value | |
| 2528 | + return out | |
| 2529 | + } | |
| 2530 | + | |
| 2531 | + // Update the height of a line, propagating the height change | |
| 2532 | + // upwards to parent nodes. | |
| 2533 | + function updateLineHeight(line, height) { | |
| 2534 | + var diff = height - line.height; | |
| 2535 | + if (diff) { for (var n = line; n; n = n.parent) { n.height += diff; } } | |
| 2536 | + } | |
| 2537 | + | |
| 2538 | + // Given a line object, find its line number by walking up through | |
| 2539 | + // its parent links. | |
| 2540 | + function lineNo(line) { | |
| 2541 | + if (line.parent == null) { return null } | |
| 2542 | + var cur = line.parent, no = indexOf(cur.lines, line); | |
| 2543 | + for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) { | |
| 2544 | + for (var i = 0;; ++i) { | |
| 2545 | + if (chunk.children[i] == cur) { break } | |
| 2546 | + no += chunk.children[i].chunkSize(); | |
| 2547 | + } | |
| 2548 | + } | |
| 2549 | + return no + cur.first | |
| 2550 | + } | |
| 2551 | + | |
| 2552 | + // Find the line at the given vertical position, using the height | |
| 2553 | + // information in the document tree. | |
| 2554 | + function lineAtHeight(chunk, h) { | |
| 2555 | + var n = chunk.first; | |
| 2556 | + outer: do { | |
| 2557 | + for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) { | |
| 2558 | + var child = chunk.children[i$1], ch = child.height; | |
| 2559 | + if (h < ch) { chunk = child; continue outer } | |
| 2560 | + h -= ch; | |
| 2561 | + n += child.chunkSize(); | |
| 2562 | + } | |
| 2563 | + return n | |
| 2564 | + } while (!chunk.lines) | |
| 2565 | + var i = 0; | |
| 2566 | + for (; i < chunk.lines.length; ++i) { | |
| 2567 | + var line = chunk.lines[i], lh = line.height; | |
| 2568 | + if (h < lh) { break } | |
| 2569 | + h -= lh; | |
| 2570 | + } | |
| 2571 | + return n + i | |
| 2572 | + } | |
| 2573 | + | |
| 2574 | + function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size} | |
| 2575 | + | |
| 2576 | + function lineNumberFor(options, i) { | |
| 2577 | + return String(options.lineNumberFormatter(i + options.firstLineNumber)) | |
| 2578 | + } | |
| 2579 | + | |
| 2580 | + // A Pos instance represents a position within the text. | |
| 2581 | + function Pos(line, ch, sticky) { | |
| 2582 | + if ( sticky === void 0 ) sticky = null; | |
| 2583 | + | |
| 2584 | + if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) } | |
| 2585 | + this.line = line; | |
| 2586 | + this.ch = ch; | |
| 2587 | + this.sticky = sticky; | |
| 2588 | + } | |
| 2589 | + | |
| 2590 | + // Compare two positions, return 0 if they are the same, a negative | |
| 2591 | + // number when a is less, and a positive number otherwise. | |
| 2592 | + function cmp(a, b) { return a.line - b.line || a.ch - b.ch } | |
| 2593 | + | |
| 2594 | + function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 } | |
| 2595 | + | |
| 2596 | + function copyPos(x) {return Pos(x.line, x.ch)} | |
| 2597 | + function maxPos(a, b) { return cmp(a, b) < 0 ? b : a } | |
| 2598 | + function minPos(a, b) { return cmp(a, b) < 0 ? a : b } | |
| 2599 | + | |
| 2600 | + // Most of the external API clips given positions to make sure they | |
| 2601 | + // actually exist within the document. | |
| 2602 | + function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))} | |
| 2603 | + function clipPos(doc, pos) { | |
| 2604 | + if (pos.line < doc.first) { return Pos(doc.first, 0) } | |
| 2605 | + var last = doc.first + doc.size - 1; | |
| 2606 | + if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) } | |
| 2607 | + return clipToLen(pos, getLine(doc, pos.line).text.length) | |
| 2608 | + } | |
| 2609 | + function clipToLen(pos, linelen) { | |
| 2610 | + var ch = pos.ch; | |
| 2611 | + if (ch == null || ch > linelen) { return Pos(pos.line, linelen) } | |
| 2612 | + else if (ch < 0) { return Pos(pos.line, 0) } | |
| 2613 | + else { return pos } | |
| 2614 | + } | |
| 2615 | + function clipPosArray(doc, array) { | |
| 2616 | + var out = []; | |
| 2617 | + for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]); } | |
| 2618 | + return out | |
| 2619 | + } | |
| 2620 | + | |
| 2621 | + var SavedContext = function(state, lookAhead) { | |
| 2622 | + this.state = state; | |
| 2623 | + this.lookAhead = lookAhead; | |
| 2624 | + }; | |
| 2625 | + | |
| 2626 | + var Context = function(doc, state, line, lookAhead) { | |
| 2627 | + this.state = state; | |
| 2628 | + this.doc = doc; | |
| 2629 | + this.line = line; | |
| 2630 | + this.maxLookAhead = lookAhead || 0; | |
| 2631 | + this.baseTokens = null; | |
| 2632 | + this.baseTokenPos = 1; | |
| 2633 | + }; | |
| 2634 | + | |
| 2635 | + Context.prototype.lookAhead = function (n) { | |
| 2636 | + var line = this.doc.getLine(this.line + n); | |
| 2637 | + if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n; } | |
| 2638 | + return line | |
| 2639 | + }; | |
| 2640 | + | |
| 2641 | + Context.prototype.baseToken = function (n) { | |
| 2642 | + if (!this.baseTokens) { return null } | |
| 2643 | + while (this.baseTokens[this.baseTokenPos] <= n) | |
| 2644 | + { this.baseTokenPos += 2; } | |
| 2645 | + var type = this.baseTokens[this.baseTokenPos + 1]; | |
| 2646 | + return {type: type && type.replace(/( |^)overlay .*/, ""), | |
| 2647 | + size: this.baseTokens[this.baseTokenPos] - n} | |
| 2648 | + }; | |
| 2649 | + | |
| 2650 | + Context.prototype.nextLine = function () { | |
| 2651 | + this.line++; | |
| 2652 | + if (this.maxLookAhead > 0) { this.maxLookAhead--; } | |
| 2653 | + }; | |
| 2654 | + | |
| 2655 | + Context.fromSaved = function (doc, saved, line) { | |
| 2656 | + if (saved instanceof SavedContext) | |
| 2657 | + { return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) } | |
| 2658 | + else | |
| 2659 | + { return new Context(doc, copyState(doc.mode, saved), line) } | |
| 2660 | + }; | |
| 2661 | + | |
| 2662 | + Context.prototype.save = function (copy) { | |
| 2663 | + var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state; | |
| 2664 | + return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state | |
| 2665 | + }; | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + // Compute a style array (an array starting with a mode generation | |
| 2669 | + // -- for invalidation -- followed by pairs of end positions and | |
| 2670 | + // style strings), which is used to highlight the tokens on the | |
| 2671 | + // line. | |
| 2672 | + function highlightLine(cm, line, context, forceToEnd) { | |
| 2673 | + // A styles array always starts with a number identifying the | |
| 2674 | + // mode/overlays that it is based on (for easy invalidation). | |
| 2675 | + var st = [cm.state.modeGen], lineClasses = {}; | |
| 2676 | + // Compute the base array of styles | |
| 2677 | + runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); }, | |
| 2678 | + lineClasses, forceToEnd); | |
| 2679 | + var state = context.state; | |
| 2680 | + | |
| 2681 | + // Run overlays, adjust style array. | |
| 2682 | + var loop = function ( o ) { | |
| 2683 | + context.baseTokens = st; | |
| 2684 | + var overlay = cm.state.overlays[o], i = 1, at = 0; | |
| 2685 | + context.state = true; | |
| 2686 | + runMode(cm, line.text, overlay.mode, context, function (end, style) { | |
| 2687 | + var start = i; | |
| 2688 | + // Ensure there's a token end at the current position, and that i points at it | |
| 2689 | + while (at < end) { | |
| 2690 | + var i_end = st[i]; | |
| 2691 | + if (i_end > end) | |
| 2692 | + { st.splice(i, 1, end, st[i+1], i_end); } | |
| 2693 | + i += 2; | |
| 2694 | + at = Math.min(end, i_end); | |
| 2695 | + } | |
| 2696 | + if (!style) { return } | |
| 2697 | + if (overlay.opaque) { | |
| 2698 | + st.splice(start, i - start, end, "overlay " + style); | |
| 2699 | + i = start + 2; | |
| 2700 | + } else { | |
| 2701 | + for (; start < i; start += 2) { | |
| 2702 | + var cur = st[start+1]; | |
| 2703 | + st[start+1] = (cur ? cur + " " : "") + "overlay " + style; | |
| 2704 | + } | |
| 2705 | + } | |
| 2706 | + }, lineClasses); | |
| 2707 | + context.state = state; | |
| 2708 | + context.baseTokens = null; | |
| 2709 | + context.baseTokenPos = 1; | |
| 2710 | + }; | |
| 2711 | + | |
| 2712 | + for (var o = 0; o < cm.state.overlays.length; ++o) loop( o ); | |
| 2713 | + | |
| 2714 | + return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null} | |
| 2715 | + } | |
| 2716 | + | |
| 2717 | + function getLineStyles(cm, line, updateFrontier) { | |
| 2718 | + if (!line.styles || line.styles[0] != cm.state.modeGen) { | |
| 2719 | + var context = getContextBefore(cm, lineNo(line)); | |
| 2720 | + var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state); | |
| 2721 | + var result = highlightLine(cm, line, context); | |
| 2722 | + if (resetState) { context.state = resetState; } | |
| 2723 | + line.stateAfter = context.save(!resetState); | |
| 2724 | + line.styles = result.styles; | |
| 2725 | + if (result.classes) { line.styleClasses = result.classes; } | |
| 2726 | + else if (line.styleClasses) { line.styleClasses = null; } | |
| 2727 | + if (updateFrontier === cm.doc.highlightFrontier) | |
| 2728 | + { cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier); } | |
| 2729 | + } | |
| 2730 | + return line.styles | |
| 2731 | + } | |
| 2732 | + | |
| 2733 | + function getContextBefore(cm, n, precise) { | |
| 2734 | + var doc = cm.doc, display = cm.display; | |
| 2735 | + if (!doc.mode.startState) { return new Context(doc, true, n) } | |
| 2736 | + var start = findStartLine(cm, n, precise); | |
| 2737 | + var saved = start > doc.first && getLine(doc, start - 1).stateAfter; | |
| 2738 | + var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start); | |
| 2739 | + | |
| 2740 | + doc.iter(start, n, function (line) { | |
| 2741 | + processLine(cm, line.text, context); | |
| 2742 | + var pos = context.line; | |
| 2743 | + line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null; | |
| 2744 | + context.nextLine(); | |
| 2745 | + }); | |
| 2746 | + if (precise) { doc.modeFrontier = context.line; } | |
| 2747 | + return context | |
| 2748 | + } | |
| 2749 | + | |
| 2750 | + // Lightweight form of highlight -- proceed over this line and | |
| 2751 | + // update state, but don't save a style array. Used for lines that | |
| 2752 | + // aren't currently visible. | |
| 2753 | + function processLine(cm, text, context, startAt) { | |
| 2754 | + var mode = cm.doc.mode; | |
| 2755 | + var stream = new StringStream(text, cm.options.tabSize, context); | |
| 2756 | + stream.start = stream.pos = startAt || 0; | |
| 2757 | + if (text == "") { callBlankLine(mode, context.state); } | |
| 2758 | + while (!stream.eol()) { | |
| 2759 | + readToken(mode, stream, context.state); | |
| 2760 | + stream.start = stream.pos; | |
| 2761 | + } | |
| 2762 | + } | |
| 2763 | + | |
| 2764 | + function callBlankLine(mode, state) { | |
| 2765 | + if (mode.blankLine) { return mode.blankLine(state) } | |
| 2766 | + if (!mode.innerMode) { return } | |
| 2767 | + var inner = innerMode(mode, state); | |
| 2768 | + if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) } | |
| 2769 | + } | |
| 2770 | + | |
| 2771 | + function readToken(mode, stream, state, inner) { | |
| 2772 | + for (var i = 0; i < 10; i++) { | |
| 2773 | + if (inner) { inner[0] = innerMode(mode, state).mode; } | |
| 2774 | + var style = mode.token(stream, state); | |
| 2775 | + if (stream.pos > stream.start) { return style } | |
| 2776 | + } | |
| 2777 | + throw new Error("Mode " + mode.name + " failed to advance stream.") | |
| 2778 | + } | |
| 2779 | + | |
| 2780 | + var Token = function(stream, type, state) { | |
| 2781 | + this.start = stream.start; this.end = stream.pos; | |
| 2782 | + this.string = stream.current(); | |
| 2783 | + this.type = type || null; | |
| 2784 | + this.state = state; | |
| 2785 | + }; | |
| 2786 | + | |
| 2787 | + // Utility for getTokenAt and getLineTokens | |
| 2788 | + function takeToken(cm, pos, precise, asArray) { | |
| 2789 | + var doc = cm.doc, mode = doc.mode, style; | |
| 2790 | + pos = clipPos(doc, pos); | |
| 2791 | + var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise); | |
| 2792 | + var stream = new StringStream(line.text, cm.options.tabSize, context), tokens; | |
| 2793 | + if (asArray) { tokens = []; } | |
| 2794 | + while ((asArray || stream.pos < pos.ch) && !stream.eol()) { | |
| 2795 | + stream.start = stream.pos; | |
| 2796 | + style = readToken(mode, stream, context.state); | |
| 2797 | + if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))); } | |
| 2798 | + } | |
| 2799 | + return asArray ? tokens : new Token(stream, style, context.state) | |
| 2800 | + } | |
| 2801 | + | |
| 2802 | + function extractLineClasses(type, output) { | |
| 2803 | + if (type) { for (;;) { | |
| 2804 | + var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/); | |
| 2805 | + if (!lineClass) { break } | |
| 2806 | + type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length); | |
| 2807 | + var prop = lineClass[1] ? "bgClass" : "textClass"; | |
| 2808 | + if (output[prop] == null) | |
| 2809 | + { output[prop] = lineClass[2]; } | |
| 2810 | + else if (!(new RegExp("(?:^|\\s)" + lineClass[2] + "(?:$|\\s)")).test(output[prop])) | |
| 2811 | + { output[prop] += " " + lineClass[2]; } | |
| 2812 | + } } | |
| 2813 | + return type | |
| 2814 | + } | |
| 2815 | + | |
| 2816 | + // Run the given mode's parser over a line, calling f for each token. | |
| 2817 | + function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) { | |
| 2818 | + var flattenSpans = mode.flattenSpans; | |
| 2819 | + if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans; } | |
| 2820 | + var curStart = 0, curStyle = null; | |
| 2821 | + var stream = new StringStream(text, cm.options.tabSize, context), style; | |
| 2822 | + var inner = cm.options.addModeClass && [null]; | |
| 2823 | + if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses); } | |
| 2824 | + while (!stream.eol()) { | |
| 2825 | + if (stream.pos > cm.options.maxHighlightLength) { | |
| 2826 | + flattenSpans = false; | |
| 2827 | + if (forceToEnd) { processLine(cm, text, context, stream.pos); } | |
| 2828 | + stream.pos = text.length; | |
| 2829 | + style = null; | |
| 2830 | + } else { | |
| 2831 | + style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses); | |
| 2832 | + } | |
| 2833 | + if (inner) { | |
| 2834 | + var mName = inner[0].name; | |
| 2835 | + if (mName) { style = "m-" + (style ? mName + " " + style : mName); } | |
| 2836 | + } | |
| 2837 | + if (!flattenSpans || curStyle != style) { | |
| 2838 | + while (curStart < stream.start) { | |
| 2839 | + curStart = Math.min(stream.start, curStart + 5000); | |
| 2840 | + f(curStart, curStyle); | |
| 2841 | + } | |
| 2842 | + curStyle = style; | |
| 2843 | + } | |
| 2844 | + stream.start = stream.pos; | |
| 2845 | + } | |
| 2846 | + while (curStart < stream.pos) { | |
| 2847 | + // Webkit seems to refuse to render text nodes longer than 57444 | |
| 2848 | + // characters, and returns inaccurate measurements in nodes | |
| 2849 | + // starting around 5000 chars. | |
| 2850 | + var pos = Math.min(stream.pos, curStart + 5000); | |
| 2851 | + f(pos, curStyle); | |
| 2852 | + curStart = pos; | |
| 2853 | + } | |
| 2854 | + } | |
| 2855 | + | |
| 2856 | + // Finds the line to start with when starting a parse. Tries to | |
| 2857 | + // find a line with a stateAfter, so that it can start with a | |
| 2858 | + // valid state. If that fails, it returns the line with the | |
| 2859 | + // smallest indentation, which tends to need the least context to | |
| 2860 | + // parse correctly. | |
| 2861 | + function findStartLine(cm, n, precise) { | |
| 2862 | + var minindent, minline, doc = cm.doc; | |
| 2863 | + var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100); | |
| 2864 | + for (var search = n; search > lim; --search) { | |
| 2865 | + if (search <= doc.first) { return doc.first } | |
| 2866 | + var line = getLine(doc, search - 1), after = line.stateAfter; | |
| 2867 | + if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier)) | |
| 2868 | + { return search } | |
| 2869 | + var indented = countColumn(line.text, null, cm.options.tabSize); | |
| 2870 | + if (minline == null || minindent > indented) { | |
| 2871 | + minline = search - 1; | |
| 2872 | + minindent = indented; | |
| 2873 | + } | |
| 2874 | + } | |
| 2875 | + return minline | |
| 2876 | + } | |
| 2877 | + | |
| 2878 | + function retreatFrontier(doc, n) { | |
| 2879 | + doc.modeFrontier = Math.min(doc.modeFrontier, n); | |
| 2880 | + if (doc.highlightFrontier < n - 10) { return } | |
| 2881 | + var start = doc.first; | |
| 2882 | + for (var line = n - 1; line > start; line--) { | |
| 2883 | + var saved = getLine(doc, line).stateAfter; | |
| 2884 | + // change is on 3 | |
| 2885 | + // state on line 1 looked ahead 2 -- so saw 3 | |
| 2886 | + // test 1 + 2 < 3 should cover this | |
| 2887 | + if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) { | |
| 2888 | + start = line + 1; | |
| 2889 | + break | |
| 2890 | + } | |
| 2891 | + } | |
| 2892 | + doc.highlightFrontier = Math.min(doc.highlightFrontier, start); | |
| 2893 | + } | |
| 2894 | + | |
| 2895 | + // Optimize some code when these features are not used. | |
| 2896 | + var sawReadOnlySpans = false, sawCollapsedSpans = false; | |
| 2897 | + | |
| 2898 | + function seeReadOnlySpans() { | |
| 2899 | + sawReadOnlySpans = true; | |
| 2900 | + } | |
| 2901 | + | |
| 2902 | + function seeCollapsedSpans() { | |
| 2903 | + sawCollapsedSpans = true; | |
| 2904 | + } | |
| 2905 | + | |
| 2906 | + // TEXTMARKER SPANS | |
| 2907 | + | |
| 2908 | + function MarkedSpan(marker, from, to) { | |
| 2909 | + this.marker = marker; | |
| 2910 | + this.from = from; this.to = to; | |
| 2911 | + } | |
| 2912 | + | |
| 2913 | + // Search an array of spans for a span matching the given marker. | |
| 2914 | + function getMarkedSpanFor(spans, marker) { | |
| 2915 | + if (spans) { for (var i = 0; i < spans.length; ++i) { | |
| 2916 | + var span = spans[i]; | |
| 2917 | + if (span.marker == marker) { return span } | |
| 2918 | + } } | |
| 2919 | + } | |
| 2920 | + // Remove a span from an array, returning undefined if no spans are | |
| 2921 | + // left (we don't store arrays for lines without spans). | |
| 2922 | + function removeMarkedSpan(spans, span) { | |
| 2923 | + var r; | |
| 2924 | + for (var i = 0; i < spans.length; ++i) | |
| 2925 | + { if (spans[i] != span) { (r || (r = [])).push(spans[i]); } } | |
| 2926 | + return r | |
| 2927 | + } | |
| 2928 | + // Add a span to a line. | |
| 2929 | + function addMarkedSpan(line, span) { | |
| 2930 | + line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span]; | |
| 2931 | + span.marker.attachLine(line); | |
| 2932 | + } | |
| 2933 | + | |
| 2934 | + // Used for the algorithm that adjusts markers for a change in the | |
| 2935 | + // document. These functions cut an array of spans at a given | |
| 2936 | + // character position, returning an array of remaining chunks (or | |
| 2937 | + // undefined if nothing remains). | |
| 2938 | + function markedSpansBefore(old, startCh, isInsert) { | |
| 2939 | + var nw; | |
| 2940 | + if (old) { for (var i = 0; i < old.length; ++i) { | |
| 2941 | + var span = old[i], marker = span.marker; | |
| 2942 | + var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh); | |
| 2943 | + if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) { | |
| 2944 | + var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh) | |
| 2945 | + ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to)); | |
| 2946 | + } | |
| 2947 | + } } | |
| 2948 | + return nw | |
| 2949 | + } | |
| 2950 | + function markedSpansAfter(old, endCh, isInsert) { | |
| 2951 | + var nw; | |
| 2952 | + if (old) { for (var i = 0; i < old.length; ++i) { | |
| 2953 | + var span = old[i], marker = span.marker; | |
| 2954 | + var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh); | |
| 2955 | + if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) { | |
| 2956 | + var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh) | |
| 2957 | + ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh, | |
| 2958 | + span.to == null ? null : span.to - endCh)); | |
| 2959 | + } | |
| 2960 | + } } | |
| 2961 | + return nw | |
| 2962 | + } | |
| 2963 | + | |
| 2964 | + // Given a change object, compute the new set of marker spans that | |
| 2965 | + // cover the line in which the change took place. Removes spans | |
| 2966 | + // entirely within the change, reconnects spans belonging to the | |
| 2967 | + // same marker that appear on both sides of the change, and cuts off | |
| 2968 | + // spans partially within the change. Returns an array of span | |
| 2969 | + // arrays with one element for each line in (after) the change. | |
| 2970 | + function stretchSpansOverChange(doc, change) { | |
| 2971 | + if (change.full) { return null } | |
| 2972 | + var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans; | |
| 2973 | + var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans; | |
| 2974 | + if (!oldFirst && !oldLast) { return null } | |
| 2975 | + | |
| 2976 | + var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0; | |
| 2977 | + // Get the spans that 'stick out' on both sides | |
| 2978 | + var first = markedSpansBefore(oldFirst, startCh, isInsert); | |
| 2979 | + var last = markedSpansAfter(oldLast, endCh, isInsert); | |
| 2980 | + | |
| 2981 | + // Next, merge those two ends | |
| 2982 | + var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0); | |
| 2983 | + if (first) { | |
| 2984 | + // Fix up .to properties of first | |
| 2985 | + for (var i = 0; i < first.length; ++i) { | |
| 2986 | + var span = first[i]; | |
| 2987 | + if (span.to == null) { | |
| 2988 | + var found = getMarkedSpanFor(last, span.marker); | |
| 2989 | + if (!found) { span.to = startCh; } | |
| 2990 | + else if (sameLine) { span.to = found.to == null ? null : found.to + offset; } | |
| 2991 | + } | |
| 2992 | + } | |
| 2993 | + } | |
| 2994 | + if (last) { | |
| 2995 | + // Fix up .from in last (or move them into first in case of sameLine) | |
| 2996 | + for (var i$1 = 0; i$1 < last.length; ++i$1) { | |
| 2997 | + var span$1 = last[i$1]; | |
| 2998 | + if (span$1.to != null) { span$1.to += offset; } | |
| 2999 | + if (span$1.from == null) { | |
| 3000 | + var found$1 = getMarkedSpanFor(first, span$1.marker); | |
| 3001 | + if (!found$1) { | |
| 3002 | + span$1.from = offset; | |
| 3003 | + if (sameLine) { (first || (first = [])).push(span$1); } | |
| 3004 | + } | |
| 3005 | + } else { | |
| 3006 | + span$1.from += offset; | |
| 3007 | + if (sameLine) { (first || (first = [])).push(span$1); } | |
| 3008 | + } | |
| 3009 | + } | |
| 3010 | + } | |
| 3011 | + // Make sure we didn't create any zero-length spans | |
| 3012 | + if (first) { first = clearEmptySpans(first); } | |
| 3013 | + if (last && last != first) { last = clearEmptySpans(last); } | |
| 3014 | + | |
| 3015 | + var newMarkers = [first]; | |
| 3016 | + if (!sameLine) { | |
| 3017 | + // Fill gap with whole-line-spans | |
| 3018 | + var gap = change.text.length - 2, gapMarkers; | |
| 3019 | + if (gap > 0 && first) | |
| 3020 | + { for (var i$2 = 0; i$2 < first.length; ++i$2) | |
| 3021 | + { if (first[i$2].to == null) | |
| 3022 | + { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)); } } } | |
| 3023 | + for (var i$3 = 0; i$3 < gap; ++i$3) | |
| 3024 | + { newMarkers.push(gapMarkers); } | |
| 3025 | + newMarkers.push(last); | |
| 3026 | + } | |
| 3027 | + return newMarkers | |
| 3028 | + } | |
| 3029 | + | |
| 3030 | + // Remove spans that are empty and don't have a clearWhenEmpty | |
| 3031 | + // option of false. | |
| 3032 | + function clearEmptySpans(spans) { | |
| 3033 | + for (var i = 0; i < spans.length; ++i) { | |
| 3034 | + var span = spans[i]; | |
| 3035 | + if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false) | |
| 3036 | + { spans.splice(i--, 1); } | |
| 3037 | + } | |
| 3038 | + if (!spans.length) { return null } | |
| 3039 | + return spans | |
| 3040 | + } | |
| 3041 | + | |
| 3042 | + // Used to 'clip' out readOnly ranges when making a change. | |
| 3043 | + function removeReadOnlyRanges(doc, from, to) { | |
| 3044 | + var markers = null; | |
| 3045 | + doc.iter(from.line, to.line + 1, function (line) { | |
| 3046 | + if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) { | |
| 3047 | + var mark = line.markedSpans[i].marker; | |
| 3048 | + if (mark.readOnly && (!markers || indexOf(markers, mark) == -1)) | |
| 3049 | + { (markers || (markers = [])).push(mark); } | |
| 3050 | + } } | |
| 3051 | + }); | |
| 3052 | + if (!markers) { return null } | |
| 3053 | + var parts = [{from: from, to: to}]; | |
| 3054 | + for (var i = 0; i < markers.length; ++i) { | |
| 3055 | + var mk = markers[i], m = mk.find(0); | |
| 3056 | + for (var j = 0; j < parts.length; ++j) { | |
| 3057 | + var p = parts[j]; | |
| 3058 | + if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue } | |
| 3059 | + var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to); | |
| 3060 | + if (dfrom < 0 || !mk.inclusiveLeft && !dfrom) | |
| 3061 | + { newParts.push({from: p.from, to: m.from}); } | |
| 3062 | + if (dto > 0 || !mk.inclusiveRight && !dto) | |
| 3063 | + { newParts.push({from: m.to, to: p.to}); } | |
| 3064 | + parts.splice.apply(parts, newParts); | |
| 3065 | + j += newParts.length - 3; | |
| 3066 | + } | |
| 3067 | + } | |
| 3068 | + return parts | |
| 3069 | + } | |
| 3070 | + | |
| 3071 | + // Connect or disconnect spans from a line. | |
| 3072 | + function detachMarkedSpans(line) { | |
| 3073 | + var spans = line.markedSpans; | |
| 3074 | + if (!spans) { return } | |
| 3075 | + for (var i = 0; i < spans.length; ++i) | |
| 3076 | + { spans[i].marker.detachLine(line); } | |
| 3077 | + line.markedSpans = null; | |
| 3078 | + } | |
| 3079 | + function attachMarkedSpans(line, spans) { | |
| 3080 | + if (!spans) { return } | |
| 3081 | + for (var i = 0; i < spans.length; ++i) | |
| 3082 | + { spans[i].marker.attachLine(line); } | |
| 3083 | + line.markedSpans = spans; | |
| 3084 | + } | |
| 3085 | + | |
| 3086 | + // Helpers used when computing which overlapping collapsed span | |
| 3087 | + // counts as the larger one. | |
| 3088 | + function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 } | |
| 3089 | + function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 } | |
| 3090 | + | |
| 3091 | + // Returns a number indicating which of two overlapping collapsed | |
| 3092 | + // spans is larger (and thus includes the other). Falls back to | |
| 3093 | + // comparing ids when the spans cover exactly the same range. | |
| 3094 | + function compareCollapsedMarkers(a, b) { | |
| 3095 | + var lenDiff = a.lines.length - b.lines.length; | |
| 3096 | + if (lenDiff != 0) { return lenDiff } | |
| 3097 | + var aPos = a.find(), bPos = b.find(); | |
| 3098 | + var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b); | |
| 3099 | + if (fromCmp) { return -fromCmp } | |
| 3100 | + var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b); | |
| 3101 | + if (toCmp) { return toCmp } | |
| 3102 | + return b.id - a.id | |
| 3103 | + } | |
| 3104 | + | |
| 3105 | + // Find out whether a line ends or starts in a collapsed span. If | |
| 3106 | + // so, return the marker for that span. | |
| 3107 | + function collapsedSpanAtSide(line, start) { | |
| 3108 | + var sps = sawCollapsedSpans && line.markedSpans, found; | |
| 3109 | + if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) { | |
| 3110 | + sp = sps[i]; | |
| 3111 | + if (sp.marker.collapsed && (start ? sp.from : sp.to) == null && | |
| 3112 | + (!found || compareCollapsedMarkers(found, sp.marker) < 0)) | |
| 3113 | + { found = sp.marker; } | |
| 3114 | + } } | |
| 3115 | + return found | |
| 3116 | + } | |
| 3117 | + function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) } | |
| 3118 | + function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) } | |
| 3119 | + | |
| 3120 | + function collapsedSpanAround(line, ch) { | |
| 3121 | + var sps = sawCollapsedSpans && line.markedSpans, found; | |
| 3122 | + if (sps) { for (var i = 0; i < sps.length; ++i) { | |
| 3123 | + var sp = sps[i]; | |
| 3124 | + if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) && | |
| 3125 | + (!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker; } | |
| 3126 | + } } | |
| 3127 | + return found | |
| 3128 | + } | |
| 3129 | + | |
| 3130 | + // Test whether there exists a collapsed span that partially | |
| 3131 | + // overlaps (covers the start or end, but not both) of a new span. | |
| 3132 | + // Such overlap is not allowed. | |
| 3133 | + function conflictingCollapsedRange(doc, lineNo, from, to, marker) { | |
| 3134 | + var line = getLine(doc, lineNo); | |
| 3135 | + var sps = sawCollapsedSpans && line.markedSpans; | |
| 3136 | + if (sps) { for (var i = 0; i < sps.length; ++i) { | |
| 3137 | + var sp = sps[i]; | |
| 3138 | + if (!sp.marker.collapsed) { continue } | |
| 3139 | + var found = sp.marker.find(0); | |
| 3140 | + var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker); | |
| 3141 | + var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker); | |
| 3142 | + if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue } | |
| 3143 | + if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) || | |
| 3144 | + fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0)) | |
| 3145 | + { return true } | |
| 3146 | + } } | |
| 3147 | + } | |
| 3148 | + | |
| 3149 | + // A visual line is a line as drawn on the screen. Folding, for | |
| 3150 | + // example, can cause multiple logical lines to appear on the same | |
| 3151 | + // visual line. This finds the start of the visual line that the | |
| 3152 | + // given line is part of (usually that is the line itself). | |
| 3153 | + function visualLine(line) { | |
| 3154 | + var merged; | |
| 3155 | + while (merged = collapsedSpanAtStart(line)) | |
| 3156 | + { line = merged.find(-1, true).line; } | |
| 3157 | + return line | |
| 3158 | + } | |
| 3159 | + | |
| 3160 | + function visualLineEnd(line) { | |
| 3161 | + var merged; | |
| 3162 | + while (merged = collapsedSpanAtEnd(line)) | |
| 3163 | + { line = merged.find(1, true).line; } | |
| 3164 | + return line | |
| 3165 | + } | |
| 3166 | + | |
| 3167 | + // Returns an array of logical lines that continue the visual line | |
| 3168 | + // started by the argument, or undefined if there are no such lines. | |
| 3169 | + function visualLineContinued(line) { | |
| 3170 | + var merged, lines; | |
| 3171 | + while (merged = collapsedSpanAtEnd(line)) { | |
| 3172 | + line = merged.find(1, true).line | |
| 3173 | + ;(lines || (lines = [])).push(line); | |
| 3174 | + } | |
| 3175 | + return lines | |
| 3176 | + } | |
| 3177 | + | |
| 3178 | + // Get the line number of the start of the visual line that the | |
| 3179 | + // given line number is part of. | |
| 3180 | + function visualLineNo(doc, lineN) { | |
| 3181 | + var line = getLine(doc, lineN), vis = visualLine(line); | |
| 3182 | + if (line == vis) { return lineN } | |
| 3183 | + return lineNo(vis) | |
| 3184 | + } | |
| 3185 | + | |
| 3186 | + // Get the line number of the start of the next visual line after | |
| 3187 | + // the given line. | |
| 3188 | + function visualLineEndNo(doc, lineN) { | |
| 3189 | + if (lineN > doc.lastLine()) { return lineN } | |
| 3190 | + var line = getLine(doc, lineN), merged; | |
| 3191 | + if (!lineIsHidden(doc, line)) { return lineN } | |
| 3192 | + while (merged = collapsedSpanAtEnd(line)) | |
| 3193 | + { line = merged.find(1, true).line; } | |
| 3194 | + return lineNo(line) + 1 | |
| 3195 | + } | |
| 3196 | + | |
| 3197 | + // Compute whether a line is hidden. Lines count as hidden when they | |
| 3198 | + // are part of a visual line that starts with another line, or when | |
| 3199 | + // they are entirely covered by collapsed, non-widget span. | |
| 3200 | + function lineIsHidden(doc, line) { | |
| 3201 | + var sps = sawCollapsedSpans && line.markedSpans; | |
| 3202 | + if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) { | |
| 3203 | + sp = sps[i]; | |
| 3204 | + if (!sp.marker.collapsed) { continue } | |
| 3205 | + if (sp.from == null) { return true } | |
| 3206 | + if (sp.marker.widgetNode) { continue } | |
| 3207 | + if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp)) | |
| 3208 | + { return true } | |
| 3209 | + } } | |
| 3210 | + } | |
| 3211 | + function lineIsHiddenInner(doc, line, span) { | |
| 3212 | + if (span.to == null) { | |
| 3213 | + var end = span.marker.find(1, true); | |
| 3214 | + return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker)) | |
| 3215 | + } | |
| 3216 | + if (span.marker.inclusiveRight && span.to == line.text.length) | |
| 3217 | + { return true } | |
| 3218 | + for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) { | |
| 3219 | + sp = line.markedSpans[i]; | |
| 3220 | + if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to && | |
| 3221 | + (sp.to == null || sp.to != span.from) && | |
| 3222 | + (sp.marker.inclusiveLeft || span.marker.inclusiveRight) && | |
| 3223 | + lineIsHiddenInner(doc, line, sp)) { return true } | |
| 3224 | + } | |
| 3225 | + } | |
| 3226 | + | |
| 3227 | + // Find the height above the given line. | |
| 3228 | + function heightAtLine(lineObj) { | |
| 3229 | + lineObj = visualLine(lineObj); | |
| 3230 | + | |
| 3231 | + var h = 0, chunk = lineObj.parent; | |
| 3232 | + for (var i = 0; i < chunk.lines.length; ++i) { | |
| 3233 | + var line = chunk.lines[i]; | |
| 3234 | + if (line == lineObj) { break } | |
| 3235 | + else { h += line.height; } | |
| 3236 | + } | |
| 3237 | + for (var p = chunk.parent; p; chunk = p, p = chunk.parent) { | |
| 3238 | + for (var i$1 = 0; i$1 < p.children.length; ++i$1) { | |
| 3239 | + var cur = p.children[i$1]; | |
| 3240 | + if (cur == chunk) { break } | |
| 3241 | + else { h += cur.height; } | |
| 3242 | + } | |
| 3243 | + } | |
| 3244 | + return h | |
| 3245 | + } | |
| 3246 | + | |
| 3247 | + // Compute the character length of a line, taking into account | |
| 3248 | + // collapsed ranges (see markText) that might hide parts, and join | |
| 3249 | + // other lines onto it. | |
| 3250 | + function lineLength(line) { | |
| 3251 | + if (line.height == 0) { return 0 } | |
| 3252 | + var len = line.text.length, merged, cur = line; | |
| 3253 | + while (merged = collapsedSpanAtStart(cur)) { | |
| 3254 | + var found = merged.find(0, true); | |
| 3255 | + cur = found.from.line; | |
| 3256 | + len += found.from.ch - found.to.ch; | |
| 3257 | + } | |
| 3258 | + cur = line; | |
| 3259 | + while (merged = collapsedSpanAtEnd(cur)) { | |
| 3260 | + var found$1 = merged.find(0, true); | |
| 3261 | + len -= cur.text.length - found$1.from.ch; | |
| 3262 | + cur = found$1.to.line; | |
| 3263 | + len += cur.text.length - found$1.to.ch; | |
| 3264 | + } | |
| 3265 | + return len | |
| 3266 | + } | |
| 3267 | + | |
| 3268 | + // Find the longest line in the document. | |
| 3269 | + function findMaxLine(cm) { | |
| 3270 | + var d = cm.display, doc = cm.doc; | |
| 3271 | + d.maxLine = getLine(doc, doc.first); | |
| 3272 | + d.maxLineLength = lineLength(d.maxLine); | |
| 3273 | + d.maxLineChanged = true; | |
| 3274 | + doc.iter(function (line) { | |
| 3275 | + var len = lineLength(line); | |
| 3276 | + if (len > d.maxLineLength) { | |
| 3277 | + d.maxLineLength = len; | |
| 3278 | + d.maxLine = line; | |
| 3279 | + } | |
| 3280 | + }); | |
| 3281 | + } | |
| 3282 | + | |
| 3283 | + // LINE DATA STRUCTURE | |
| 3284 | + | |
| 3285 | + // Line objects. These hold state related to a line, including | |
| 3286 | + // highlighting info (the styles array). | |
| 3287 | + var Line = function(text, markedSpans, estimateHeight) { | |
| 3288 | + this.text = text; | |
| 3289 | + attachMarkedSpans(this, markedSpans); | |
| 3290 | + this.height = estimateHeight ? estimateHeight(this) : 1; | |
| 3291 | + }; | |
| 3292 | + | |
| 3293 | + Line.prototype.lineNo = function () { return lineNo(this) }; | |
| 3294 | + eventMixin(Line); | |
| 3295 | + | |
| 3296 | + // Change the content (text, markers) of a line. Automatically | |
| 3297 | + // invalidates cached information and tries to re-estimate the | |
| 3298 | + // line's height. | |
| 3299 | + function updateLine(line, text, markedSpans, estimateHeight) { | |
| 3300 | + line.text = text; | |
| 3301 | + if (line.stateAfter) { line.stateAfter = null; } | |
| 3302 | + if (line.styles) { line.styles = null; } | |
| 3303 | + if (line.order != null) { line.order = null; } | |
| 3304 | + detachMarkedSpans(line); | |
| 3305 | + attachMarkedSpans(line, markedSpans); | |
| 3306 | + var estHeight = estimateHeight ? estimateHeight(line) : 1; | |
| 3307 | + if (estHeight != line.height) { updateLineHeight(line, estHeight); } | |
| 3308 | + } | |
| 3309 | + | |
| 3310 | + // Detach a line from the document tree and its markers. | |
| 3311 | + function cleanUpLine(line) { | |
| 3312 | + line.parent = null; | |
| 3313 | + detachMarkedSpans(line); | |
| 3314 | + } | |
| 3315 | + | |
| 3316 | + // Convert a style as returned by a mode (either null, or a string | |
| 3317 | + // containing one or more styles) to a CSS style. This is cached, | |
| 3318 | + // and also looks for line-wide styles. | |
| 3319 | + var styleToClassCache = {}, styleToClassCacheWithMode = {}; | |
| 3320 | + function interpretTokenStyle(style, options) { | |
| 3321 | + if (!style || /^\s*$/.test(style)) { return null } | |
| 3322 | + var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache; | |
| 3323 | + return cache[style] || | |
| 3324 | + (cache[style] = style.replace(/\S+/g, "cm-$&")) | |
| 3325 | + } | |
| 3326 | + | |
| 3327 | + // Render the DOM representation of the text of a line. Also builds | |
| 3328 | + // up a 'line map', which points at the DOM nodes that represent | |
| 3329 | + // specific stretches of text, and is used by the measuring code. | |
| 3330 | + // The returned object contains the DOM node, this map, and | |
| 3331 | + // information about line-wide styles that were set by the mode. | |
| 3332 | + function buildLineContent(cm, lineView) { | |
| 3333 | + // The padding-right forces the element to have a 'border', which | |
| 3334 | + // is needed on Webkit to be able to get line-level bounding | |
| 3335 | + // rectangles for it (in measureChar). | |
| 3336 | + var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null); | |
| 3337 | + var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content, | |
| 3338 | + col: 0, pos: 0, cm: cm, | |
| 3339 | + trailingSpace: false, | |
| 3340 | + splitSpaces: cm.getOption("lineWrapping")}; | |
| 3341 | + lineView.measure = {}; | |
| 3342 | + | |
| 3343 | + // Iterate over the logical lines that make up this visual line. | |
| 3344 | + for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) { | |
| 3345 | + var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0); | |
| 3346 | + builder.pos = 0; | |
| 3347 | + builder.addToken = buildToken; | |
| 3348 | + // Optionally wire in some hacks into the token-rendering | |
| 3349 | + // algorithm, to deal with browser quirks. | |
| 3350 | + if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) | |
| 3351 | + { builder.addToken = buildTokenBadBidi(builder.addToken, order); } | |
| 3352 | + builder.map = []; | |
| 3353 | + var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line); | |
| 3354 | + insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate)); | |
| 3355 | + if (line.styleClasses) { | |
| 3356 | + if (line.styleClasses.bgClass) | |
| 3357 | + { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || ""); } | |
| 3358 | + if (line.styleClasses.textClass) | |
| 3359 | + { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || ""); } | |
| 3360 | + } | |
| 3361 | + | |
| 3362 | + // Ensure at least a single node is present, for measuring. | |
| 3363 | + if (builder.map.length == 0) | |
| 3364 | + { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))); } | |
| 3365 | + | |
| 3366 | + // Store the map and a cache object for the current logical line | |
| 3367 | + if (i == 0) { | |
| 3368 | + lineView.measure.map = builder.map; | |
| 3369 | + lineView.measure.cache = {}; | |
| 3370 | + } else { | |
| 3371 | + (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map) | |
| 3372 | + ;(lineView.measure.caches || (lineView.measure.caches = [])).push({}); | |
| 3373 | + } | |
| 3374 | + } | |
| 3375 | + | |
| 3376 | + // See issue #2901 | |
| 3377 | + if (webkit) { | |
| 3378 | + var last = builder.content.lastChild; | |
| 3379 | + if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab"))) | |
| 3380 | + { builder.content.className = "cm-tab-wrap-hack"; } | |
| 3381 | + } | |
| 3382 | + | |
| 3383 | + signal(cm, "renderLine", cm, lineView.line, builder.pre); | |
| 3384 | + if (builder.pre.className) | |
| 3385 | + { builder.textClass = joinClasses(builder.pre.className, builder.textClass || ""); } | |
| 3386 | + | |
| 3387 | + return builder | |
| 3388 | + } | |
| 3389 | + | |
| 3390 | + function defaultSpecialCharPlaceholder(ch) { | |
| 3391 | + var token = elt("span", "\u2022", "cm-invalidchar"); | |
| 3392 | + token.title = "\\u" + ch.charCodeAt(0).toString(16); | |
| 3393 | + token.setAttribute("aria-label", token.title); | |
| 3394 | + return token | |
| 3395 | + } | |
| 3396 | + | |
| 3397 | + // Build up the DOM representation for a single token, and add it to | |
| 3398 | + // the line map. Takes care to render special characters separately. | |
| 3399 | + function buildToken(builder, text, style, startStyle, endStyle, css, attributes) { | |
| 3400 | + if (!text) { return } | |
| 3401 | + var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text; | |
| 3402 | + var special = builder.cm.state.specialChars, mustWrap = false; | |
| 3403 | + var content; | |
| 3404 | + if (!special.test(text)) { | |
| 3405 | + builder.col += text.length; | |
| 3406 | + content = document.createTextNode(displayText); | |
| 3407 | + builder.map.push(builder.pos, builder.pos + text.length, content); | |
| 3408 | + if (ie && ie_version < 9) { mustWrap = true; } | |
| 3409 | + builder.pos += text.length; | |
| 3410 | + } else { | |
| 3411 | + content = document.createDocumentFragment(); | |
| 3412 | + var pos = 0; | |
| 3413 | + while (true) { | |
| 3414 | + special.lastIndex = pos; | |
| 3415 | + var m = special.exec(text); | |
| 3416 | + var skipped = m ? m.index - pos : text.length - pos; | |
| 3417 | + if (skipped) { | |
| 3418 | + var txt = document.createTextNode(displayText.slice(pos, pos + skipped)); | |
| 3419 | + if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])); } | |
| 3420 | + else { content.appendChild(txt); } | |
| 3421 | + builder.map.push(builder.pos, builder.pos + skipped, txt); | |
| 3422 | + builder.col += skipped; | |
| 3423 | + builder.pos += skipped; | |
| 3424 | + } | |
| 3425 | + if (!m) { break } | |
| 3426 | + pos += skipped + 1; | |
| 3427 | + var txt$1 = (void 0); | |
| 3428 | + if (m[0] == "\t") { | |
| 3429 | + var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize; | |
| 3430 | + txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab")); | |
| 3431 | + txt$1.setAttribute("role", "presentation"); | |
| 3432 | + txt$1.setAttribute("cm-text", "\t"); | |
| 3433 | + builder.col += tabWidth; | |
| 3434 | + } else if (m[0] == "\r" || m[0] == "\n") { | |
| 3435 | + txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar")); | |
| 3436 | + txt$1.setAttribute("cm-text", m[0]); | |
| 3437 | + builder.col += 1; | |
| 3438 | + } else { | |
| 3439 | + txt$1 = builder.cm.options.specialCharPlaceholder(m[0]); | |
| 3440 | + txt$1.setAttribute("cm-text", m[0]); | |
| 3441 | + if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])); } | |
| 3442 | + else { content.appendChild(txt$1); } | |
| 3443 | + builder.col += 1; | |
| 3444 | + } | |
| 3445 | + builder.map.push(builder.pos, builder.pos + 1, txt$1); | |
| 3446 | + builder.pos++; | |
| 3447 | + } | |
| 3448 | + } | |
| 3449 | + builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32; | |
| 3450 | + if (style || startStyle || endStyle || mustWrap || css || attributes) { | |
| 3451 | + var fullStyle = style || ""; | |
| 3452 | + if (startStyle) { fullStyle += startStyle; } | |
| 3453 | + if (endStyle) { fullStyle += endStyle; } | |
| 3454 | + var token = elt("span", [content], fullStyle, css); | |
| 3455 | + if (attributes) { | |
| 3456 | + for (var attr in attributes) { if (attributes.hasOwnProperty(attr) && attr != "style" && attr != "class") | |
| 3457 | + { token.setAttribute(attr, attributes[attr]); } } | |
| 3458 | + } | |
| 3459 | + return builder.content.appendChild(token) | |
| 3460 | + } | |
| 3461 | + builder.content.appendChild(content); | |
| 3462 | + } | |
| 3463 | + | |
| 3464 | + // Change some spaces to NBSP to prevent the browser from collapsing | |
| 3465 | + // trailing spaces at the end of a line when rendering text (issue #1362). | |
| 3466 | + function splitSpaces(text, trailingBefore) { | |
| 3467 | + if (text.length > 1 && !/ /.test(text)) { return text } | |
| 3468 | + var spaceBefore = trailingBefore, result = ""; | |
| 3469 | + for (var i = 0; i < text.length; i++) { | |
| 3470 | + var ch = text.charAt(i); | |
| 3471 | + if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) | |
| 3472 | + { ch = "\u00a0"; } | |
| 3473 | + result += ch; | |
| 3474 | + spaceBefore = ch == " "; | |
| 3475 | + } | |
| 3476 | + return result | |
| 3477 | + } | |
| 3478 | + | |
| 3479 | + // Work around nonsense dimensions being reported for stretches of | |
| 3480 | + // right-to-left text. | |
| 3481 | + function buildTokenBadBidi(inner, order) { | |
| 3482 | + return function (builder, text, style, startStyle, endStyle, css, attributes) { | |
| 3483 | + style = style ? style + " cm-force-border" : "cm-force-border"; | |
| 3484 | + var start = builder.pos, end = start + text.length; | |
| 3485 | + for (;;) { | |
| 3486 | + // Find the part that overlaps with the start of this text | |
| 3487 | + var part = (void 0); | |
| 3488 | + for (var i = 0; i < order.length; i++) { | |
| 3489 | + part = order[i]; | |
| 3490 | + if (part.to > start && part.from <= start) { break } | |
| 3491 | + } | |
| 3492 | + if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, css, attributes) } | |
| 3493 | + inner(builder, text.slice(0, part.to - start), style, startStyle, null, css, attributes); | |
| 3494 | + startStyle = null; | |
| 3495 | + text = text.slice(part.to - start); | |
| 3496 | + start = part.to; | |
| 3497 | + } | |
| 3498 | + } | |
| 3499 | + } | |
| 3500 | + | |
| 3501 | + function buildCollapsedSpan(builder, size, marker, ignoreWidget) { | |
| 3502 | + var widget = !ignoreWidget && marker.widgetNode; | |
| 3503 | + if (widget) { builder.map.push(builder.pos, builder.pos + size, widget); } | |
| 3504 | + if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) { | |
| 3505 | + if (!widget) | |
| 3506 | + { widget = builder.content.appendChild(document.createElement("span")); } | |
| 3507 | + widget.setAttribute("cm-marker", marker.id); | |
| 3508 | + } | |
| 3509 | + if (widget) { | |
| 3510 | + builder.cm.display.input.setUneditable(widget); | |
| 3511 | + builder.content.appendChild(widget); | |
| 3512 | + } | |
| 3513 | + builder.pos += size; | |
| 3514 | + builder.trailingSpace = false; | |
| 3515 | + } | |
| 3516 | + | |
| 3517 | + // Outputs a number of spans to make up a line, taking highlighting | |
| 3518 | + // and marked text into account. | |
| 3519 | + function insertLineContent(line, builder, styles) { | |
| 3520 | + var spans = line.markedSpans, allText = line.text, at = 0; | |
| 3521 | + if (!spans) { | |
| 3522 | + for (var i$1 = 1; i$1 < styles.length; i$1+=2) | |
| 3523 | + { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)); } | |
| 3524 | + return | |
| 3525 | + } | |
| 3526 | + | |
| 3527 | + var len = allText.length, pos = 0, i = 1, text = "", style, css; | |
| 3528 | + var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed, attributes; | |
| 3529 | + for (;;) { | |
| 3530 | + if (nextChange == pos) { // Update current marker set | |
| 3531 | + spanStyle = spanEndStyle = spanStartStyle = css = ""; | |
| 3532 | + attributes = null; | |
| 3533 | + collapsed = null; nextChange = Infinity; | |
| 3534 | + var foundBookmarks = [], endStyles = (void 0); | |
| 3535 | + for (var j = 0; j < spans.length; ++j) { | |
| 3536 | + var sp = spans[j], m = sp.marker; | |
| 3537 | + if (m.type == "bookmark" && sp.from == pos && m.widgetNode) { | |
| 3538 | + foundBookmarks.push(m); | |
| 3539 | + } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) { | |
| 3540 | + if (sp.to != null && sp.to != pos && nextChange > sp.to) { | |
| 3541 | + nextChange = sp.to; | |
| 3542 | + spanEndStyle = ""; | |
| 3543 | + } | |
| 3544 | + if (m.className) { spanStyle += " " + m.className; } | |
| 3545 | + if (m.css) { css = (css ? css + ";" : "") + m.css; } | |
| 3546 | + if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle; } | |
| 3547 | + if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to); } | |
| 3548 | + // support for the old title property | |
| 3549 | + // https://github.com/codemirror/CodeMirror/pull/5673 | |
| 3550 | + if (m.title) { (attributes || (attributes = {})).title = m.title; } | |
| 3551 | + if (m.attributes) { | |
| 3552 | + for (var attr in m.attributes) | |
| 3553 | + { (attributes || (attributes = {}))[attr] = m.attributes[attr]; } | |
| 3554 | + } | |
| 3555 | + if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0)) | |
| 3556 | + { collapsed = sp; } | |
| 3557 | + } else if (sp.from > pos && nextChange > sp.from) { | |
| 3558 | + nextChange = sp.from; | |
| 3559 | + } | |
| 3560 | + } | |
| 3561 | + if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2) | |
| 3562 | + { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1]; } } } | |
| 3563 | + | |
| 3564 | + if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2) | |
| 3565 | + { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]); } } | |
| 3566 | + if (collapsed && (collapsed.from || 0) == pos) { | |
| 3567 | + buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos, | |
| 3568 | + collapsed.marker, collapsed.from == null); | |
| 3569 | + if (collapsed.to == null) { return } | |
| 3570 | + if (collapsed.to == pos) { collapsed = false; } | |
| 3571 | + } | |
| 3572 | + } | |
| 3573 | + if (pos >= len) { break } | |
| 3574 | + | |
| 3575 | + var upto = Math.min(len, nextChange); | |
| 3576 | + while (true) { | |
| 3577 | + if (text) { | |
| 3578 | + var end = pos + text.length; | |
| 3579 | + if (!collapsed) { | |
| 3580 | + var tokenText = end > upto ? text.slice(0, upto - pos) : text; | |
| 3581 | + builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle, | |
| 3582 | + spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", css, attributes); | |
| 3583 | + } | |
| 3584 | + if (end >= upto) {text = text.slice(upto - pos); pos = upto; break} | |
| 3585 | + pos = end; | |
| 3586 | + spanStartStyle = ""; | |
| 3587 | + } | |
| 3588 | + text = allText.slice(at, at = styles[i++]); | |
| 3589 | + style = interpretTokenStyle(styles[i++], builder.cm.options); | |
| 3590 | + } | |
| 3591 | + } | |
| 3592 | + } | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + // These objects are used to represent the visible (currently drawn) | |
| 3596 | + // part of the document. A LineView may correspond to multiple | |
| 3597 | + // logical lines, if those are connected by collapsed ranges. | |
| 3598 | + function LineView(doc, line, lineN) { | |
| 3599 | + // The starting line | |
| 3600 | + this.line = line; | |
| 3601 | + // Continuing lines, if any | |
| 3602 | + this.rest = visualLineContinued(line); | |
| 3603 | + // Number of logical lines in this visual line | |
| 3604 | + this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1; | |
| 3605 | + this.node = this.text = null; | |
| 3606 | + this.hidden = lineIsHidden(doc, line); | |
| 3607 | + } | |
| 3608 | + | |
| 3609 | + // Create a range of LineView objects for the given lines. | |
| 3610 | + function buildViewArray(cm, from, to) { | |
| 3611 | + var array = [], nextPos; | |
| 3612 | + for (var pos = from; pos < to; pos = nextPos) { | |
| 3613 | + var view = new LineView(cm.doc, getLine(cm.doc, pos), pos); | |
| 3614 | + nextPos = pos + view.size; | |
| 3615 | + array.push(view); | |
| 3616 | + } | |
| 3617 | + return array | |
| 3618 | + } | |
| 3619 | + | |
| 3620 | + var operationGroup = null; | |
| 3621 | + | |
| 3622 | + function pushOperation(op) { | |
| 3623 | + if (operationGroup) { | |
| 3624 | + operationGroup.ops.push(op); | |
| 3625 | + } else { | |
| 3626 | + op.ownsGroup = operationGroup = { | |
| 3627 | + ops: [op], | |
| 3628 | + delayedCallbacks: [] | |
| 3629 | + }; | |
| 3630 | + } | |
| 3631 | + } | |
| 3632 | + | |
| 3633 | + function fireCallbacksForOps(group) { | |
| 3634 | + // Calls delayed callbacks and cursorActivity handlers until no | |
| 3635 | + // new ones appear | |
| 3636 | + var callbacks = group.delayedCallbacks, i = 0; | |
| 3637 | + do { | |
| 3638 | + for (; i < callbacks.length; i++) | |
| 3639 | + { callbacks[i].call(null); } | |
| 3640 | + for (var j = 0; j < group.ops.length; j++) { | |
| 3641 | + var op = group.ops[j]; | |
| 3642 | + if (op.cursorActivityHandlers) | |
| 3643 | + { while (op.cursorActivityCalled < op.cursorActivityHandlers.length) | |
| 3644 | + { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm); } } | |
| 3645 | + } | |
| 3646 | + } while (i < callbacks.length) | |
| 3647 | + } | |
| 3648 | + | |
| 3649 | + function finishOperation(op, endCb) { | |
| 3650 | + var group = op.ownsGroup; | |
| 3651 | + if (!group) { return } | |
| 3652 | + | |
| 3653 | + try { fireCallbacksForOps(group); } | |
| 3654 | + finally { | |
| 3655 | + operationGroup = null; | |
| 3656 | + endCb(group); | |
| 3657 | + } | |
| 3658 | + } | |
| 3659 | + | |
| 3660 | + var orphanDelayedCallbacks = null; | |
| 3661 | + | |
| 3662 | + // Often, we want to signal events at a point where we are in the | |
| 3663 | + // middle of some work, but don't want the handler to start calling | |
| 3664 | + // other methods on the editor, which might be in an inconsistent | |
| 3665 | + // state or simply not expect any other events to happen. | |
| 3666 | + // signalLater looks whether there are any handlers, and schedules | |
| 3667 | + // them to be executed when the last operation ends, or, if no | |
| 3668 | + // operation is active, when a timeout fires. | |
| 3669 | + function signalLater(emitter, type /*, values...*/) { | |
| 3670 | + var arr = getHandlers(emitter, type); | |
| 3671 | + if (!arr.length) { return } | |
| 3672 | + var args = Array.prototype.slice.call(arguments, 2), list; | |
| 3673 | + if (operationGroup) { | |
| 3674 | + list = operationGroup.delayedCallbacks; | |
| 3675 | + } else if (orphanDelayedCallbacks) { | |
| 3676 | + list = orphanDelayedCallbacks; | |
| 3677 | + } else { | |
| 3678 | + list = orphanDelayedCallbacks = []; | |
| 3679 | + setTimeout(fireOrphanDelayed, 0); | |
| 3680 | + } | |
| 3681 | + var loop = function ( i ) { | |
| 3682 | + list.push(function () { return arr[i].apply(null, args); }); | |
| 3683 | + }; | |
| 3684 | + | |
| 3685 | + for (var i = 0; i < arr.length; ++i) | |
| 3686 | + loop( i ); | |
| 3687 | + } | |
| 3688 | + | |
| 3689 | + function fireOrphanDelayed() { | |
| 3690 | + var delayed = orphanDelayedCallbacks; | |
| 3691 | + orphanDelayedCallbacks = null; | |
| 3692 | + for (var i = 0; i < delayed.length; ++i) { delayed[i](); } | |
| 3693 | + } | |
| 3694 | + | |
| 3695 | + // When an aspect of a line changes, a string is added to | |
| 3696 | + // lineView.changes. This updates the relevant part of the line's | |
| 3697 | + // DOM structure. | |
| 3698 | + function updateLineForChanges(cm, lineView, lineN, dims) { | |
| 3699 | + for (var j = 0; j < lineView.changes.length; j++) { | |
| 3700 | + var type = lineView.changes[j]; | |
| 3701 | + if (type == "text") { updateLineText(cm, lineView); } | |
| 3702 | + else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims); } | |
| 3703 | + else if (type == "class") { updateLineClasses(cm, lineView); } | |
| 3704 | + else if (type == "widget") { updateLineWidgets(cm, lineView, dims); } | |
| 3705 | + } | |
| 3706 | + lineView.changes = null; | |
| 3707 | + } | |
| 3708 | + | |
| 3709 | + // Lines with gutter elements, widgets or a background class need to | |
| 3710 | + // be wrapped, and have the extra elements added to the wrapper div | |
| 3711 | + function ensureLineWrapped(lineView) { | |
| 3712 | + if (lineView.node == lineView.text) { | |
| 3713 | + lineView.node = elt("div", null, null, "position: relative"); | |
| 3714 | + if (lineView.text.parentNode) | |
| 3715 | + { lineView.text.parentNode.replaceChild(lineView.node, lineView.text); } | |
| 3716 | + lineView.node.appendChild(lineView.text); | |
| 3717 | + if (ie && ie_version < 8) { lineView.node.style.zIndex = 2; } | |
| 3718 | + } | |
| 3719 | + return lineView.node | |
| 3720 | + } | |
| 3721 | + | |
| 3722 | + function updateLineBackground(cm, lineView) { | |
| 3723 | + var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass; | |
| 3724 | + if (cls) { cls += " CodeMirror-linebackground"; } | |
| 3725 | + if (lineView.background) { | |
| 3726 | + if (cls) { lineView.background.className = cls; } | |
| 3727 | + else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; } | |
| 3728 | + } else if (cls) { | |
| 3729 | + var wrap = ensureLineWrapped(lineView); | |
| 3730 | + lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild); | |
| 3731 | + cm.display.input.setUneditable(lineView.background); | |
| 3732 | + } | |
| 3733 | + } | |
| 3734 | + | |
| 3735 | + // Wrapper around buildLineContent which will reuse the structure | |
| 3736 | + // in display.externalMeasured when possible. | |
| 3737 | + function getLineContent(cm, lineView) { | |
| 3738 | + var ext = cm.display.externalMeasured; | |
| 3739 | + if (ext && ext.line == lineView.line) { | |
| 3740 | + cm.display.externalMeasured = null; | |
| 3741 | + lineView.measure = ext.measure; | |
| 3742 | + return ext.built | |
| 3743 | + } | |
| 3744 | + return buildLineContent(cm, lineView) | |
| 3745 | + } | |
| 3746 | + | |
| 3747 | + // Redraw the line's text. Interacts with the background and text | |
| 3748 | + // classes because the mode may output tokens that influence these | |
| 3749 | + // classes. | |
| 3750 | + function updateLineText(cm, lineView) { | |
| 3751 | + var cls = lineView.text.className; | |
| 3752 | + var built = getLineContent(cm, lineView); | |
| 3753 | + if (lineView.text == lineView.node) { lineView.node = built.pre; } | |
| 3754 | + lineView.text.parentNode.replaceChild(built.pre, lineView.text); | |
| 3755 | + lineView.text = built.pre; | |
| 3756 | + if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) { | |
| 3757 | + lineView.bgClass = built.bgClass; | |
| 3758 | + lineView.textClass = built.textClass; | |
| 3759 | + updateLineClasses(cm, lineView); | |
| 3760 | + } else if (cls) { | |
| 3761 | + lineView.text.className = cls; | |
| 3762 | + } | |
| 3763 | + } | |
| 3764 | + | |
| 3765 | + function updateLineClasses(cm, lineView) { | |
| 3766 | + updateLineBackground(cm, lineView); | |
| 3767 | + if (lineView.line.wrapClass) | |
| 3768 | + { ensureLineWrapped(lineView).className = lineView.line.wrapClass; } | |
| 3769 | + else if (lineView.node != lineView.text) | |
| 3770 | + { lineView.node.className = ""; } | |
| 3771 | + var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass; | |
| 3772 | + lineView.text.className = textClass || ""; | |
| 3773 | + } | |
| 3774 | + | |
| 3775 | + function updateLineGutter(cm, lineView, lineN, dims) { | |
| 3776 | + if (lineView.gutter) { | |
| 3777 | + lineView.node.removeChild(lineView.gutter); | |
| 3778 | + lineView.gutter = null; | |
| 3779 | + } | |
| 3780 | + if (lineView.gutterBackground) { | |
| 3781 | + lineView.node.removeChild(lineView.gutterBackground); | |
| 3782 | + lineView.gutterBackground = null; | |
| 3783 | + } | |
| 3784 | + if (lineView.line.gutterClass) { | |
| 3785 | + var wrap = ensureLineWrapped(lineView); | |
| 3786 | + lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass, | |
| 3787 | + ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px")); | |
| 3788 | + cm.display.input.setUneditable(lineView.gutterBackground); | |
| 3789 | + wrap.insertBefore(lineView.gutterBackground, lineView.text); | |
| 3790 | + } | |
| 3791 | + var markers = lineView.line.gutterMarkers; | |
| 3792 | + if (cm.options.lineNumbers || markers) { | |
| 3793 | + var wrap$1 = ensureLineWrapped(lineView); | |
| 3794 | + var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px")); | |
| 3795 | + gutterWrap.setAttribute("aria-hidden", "true"); | |
| 3796 | + cm.display.input.setUneditable(gutterWrap); | |
| 3797 | + wrap$1.insertBefore(gutterWrap, lineView.text); | |
| 3798 | + if (lineView.line.gutterClass) | |
| 3799 | + { gutterWrap.className += " " + lineView.line.gutterClass; } | |
| 3800 | + if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"])) | |
| 3801 | + { lineView.lineNumber = gutterWrap.appendChild( | |
| 3802 | + elt("div", lineNumberFor(cm.options, lineN), | |
| 3803 | + "CodeMirror-linenumber CodeMirror-gutter-elt", | |
| 3804 | + ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))); } | |
| 3805 | + if (markers) { for (var k = 0; k < cm.display.gutterSpecs.length; ++k) { | |
| 3806 | + var id = cm.display.gutterSpecs[k].className, found = markers.hasOwnProperty(id) && markers[id]; | |
| 3807 | + if (found) | |
| 3808 | + { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", | |
| 3809 | + ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))); } | |
| 3810 | + } } | |
| 3811 | + } | |
| 3812 | + } | |
| 3813 | + | |
| 3814 | + function updateLineWidgets(cm, lineView, dims) { | |
| 3815 | + if (lineView.alignable) { lineView.alignable = null; } | |
| 3816 | + var isWidget = classTest("CodeMirror-linewidget"); | |
| 3817 | + for (var node = lineView.node.firstChild, next = (void 0); node; node = next) { | |
| 3818 | + next = node.nextSibling; | |
| 3819 | + if (isWidget.test(node.className)) { lineView.node.removeChild(node); } | |
| 3820 | + } | |
| 3821 | + insertLineWidgets(cm, lineView, dims); | |
| 3822 | + } | |
| 3823 | + | |
| 3824 | + // Build a line's DOM representation from scratch | |
| 3825 | + function buildLineElement(cm, lineView, lineN, dims) { | |
| 3826 | + var built = getLineContent(cm, lineView); | |
| 3827 | + lineView.text = lineView.node = built.pre; | |
| 3828 | + if (built.bgClass) { lineView.bgClass = built.bgClass; } | |
| 3829 | + if (built.textClass) { lineView.textClass = built.textClass; } | |
| 3830 | + | |
| 3831 | + updateLineClasses(cm, lineView); | |
| 3832 | + updateLineGutter(cm, lineView, lineN, dims); | |
| 3833 | + insertLineWidgets(cm, lineView, dims); | |
| 3834 | + return lineView.node | |
| 3835 | + } | |
| 3836 | + | |
| 3837 | + // A lineView may contain multiple logical lines (when merged by | |
| 3838 | + // collapsed spans). The widgets for all of them need to be drawn. | |
| 3839 | + function insertLineWidgets(cm, lineView, dims) { | |
| 3840 | + insertLineWidgetsFor(cm, lineView.line, lineView, dims, true); | |
| 3841 | + if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++) | |
| 3842 | + { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false); } } | |
| 3843 | + } | |
| 3844 | + | |
| 3845 | + function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) { | |
| 3846 | + if (!line.widgets) { return } | |
| 3847 | + var wrap = ensureLineWrapped(lineView); | |
| 3848 | + for (var i = 0, ws = line.widgets; i < ws.length; ++i) { | |
| 3849 | + var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget" + (widget.className ? " " + widget.className : "")); | |
| 3850 | + if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true"); } | |
| 3851 | + positionLineWidget(widget, node, lineView, dims); | |
| 3852 | + cm.display.input.setUneditable(node); | |
| 3853 | + if (allowAbove && widget.above) | |
| 3854 | + { wrap.insertBefore(node, lineView.gutter || lineView.text); } | |
| 3855 | + else | |
| 3856 | + { wrap.appendChild(node); } | |
| 3857 | + signalLater(widget, "redraw"); | |
| 3858 | + } | |
| 3859 | + } | |
| 3860 | + | |
| 3861 | + function positionLineWidget(widget, node, lineView, dims) { | |
| 3862 | + if (widget.noHScroll) { | |
| 3863 | + (lineView.alignable || (lineView.alignable = [])).push(node); | |
| 3864 | + var width = dims.wrapperWidth; | |
| 3865 | + node.style.left = dims.fixedPos + "px"; | |
| 3866 | + if (!widget.coverGutter) { | |
| 3867 | + width -= dims.gutterTotalWidth; | |
| 3868 | + node.style.paddingLeft = dims.gutterTotalWidth + "px"; | |
| 3869 | + } | |
| 3870 | + node.style.width = width + "px"; | |
| 3871 | + } | |
| 3872 | + if (widget.coverGutter) { | |
| 3873 | + node.style.zIndex = 5; | |
| 3874 | + node.style.position = "relative"; | |
| 3875 | + if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px"; } | |
| 3876 | + } | |
| 3877 | + } | |
| 3878 | + | |
| 3879 | + function widgetHeight(widget) { | |
| 3880 | + if (widget.height != null) { return widget.height } | |
| 3881 | + var cm = widget.doc.cm; | |
| 3882 | + if (!cm) { return 0 } | |
| 3883 | + if (!contains(document.body, widget.node)) { | |
| 3884 | + var parentStyle = "position: relative;"; | |
| 3885 | + if (widget.coverGutter) | |
| 3886 | + { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"; } | |
| 3887 | + if (widget.noHScroll) | |
| 3888 | + { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"; } | |
| 3889 | + removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle)); | |
| 3890 | + } | |
| 3891 | + return widget.height = widget.node.parentNode.offsetHeight | |
| 3892 | + } | |
| 3893 | + | |
| 3894 | + // Return true when the given mouse event happened in a widget | |
| 3895 | + function eventInWidget(display, e) { | |
| 3896 | + for (var n = e_target(e); n != display.wrapper; n = n.parentNode) { | |
| 3897 | + if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") || | |
| 3898 | + (n.parentNode == display.sizer && n != display.mover)) | |
| 3899 | + { return true } | |
| 3900 | + } | |
| 3901 | + } | |
| 3902 | + | |
| 3903 | + // POSITION MEASUREMENT | |
| 3904 | + | |
| 3905 | + function paddingTop(display) {return display.lineSpace.offsetTop} | |
| 3906 | + function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight} | |
| 3907 | + function paddingH(display) { | |
| 3908 | + if (display.cachedPaddingH) { return display.cachedPaddingH } | |
| 3909 | + var e = removeChildrenAndAdd(display.measure, elt("pre", "x", "CodeMirror-line-like")); | |
| 3910 | + var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle; | |
| 3911 | + var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)}; | |
| 3912 | + if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data; } | |
| 3913 | + return data | |
| 3914 | + } | |
| 3915 | + | |
| 3916 | + function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth } | |
| 3917 | + function displayWidth(cm) { | |
| 3918 | + return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth | |
| 3919 | + } | |
| 3920 | + function displayHeight(cm) { | |
| 3921 | + return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight | |
| 3922 | + } | |
| 3923 | + | |
| 3924 | + // Ensure the lineView.wrapping.heights array is populated. This is | |
| 3925 | + // an array of bottom offsets for the lines that make up a drawn | |
| 3926 | + // line. When lineWrapping is on, there might be more than one | |
| 3927 | + // height. | |
| 3928 | + function ensureLineHeights(cm, lineView, rect) { | |
| 3929 | + var wrapping = cm.options.lineWrapping; | |
| 3930 | + var curWidth = wrapping && displayWidth(cm); | |
| 3931 | + if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) { | |
| 3932 | + var heights = lineView.measure.heights = []; | |
| 3933 | + if (wrapping) { | |
| 3934 | + lineView.measure.width = curWidth; | |
| 3935 | + var rects = lineView.text.firstChild.getClientRects(); | |
| 3936 | + for (var i = 0; i < rects.length - 1; i++) { | |
| 3937 | + var cur = rects[i], next = rects[i + 1]; | |
| 3938 | + if (Math.abs(cur.bottom - next.bottom) > 2) | |
| 3939 | + { heights.push((cur.bottom + next.top) / 2 - rect.top); } | |
| 3940 | + } | |
| 3941 | + } | |
| 3942 | + heights.push(rect.bottom - rect.top); | |
| 3943 | + } | |
| 3944 | + } | |
| 3945 | + | |
| 3946 | + // Find a line map (mapping character offsets to text nodes) and a | |
| 3947 | + // measurement cache for the given line number. (A line view might | |
| 3948 | + // contain multiple lines when collapsed ranges are present.) | |
| 3949 | + function mapFromLineView(lineView, line, lineN) { | |
| 3950 | + if (lineView.line == line) | |
| 3951 | + { return {map: lineView.measure.map, cache: lineView.measure.cache} } | |
| 3952 | + for (var i = 0; i < lineView.rest.length; i++) | |
| 3953 | + { if (lineView.rest[i] == line) | |
| 3954 | + { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } } | |
| 3955 | + for (var i$1 = 0; i$1 < lineView.rest.length; i$1++) | |
| 3956 | + { if (lineNo(lineView.rest[i$1]) > lineN) | |
| 3957 | + { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } } | |
| 3958 | + } | |
| 3959 | + | |
| 3960 | + // Render a line into the hidden node display.externalMeasured. Used | |
| 3961 | + // when measurement is needed for a line that's not in the viewport. | |
| 3962 | + function updateExternalMeasurement(cm, line) { | |
| 3963 | + line = visualLine(line); | |
| 3964 | + var lineN = lineNo(line); | |
| 3965 | + var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN); | |
| 3966 | + view.lineN = lineN; | |
| 3967 | + var built = view.built = buildLineContent(cm, view); | |
| 3968 | + view.text = built.pre; | |
| 3969 | + removeChildrenAndAdd(cm.display.lineMeasure, built.pre); | |
| 3970 | + return view | |
| 3971 | + } | |
| 3972 | + | |
| 3973 | + // Get a {top, bottom, left, right} box (in line-local coordinates) | |
| 3974 | + // for a given character. | |
| 3975 | + function measureChar(cm, line, ch, bias) { | |
| 3976 | + return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias) | |
| 3977 | + } | |
| 3978 | + | |
| 3979 | + // Find a line view that corresponds to the given line number. | |
| 3980 | + function findViewForLine(cm, lineN) { | |
| 3981 | + if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo) | |
| 3982 | + { return cm.display.view[findViewIndex(cm, lineN)] } | |
| 3983 | + var ext = cm.display.externalMeasured; | |
| 3984 | + if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size) | |
| 3985 | + { return ext } | |
| 3986 | + } | |
| 3987 | + | |
| 3988 | + // Measurement can be split in two steps, the set-up work that | |
| 3989 | + // applies to the whole line, and the measurement of the actual | |
| 3990 | + // character. Functions like coordsChar, that need to do a lot of | |
| 3991 | + // measurements in a row, can thus ensure that the set-up work is | |
| 3992 | + // only done once. | |
| 3993 | + function prepareMeasureForLine(cm, line) { | |
| 3994 | + var lineN = lineNo(line); | |
| 3995 | + var view = findViewForLine(cm, lineN); | |
| 3996 | + if (view && !view.text) { | |
| 3997 | + view = null; | |
| 3998 | + } else if (view && view.changes) { | |
| 3999 | + updateLineForChanges(cm, view, lineN, getDimensions(cm)); | |
| 4000 | + cm.curOp.forceUpdate = true; | |
| 4001 | + } | |
| 4002 | + if (!view) | |
| 4003 | + { view = updateExternalMeasurement(cm, line); } | |
| 4004 | + | |
| 4005 | + var info = mapFromLineView(view, line, lineN); | |
| 4006 | + return { | |
| 4007 | + line: line, view: view, rect: null, | |
| 4008 | + map: info.map, cache: info.cache, before: info.before, | |
| 4009 | + hasHeights: false | |
| 4010 | + } | |
| 4011 | + } | |
| 4012 | + | |
| 4013 | + // Given a prepared measurement object, measures the position of an | |
| 4014 | + // actual character (or fetches it from the cache). | |
| 4015 | + function measureCharPrepared(cm, prepared, ch, bias, varHeight) { | |
| 4016 | + if (prepared.before) { ch = -1; } | |
| 4017 | + var key = ch + (bias || ""), found; | |
| 4018 | + if (prepared.cache.hasOwnProperty(key)) { | |
| 4019 | + found = prepared.cache[key]; | |
| 4020 | + } else { | |
| 4021 | + if (!prepared.rect) | |
| 4022 | + { prepared.rect = prepared.view.text.getBoundingClientRect(); } | |
| 4023 | + if (!prepared.hasHeights) { | |
| 4024 | + ensureLineHeights(cm, prepared.view, prepared.rect); | |
| 4025 | + prepared.hasHeights = true; | |
| 4026 | + } | |
| 4027 | + found = measureCharInner(cm, prepared, ch, bias); | |
| 4028 | + if (!found.bogus) { prepared.cache[key] = found; } | |
| 4029 | + } | |
| 4030 | + return {left: found.left, right: found.right, | |
| 4031 | + top: varHeight ? found.rtop : found.top, | |
| 4032 | + bottom: varHeight ? found.rbottom : found.bottom} | |
| 4033 | + } | |
| 4034 | + | |
| 4035 | + var nullRect = {left: 0, right: 0, top: 0, bottom: 0}; | |
| 4036 | + | |
| 4037 | + function nodeAndOffsetInLineMap(map, ch, bias) { | |
| 4038 | + var node, start, end, collapse, mStart, mEnd; | |
| 4039 | + // First, search the line map for the text node corresponding to, | |
| 4040 | + // or closest to, the target character. | |
| 4041 | + for (var i = 0; i < map.length; i += 3) { | |
| 4042 | + mStart = map[i]; | |
| 4043 | + mEnd = map[i + 1]; | |
| 4044 | + if (ch < mStart) { | |
| 4045 | + start = 0; end = 1; | |
| 4046 | + collapse = "left"; | |
| 4047 | + } else if (ch < mEnd) { | |
| 4048 | + start = ch - mStart; | |
| 4049 | + end = start + 1; | |
| 4050 | + } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) { | |
| 4051 | + end = mEnd - mStart; | |
| 4052 | + start = end - 1; | |
| 4053 | + if (ch >= mEnd) { collapse = "right"; } | |
| 4054 | + } | |
| 4055 | + if (start != null) { | |
| 4056 | + node = map[i + 2]; | |
| 4057 | + if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right")) | |
| 4058 | + { collapse = bias; } | |
| 4059 | + if (bias == "left" && start == 0) | |
| 4060 | + { while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) { | |
| 4061 | + node = map[(i -= 3) + 2]; | |
| 4062 | + collapse = "left"; | |
| 4063 | + } } | |
| 4064 | + if (bias == "right" && start == mEnd - mStart) | |
| 4065 | + { while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) { | |
| 4066 | + node = map[(i += 3) + 2]; | |
| 4067 | + collapse = "right"; | |
| 4068 | + } } | |
| 4069 | + break | |
| 4070 | + } | |
| 4071 | + } | |
| 4072 | + return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd} | |
| 4073 | + } | |
| 4074 | + | |
| 4075 | + function getUsefulRect(rects, bias) { | |
| 4076 | + var rect = nullRect; | |
| 4077 | + if (bias == "left") { for (var i = 0; i < rects.length; i++) { | |
| 4078 | + if ((rect = rects[i]).left != rect.right) { break } | |
| 4079 | + } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) { | |
| 4080 | + if ((rect = rects[i$1]).left != rect.right) { break } | |
| 4081 | + } } | |
| 4082 | + return rect | |
| 4083 | + } | |
| 4084 | + | |
| 4085 | + function measureCharInner(cm, prepared, ch, bias) { | |
| 4086 | + var place = nodeAndOffsetInLineMap(prepared.map, ch, bias); | |
| 4087 | + var node = place.node, start = place.start, end = place.end, collapse = place.collapse; | |
| 4088 | + | |
| 4089 | + var rect; | |
| 4090 | + if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates. | |
| 4091 | + for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned | |
| 4092 | + while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start; } | |
| 4093 | + while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end; } | |
| 4094 | + if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) | |
| 4095 | + { rect = node.parentNode.getBoundingClientRect(); } | |
| 4096 | + else | |
| 4097 | + { rect = getUsefulRect(range(node, start, end).getClientRects(), bias); } | |
| 4098 | + if (rect.left || rect.right || start == 0) { break } | |
| 4099 | + end = start; | |
| 4100 | + start = start - 1; | |
| 4101 | + collapse = "right"; | |
| 4102 | + } | |
| 4103 | + if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect); } | |
| 4104 | + } else { // If it is a widget, simply get the box for the whole widget. | |
| 4105 | + if (start > 0) { collapse = bias = "right"; } | |
| 4106 | + var rects; | |
| 4107 | + if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1) | |
| 4108 | + { rect = rects[bias == "right" ? rects.length - 1 : 0]; } | |
| 4109 | + else | |
| 4110 | + { rect = node.getBoundingClientRect(); } | |
| 4111 | + } | |
| 4112 | + if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) { | |
| 4113 | + var rSpan = node.parentNode.getClientRects()[0]; | |
| 4114 | + if (rSpan) | |
| 4115 | + { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom}; } | |
| 4116 | + else | |
| 4117 | + { rect = nullRect; } | |
| 4118 | + } | |
| 4119 | + | |
| 4120 | + var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top; | |
| 4121 | + var mid = (rtop + rbot) / 2; | |
| 4122 | + var heights = prepared.view.measure.heights; | |
| 4123 | + var i = 0; | |
| 4124 | + for (; i < heights.length - 1; i++) | |
| 4125 | + { if (mid < heights[i]) { break } } | |
| 4126 | + var top = i ? heights[i - 1] : 0, bot = heights[i]; | |
| 4127 | + var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left, | |
| 4128 | + right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left, | |
| 4129 | + top: top, bottom: bot}; | |
| 4130 | + if (!rect.left && !rect.right) { result.bogus = true; } | |
| 4131 | + if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; } | |
| 4132 | + | |
| 4133 | + return result | |
| 4134 | + } | |
| 4135 | + | |
| 4136 | + // Work around problem with bounding client rects on ranges being | |
| 4137 | + // returned incorrectly when zoomed on IE10 and below. | |
| 4138 | + function maybeUpdateRectForZooming(measure, rect) { | |
| 4139 | + if (!window.screen || screen.logicalXDPI == null || | |
| 4140 | + screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure)) | |
| 4141 | + { return rect } | |
| 4142 | + var scaleX = screen.logicalXDPI / screen.deviceXDPI; | |
| 4143 | + var scaleY = screen.logicalYDPI / screen.deviceYDPI; | |
| 4144 | + return {left: rect.left * scaleX, right: rect.right * scaleX, | |
| 4145 | + top: rect.top * scaleY, bottom: rect.bottom * scaleY} | |
| 4146 | + } | |
| 4147 | + | |
| 4148 | + function clearLineMeasurementCacheFor(lineView) { | |
| 4149 | + if (lineView.measure) { | |
| 4150 | + lineView.measure.cache = {}; | |
| 4151 | + lineView.measure.heights = null; | |
| 4152 | + if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++) | |
| 4153 | + { lineView.measure.caches[i] = {}; } } | |
| 4154 | + } | |
| 4155 | + } | |
| 4156 | + | |
| 4157 | + function clearLineMeasurementCache(cm) { | |
| 4158 | + cm.display.externalMeasure = null; | |
| 4159 | + removeChildren(cm.display.lineMeasure); | |
| 4160 | + for (var i = 0; i < cm.display.view.length; i++) | |
| 4161 | + { clearLineMeasurementCacheFor(cm.display.view[i]); } | |
| 4162 | + } | |
| 4163 | + | |
| 4164 | + function clearCaches(cm) { | |
| 4165 | + clearLineMeasurementCache(cm); | |
| 4166 | + cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null; | |
| 4167 | + if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true; } | |
| 4168 | + cm.display.lineNumChars = null; | |
| 4169 | + } | |
| 4170 | + | |
| 4171 | + function pageScrollX() { | |
| 4172 | + // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206 | |
| 4173 | + // which causes page_Offset and bounding client rects to use | |
| 4174 | + // different reference viewports and invalidate our calculations. | |
| 4175 | + if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) } | |
| 4176 | + return window.pageXOffset || (document.documentElement || document.body).scrollLeft | |
| 4177 | + } | |
| 4178 | + function pageScrollY() { | |
| 4179 | + if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) } | |
| 4180 | + return window.pageYOffset || (document.documentElement || document.body).scrollTop | |
| 4181 | + } | |
| 4182 | + | |
| 4183 | + function widgetTopHeight(lineObj) { | |
| 4184 | + var height = 0; | |
| 4185 | + if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above) | |
| 4186 | + { height += widgetHeight(lineObj.widgets[i]); } } } | |
| 4187 | + return height | |
| 4188 | + } | |
| 4189 | + | |
| 4190 | + // Converts a {top, bottom, left, right} box from line-local | |
| 4191 | + // coordinates into another coordinate system. Context may be one of | |
| 4192 | + // "line", "div" (display.lineDiv), "local"./null (editor), "window", | |
| 4193 | + // or "page". | |
| 4194 | + function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) { | |
| 4195 | + if (!includeWidgets) { | |
| 4196 | + var height = widgetTopHeight(lineObj); | |
| 4197 | + rect.top += height; rect.bottom += height; | |
| 4198 | + } | |
| 4199 | + if (context == "line") { return rect } | |
| 4200 | + if (!context) { context = "local"; } | |
| 4201 | + var yOff = heightAtLine(lineObj); | |
| 4202 | + if (context == "local") { yOff += paddingTop(cm.display); } | |
| 4203 | + else { yOff -= cm.display.viewOffset; } | |
| 4204 | + if (context == "page" || context == "window") { | |
| 4205 | + var lOff = cm.display.lineSpace.getBoundingClientRect(); | |
| 4206 | + yOff += lOff.top + (context == "window" ? 0 : pageScrollY()); | |
| 4207 | + var xOff = lOff.left + (context == "window" ? 0 : pageScrollX()); | |
| 4208 | + rect.left += xOff; rect.right += xOff; | |
| 4209 | + } | |
| 4210 | + rect.top += yOff; rect.bottom += yOff; | |
| 4211 | + return rect | |
| 4212 | + } | |
| 4213 | + | |
| 4214 | + // Coverts a box from "div" coords to another coordinate system. | |
| 4215 | + // Context may be "window", "page", "div", or "local"./null. | |
| 4216 | + function fromCoordSystem(cm, coords, context) { | |
| 4217 | + if (context == "div") { return coords } | |
| 4218 | + var left = coords.left, top = coords.top; | |
| 4219 | + // First move into "page" coordinate system | |
| 4220 | + if (context == "page") { | |
| 4221 | + left -= pageScrollX(); | |
| 4222 | + top -= pageScrollY(); | |
| 4223 | + } else if (context == "local" || !context) { | |
| 4224 | + var localBox = cm.display.sizer.getBoundingClientRect(); | |
| 4225 | + left += localBox.left; | |
| 4226 | + top += localBox.top; | |
| 4227 | + } | |
| 4228 | + | |
| 4229 | + var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect(); | |
| 4230 | + return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top} | |
| 4231 | + } | |
| 4232 | + | |
| 4233 | + function charCoords(cm, pos, context, lineObj, bias) { | |
| 4234 | + if (!lineObj) { lineObj = getLine(cm.doc, pos.line); } | |
| 4235 | + return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context) | |
| 4236 | + } | |
| 4237 | + | |
| 4238 | + // Returns a box for a given cursor position, which may have an | |
| 4239 | + // 'other' property containing the position of the secondary cursor | |
| 4240 | + // on a bidi boundary. | |
| 4241 | + // A cursor Pos(line, char, "before") is on the same visual line as `char - 1` | |
| 4242 | + // and after `char - 1` in writing order of `char - 1` | |
| 4243 | + // A cursor Pos(line, char, "after") is on the same visual line as `char` | |
| 4244 | + // and before `char` in writing order of `char` | |
| 4245 | + // Examples (upper-case letters are RTL, lower-case are LTR): | |
| 4246 | + // Pos(0, 1, ...) | |
| 4247 | + // before after | |
| 4248 | + // ab a|b a|b | |
| 4249 | + // aB a|B aB| | |
| 4250 | + // Ab |Ab A|b | |
| 4251 | + // AB B|A B|A | |
| 4252 | + // Every position after the last character on a line is considered to stick | |
| 4253 | + // to the last character on the line. | |
| 4254 | + function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) { | |
| 4255 | + lineObj = lineObj || getLine(cm.doc, pos.line); | |
| 4256 | + if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); } | |
| 4257 | + function get(ch, right) { | |
| 4258 | + var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight); | |
| 4259 | + if (right) { m.left = m.right; } else { m.right = m.left; } | |
| 4260 | + return intoCoordSystem(cm, lineObj, m, context) | |
| 4261 | + } | |
| 4262 | + var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky; | |
| 4263 | + if (ch >= lineObj.text.length) { | |
| 4264 | + ch = lineObj.text.length; | |
| 4265 | + sticky = "before"; | |
| 4266 | + } else if (ch <= 0) { | |
| 4267 | + ch = 0; | |
| 4268 | + sticky = "after"; | |
| 4269 | + } | |
| 4270 | + if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") } | |
| 4271 | + | |
| 4272 | + function getBidi(ch, partPos, invert) { | |
| 4273 | + var part = order[partPos], right = part.level == 1; | |
| 4274 | + return get(invert ? ch - 1 : ch, right != invert) | |
| 4275 | + } | |
| 4276 | + var partPos = getBidiPartAt(order, ch, sticky); | |
| 4277 | + var other = bidiOther; | |
| 4278 | + var val = getBidi(ch, partPos, sticky == "before"); | |
| 4279 | + if (other != null) { val.other = getBidi(ch, other, sticky != "before"); } | |
| 4280 | + return val | |
| 4281 | + } | |
| 4282 | + | |
| 4283 | + // Used to cheaply estimate the coordinates for a position. Used for | |
| 4284 | + // intermediate scroll updates. | |
| 4285 | + function estimateCoords(cm, pos) { | |
| 4286 | + var left = 0; | |
| 4287 | + pos = clipPos(cm.doc, pos); | |
| 4288 | + if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch; } | |
| 4289 | + var lineObj = getLine(cm.doc, pos.line); | |
| 4290 | + var top = heightAtLine(lineObj) + paddingTop(cm.display); | |
| 4291 | + return {left: left, right: left, top: top, bottom: top + lineObj.height} | |
| 4292 | + } | |
| 4293 | + | |
| 4294 | + // Positions returned by coordsChar contain some extra information. | |
| 4295 | + // xRel is the relative x position of the input coordinates compared | |
| 4296 | + // to the found position (so xRel > 0 means the coordinates are to | |
| 4297 | + // the right of the character position, for example). When outside | |
| 4298 | + // is true, that means the coordinates lie outside the line's | |
| 4299 | + // vertical range. | |
| 4300 | + function PosWithInfo(line, ch, sticky, outside, xRel) { | |
| 4301 | + var pos = Pos(line, ch, sticky); | |
| 4302 | + pos.xRel = xRel; | |
| 4303 | + if (outside) { pos.outside = outside; } | |
| 4304 | + return pos | |
| 4305 | + } | |
| 4306 | + | |
| 4307 | + // Compute the character position closest to the given coordinates. | |
| 4308 | + // Input must be lineSpace-local ("div" coordinate system). | |
| 4309 | + function coordsChar(cm, x, y) { | |
| 4310 | + var doc = cm.doc; | |
| 4311 | + y += cm.display.viewOffset; | |
| 4312 | + if (y < 0) { return PosWithInfo(doc.first, 0, null, -1, -1) } | |
| 4313 | + var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1; | |
| 4314 | + if (lineN > last) | |
| 4315 | + { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, 1, 1) } | |
| 4316 | + if (x < 0) { x = 0; } | |
| 4317 | + | |
| 4318 | + var lineObj = getLine(doc, lineN); | |
| 4319 | + for (;;) { | |
| 4320 | + var found = coordsCharInner(cm, lineObj, lineN, x, y); | |
| 4321 | + var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 || found.outside > 0 ? 1 : 0)); | |
| 4322 | + if (!collapsed) { return found } | |
| 4323 | + var rangeEnd = collapsed.find(1); | |
| 4324 | + if (rangeEnd.line == lineN) { return rangeEnd } | |
| 4325 | + lineObj = getLine(doc, lineN = rangeEnd.line); | |
| 4326 | + } | |
| 4327 | + } | |
| 4328 | + | |
| 4329 | + function wrappedLineExtent(cm, lineObj, preparedMeasure, y) { | |
| 4330 | + y -= widgetTopHeight(lineObj); | |
| 4331 | + var end = lineObj.text.length; | |
| 4332 | + var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0); | |
| 4333 | + end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end); | |
| 4334 | + return {begin: begin, end: end} | |
| 4335 | + } | |
| 4336 | + | |
| 4337 | + function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) { | |
| 4338 | + if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); } | |
| 4339 | + var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top; | |
| 4340 | + return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop) | |
| 4341 | + } | |
| 4342 | + | |
| 4343 | + // Returns true if the given side of a box is after the given | |
| 4344 | + // coordinates, in top-to-bottom, left-to-right order. | |
| 4345 | + function boxIsAfter(box, x, y, left) { | |
| 4346 | + return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x | |
| 4347 | + } | |
| 4348 | + | |
| 4349 | + function coordsCharInner(cm, lineObj, lineNo, x, y) { | |
| 4350 | + // Move y into line-local coordinate space | |
| 4351 | + y -= heightAtLine(lineObj); | |
| 4352 | + var preparedMeasure = prepareMeasureForLine(cm, lineObj); | |
| 4353 | + // When directly calling `measureCharPrepared`, we have to adjust | |
| 4354 | + // for the widgets at this line. | |
| 4355 | + var widgetHeight = widgetTopHeight(lineObj); | |
| 4356 | + var begin = 0, end = lineObj.text.length, ltr = true; | |
| 4357 | + | |
| 4358 | + var order = getOrder(lineObj, cm.doc.direction); | |
| 4359 | + // If the line isn't plain left-to-right text, first figure out | |
| 4360 | + // which bidi section the coordinates fall into. | |
| 4361 | + if (order) { | |
| 4362 | + var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart) | |
| 4363 | + (cm, lineObj, lineNo, preparedMeasure, order, x, y); | |
| 4364 | + ltr = part.level != 1; | |
| 4365 | + // The awkward -1 offsets are needed because findFirst (called | |
| 4366 | + // on these below) will treat its first bound as inclusive, | |
| 4367 | + // second as exclusive, but we want to actually address the | |
| 4368 | + // characters in the part's range | |
| 4369 | + begin = ltr ? part.from : part.to - 1; | |
| 4370 | + end = ltr ? part.to : part.from - 1; | |
| 4371 | + } | |
| 4372 | + | |
| 4373 | + // A binary search to find the first character whose bounding box | |
| 4374 | + // starts after the coordinates. If we run across any whose box wrap | |
| 4375 | + // the coordinates, store that. | |
| 4376 | + var chAround = null, boxAround = null; | |
| 4377 | + var ch = findFirst(function (ch) { | |
| 4378 | + var box = measureCharPrepared(cm, preparedMeasure, ch); | |
| 4379 | + box.top += widgetHeight; box.bottom += widgetHeight; | |
| 4380 | + if (!boxIsAfter(box, x, y, false)) { return false } | |
| 4381 | + if (box.top <= y && box.left <= x) { | |
| 4382 | + chAround = ch; | |
| 4383 | + boxAround = box; | |
| 4384 | + } | |
| 4385 | + return true | |
| 4386 | + }, begin, end); | |
| 4387 | + | |
| 4388 | + var baseX, sticky, outside = false; | |
| 4389 | + // If a box around the coordinates was found, use that | |
| 4390 | + if (boxAround) { | |
| 4391 | + // Distinguish coordinates nearer to the left or right side of the box | |
| 4392 | + var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr; | |
| 4393 | + ch = chAround + (atStart ? 0 : 1); | |
| 4394 | + sticky = atStart ? "after" : "before"; | |
| 4395 | + baseX = atLeft ? boxAround.left : boxAround.right; | |
| 4396 | + } else { | |
| 4397 | + // (Adjust for extended bound, if necessary.) | |
| 4398 | + if (!ltr && (ch == end || ch == begin)) { ch++; } | |
| 4399 | + // To determine which side to associate with, get the box to the | |
| 4400 | + // left of the character and compare it's vertical position to the | |
| 4401 | + // coordinates | |
| 4402 | + sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" : | |
| 4403 | + (measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight <= y) == ltr ? | |
| 4404 | + "after" : "before"; | |
| 4405 | + // Now get accurate coordinates for this place, in order to get a | |
| 4406 | + // base X position | |
| 4407 | + var coords = cursorCoords(cm, Pos(lineNo, ch, sticky), "line", lineObj, preparedMeasure); | |
| 4408 | + baseX = coords.left; | |
| 4409 | + outside = y < coords.top ? -1 : y >= coords.bottom ? 1 : 0; | |
| 4410 | + } | |
| 4411 | + | |
| 4412 | + ch = skipExtendingChars(lineObj.text, ch, 1); | |
| 4413 | + return PosWithInfo(lineNo, ch, sticky, outside, x - baseX) | |
| 4414 | + } | |
| 4415 | + | |
| 4416 | + function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) { | |
| 4417 | + // Bidi parts are sorted left-to-right, and in a non-line-wrapping | |
| 4418 | + // situation, we can take this ordering to correspond to the visual | |
| 4419 | + // ordering. This finds the first part whose end is after the given | |
| 4420 | + // coordinates. | |
| 4421 | + var index = findFirst(function (i) { | |
| 4422 | + var part = order[i], ltr = part.level != 1; | |
| 4423 | + return boxIsAfter(cursorCoords(cm, Pos(lineNo, ltr ? part.to : part.from, ltr ? "before" : "after"), | |
| 4424 | + "line", lineObj, preparedMeasure), x, y, true) | |
| 4425 | + }, 0, order.length - 1); | |
| 4426 | + var part = order[index]; | |
| 4427 | + // If this isn't the first part, the part's start is also after | |
| 4428 | + // the coordinates, and the coordinates aren't on the same line as | |
| 4429 | + // that start, move one part back. | |
| 4430 | + if (index > 0) { | |
| 4431 | + var ltr = part.level != 1; | |
| 4432 | + var start = cursorCoords(cm, Pos(lineNo, ltr ? part.from : part.to, ltr ? "after" : "before"), | |
| 4433 | + "line", lineObj, preparedMeasure); | |
| 4434 | + if (boxIsAfter(start, x, y, true) && start.top > y) | |
| 4435 | + { part = order[index - 1]; } | |
| 4436 | + } | |
| 4437 | + return part | |
| 4438 | + } | |
| 4439 | + | |
| 4440 | + function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) { | |
| 4441 | + // In a wrapped line, rtl text on wrapping boundaries can do things | |
| 4442 | + // that don't correspond to the ordering in our `order` array at | |
| 4443 | + // all, so a binary search doesn't work, and we want to return a | |
| 4444 | + // part that only spans one line so that the binary search in | |
| 4445 | + // coordsCharInner is safe. As such, we first find the extent of the | |
| 4446 | + // wrapped line, and then do a flat search in which we discard any | |
| 4447 | + // spans that aren't on the line. | |
| 4448 | + var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y); | |
| 4449 | + var begin = ref.begin; | |
| 4450 | + var end = ref.end; | |
| 4451 | + if (/\s/.test(lineObj.text.charAt(end - 1))) { end--; } | |
| 4452 | + var part = null, closestDist = null; | |
| 4453 | + for (var i = 0; i < order.length; i++) { | |
| 4454 | + var p = order[i]; | |
| 4455 | + if (p.from >= end || p.to <= begin) { continue } | |
| 4456 | + var ltr = p.level != 1; | |
| 4457 | + var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right; | |
| 4458 | + // Weigh against spans ending before this, so that they are only | |
| 4459 | + // picked if nothing ends after | |
| 4460 | + var dist = endX < x ? x - endX + 1e9 : endX - x; | |
| 4461 | + if (!part || closestDist > dist) { | |
| 4462 | + part = p; | |
| 4463 | + closestDist = dist; | |
| 4464 | + } | |
| 4465 | + } | |
| 4466 | + if (!part) { part = order[order.length - 1]; } | |
| 4467 | + // Clip the part to the wrapped line. | |
| 4468 | + if (part.from < begin) { part = {from: begin, to: part.to, level: part.level}; } | |
| 4469 | + if (part.to > end) { part = {from: part.from, to: end, level: part.level}; } | |
| 4470 | + return part | |
| 4471 | + } | |
| 4472 | + | |
| 4473 | + var measureText; | |
| 4474 | + // Compute the default text height. | |
| 4475 | + function textHeight(display) { | |
| 4476 | + if (display.cachedTextHeight != null) { return display.cachedTextHeight } | |
| 4477 | + if (measureText == null) { | |
| 4478 | + measureText = elt("pre", null, "CodeMirror-line-like"); | |
| 4479 | + // Measure a bunch of lines, for browsers that compute | |
| 4480 | + // fractional heights. | |
| 4481 | + for (var i = 0; i < 49; ++i) { | |
| 4482 | + measureText.appendChild(document.createTextNode("x")); | |
| 4483 | + measureText.appendChild(elt("br")); | |
| 4484 | + } | |
| 4485 | + measureText.appendChild(document.createTextNode("x")); | |
| 4486 | + } | |
| 4487 | + removeChildrenAndAdd(display.measure, measureText); | |
| 4488 | + var height = measureText.offsetHeight / 50; | |
| 4489 | + if (height > 3) { display.cachedTextHeight = height; } | |
| 4490 | + removeChildren(display.measure); | |
| 4491 | + return height || 1 | |
| 4492 | + } | |
| 4493 | + | |
| 4494 | + // Compute the default character width. | |
| 4495 | + function charWidth(display) { | |
| 4496 | + if (display.cachedCharWidth != null) { return display.cachedCharWidth } | |
| 4497 | + var anchor = elt("span", "xxxxxxxxxx"); | |
| 4498 | + var pre = elt("pre", [anchor], "CodeMirror-line-like"); | |
| 4499 | + removeChildrenAndAdd(display.measure, pre); | |
| 4500 | + var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10; | |
| 4501 | + if (width > 2) { display.cachedCharWidth = width; } | |
| 4502 | + return width || 10 | |
| 4503 | + } | |
| 4504 | + | |
| 4505 | + // Do a bulk-read of the DOM positions and sizes needed to draw the | |
| 4506 | + // view, so that we don't interleave reading and writing to the DOM. | |
| 4507 | + function getDimensions(cm) { | |
| 4508 | + var d = cm.display, left = {}, width = {}; | |
| 4509 | + var gutterLeft = d.gutters.clientLeft; | |
| 4510 | + for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) { | |
| 4511 | + var id = cm.display.gutterSpecs[i].className; | |
| 4512 | + left[id] = n.offsetLeft + n.clientLeft + gutterLeft; | |
| 4513 | + width[id] = n.clientWidth; | |
| 4514 | + } | |
| 4515 | + return {fixedPos: compensateForHScroll(d), | |
| 4516 | + gutterTotalWidth: d.gutters.offsetWidth, | |
| 4517 | + gutterLeft: left, | |
| 4518 | + gutterWidth: width, | |
| 4519 | + wrapperWidth: d.wrapper.clientWidth} | |
| 4520 | + } | |
| 4521 | + | |
| 4522 | + // Computes display.scroller.scrollLeft + display.gutters.offsetWidth, | |
| 4523 | + // but using getBoundingClientRect to get a sub-pixel-accurate | |
| 4524 | + // result. | |
| 4525 | + function compensateForHScroll(display) { | |
| 4526 | + return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left | |
| 4527 | + } | |
| 4528 | + | |
| 4529 | + // Returns a function that estimates the height of a line, to use as | |
| 4530 | + // first approximation until the line becomes visible (and is thus | |
| 4531 | + // properly measurable). | |
| 4532 | + function estimateHeight(cm) { | |
| 4533 | + var th = textHeight(cm.display), wrapping = cm.options.lineWrapping; | |
| 4534 | + var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3); | |
| 4535 | + return function (line) { | |
| 4536 | + if (lineIsHidden(cm.doc, line)) { return 0 } | |
| 4537 | + | |
| 4538 | + var widgetsHeight = 0; | |
| 4539 | + if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) { | |
| 4540 | + if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height; } | |
| 4541 | + } } | |
| 4542 | + | |
| 4543 | + if (wrapping) | |
| 4544 | + { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th } | |
| 4545 | + else | |
| 4546 | + { return widgetsHeight + th } | |
| 4547 | + } | |
| 4548 | + } | |
| 4549 | + | |
| 4550 | + function estimateLineHeights(cm) { | |
| 4551 | + var doc = cm.doc, est = estimateHeight(cm); | |
| 4552 | + doc.iter(function (line) { | |
| 4553 | + var estHeight = est(line); | |
| 4554 | + if (estHeight != line.height) { updateLineHeight(line, estHeight); } | |
| 4555 | + }); | |
| 4556 | + } | |
| 4557 | + | |
| 4558 | + // Given a mouse event, find the corresponding position. If liberal | |
| 4559 | + // is false, it checks whether a gutter or scrollbar was clicked, | |
| 4560 | + // and returns null if it was. forRect is used by rectangular | |
| 4561 | + // selections, and tries to estimate a character position even for | |
| 4562 | + // coordinates beyond the right of the text. | |
| 4563 | + function posFromMouse(cm, e, liberal, forRect) { | |
| 4564 | + var display = cm.display; | |
| 4565 | + if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null } | |
| 4566 | + | |
| 4567 | + var x, y, space = display.lineSpace.getBoundingClientRect(); | |
| 4568 | + // Fails unpredictably on IE[67] when mouse is dragged around quickly. | |
| 4569 | + try { x = e.clientX - space.left; y = e.clientY - space.top; } | |
| 4570 | + catch (e$1) { return null } | |
| 4571 | + var coords = coordsChar(cm, x, y), line; | |
| 4572 | + if (forRect && coords.xRel > 0 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) { | |
| 4573 | + var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length; | |
| 4574 | + coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff)); | |
| 4575 | + } | |
| 4576 | + return coords | |
| 4577 | + } | |
| 4578 | + | |
| 4579 | + // Find the view element corresponding to a given line. Return null | |
| 4580 | + // when the line isn't visible. | |
| 4581 | + function findViewIndex(cm, n) { | |
| 4582 | + if (n >= cm.display.viewTo) { return null } | |
| 4583 | + n -= cm.display.viewFrom; | |
| 4584 | + if (n < 0) { return null } | |
| 4585 | + var view = cm.display.view; | |
| 4586 | + for (var i = 0; i < view.length; i++) { | |
| 4587 | + n -= view[i].size; | |
| 4588 | + if (n < 0) { return i } | |
| 4589 | + } | |
| 4590 | + } | |
| 4591 | + | |
| 4592 | + // Updates the display.view data structure for a given change to the | |
| 4593 | + // document. From and to are in pre-change coordinates. Lendiff is | |
| 4594 | + // the amount of lines added or subtracted by the change. This is | |
| 4595 | + // used for changes that span multiple lines, or change the way | |
| 4596 | + // lines are divided into visual lines. regLineChange (below) | |
| 4597 | + // registers single-line changes. | |
| 4598 | + function regChange(cm, from, to, lendiff) { | |
| 4599 | + if (from == null) { from = cm.doc.first; } | |
| 4600 | + if (to == null) { to = cm.doc.first + cm.doc.size; } | |
| 4601 | + if (!lendiff) { lendiff = 0; } | |
| 4602 | + | |
| 4603 | + var display = cm.display; | |
| 4604 | + if (lendiff && to < display.viewTo && | |
| 4605 | + (display.updateLineNumbers == null || display.updateLineNumbers > from)) | |
| 4606 | + { display.updateLineNumbers = from; } | |
| 4607 | + | |
| 4608 | + cm.curOp.viewChanged = true; | |
| 4609 | + | |
| 4610 | + if (from >= display.viewTo) { // Change after | |
| 4611 | + if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo) | |
| 4612 | + { resetView(cm); } | |
| 4613 | + } else if (to <= display.viewFrom) { // Change before | |
| 4614 | + if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) { | |
| 4615 | + resetView(cm); | |
| 4616 | + } else { | |
| 4617 | + display.viewFrom += lendiff; | |
| 4618 | + display.viewTo += lendiff; | |
| 4619 | + } | |
| 4620 | + } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap | |
| 4621 | + resetView(cm); | |
| 4622 | + } else if (from <= display.viewFrom) { // Top overlap | |
| 4623 | + var cut = viewCuttingPoint(cm, to, to + lendiff, 1); | |
| 4624 | + if (cut) { | |
| 4625 | + display.view = display.view.slice(cut.index); | |
| 4626 | + display.viewFrom = cut.lineN; | |
| 4627 | + display.viewTo += lendiff; | |
| 4628 | + } else { | |
| 4629 | + resetView(cm); | |
| 4630 | + } | |
| 4631 | + } else if (to >= display.viewTo) { // Bottom overlap | |
| 4632 | + var cut$1 = viewCuttingPoint(cm, from, from, -1); | |
| 4633 | + if (cut$1) { | |
| 4634 | + display.view = display.view.slice(0, cut$1.index); | |
| 4635 | + display.viewTo = cut$1.lineN; | |
| 4636 | + } else { | |
| 4637 | + resetView(cm); | |
| 4638 | + } | |
| 4639 | + } else { // Gap in the middle | |
| 4640 | + var cutTop = viewCuttingPoint(cm, from, from, -1); | |
| 4641 | + var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1); | |
| 4642 | + if (cutTop && cutBot) { | |
| 4643 | + display.view = display.view.slice(0, cutTop.index) | |
| 4644 | + .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN)) | |
| 4645 | + .concat(display.view.slice(cutBot.index)); | |
| 4646 | + display.viewTo += lendiff; | |
| 4647 | + } else { | |
| 4648 | + resetView(cm); | |
| 4649 | + } | |
| 4650 | + } | |
| 4651 | + | |
| 4652 | + var ext = display.externalMeasured; | |
| 4653 | + if (ext) { | |
| 4654 | + if (to < ext.lineN) | |
| 4655 | + { ext.lineN += lendiff; } | |
| 4656 | + else if (from < ext.lineN + ext.size) | |
| 4657 | + { display.externalMeasured = null; } | |
| 4658 | + } | |
| 4659 | + } | |
| 4660 | + | |
| 4661 | + // Register a change to a single line. Type must be one of "text", | |
| 4662 | + // "gutter", "class", "widget" | |
| 4663 | + function regLineChange(cm, line, type) { | |
| 4664 | + cm.curOp.viewChanged = true; | |
| 4665 | + var display = cm.display, ext = cm.display.externalMeasured; | |
| 4666 | + if (ext && line >= ext.lineN && line < ext.lineN + ext.size) | |
| 4667 | + { display.externalMeasured = null; } | |
| 4668 | + | |
| 4669 | + if (line < display.viewFrom || line >= display.viewTo) { return } | |
| 4670 | + var lineView = display.view[findViewIndex(cm, line)]; | |
| 4671 | + if (lineView.node == null) { return } | |
| 4672 | + var arr = lineView.changes || (lineView.changes = []); | |
| 4673 | + if (indexOf(arr, type) == -1) { arr.push(type); } | |
| 4674 | + } | |
| 4675 | + | |
| 4676 | + // Clear the view. | |
| 4677 | + function resetView(cm) { | |
| 4678 | + cm.display.viewFrom = cm.display.viewTo = cm.doc.first; | |
| 4679 | + cm.display.view = []; | |
| 4680 | + cm.display.viewOffset = 0; | |
| 4681 | + } | |
| 4682 | + | |
| 4683 | + function viewCuttingPoint(cm, oldN, newN, dir) { | |
| 4684 | + var index = findViewIndex(cm, oldN), diff, view = cm.display.view; | |
| 4685 | + if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size) | |
| 4686 | + { return {index: index, lineN: newN} } | |
| 4687 | + var n = cm.display.viewFrom; | |
| 4688 | + for (var i = 0; i < index; i++) | |
| 4689 | + { n += view[i].size; } | |
| 4690 | + if (n != oldN) { | |
| 4691 | + if (dir > 0) { | |
| 4692 | + if (index == view.length - 1) { return null } | |
| 4693 | + diff = (n + view[index].size) - oldN; | |
| 4694 | + index++; | |
| 4695 | + } else { | |
| 4696 | + diff = n - oldN; | |
| 4697 | + } | |
| 4698 | + oldN += diff; newN += diff; | |
| 4699 | + } | |
| 4700 | + while (visualLineNo(cm.doc, newN) != newN) { | |
| 4701 | + if (index == (dir < 0 ? 0 : view.length - 1)) { return null } | |
| 4702 | + newN += dir * view[index - (dir < 0 ? 1 : 0)].size; | |
| 4703 | + index += dir; | |
| 4704 | + } | |
| 4705 | + return {index: index, lineN: newN} | |
| 4706 | + } | |
| 4707 | + | |
| 4708 | + // Force the view to cover a given range, adding empty view element | |
| 4709 | + // or clipping off existing ones as needed. | |
| 4710 | + function adjustView(cm, from, to) { | |
| 4711 | + var display = cm.display, view = display.view; | |
| 4712 | + if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) { | |
| 4713 | + display.view = buildViewArray(cm, from, to); | |
| 4714 | + display.viewFrom = from; | |
| 4715 | + } else { | |
| 4716 | + if (display.viewFrom > from) | |
| 4717 | + { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view); } | |
| 4718 | + else if (display.viewFrom < from) | |
| 4719 | + { display.view = display.view.slice(findViewIndex(cm, from)); } | |
| 4720 | + display.viewFrom = from; | |
| 4721 | + if (display.viewTo < to) | |
| 4722 | + { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)); } | |
| 4723 | + else if (display.viewTo > to) | |
| 4724 | + { display.view = display.view.slice(0, findViewIndex(cm, to)); } | |
| 4725 | + } | |
| 4726 | + display.viewTo = to; | |
| 4727 | + } | |
| 4728 | + | |
| 4729 | + // Count the number of lines in the view whose DOM representation is | |
| 4730 | + // out of date (or nonexistent). | |
| 4731 | + function countDirtyView(cm) { | |
| 4732 | + var view = cm.display.view, dirty = 0; | |
| 4733 | + for (var i = 0; i < view.length; i++) { | |
| 4734 | + var lineView = view[i]; | |
| 4735 | + if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty; } | |
| 4736 | + } | |
| 4737 | + return dirty | |
| 4738 | + } | |
| 4739 | + | |
| 4740 | + function updateSelection(cm) { | |
| 4741 | + cm.display.input.showSelection(cm.display.input.prepareSelection()); | |
| 4742 | + } | |
| 4743 | + | |
| 4744 | + function prepareSelection(cm, primary) { | |
| 4745 | + if ( primary === void 0 ) primary = true; | |
| 4746 | + | |
| 4747 | + var doc = cm.doc, result = {}; | |
| 4748 | + var curFragment = result.cursors = document.createDocumentFragment(); | |
| 4749 | + var selFragment = result.selection = document.createDocumentFragment(); | |
| 4750 | + | |
| 4751 | + for (var i = 0; i < doc.sel.ranges.length; i++) { | |
| 4752 | + if (!primary && i == doc.sel.primIndex) { continue } | |
| 4753 | + var range = doc.sel.ranges[i]; | |
| 4754 | + if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) { continue } | |
| 4755 | + var collapsed = range.empty(); | |
| 4756 | + if (collapsed || cm.options.showCursorWhenSelecting) | |
| 4757 | + { drawSelectionCursor(cm, range.head, curFragment); } | |
| 4758 | + if (!collapsed) | |
| 4759 | + { drawSelectionRange(cm, range, selFragment); } | |
| 4760 | + } | |
| 4761 | + return result | |
| 4762 | + } | |
| 4763 | + | |
| 4764 | + // Draws a cursor for the given range | |
| 4765 | + function drawSelectionCursor(cm, head, output) { | |
| 4766 | + var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine); | |
| 4767 | + | |
| 4768 | + var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor")); | |
| 4769 | + cursor.style.left = pos.left + "px"; | |
| 4770 | + cursor.style.top = pos.top + "px"; | |
| 4771 | + cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px"; | |
| 4772 | + | |
| 4773 | + if (pos.other) { | |
| 4774 | + // Secondary cursor, shown when on a 'jump' in bi-directional text | |
| 4775 | + var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor")); | |
| 4776 | + otherCursor.style.display = ""; | |
| 4777 | + otherCursor.style.left = pos.other.left + "px"; | |
| 4778 | + otherCursor.style.top = pos.other.top + "px"; | |
| 4779 | + otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px"; | |
| 4780 | + } | |
| 4781 | + } | |
| 4782 | + | |
| 4783 | + function cmpCoords(a, b) { return a.top - b.top || a.left - b.left } | |
| 4784 | + | |
| 4785 | + // Draws the given range as a highlighted selection | |
| 4786 | + function drawSelectionRange(cm, range, output) { | |
| 4787 | + var display = cm.display, doc = cm.doc; | |
| 4788 | + var fragment = document.createDocumentFragment(); | |
| 4789 | + var padding = paddingH(cm.display), leftSide = padding.left; | |
| 4790 | + var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right; | |
| 4791 | + var docLTR = doc.direction == "ltr"; | |
| 4792 | + | |
| 4793 | + function add(left, top, width, bottom) { | |
| 4794 | + if (top < 0) { top = 0; } | |
| 4795 | + top = Math.round(top); | |
| 4796 | + bottom = Math.round(bottom); | |
| 4797 | + fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px"))); | |
| 4798 | + } | |
| 4799 | + | |
| 4800 | + function drawForLine(line, fromArg, toArg) { | |
| 4801 | + var lineObj = getLine(doc, line); | |
| 4802 | + var lineLen = lineObj.text.length; | |
| 4803 | + var start, end; | |
| 4804 | + function coords(ch, bias) { | |
| 4805 | + return charCoords(cm, Pos(line, ch), "div", lineObj, bias) | |
| 4806 | + } | |
| 4807 | + | |
| 4808 | + function wrapX(pos, dir, side) { | |
| 4809 | + var extent = wrappedLineExtentChar(cm, lineObj, null, pos); | |
| 4810 | + var prop = (dir == "ltr") == (side == "after") ? "left" : "right"; | |
| 4811 | + var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1); | |
| 4812 | + return coords(ch, prop)[prop] | |
| 4813 | + } | |
| 4814 | + | |
| 4815 | + var order = getOrder(lineObj, doc.direction); | |
| 4816 | + iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) { | |
| 4817 | + var ltr = dir == "ltr"; | |
| 4818 | + var fromPos = coords(from, ltr ? "left" : "right"); | |
| 4819 | + var toPos = coords(to - 1, ltr ? "right" : "left"); | |
| 4820 | + | |
| 4821 | + var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen; | |
| 4822 | + var first = i == 0, last = !order || i == order.length - 1; | |
| 4823 | + if (toPos.top - fromPos.top <= 3) { // Single line | |
| 4824 | + var openLeft = (docLTR ? openStart : openEnd) && first; | |
| 4825 | + var openRight = (docLTR ? openEnd : openStart) && last; | |
| 4826 | + var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left; | |
| 4827 | + var right = openRight ? rightSide : (ltr ? toPos : fromPos).right; | |
| 4828 | + add(left, fromPos.top, right - left, fromPos.bottom); | |
| 4829 | + } else { // Multiple lines | |
| 4830 | + var topLeft, topRight, botLeft, botRight; | |
| 4831 | + if (ltr) { | |
| 4832 | + topLeft = docLTR && openStart && first ? leftSide : fromPos.left; | |
| 4833 | + topRight = docLTR ? rightSide : wrapX(from, dir, "before"); | |
| 4834 | + botLeft = docLTR ? leftSide : wrapX(to, dir, "after"); | |
| 4835 | + botRight = docLTR && openEnd && last ? rightSide : toPos.right; | |
| 4836 | + } else { | |
| 4837 | + topLeft = !docLTR ? leftSide : wrapX(from, dir, "before"); | |
| 4838 | + topRight = !docLTR && openStart && first ? rightSide : fromPos.right; | |
| 4839 | + botLeft = !docLTR && openEnd && last ? leftSide : toPos.left; | |
| 4840 | + botRight = !docLTR ? rightSide : wrapX(to, dir, "after"); | |
| 4841 | + } | |
| 4842 | + add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom); | |
| 4843 | + if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top); } | |
| 4844 | + add(botLeft, toPos.top, botRight - botLeft, toPos.bottom); | |
| 4845 | + } | |
| 4846 | + | |
| 4847 | + if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos; } | |
| 4848 | + if (cmpCoords(toPos, start) < 0) { start = toPos; } | |
| 4849 | + if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos; } | |
| 4850 | + if (cmpCoords(toPos, end) < 0) { end = toPos; } | |
| 4851 | + }); | |
| 4852 | + return {start: start, end: end} | |
| 4853 | + } | |
| 4854 | + | |
| 4855 | + var sFrom = range.from(), sTo = range.to(); | |
| 4856 | + if (sFrom.line == sTo.line) { | |
| 4857 | + drawForLine(sFrom.line, sFrom.ch, sTo.ch); | |
| 4858 | + } else { | |
| 4859 | + var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line); | |
| 4860 | + var singleVLine = visualLine(fromLine) == visualLine(toLine); | |
| 4861 | + var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end; | |
| 4862 | + var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start; | |
| 4863 | + if (singleVLine) { | |
| 4864 | + if (leftEnd.top < rightStart.top - 2) { | |
| 4865 | + add(leftEnd.right, leftEnd.top, null, leftEnd.bottom); | |
| 4866 | + add(leftSide, rightStart.top, rightStart.left, rightStart.bottom); | |
| 4867 | + } else { | |
| 4868 | + add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom); | |
| 4869 | + } | |
| 4870 | + } | |
| 4871 | + if (leftEnd.bottom < rightStart.top) | |
| 4872 | + { add(leftSide, leftEnd.bottom, null, rightStart.top); } | |
| 4873 | + } | |
| 4874 | + | |
| 4875 | + output.appendChild(fragment); | |
| 4876 | + } | |
| 4877 | + | |
| 4878 | + // Cursor-blinking | |
| 4879 | + function restartBlink(cm) { | |
| 4880 | + if (!cm.state.focused) { return } | |
| 4881 | + var display = cm.display; | |
| 4882 | + clearInterval(display.blinker); | |
| 4883 | + var on = true; | |
| 4884 | + display.cursorDiv.style.visibility = ""; | |
| 4885 | + if (cm.options.cursorBlinkRate > 0) | |
| 4886 | + { display.blinker = setInterval(function () { | |
| 4887 | + if (!cm.hasFocus()) { onBlur(cm); } | |
| 4888 | + display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; | |
| 4889 | + }, cm.options.cursorBlinkRate); } | |
| 4890 | + else if (cm.options.cursorBlinkRate < 0) | |
| 4891 | + { display.cursorDiv.style.visibility = "hidden"; } | |
| 4892 | + } | |
| 4893 | + | |
| 4894 | + function ensureFocus(cm) { | |
| 4895 | + if (!cm.hasFocus()) { | |
| 4896 | + cm.display.input.focus(); | |
| 4897 | + if (!cm.state.focused) { onFocus(cm); } | |
| 4898 | + } | |
| 4899 | + } | |
| 4900 | + | |
| 4901 | + function delayBlurEvent(cm) { | |
| 4902 | + cm.state.delayingBlurEvent = true; | |
| 4903 | + setTimeout(function () { if (cm.state.delayingBlurEvent) { | |
| 4904 | + cm.state.delayingBlurEvent = false; | |
| 4905 | + if (cm.state.focused) { onBlur(cm); } | |
| 4906 | + } }, 100); | |
| 4907 | + } | |
| 4908 | + | |
| 4909 | + function onFocus(cm, e) { | |
| 4910 | + if (cm.state.delayingBlurEvent && !cm.state.draggingText) { cm.state.delayingBlurEvent = false; } | |
| 4911 | + | |
| 4912 | + if (cm.options.readOnly == "nocursor") { return } | |
| 4913 | + if (!cm.state.focused) { | |
| 4914 | + signal(cm, "focus", cm, e); | |
| 4915 | + cm.state.focused = true; | |
| 4916 | + addClass(cm.display.wrapper, "CodeMirror-focused"); | |
| 4917 | + // This test prevents this from firing when a context | |
| 4918 | + // menu is closed (since the input reset would kill the | |
| 4919 | + // select-all detection hack) | |
| 4920 | + if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) { | |
| 4921 | + cm.display.input.reset(); | |
| 4922 | + if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20); } // Issue #1730 | |
| 4923 | + } | |
| 4924 | + cm.display.input.receivedFocus(); | |
| 4925 | + } | |
| 4926 | + restartBlink(cm); | |
| 4927 | + } | |
| 4928 | + function onBlur(cm, e) { | |
| 4929 | + if (cm.state.delayingBlurEvent) { return } | |
| 4930 | + | |
| 4931 | + if (cm.state.focused) { | |
| 4932 | + signal(cm, "blur", cm, e); | |
| 4933 | + cm.state.focused = false; | |
| 4934 | + rmClass(cm.display.wrapper, "CodeMirror-focused"); | |
| 4935 | + } | |
| 4936 | + clearInterval(cm.display.blinker); | |
| 4937 | + setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false; } }, 150); | |
| 4938 | + } | |
| 4939 | + | |
| 4940 | + // Read the actual heights of the rendered lines, and update their | |
| 4941 | + // stored heights to match. | |
| 4942 | + function updateHeightsInViewport(cm) { | |
| 4943 | + var display = cm.display; | |
| 4944 | + var prevBottom = display.lineDiv.offsetTop; | |
| 4945 | + for (var i = 0; i < display.view.length; i++) { | |
| 4946 | + var cur = display.view[i], wrapping = cm.options.lineWrapping; | |
| 4947 | + var height = (void 0), width = 0; | |
| 4948 | + if (cur.hidden) { continue } | |
| 4949 | + if (ie && ie_version < 8) { | |
| 4950 | + var bot = cur.node.offsetTop + cur.node.offsetHeight; | |
| 4951 | + height = bot - prevBottom; | |
| 4952 | + prevBottom = bot; | |
| 4953 | + } else { | |
| 4954 | + var box = cur.node.getBoundingClientRect(); | |
| 4955 | + height = box.bottom - box.top; | |
| 4956 | + // Check that lines don't extend past the right of the current | |
| 4957 | + // editor width | |
| 4958 | + if (!wrapping && cur.text.firstChild) | |
| 4959 | + { width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1; } | |
| 4960 | + } | |
| 4961 | + var diff = cur.line.height - height; | |
| 4962 | + if (diff > .005 || diff < -.005) { | |
| 4963 | + updateLineHeight(cur.line, height); | |
| 4964 | + updateWidgetHeight(cur.line); | |
| 4965 | + if (cur.rest) { for (var j = 0; j < cur.rest.length; j++) | |
| 4966 | + { updateWidgetHeight(cur.rest[j]); } } | |
| 4967 | + } | |
| 4968 | + if (width > cm.display.sizerWidth) { | |
| 4969 | + var chWidth = Math.ceil(width / charWidth(cm.display)); | |
| 4970 | + if (chWidth > cm.display.maxLineLength) { | |
| 4971 | + cm.display.maxLineLength = chWidth; | |
| 4972 | + cm.display.maxLine = cur.line; | |
| 4973 | + cm.display.maxLineChanged = true; | |
| 4974 | + } | |
| 4975 | + } | |
| 4976 | + } | |
| 4977 | + } | |
| 4978 | + | |
| 4979 | + // Read and store the height of line widgets associated with the | |
| 4980 | + // given line. | |
| 4981 | + function updateWidgetHeight(line) { | |
| 4982 | + if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) { | |
| 4983 | + var w = line.widgets[i], parent = w.node.parentNode; | |
| 4984 | + if (parent) { w.height = parent.offsetHeight; } | |
| 4985 | + } } | |
| 4986 | + } | |
| 4987 | + | |
| 4988 | + // Compute the lines that are visible in a given viewport (defaults | |
| 4989 | + // the the current scroll position). viewport may contain top, | |
| 4990 | + // height, and ensure (see op.scrollToPos) properties. | |
| 4991 | + function visibleLines(display, doc, viewport) { | |
| 4992 | + var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop; | |
| 4993 | + top = Math.floor(top - paddingTop(display)); | |
| 4994 | + var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight; | |
| 4995 | + | |
| 4996 | + var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom); | |
| 4997 | + // Ensure is a {from: {line, ch}, to: {line, ch}} object, and | |
| 4998 | + // forces those lines into the viewport (if possible). | |
| 4999 | + if (viewport && viewport.ensure) { | |
| 5000 | + var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line; | |
| 5001 | + if (ensureFrom < from) { | |
| 5002 | + from = ensureFrom; | |
| 5003 | + to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight); | |
| 5004 | + } else if (Math.min(ensureTo, doc.lastLine()) >= to) { | |
| 5005 | + from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight); | |
| 5006 | + to = ensureTo; | |
| 5007 | + } | |
| 5008 | + } | |
| 5009 | + return {from: from, to: Math.max(to, from + 1)} | |
| 5010 | + } | |
| 5011 | + | |
| 5012 | + // SCROLLING THINGS INTO VIEW | |
| 5013 | + | |
| 5014 | + // If an editor sits on the top or bottom of the window, partially | |
| 5015 | + // scrolled out of view, this ensures that the cursor is visible. | |
| 5016 | + function maybeScrollWindow(cm, rect) { | |
| 5017 | + if (signalDOMEvent(cm, "scrollCursorIntoView")) { return } | |
| 5018 | + | |
| 5019 | + var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null; | |
| 5020 | + if (rect.top + box.top < 0) { doScroll = true; } | |
| 5021 | + else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false; } | |
| 5022 | + if (doScroll != null && !phantom) { | |
| 5023 | + var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;")); | |
| 5024 | + cm.display.lineSpace.appendChild(scrollNode); | |
| 5025 | + scrollNode.scrollIntoView(doScroll); | |
| 5026 | + cm.display.lineSpace.removeChild(scrollNode); | |
| 5027 | + } | |
| 5028 | + } | |
| 5029 | + | |
| 5030 | + // Scroll a given position into view (immediately), verifying that | |
| 5031 | + // it actually became visible (as line heights are accurately | |
| 5032 | + // measured, the position of something may 'drift' during drawing). | |
| 5033 | + function scrollPosIntoView(cm, pos, end, margin) { | |
| 5034 | + if (margin == null) { margin = 0; } | |
| 5035 | + var rect; | |
| 5036 | + if (!cm.options.lineWrapping && pos == end) { | |
| 5037 | + // Set pos and end to the cursor positions around the character pos sticks to | |
| 5038 | + // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch | |
| 5039 | + // If pos == Pos(_, 0, "before"), pos and end are unchanged | |
| 5040 | + pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos; | |
| 5041 | + end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos; | |
| 5042 | + } | |
| 5043 | + for (var limit = 0; limit < 5; limit++) { | |
| 5044 | + var changed = false; | |
| 5045 | + var coords = cursorCoords(cm, pos); | |
| 5046 | + var endCoords = !end || end == pos ? coords : cursorCoords(cm, end); | |
| 5047 | + rect = {left: Math.min(coords.left, endCoords.left), | |
| 5048 | + top: Math.min(coords.top, endCoords.top) - margin, | |
| 5049 | + right: Math.max(coords.left, endCoords.left), | |
| 5050 | + bottom: Math.max(coords.bottom, endCoords.bottom) + margin}; | |
| 5051 | + var scrollPos = calculateScrollPos(cm, rect); | |
| 5052 | + var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft; | |
| 5053 | + if (scrollPos.scrollTop != null) { | |
| 5054 | + updateScrollTop(cm, scrollPos.scrollTop); | |
| 5055 | + if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true; } | |
| 5056 | + } | |
| 5057 | + if (scrollPos.scrollLeft != null) { | |
| 5058 | + setScrollLeft(cm, scrollPos.scrollLeft); | |
| 5059 | + if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true; } | |
| 5060 | + } | |
| 5061 | + if (!changed) { break } | |
| 5062 | + } | |
| 5063 | + return rect | |
| 5064 | + } | |
| 5065 | + | |
| 5066 | + // Scroll a given set of coordinates into view (immediately). | |
| 5067 | + function scrollIntoView(cm, rect) { | |
| 5068 | + var scrollPos = calculateScrollPos(cm, rect); | |
| 5069 | + if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop); } | |
| 5070 | + if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft); } | |
| 5071 | + } | |
| 5072 | + | |
| 5073 | + // Calculate a new scroll position needed to scroll the given | |
| 5074 | + // rectangle into view. Returns an object with scrollTop and | |
| 5075 | + // scrollLeft properties. When these are undefined, the | |
| 5076 | + // vertical/horizontal position does not need to be adjusted. | |
| 5077 | + function calculateScrollPos(cm, rect) { | |
| 5078 | + var display = cm.display, snapMargin = textHeight(cm.display); | |
| 5079 | + if (rect.top < 0) { rect.top = 0; } | |
| 5080 | + var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop; | |
| 5081 | + var screen = displayHeight(cm), result = {}; | |
| 5082 | + if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen; } | |
| 5083 | + var docBottom = cm.doc.height + paddingVert(display); | |
| 5084 | + var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin; | |
| 5085 | + if (rect.top < screentop) { | |
| 5086 | + result.scrollTop = atTop ? 0 : rect.top; | |
| 5087 | + } else if (rect.bottom > screentop + screen) { | |
| 5088 | + var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen); | |
| 5089 | + if (newTop != screentop) { result.scrollTop = newTop; } | |
| 5090 | + } | |
| 5091 | + | |
| 5092 | + var gutterSpace = cm.options.fixedGutter ? 0 : display.gutters.offsetWidth; | |
| 5093 | + var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft - gutterSpace; | |
| 5094 | + var screenw = displayWidth(cm) - display.gutters.offsetWidth; | |
| 5095 | + var tooWide = rect.right - rect.left > screenw; | |
| 5096 | + if (tooWide) { rect.right = rect.left + screenw; } | |
| 5097 | + if (rect.left < 10) | |
| 5098 | + { result.scrollLeft = 0; } | |
| 5099 | + else if (rect.left < screenleft) | |
| 5100 | + { result.scrollLeft = Math.max(0, rect.left + gutterSpace - (tooWide ? 0 : 10)); } | |
| 5101 | + else if (rect.right > screenw + screenleft - 3) | |
| 5102 | + { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw; } | |
| 5103 | + return result | |
| 5104 | + } | |
| 5105 | + | |
| 5106 | + // Store a relative adjustment to the scroll position in the current | |
| 5107 | + // operation (to be applied when the operation finishes). | |
| 5108 | + function addToScrollTop(cm, top) { | |
| 5109 | + if (top == null) { return } | |
| 5110 | + resolveScrollToPos(cm); | |
| 5111 | + cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top; | |
| 5112 | + } | |
| 5113 | + | |
| 5114 | + // Make sure that at the end of the operation the current cursor is | |
| 5115 | + // shown. | |
| 5116 | + function ensureCursorVisible(cm) { | |
| 5117 | + resolveScrollToPos(cm); | |
| 5118 | + var cur = cm.getCursor(); | |
| 5119 | + cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin}; | |
| 5120 | + } | |
| 5121 | + | |
| 5122 | + function scrollToCoords(cm, x, y) { | |
| 5123 | + if (x != null || y != null) { resolveScrollToPos(cm); } | |
| 5124 | + if (x != null) { cm.curOp.scrollLeft = x; } | |
| 5125 | + if (y != null) { cm.curOp.scrollTop = y; } | |
| 5126 | + } | |
| 5127 | + | |
| 5128 | + function scrollToRange(cm, range) { | |
| 5129 | + resolveScrollToPos(cm); | |
| 5130 | + cm.curOp.scrollToPos = range; | |
| 5131 | + } | |
| 5132 | + | |
| 5133 | + // When an operation has its scrollToPos property set, and another | |
| 5134 | + // scroll action is applied before the end of the operation, this | |
| 5135 | + // 'simulates' scrolling that position into view in a cheap way, so | |
| 5136 | + // that the effect of intermediate scroll commands is not ignored. | |
| 5137 | + function resolveScrollToPos(cm) { | |
| 5138 | + var range = cm.curOp.scrollToPos; | |
| 5139 | + if (range) { | |
| 5140 | + cm.curOp.scrollToPos = null; | |
| 5141 | + var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to); | |
| 5142 | + scrollToCoordsRange(cm, from, to, range.margin); | |
| 5143 | + } | |
| 5144 | + } | |
| 5145 | + | |
| 5146 | + function scrollToCoordsRange(cm, from, to, margin) { | |
| 5147 | + var sPos = calculateScrollPos(cm, { | |
| 5148 | + left: Math.min(from.left, to.left), | |
| 5149 | + top: Math.min(from.top, to.top) - margin, | |
| 5150 | + right: Math.max(from.right, to.right), | |
| 5151 | + bottom: Math.max(from.bottom, to.bottom) + margin | |
| 5152 | + }); | |
| 5153 | + scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop); | |
| 5154 | + } | |
| 5155 | + | |
| 5156 | + // Sync the scrollable area and scrollbars, ensure the viewport | |
| 5157 | + // covers the visible area. | |
| 5158 | + function updateScrollTop(cm, val) { | |
| 5159 | + if (Math.abs(cm.doc.scrollTop - val) < 2) { return } | |
| 5160 | + if (!gecko) { updateDisplaySimple(cm, {top: val}); } | |
| 5161 | + setScrollTop(cm, val, true); | |
| 5162 | + if (gecko) { updateDisplaySimple(cm); } | |
| 5163 | + startWorker(cm, 100); | |
| 5164 | + } | |
| 5165 | + | |
| 5166 | + function setScrollTop(cm, val, forceScroll) { | |
| 5167 | + val = Math.max(0, Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val)); | |
| 5168 | + if (cm.display.scroller.scrollTop == val && !forceScroll) { return } | |
| 5169 | + cm.doc.scrollTop = val; | |
| 5170 | + cm.display.scrollbars.setScrollTop(val); | |
| 5171 | + if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val; } | |
| 5172 | + } | |
| 5173 | + | |
| 5174 | + // Sync scroller and scrollbar, ensure the gutter elements are | |
| 5175 | + // aligned. | |
| 5176 | + function setScrollLeft(cm, val, isScroller, forceScroll) { | |
| 5177 | + val = Math.max(0, Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth)); | |
| 5178 | + if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return } | |
| 5179 | + cm.doc.scrollLeft = val; | |
| 5180 | + alignHorizontally(cm); | |
| 5181 | + if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val; } | |
| 5182 | + cm.display.scrollbars.setScrollLeft(val); | |
| 5183 | + } | |
| 5184 | + | |
| 5185 | + // SCROLLBARS | |
| 5186 | + | |
| 5187 | + // Prepare DOM reads needed to update the scrollbars. Done in one | |
| 5188 | + // shot to minimize update/measure roundtrips. | |
| 5189 | + function measureForScrollbars(cm) { | |
| 5190 | + var d = cm.display, gutterW = d.gutters.offsetWidth; | |
| 5191 | + var docH = Math.round(cm.doc.height + paddingVert(cm.display)); | |
| 5192 | + return { | |
| 5193 | + clientHeight: d.scroller.clientHeight, | |
| 5194 | + viewHeight: d.wrapper.clientHeight, | |
| 5195 | + scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth, | |
| 5196 | + viewWidth: d.wrapper.clientWidth, | |
| 5197 | + barLeft: cm.options.fixedGutter ? gutterW : 0, | |
| 5198 | + docHeight: docH, | |
| 5199 | + scrollHeight: docH + scrollGap(cm) + d.barHeight, | |
| 5200 | + nativeBarWidth: d.nativeBarWidth, | |
| 5201 | + gutterWidth: gutterW | |
| 5202 | + } | |
| 5203 | + } | |
| 5204 | + | |
| 5205 | + var NativeScrollbars = function(place, scroll, cm) { | |
| 5206 | + this.cm = cm; | |
| 5207 | + var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar"); | |
| 5208 | + var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar"); | |
| 5209 | + vert.tabIndex = horiz.tabIndex = -1; | |
| 5210 | + place(vert); place(horiz); | |
| 5211 | + | |
| 5212 | + on(vert, "scroll", function () { | |
| 5213 | + if (vert.clientHeight) { scroll(vert.scrollTop, "vertical"); } | |
| 5214 | + }); | |
| 5215 | + on(horiz, "scroll", function () { | |
| 5216 | + if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal"); } | |
| 5217 | + }); | |
| 5218 | + | |
| 5219 | + this.checkedZeroWidth = false; | |
| 5220 | + // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8). | |
| 5221 | + if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px"; } | |
| 5222 | + }; | |
| 5223 | + | |
| 5224 | + NativeScrollbars.prototype.update = function (measure) { | |
| 5225 | + var needsH = measure.scrollWidth > measure.clientWidth + 1; | |
| 5226 | + var needsV = measure.scrollHeight > measure.clientHeight + 1; | |
| 5227 | + var sWidth = measure.nativeBarWidth; | |
| 5228 | + | |
| 5229 | + if (needsV) { | |
| 5230 | + this.vert.style.display = "block"; | |
| 5231 | + this.vert.style.bottom = needsH ? sWidth + "px" : "0"; | |
| 5232 | + var totalHeight = measure.viewHeight - (needsH ? sWidth : 0); | |
| 5233 | + // A bug in IE8 can cause this value to be negative, so guard it. | |
| 5234 | + this.vert.firstChild.style.height = | |
| 5235 | + Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px"; | |
| 5236 | + } else { | |
| 5237 | + this.vert.style.display = ""; | |
| 5238 | + this.vert.firstChild.style.height = "0"; | |
| 5239 | + } | |
| 5240 | + | |
| 5241 | + if (needsH) { | |
| 5242 | + this.horiz.style.display = "block"; | |
| 5243 | + this.horiz.style.right = needsV ? sWidth + "px" : "0"; | |
| 5244 | + this.horiz.style.left = measure.barLeft + "px"; | |
| 5245 | + var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0); | |
| 5246 | + this.horiz.firstChild.style.width = | |
| 5247 | + Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px"; | |
| 5248 | + } else { | |
| 5249 | + this.horiz.style.display = ""; | |
| 5250 | + this.horiz.firstChild.style.width = "0"; | |
| 5251 | + } | |
| 5252 | + | |
| 5253 | + if (!this.checkedZeroWidth && measure.clientHeight > 0) { | |
| 5254 | + if (sWidth == 0) { this.zeroWidthHack(); } | |
| 5255 | + this.checkedZeroWidth = true; | |
| 5256 | + } | |
| 5257 | + | |
| 5258 | + return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0} | |
| 5259 | + }; | |
| 5260 | + | |
| 5261 | + NativeScrollbars.prototype.setScrollLeft = function (pos) { | |
| 5262 | + if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos; } | |
| 5263 | + if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz"); } | |
| 5264 | + }; | |
| 5265 | + | |
| 5266 | + NativeScrollbars.prototype.setScrollTop = function (pos) { | |
| 5267 | + if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos; } | |
| 5268 | + if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert"); } | |
| 5269 | + }; | |
| 5270 | + | |
| 5271 | + NativeScrollbars.prototype.zeroWidthHack = function () { | |
| 5272 | + var w = mac && !mac_geMountainLion ? "12px" : "18px"; | |
| 5273 | + this.horiz.style.height = this.vert.style.width = w; | |
| 5274 | + this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none"; | |
| 5275 | + this.disableHoriz = new Delayed; | |
| 5276 | + this.disableVert = new Delayed; | |
| 5277 | + }; | |
| 5278 | + | |
| 5279 | + NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) { | |
| 5280 | + bar.style.pointerEvents = "auto"; | |
| 5281 | + function maybeDisable() { | |
| 5282 | + // To find out whether the scrollbar is still visible, we | |
| 5283 | + // check whether the element under the pixel in the bottom | |
| 5284 | + // right corner of the scrollbar box is the scrollbar box | |
| 5285 | + // itself (when the bar is still visible) or its filler child | |
| 5286 | + // (when the bar is hidden). If it is still visible, we keep | |
| 5287 | + // it enabled, if it's hidden, we disable pointer events. | |
| 5288 | + var box = bar.getBoundingClientRect(); | |
| 5289 | + var elt = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2) | |
| 5290 | + : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1); | |
| 5291 | + if (elt != bar) { bar.style.pointerEvents = "none"; } | |
| 5292 | + else { delay.set(1000, maybeDisable); } | |
| 5293 | + } | |
| 5294 | + delay.set(1000, maybeDisable); | |
| 5295 | + }; | |
| 5296 | + | |
| 5297 | + NativeScrollbars.prototype.clear = function () { | |
| 5298 | + var parent = this.horiz.parentNode; | |
| 5299 | + parent.removeChild(this.horiz); | |
| 5300 | + parent.removeChild(this.vert); | |
| 5301 | + }; | |
| 5302 | + | |
| 5303 | + var NullScrollbars = function () {}; | |
| 5304 | + | |
| 5305 | + NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} }; | |
| 5306 | + NullScrollbars.prototype.setScrollLeft = function () {}; | |
| 5307 | + NullScrollbars.prototype.setScrollTop = function () {}; | |
| 5308 | + NullScrollbars.prototype.clear = function () {}; | |
| 5309 | + | |
| 5310 | + function updateScrollbars(cm, measure) { | |
| 5311 | + if (!measure) { measure = measureForScrollbars(cm); } | |
| 5312 | + var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight; | |
| 5313 | + updateScrollbarsInner(cm, measure); | |
| 5314 | + for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) { | |
| 5315 | + if (startWidth != cm.display.barWidth && cm.options.lineWrapping) | |
| 5316 | + { updateHeightsInViewport(cm); } | |
| 5317 | + updateScrollbarsInner(cm, measureForScrollbars(cm)); | |
| 5318 | + startWidth = cm.display.barWidth; startHeight = cm.display.barHeight; | |
| 5319 | + } | |
| 5320 | + } | |
| 5321 | + | |
| 5322 | + // Re-synchronize the fake scrollbars with the actual size of the | |
| 5323 | + // content. | |
| 5324 | + function updateScrollbarsInner(cm, measure) { | |
| 5325 | + var d = cm.display; | |
| 5326 | + var sizes = d.scrollbars.update(measure); | |
| 5327 | + | |
| 5328 | + d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px"; | |
| 5329 | + d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px"; | |
| 5330 | + d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent"; | |
| 5331 | + | |
| 5332 | + if (sizes.right && sizes.bottom) { | |
| 5333 | + d.scrollbarFiller.style.display = "block"; | |
| 5334 | + d.scrollbarFiller.style.height = sizes.bottom + "px"; | |
| 5335 | + d.scrollbarFiller.style.width = sizes.right + "px"; | |
| 5336 | + } else { d.scrollbarFiller.style.display = ""; } | |
| 5337 | + if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) { | |
| 5338 | + d.gutterFiller.style.display = "block"; | |
| 5339 | + d.gutterFiller.style.height = sizes.bottom + "px"; | |
| 5340 | + d.gutterFiller.style.width = measure.gutterWidth + "px"; | |
| 5341 | + } else { d.gutterFiller.style.display = ""; } | |
| 5342 | + } | |
| 5343 | + | |
| 5344 | + var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars}; | |
| 5345 | + | |
| 5346 | + function initScrollbars(cm) { | |
| 5347 | + if (cm.display.scrollbars) { | |
| 5348 | + cm.display.scrollbars.clear(); | |
| 5349 | + if (cm.display.scrollbars.addClass) | |
| 5350 | + { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass); } | |
| 5351 | + } | |
| 5352 | + | |
| 5353 | + cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) { | |
| 5354 | + cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller); | |
| 5355 | + // Prevent clicks in the scrollbars from killing focus | |
| 5356 | + on(node, "mousedown", function () { | |
| 5357 | + if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0); } | |
| 5358 | + }); | |
| 5359 | + node.setAttribute("cm-not-content", "true"); | |
| 5360 | + }, function (pos, axis) { | |
| 5361 | + if (axis == "horizontal") { setScrollLeft(cm, pos); } | |
| 5362 | + else { updateScrollTop(cm, pos); } | |
| 5363 | + }, cm); | |
| 5364 | + if (cm.display.scrollbars.addClass) | |
| 5365 | + { addClass(cm.display.wrapper, cm.display.scrollbars.addClass); } | |
| 5366 | + } | |
| 5367 | + | |
| 5368 | + // Operations are used to wrap a series of changes to the editor | |
| 5369 | + // state in such a way that each change won't have to update the | |
| 5370 | + // cursor and display (which would be awkward, slow, and | |
| 5371 | + // error-prone). Instead, display updates are batched and then all | |
| 5372 | + // combined and executed at once. | |
| 5373 | + | |
| 5374 | + var nextOpId = 0; | |
| 5375 | + // Start a new operation. | |
| 5376 | + function startOperation(cm) { | |
| 5377 | + cm.curOp = { | |
| 5378 | + cm: cm, | |
| 5379 | + viewChanged: false, // Flag that indicates that lines might need to be redrawn | |
| 5380 | + startHeight: cm.doc.height, // Used to detect need to update scrollbar | |
| 5381 | + forceUpdate: false, // Used to force a redraw | |
| 5382 | + updateInput: 0, // Whether to reset the input textarea | |
| 5383 | + typing: false, // Whether this reset should be careful to leave existing text (for compositing) | |
| 5384 | + changeObjs: null, // Accumulated changes, for firing change events | |
| 5385 | + cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on | |
| 5386 | + cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already | |
| 5387 | + selectionChanged: false, // Whether the selection needs to be redrawn | |
| 5388 | + updateMaxLine: false, // Set when the widest line needs to be determined anew | |
| 5389 | + scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet | |
| 5390 | + scrollToPos: null, // Used to scroll to a specific position | |
| 5391 | + focus: false, | |
| 5392 | + id: ++nextOpId // Unique ID | |
| 5393 | + }; | |
| 5394 | + pushOperation(cm.curOp); | |
| 5395 | + } | |
| 5396 | + | |
| 5397 | + // Finish an operation, updating the display and signalling delayed events | |
| 5398 | + function endOperation(cm) { | |
| 5399 | + var op = cm.curOp; | |
| 5400 | + if (op) { finishOperation(op, function (group) { | |
| 5401 | + for (var i = 0; i < group.ops.length; i++) | |
| 5402 | + { group.ops[i].cm.curOp = null; } | |
| 5403 | + endOperations(group); | |
| 5404 | + }); } | |
| 5405 | + } | |
| 5406 | + | |
| 5407 | + // The DOM updates done when an operation finishes are batched so | |
| 5408 | + // that the minimum number of relayouts are required. | |
| 5409 | + function endOperations(group) { | |
| 5410 | + var ops = group.ops; | |
| 5411 | + for (var i = 0; i < ops.length; i++) // Read DOM | |
| 5412 | + { endOperation_R1(ops[i]); } | |
| 5413 | + for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe) | |
| 5414 | + { endOperation_W1(ops[i$1]); } | |
| 5415 | + for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM | |
| 5416 | + { endOperation_R2(ops[i$2]); } | |
| 5417 | + for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe) | |
| 5418 | + { endOperation_W2(ops[i$3]); } | |
| 5419 | + for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM | |
| 5420 | + { endOperation_finish(ops[i$4]); } | |
| 5421 | + } | |
| 5422 | + | |
| 5423 | + function endOperation_R1(op) { | |
| 5424 | + var cm = op.cm, display = cm.display; | |
| 5425 | + maybeClipScrollbars(cm); | |
| 5426 | + if (op.updateMaxLine) { findMaxLine(cm); } | |
| 5427 | + | |
| 5428 | + op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null || | |
| 5429 | + op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom || | |
| 5430 | + op.scrollToPos.to.line >= display.viewTo) || | |
| 5431 | + display.maxLineChanged && cm.options.lineWrapping; | |
| 5432 | + op.update = op.mustUpdate && | |
| 5433 | + new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate); | |
| 5434 | + } | |
| 5435 | + | |
| 5436 | + function endOperation_W1(op) { | |
| 5437 | + op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update); | |
| 5438 | + } | |
| 5439 | + | |
| 5440 | + function endOperation_R2(op) { | |
| 5441 | + var cm = op.cm, display = cm.display; | |
| 5442 | + if (op.updatedDisplay) { updateHeightsInViewport(cm); } | |
| 5443 | + | |
| 5444 | + op.barMeasure = measureForScrollbars(cm); | |
| 5445 | + | |
| 5446 | + // If the max line changed since it was last measured, measure it, | |
| 5447 | + // and ensure the document's width matches it. | |
| 5448 | + // updateDisplay_W2 will use these properties to do the actual resizing | |
| 5449 | + if (display.maxLineChanged && !cm.options.lineWrapping) { | |
| 5450 | + op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3; | |
| 5451 | + cm.display.sizerWidth = op.adjustWidthTo; | |
| 5452 | + op.barMeasure.scrollWidth = | |
| 5453 | + Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth); | |
| 5454 | + op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm)); | |
| 5455 | + } | |
| 5456 | + | |
| 5457 | + if (op.updatedDisplay || op.selectionChanged) | |
| 5458 | + { op.preparedSelection = display.input.prepareSelection(); } | |
| 5459 | + } | |
| 5460 | + | |
| 5461 | + function endOperation_W2(op) { | |
| 5462 | + var cm = op.cm; | |
| 5463 | + | |
| 5464 | + if (op.adjustWidthTo != null) { | |
| 5465 | + cm.display.sizer.style.minWidth = op.adjustWidthTo + "px"; | |
| 5466 | + if (op.maxScrollLeft < cm.doc.scrollLeft) | |
| 5467 | + { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); } | |
| 5468 | + cm.display.maxLineChanged = false; | |
| 5469 | + } | |
| 5470 | + | |
| 5471 | + var takeFocus = op.focus && op.focus == activeElt(); | |
| 5472 | + if (op.preparedSelection) | |
| 5473 | + { cm.display.input.showSelection(op.preparedSelection, takeFocus); } | |
| 5474 | + if (op.updatedDisplay || op.startHeight != cm.doc.height) | |
| 5475 | + { updateScrollbars(cm, op.barMeasure); } | |
| 5476 | + if (op.updatedDisplay) | |
| 5477 | + { setDocumentHeight(cm, op.barMeasure); } | |
| 5478 | + | |
| 5479 | + if (op.selectionChanged) { restartBlink(cm); } | |
| 5480 | + | |
| 5481 | + if (cm.state.focused && op.updateInput) | |
| 5482 | + { cm.display.input.reset(op.typing); } | |
| 5483 | + if (takeFocus) { ensureFocus(op.cm); } | |
| 5484 | + } | |
| 5485 | + | |
| 5486 | + function endOperation_finish(op) { | |
| 5487 | + var cm = op.cm, display = cm.display, doc = cm.doc; | |
| 5488 | + | |
| 5489 | + if (op.updatedDisplay) { postUpdateDisplay(cm, op.update); } | |
| 5490 | + | |
| 5491 | + // Abort mouse wheel delta measurement, when scrolling explicitly | |
| 5492 | + if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos)) | |
| 5493 | + { display.wheelStartX = display.wheelStartY = null; } | |
| 5494 | + | |
| 5495 | + // Propagate the scroll position to the actual DOM scroller | |
| 5496 | + if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll); } | |
| 5497 | + | |
| 5498 | + if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true); } | |
| 5499 | + // If we need to scroll a specific position into view, do so. | |
| 5500 | + if (op.scrollToPos) { | |
| 5501 | + var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from), | |
| 5502 | + clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin); | |
| 5503 | + maybeScrollWindow(cm, rect); | |
| 5504 | + } | |
| 5505 | + | |
| 5506 | + // Fire events for markers that are hidden/unidden by editing or | |
| 5507 | + // undoing | |
| 5508 | + var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers; | |
| 5509 | + if (hidden) { for (var i = 0; i < hidden.length; ++i) | |
| 5510 | + { if (!hidden[i].lines.length) { signal(hidden[i], "hide"); } } } | |
| 5511 | + if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1) | |
| 5512 | + { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide"); } } } | |
| 5513 | + | |
| 5514 | + if (display.wrapper.offsetHeight) | |
| 5515 | + { doc.scrollTop = cm.display.scroller.scrollTop; } | |
| 5516 | + | |
| 5517 | + // Fire change events, and delayed event handlers | |
| 5518 | + if (op.changeObjs) | |
| 5519 | + { signal(cm, "changes", cm, op.changeObjs); } | |
| 5520 | + if (op.update) | |
| 5521 | + { op.update.finish(); } | |
| 5522 | + } | |
| 5523 | + | |
| 5524 | + // Run the given function in an operation | |
| 5525 | + function runInOp(cm, f) { | |
| 5526 | + if (cm.curOp) { return f() } | |
| 5527 | + startOperation(cm); | |
| 5528 | + try { return f() } | |
| 5529 | + finally { endOperation(cm); } | |
| 5530 | + } | |
| 5531 | + // Wraps a function in an operation. Returns the wrapped function. | |
| 5532 | + function operation(cm, f) { | |
| 5533 | + return function() { | |
| 5534 | + if (cm.curOp) { return f.apply(cm, arguments) } | |
| 5535 | + startOperation(cm); | |
| 5536 | + try { return f.apply(cm, arguments) } | |
| 5537 | + finally { endOperation(cm); } | |
| 5538 | + } | |
| 5539 | + } | |
| 5540 | + // Used to add methods to editor and doc instances, wrapping them in | |
| 5541 | + // operations. | |
| 5542 | + function methodOp(f) { | |
| 5543 | + return function() { | |
| 5544 | + if (this.curOp) { return f.apply(this, arguments) } | |
| 5545 | + startOperation(this); | |
| 5546 | + try { return f.apply(this, arguments) } | |
| 5547 | + finally { endOperation(this); } | |
| 5548 | + } | |
| 5549 | + } | |
| 5550 | + function docMethodOp(f) { | |
| 5551 | + return function() { | |
| 5552 | + var cm = this.cm; | |
| 5553 | + if (!cm || cm.curOp) { return f.apply(this, arguments) } | |
| 5554 | + startOperation(cm); | |
| 5555 | + try { return f.apply(this, arguments) } | |
| 5556 | + finally { endOperation(cm); } | |
| 5557 | + } | |
| 5558 | + } | |
| 5559 | + | |
| 5560 | + // HIGHLIGHT WORKER | |
| 5561 | + | |
| 5562 | + function startWorker(cm, time) { | |
| 5563 | + if (cm.doc.highlightFrontier < cm.display.viewTo) | |
| 5564 | + { cm.state.highlight.set(time, bind(highlightWorker, cm)); } | |
| 5565 | + } | |
| 5566 | + | |
| 5567 | + function highlightWorker(cm) { | |
| 5568 | + var doc = cm.doc; | |
| 5569 | + if (doc.highlightFrontier >= cm.display.viewTo) { return } | |
| 5570 | + var end = +new Date + cm.options.workTime; | |
| 5571 | + var context = getContextBefore(cm, doc.highlightFrontier); | |
| 5572 | + var changedLines = []; | |
| 5573 | + | |
| 5574 | + doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) { | |
| 5575 | + if (context.line >= cm.display.viewFrom) { // Visible | |
| 5576 | + var oldStyles = line.styles; | |
| 5577 | + var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null; | |
| 5578 | + var highlighted = highlightLine(cm, line, context, true); | |
| 5579 | + if (resetState) { context.state = resetState; } | |
| 5580 | + line.styles = highlighted.styles; | |
| 5581 | + var oldCls = line.styleClasses, newCls = highlighted.classes; | |
| 5582 | + if (newCls) { line.styleClasses = newCls; } | |
| 5583 | + else if (oldCls) { line.styleClasses = null; } | |
| 5584 | + var ischange = !oldStyles || oldStyles.length != line.styles.length || | |
| 5585 | + oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass); | |
| 5586 | + for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i]; } | |
| 5587 | + if (ischange) { changedLines.push(context.line); } | |
| 5588 | + line.stateAfter = context.save(); | |
| 5589 | + context.nextLine(); | |
| 5590 | + } else { | |
| 5591 | + if (line.text.length <= cm.options.maxHighlightLength) | |
| 5592 | + { processLine(cm, line.text, context); } | |
| 5593 | + line.stateAfter = context.line % 5 == 0 ? context.save() : null; | |
| 5594 | + context.nextLine(); | |
| 5595 | + } | |
| 5596 | + if (+new Date > end) { | |
| 5597 | + startWorker(cm, cm.options.workDelay); | |
| 5598 | + return true | |
| 5599 | + } | |
| 5600 | + }); | |
| 5601 | + doc.highlightFrontier = context.line; | |
| 5602 | + doc.modeFrontier = Math.max(doc.modeFrontier, context.line); | |
| 5603 | + if (changedLines.length) { runInOp(cm, function () { | |
| 5604 | + for (var i = 0; i < changedLines.length; i++) | |
| 5605 | + { regLineChange(cm, changedLines[i], "text"); } | |
| 5606 | + }); } | |
| 5607 | + } | |
| 5608 | + | |
| 5609 | + // DISPLAY DRAWING | |
| 5610 | + | |
| 5611 | + var DisplayUpdate = function(cm, viewport, force) { | |
| 5612 | + var display = cm.display; | |
| 5613 | + | |
| 5614 | + this.viewport = viewport; | |
| 5615 | + // Store some values that we'll need later (but don't want to force a relayout for) | |
| 5616 | + this.visible = visibleLines(display, cm.doc, viewport); | |
| 5617 | + this.editorIsHidden = !display.wrapper.offsetWidth; | |
| 5618 | + this.wrapperHeight = display.wrapper.clientHeight; | |
| 5619 | + this.wrapperWidth = display.wrapper.clientWidth; | |
| 5620 | + this.oldDisplayWidth = displayWidth(cm); | |
| 5621 | + this.force = force; | |
| 5622 | + this.dims = getDimensions(cm); | |
| 5623 | + this.events = []; | |
| 5624 | + }; | |
| 5625 | + | |
| 5626 | + DisplayUpdate.prototype.signal = function (emitter, type) { | |
| 5627 | + if (hasHandler(emitter, type)) | |
| 5628 | + { this.events.push(arguments); } | |
| 5629 | + }; | |
| 5630 | + DisplayUpdate.prototype.finish = function () { | |
| 5631 | + for (var i = 0; i < this.events.length; i++) | |
| 5632 | + { signal.apply(null, this.events[i]); } | |
| 5633 | + }; | |
| 5634 | + | |
| 5635 | + function maybeClipScrollbars(cm) { | |
| 5636 | + var display = cm.display; | |
| 5637 | + if (!display.scrollbarsClipped && display.scroller.offsetWidth) { | |
| 5638 | + display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth; | |
| 5639 | + display.heightForcer.style.height = scrollGap(cm) + "px"; | |
| 5640 | + display.sizer.style.marginBottom = -display.nativeBarWidth + "px"; | |
| 5641 | + display.sizer.style.borderRightWidth = scrollGap(cm) + "px"; | |
| 5642 | + display.scrollbarsClipped = true; | |
| 5643 | + } | |
| 5644 | + } | |
| 5645 | + | |
| 5646 | + function selectionSnapshot(cm) { | |
| 5647 | + if (cm.hasFocus()) { return null } | |
| 5648 | + var active = activeElt(); | |
| 5649 | + if (!active || !contains(cm.display.lineDiv, active)) { return null } | |
| 5650 | + var result = {activeElt: active}; | |
| 5651 | + if (window.getSelection) { | |
| 5652 | + var sel = window.getSelection(); | |
| 5653 | + if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) { | |
| 5654 | + result.anchorNode = sel.anchorNode; | |
| 5655 | + result.anchorOffset = sel.anchorOffset; | |
| 5656 | + result.focusNode = sel.focusNode; | |
| 5657 | + result.focusOffset = sel.focusOffset; | |
| 5658 | + } | |
| 5659 | + } | |
| 5660 | + return result | |
| 5661 | + } | |
| 5662 | + | |
| 5663 | + function restoreSelection(snapshot) { | |
| 5664 | + if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return } | |
| 5665 | + snapshot.activeElt.focus(); | |
| 5666 | + if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) && | |
| 5667 | + snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) { | |
| 5668 | + var sel = window.getSelection(), range = document.createRange(); | |
| 5669 | + range.setEnd(snapshot.anchorNode, snapshot.anchorOffset); | |
| 5670 | + range.collapse(false); | |
| 5671 | + sel.removeAllRanges(); | |
| 5672 | + sel.addRange(range); | |
| 5673 | + sel.extend(snapshot.focusNode, snapshot.focusOffset); | |
| 5674 | + } | |
| 5675 | + } | |
| 5676 | + | |
| 5677 | + // Does the actual updating of the line display. Bails out | |
| 5678 | + // (returning false) when there is nothing to be done and forced is | |
| 5679 | + // false. | |
| 5680 | + function updateDisplayIfNeeded(cm, update) { | |
| 5681 | + var display = cm.display, doc = cm.doc; | |
| 5682 | + | |
| 5683 | + if (update.editorIsHidden) { | |
| 5684 | + resetView(cm); | |
| 5685 | + return false | |
| 5686 | + } | |
| 5687 | + | |
| 5688 | + // Bail out if the visible area is already rendered and nothing changed. | |
| 5689 | + if (!update.force && | |
| 5690 | + update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && | |
| 5691 | + (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && | |
| 5692 | + display.renderedView == display.view && countDirtyView(cm) == 0) | |
| 5693 | + { return false } | |
| 5694 | + | |
| 5695 | + if (maybeUpdateLineNumberWidth(cm)) { | |
| 5696 | + resetView(cm); | |
| 5697 | + update.dims = getDimensions(cm); | |
| 5698 | + } | |
| 5699 | + | |
| 5700 | + // Compute a suitable new viewport (from & to) | |
| 5701 | + var end = doc.first + doc.size; | |
| 5702 | + var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first); | |
| 5703 | + var to = Math.min(end, update.visible.to + cm.options.viewportMargin); | |
| 5704 | + if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); } | |
| 5705 | + if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); } | |
| 5706 | + if (sawCollapsedSpans) { | |
| 5707 | + from = visualLineNo(cm.doc, from); | |
| 5708 | + to = visualLineEndNo(cm.doc, to); | |
| 5709 | + } | |
| 5710 | + | |
| 5711 | + var different = from != display.viewFrom || to != display.viewTo || | |
| 5712 | + display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth; | |
| 5713 | + adjustView(cm, from, to); | |
| 5714 | + | |
| 5715 | + display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom)); | |
| 5716 | + // Position the mover div to align with the current scroll position | |
| 5717 | + cm.display.mover.style.top = display.viewOffset + "px"; | |
| 5718 | + | |
| 5719 | + var toUpdate = countDirtyView(cm); | |
| 5720 | + if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && | |
| 5721 | + (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) | |
| 5722 | + { return false } | |
| 5723 | + | |
| 5724 | + // For big changes, we hide the enclosing element during the | |
| 5725 | + // update, since that speeds up the operations on most browsers. | |
| 5726 | + var selSnapshot = selectionSnapshot(cm); | |
| 5727 | + if (toUpdate > 4) { display.lineDiv.style.display = "none"; } | |
| 5728 | + patchDisplay(cm, display.updateLineNumbers, update.dims); | |
| 5729 | + if (toUpdate > 4) { display.lineDiv.style.display = ""; } | |
| 5730 | + display.renderedView = display.view; | |
| 5731 | + // There might have been a widget with a focused element that got | |
| 5732 | + // hidden or updated, if so re-focus it. | |
| 5733 | + restoreSelection(selSnapshot); | |
| 5734 | + | |
| 5735 | + // Prevent selection and cursors from interfering with the scroll | |
| 5736 | + // width and height. | |
| 5737 | + removeChildren(display.cursorDiv); | |
| 5738 | + removeChildren(display.selectionDiv); | |
| 5739 | + display.gutters.style.height = display.sizer.style.minHeight = 0; | |
| 5740 | + | |
| 5741 | + if (different) { | |
| 5742 | + display.lastWrapHeight = update.wrapperHeight; | |
| 5743 | + display.lastWrapWidth = update.wrapperWidth; | |
| 5744 | + startWorker(cm, 400); | |
| 5745 | + } | |
| 5746 | + | |
| 5747 | + display.updateLineNumbers = null; | |
| 5748 | + | |
| 5749 | + return true | |
| 5750 | + } | |
| 5751 | + | |
| 5752 | + function postUpdateDisplay(cm, update) { | |
| 5753 | + var viewport = update.viewport; | |
| 5754 | + | |
| 5755 | + for (var first = true;; first = false) { | |
| 5756 | + if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) { | |
| 5757 | + // Clip forced viewport to actual scrollable area. | |
| 5758 | + if (viewport && viewport.top != null) | |
| 5759 | + { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}; } | |
| 5760 | + // Updated line heights might result in the drawn area not | |
| 5761 | + // actually covering the viewport. Keep looping until it does. | |
| 5762 | + update.visible = visibleLines(cm.display, cm.doc, viewport); | |
| 5763 | + if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo) | |
| 5764 | + { break } | |
| 5765 | + } else if (first) { | |
| 5766 | + update.visible = visibleLines(cm.display, cm.doc, viewport); | |
| 5767 | + } | |
| 5768 | + if (!updateDisplayIfNeeded(cm, update)) { break } | |
| 5769 | + updateHeightsInViewport(cm); | |
| 5770 | + var barMeasure = measureForScrollbars(cm); | |
| 5771 | + updateSelection(cm); | |
| 5772 | + updateScrollbars(cm, barMeasure); | |
| 5773 | + setDocumentHeight(cm, barMeasure); | |
| 5774 | + update.force = false; | |
| 5775 | + } | |
| 5776 | + | |
| 5777 | + update.signal(cm, "update", cm); | |
| 5778 | + if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) { | |
| 5779 | + update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo); | |
| 5780 | + cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo; | |
| 5781 | + } | |
| 5782 | + } | |
| 5783 | + | |
| 5784 | + function updateDisplaySimple(cm, viewport) { | |
| 5785 | + var update = new DisplayUpdate(cm, viewport); | |
| 5786 | + if (updateDisplayIfNeeded(cm, update)) { | |
| 5787 | + updateHeightsInViewport(cm); | |
| 5788 | + postUpdateDisplay(cm, update); | |
| 5789 | + var barMeasure = measureForScrollbars(cm); | |
| 5790 | + updateSelection(cm); | |
| 5791 | + updateScrollbars(cm, barMeasure); | |
| 5792 | + setDocumentHeight(cm, barMeasure); | |
| 5793 | + update.finish(); | |
| 5794 | + } | |
| 5795 | + } | |
| 5796 | + | |
| 5797 | + // Sync the actual display DOM structure with display.view, removing | |
| 5798 | + // nodes for lines that are no longer in view, and creating the ones | |
| 5799 | + // that are not there yet, and updating the ones that are out of | |
| 5800 | + // date. | |
| 5801 | + function patchDisplay(cm, updateNumbersFrom, dims) { | |
| 5802 | + var display = cm.display, lineNumbers = cm.options.lineNumbers; | |
| 5803 | + var container = display.lineDiv, cur = container.firstChild; | |
| 5804 | + | |
| 5805 | + function rm(node) { | |
| 5806 | + var next = node.nextSibling; | |
| 5807 | + // Works around a throw-scroll bug in OS X Webkit | |
| 5808 | + if (webkit && mac && cm.display.currentWheelTarget == node) | |
| 5809 | + { node.style.display = "none"; } | |
| 5810 | + else | |
| 5811 | + { node.parentNode.removeChild(node); } | |
| 5812 | + return next | |
| 5813 | + } | |
| 5814 | + | |
| 5815 | + var view = display.view, lineN = display.viewFrom; | |
| 5816 | + // Loop over the elements in the view, syncing cur (the DOM nodes | |
| 5817 | + // in display.lineDiv) with the view as we go. | |
| 5818 | + for (var i = 0; i < view.length; i++) { | |
| 5819 | + var lineView = view[i]; | |
| 5820 | + if (lineView.hidden) ; else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet | |
| 5821 | + var node = buildLineElement(cm, lineView, lineN, dims); | |
| 5822 | + container.insertBefore(node, cur); | |
| 5823 | + } else { // Already drawn | |
| 5824 | + while (cur != lineView.node) { cur = rm(cur); } | |
| 5825 | + var updateNumber = lineNumbers && updateNumbersFrom != null && | |
| 5826 | + updateNumbersFrom <= lineN && lineView.lineNumber; | |
| 5827 | + if (lineView.changes) { | |
| 5828 | + if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false; } | |
| 5829 | + updateLineForChanges(cm, lineView, lineN, dims); | |
| 5830 | + } | |
| 5831 | + if (updateNumber) { | |
| 5832 | + removeChildren(lineView.lineNumber); | |
| 5833 | + lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN))); | |
| 5834 | + } | |
| 5835 | + cur = lineView.node.nextSibling; | |
| 5836 | + } | |
| 5837 | + lineN += lineView.size; | |
| 5838 | + } | |
| 5839 | + while (cur) { cur = rm(cur); } | |
| 5840 | + } | |
| 5841 | + | |
| 5842 | + function updateGutterSpace(display) { | |
| 5843 | + var width = display.gutters.offsetWidth; | |
| 5844 | + display.sizer.style.marginLeft = width + "px"; | |
| 5845 | + // Send an event to consumers responding to changes in gutter width. | |
| 5846 | + signalLater(display, "gutterChanged", display); | |
| 5847 | + } | |
| 5848 | + | |
| 5849 | + function setDocumentHeight(cm, measure) { | |
| 5850 | + cm.display.sizer.style.minHeight = measure.docHeight + "px"; | |
| 5851 | + cm.display.heightForcer.style.top = measure.docHeight + "px"; | |
| 5852 | + cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px"; | |
| 5853 | + } | |
| 5854 | + | |
| 5855 | + // Re-align line numbers and gutter marks to compensate for | |
| 5856 | + // horizontal scrolling. | |
| 5857 | + function alignHorizontally(cm) { | |
| 5858 | + var display = cm.display, view = display.view; | |
| 5859 | + if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return } | |
| 5860 | + var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft; | |
| 5861 | + var gutterW = display.gutters.offsetWidth, left = comp + "px"; | |
| 5862 | + for (var i = 0; i < view.length; i++) { if (!view[i].hidden) { | |
| 5863 | + if (cm.options.fixedGutter) { | |
| 5864 | + if (view[i].gutter) | |
| 5865 | + { view[i].gutter.style.left = left; } | |
| 5866 | + if (view[i].gutterBackground) | |
| 5867 | + { view[i].gutterBackground.style.left = left; } | |
| 5868 | + } | |
| 5869 | + var align = view[i].alignable; | |
| 5870 | + if (align) { for (var j = 0; j < align.length; j++) | |
| 5871 | + { align[j].style.left = left; } } | |
| 5872 | + } } | |
| 5873 | + if (cm.options.fixedGutter) | |
| 5874 | + { display.gutters.style.left = (comp + gutterW) + "px"; } | |
| 5875 | + } | |
| 5876 | + | |
| 5877 | + // Used to ensure that the line number gutter is still the right | |
| 5878 | + // size for the current document size. Returns true when an update | |
| 5879 | + // is needed. | |
| 5880 | + function maybeUpdateLineNumberWidth(cm) { | |
| 5881 | + if (!cm.options.lineNumbers) { return false } | |
| 5882 | + var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display; | |
| 5883 | + if (last.length != display.lineNumChars) { | |
| 5884 | + var test = display.measure.appendChild(elt("div", [elt("div", last)], | |
| 5885 | + "CodeMirror-linenumber CodeMirror-gutter-elt")); | |
| 5886 | + var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW; | |
| 5887 | + display.lineGutter.style.width = ""; | |
| 5888 | + display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1; | |
| 5889 | + display.lineNumWidth = display.lineNumInnerWidth + padding; | |
| 5890 | + display.lineNumChars = display.lineNumInnerWidth ? last.length : -1; | |
| 5891 | + display.lineGutter.style.width = display.lineNumWidth + "px"; | |
| 5892 | + updateGutterSpace(cm.display); | |
| 5893 | + return true | |
| 5894 | + } | |
| 5895 | + return false | |
| 5896 | + } | |
| 5897 | + | |
| 5898 | + function getGutters(gutters, lineNumbers) { | |
| 5899 | + var result = [], sawLineNumbers = false; | |
| 5900 | + for (var i = 0; i < gutters.length; i++) { | |
| 5901 | + var name = gutters[i], style = null; | |
| 5902 | + if (typeof name != "string") { style = name.style; name = name.className; } | |
| 5903 | + if (name == "CodeMirror-linenumbers") { | |
| 5904 | + if (!lineNumbers) { continue } | |
| 5905 | + else { sawLineNumbers = true; } | |
| 5906 | + } | |
| 5907 | + result.push({className: name, style: style}); | |
| 5908 | + } | |
| 5909 | + if (lineNumbers && !sawLineNumbers) { result.push({className: "CodeMirror-linenumbers", style: null}); } | |
| 5910 | + return result | |
| 5911 | + } | |
| 5912 | + | |
| 5913 | + // Rebuild the gutter elements, ensure the margin to the left of the | |
| 5914 | + // code matches their width. | |
| 5915 | + function renderGutters(display) { | |
| 5916 | + var gutters = display.gutters, specs = display.gutterSpecs; | |
| 5917 | + removeChildren(gutters); | |
| 5918 | + display.lineGutter = null; | |
| 5919 | + for (var i = 0; i < specs.length; ++i) { | |
| 5920 | + var ref = specs[i]; | |
| 5921 | + var className = ref.className; | |
| 5922 | + var style = ref.style; | |
| 5923 | + var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + className)); | |
| 5924 | + if (style) { gElt.style.cssText = style; } | |
| 5925 | + if (className == "CodeMirror-linenumbers") { | |
| 5926 | + display.lineGutter = gElt; | |
| 5927 | + gElt.style.width = (display.lineNumWidth || 1) + "px"; | |
| 5928 | + } | |
| 5929 | + } | |
| 5930 | + gutters.style.display = specs.length ? "" : "none"; | |
| 5931 | + updateGutterSpace(display); | |
| 5932 | + } | |
| 5933 | + | |
| 5934 | + function updateGutters(cm) { | |
| 5935 | + renderGutters(cm.display); | |
| 5936 | + regChange(cm); | |
| 5937 | + alignHorizontally(cm); | |
| 5938 | + } | |
| 5939 | + | |
| 5940 | + // The display handles the DOM integration, both for input reading | |
| 5941 | + // and content drawing. It holds references to DOM nodes and | |
| 5942 | + // display-related state. | |
| 5943 | + | |
| 5944 | + function Display(place, doc, input, options) { | |
| 5945 | + var d = this; | |
| 5946 | + this.input = input; | |
| 5947 | + | |
| 5948 | + // Covers bottom-right square when both scrollbars are present. | |
| 5949 | + d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler"); | |
| 5950 | + d.scrollbarFiller.setAttribute("cm-not-content", "true"); | |
| 5951 | + // Covers bottom of gutter when coverGutterNextToScrollbar is on | |
| 5952 | + // and h scrollbar is present. | |
| 5953 | + d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler"); | |
| 5954 | + d.gutterFiller.setAttribute("cm-not-content", "true"); | |
| 5955 | + // Will contain the actual code, positioned to cover the viewport. | |
| 5956 | + d.lineDiv = eltP("div", null, "CodeMirror-code"); | |
| 5957 | + // Elements are added to these to represent selection and cursors. | |
| 5958 | + d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1"); | |
| 5959 | + d.cursorDiv = elt("div", null, "CodeMirror-cursors"); | |
| 5960 | + // A visibility: hidden element used to find the size of things. | |
| 5961 | + d.measure = elt("div", null, "CodeMirror-measure"); | |
| 5962 | + // When lines outside of the viewport are measured, they are drawn in this. | |
| 5963 | + d.lineMeasure = elt("div", null, "CodeMirror-measure"); | |
| 5964 | + // Wraps everything that needs to exist inside the vertically-padded coordinate system | |
| 5965 | + d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv], | |
| 5966 | + null, "position: relative; outline: none"); | |
| 5967 | + var lines = eltP("div", [d.lineSpace], "CodeMirror-lines"); | |
| 5968 | + // Moved around its parent to cover visible view. | |
| 5969 | + d.mover = elt("div", [lines], null, "position: relative"); | |
| 5970 | + // Set to the height of the document, allowing scrolling. | |
| 5971 | + d.sizer = elt("div", [d.mover], "CodeMirror-sizer"); | |
| 5972 | + d.sizerWidth = null; | |
| 5973 | + // Behavior of elts with overflow: auto and padding is | |
| 5974 | + // inconsistent across browsers. This is used to ensure the | |
| 5975 | + // scrollable area is big enough. | |
| 5976 | + d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;"); | |
| 5977 | + // Will contain the gutters, if any. | |
| 5978 | + d.gutters = elt("div", null, "CodeMirror-gutters"); | |
| 5979 | + d.lineGutter = null; | |
| 5980 | + // Actual scrollable element. | |
| 5981 | + d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll"); | |
| 5982 | + d.scroller.setAttribute("tabIndex", "-1"); | |
| 5983 | + // The element in which the editor lives. | |
| 5984 | + d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror"); | |
| 5985 | + | |
| 5986 | + // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported) | |
| 5987 | + if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; } | |
| 5988 | + if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true; } | |
| 5989 | + | |
| 5990 | + if (place) { | |
| 5991 | + if (place.appendChild) { place.appendChild(d.wrapper); } | |
| 5992 | + else { place(d.wrapper); } | |
| 5993 | + } | |
| 5994 | + | |
| 5995 | + // Current rendered range (may be bigger than the view window). | |
| 5996 | + d.viewFrom = d.viewTo = doc.first; | |
| 5997 | + d.reportedViewFrom = d.reportedViewTo = doc.first; | |
| 5998 | + // Information about the rendered lines. | |
| 5999 | + d.view = []; | |
| 6000 | + d.renderedView = null; | |
| 6001 | + // Holds info about a single rendered line when it was rendered | |
| 6002 | + // for measurement, while not in view. | |
| 6003 | + d.externalMeasured = null; | |
| 6004 | + // Empty space (in pixels) above the view | |
| 6005 | + d.viewOffset = 0; | |
| 6006 | + d.lastWrapHeight = d.lastWrapWidth = 0; | |
| 6007 | + d.updateLineNumbers = null; | |
| 6008 | + | |
| 6009 | + d.nativeBarWidth = d.barHeight = d.barWidth = 0; | |
| 6010 | + d.scrollbarsClipped = false; | |
| 6011 | + | |
| 6012 | + // Used to only resize the line number gutter when necessary (when | |
| 6013 | + // the amount of lines crosses a boundary that makes its width change) | |
| 6014 | + d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null; | |
| 6015 | + // Set to true when a non-horizontal-scrolling line widget is | |
| 6016 | + // added. As an optimization, line widget aligning is skipped when | |
| 6017 | + // this is false. | |
| 6018 | + d.alignWidgets = false; | |
| 6019 | + | |
| 6020 | + d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null; | |
| 6021 | + | |
| 6022 | + // Tracks the maximum line length so that the horizontal scrollbar | |
| 6023 | + // can be kept static when scrolling. | |
| 6024 | + d.maxLine = null; | |
| 6025 | + d.maxLineLength = 0; | |
| 6026 | + d.maxLineChanged = false; | |
| 6027 | + | |
| 6028 | + // Used for measuring wheel scrolling granularity | |
| 6029 | + d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null; | |
| 6030 | + | |
| 6031 | + // True when shift is held down. | |
| 6032 | + d.shift = false; | |
| 6033 | + | |
| 6034 | + // Used to track whether anything happened since the context menu | |
| 6035 | + // was opened. | |
| 6036 | + d.selForContextMenu = null; | |
| 6037 | + | |
| 6038 | + d.activeTouch = null; | |
| 6039 | + | |
| 6040 | + d.gutterSpecs = getGutters(options.gutters, options.lineNumbers); | |
| 6041 | + renderGutters(d); | |
| 6042 | + | |
| 6043 | + input.init(d); | |
| 6044 | + } | |
| 6045 | + | |
| 6046 | + // Since the delta values reported on mouse wheel events are | |
| 6047 | + // unstandardized between browsers and even browser versions, and | |
| 6048 | + // generally horribly unpredictable, this code starts by measuring | |
| 6049 | + // the scroll effect that the first few mouse wheel events have, | |
| 6050 | + // and, from that, detects the way it can convert deltas to pixel | |
| 6051 | + // offsets afterwards. | |
| 6052 | + // | |
| 6053 | + // The reason we want to know the amount a wheel event will scroll | |
| 6054 | + // is that it gives us a chance to update the display before the | |
| 6055 | + // actual scrolling happens, reducing flickering. | |
| 6056 | + | |
| 6057 | + var wheelSamples = 0, wheelPixelsPerUnit = null; | |
| 6058 | + // Fill in a browser-detected starting value on browsers where we | |
| 6059 | + // know one. These don't have to be accurate -- the result of them | |
| 6060 | + // being wrong would just be a slight flicker on the first wheel | |
| 6061 | + // scroll (if it is large enough). | |
| 6062 | + if (ie) { wheelPixelsPerUnit = -.53; } | |
| 6063 | + else if (gecko) { wheelPixelsPerUnit = 15; } | |
| 6064 | + else if (chrome) { wheelPixelsPerUnit = -.7; } | |
| 6065 | + else if (safari) { wheelPixelsPerUnit = -1/3; } | |
| 6066 | + | |
| 6067 | + function wheelEventDelta(e) { | |
| 6068 | + var dx = e.wheelDeltaX, dy = e.wheelDeltaY; | |
| 6069 | + if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail; } | |
| 6070 | + if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail; } | |
| 6071 | + else if (dy == null) { dy = e.wheelDelta; } | |
| 6072 | + return {x: dx, y: dy} | |
| 6073 | + } | |
| 6074 | + function wheelEventPixels(e) { | |
| 6075 | + var delta = wheelEventDelta(e); | |
| 6076 | + delta.x *= wheelPixelsPerUnit; | |
| 6077 | + delta.y *= wheelPixelsPerUnit; | |
| 6078 | + return delta | |
| 6079 | + } | |
| 6080 | + | |
| 6081 | + function onScrollWheel(cm, e) { | |
| 6082 | + var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y; | |
| 6083 | + | |
| 6084 | + var display = cm.display, scroll = display.scroller; | |
| 6085 | + // Quit if there's nothing to scroll here | |
| 6086 | + var canScrollX = scroll.scrollWidth > scroll.clientWidth; | |
| 6087 | + var canScrollY = scroll.scrollHeight > scroll.clientHeight; | |
| 6088 | + if (!(dx && canScrollX || dy && canScrollY)) { return } | |
| 6089 | + | |
| 6090 | + // Webkit browsers on OS X abort momentum scrolls when the target | |
| 6091 | + // of the scroll event is removed from the scrollable element. | |
| 6092 | + // This hack (see related code in patchDisplay) makes sure the | |
| 6093 | + // element is kept around. | |
| 6094 | + if (dy && mac && webkit) { | |
| 6095 | + outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) { | |
| 6096 | + for (var i = 0; i < view.length; i++) { | |
| 6097 | + if (view[i].node == cur) { | |
| 6098 | + cm.display.currentWheelTarget = cur; | |
| 6099 | + break outer | |
| 6100 | + } | |
| 6101 | + } | |
| 6102 | + } | |
| 6103 | + } | |
| 6104 | + | |
| 6105 | + // On some browsers, horizontal scrolling will cause redraws to | |
| 6106 | + // happen before the gutter has been realigned, causing it to | |
| 6107 | + // wriggle around in a most unseemly way. When we have an | |
| 6108 | + // estimated pixels/delta value, we just handle horizontal | |
| 6109 | + // scrolling entirely here. It'll be slightly off from native, but | |
| 6110 | + // better than glitching out. | |
| 6111 | + if (dx && !gecko && !presto && wheelPixelsPerUnit != null) { | |
| 6112 | + if (dy && canScrollY) | |
| 6113 | + { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)); } | |
| 6114 | + setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit)); | |
| 6115 | + // Only prevent default scrolling if vertical scrolling is | |
| 6116 | + // actually possible. Otherwise, it causes vertical scroll | |
| 6117 | + // jitter on OSX trackpads when deltaX is small and deltaY | |
| 6118 | + // is large (issue #3579) | |
| 6119 | + if (!dy || (dy && canScrollY)) | |
| 6120 | + { e_preventDefault(e); } | |
| 6121 | + display.wheelStartX = null; // Abort measurement, if in progress | |
| 6122 | + return | |
| 6123 | + } | |
| 6124 | + | |
| 6125 | + // 'Project' the visible viewport to cover the area that is being | |
| 6126 | + // scrolled into view (if we know enough to estimate it). | |
| 6127 | + if (dy && wheelPixelsPerUnit != null) { | |
| 6128 | + var pixels = dy * wheelPixelsPerUnit; | |
| 6129 | + var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight; | |
| 6130 | + if (pixels < 0) { top = Math.max(0, top + pixels - 50); } | |
| 6131 | + else { bot = Math.min(cm.doc.height, bot + pixels + 50); } | |
| 6132 | + updateDisplaySimple(cm, {top: top, bottom: bot}); | |
| 6133 | + } | |
| 6134 | + | |
| 6135 | + if (wheelSamples < 20) { | |
| 6136 | + if (display.wheelStartX == null) { | |
| 6137 | + display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop; | |
| 6138 | + display.wheelDX = dx; display.wheelDY = dy; | |
| 6139 | + setTimeout(function () { | |
| 6140 | + if (display.wheelStartX == null) { return } | |
| 6141 | + var movedX = scroll.scrollLeft - display.wheelStartX; | |
| 6142 | + var movedY = scroll.scrollTop - display.wheelStartY; | |
| 6143 | + var sample = (movedY && display.wheelDY && movedY / display.wheelDY) || | |
| 6144 | + (movedX && display.wheelDX && movedX / display.wheelDX); | |
| 6145 | + display.wheelStartX = display.wheelStartY = null; | |
| 6146 | + if (!sample) { return } | |
| 6147 | + wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1); | |
| 6148 | + ++wheelSamples; | |
| 6149 | + }, 200); | |
| 6150 | + } else { | |
| 6151 | + display.wheelDX += dx; display.wheelDY += dy; | |
| 6152 | + } | |
| 6153 | + } | |
| 6154 | + } | |
| 6155 | + | |
| 6156 | + // Selection objects are immutable. A new one is created every time | |
| 6157 | + // the selection changes. A selection is one or more non-overlapping | |
| 6158 | + // (and non-touching) ranges, sorted, and an integer that indicates | |
| 6159 | + // which one is the primary selection (the one that's scrolled into | |
| 6160 | + // view, that getCursor returns, etc). | |
| 6161 | + var Selection = function(ranges, primIndex) { | |
| 6162 | + this.ranges = ranges; | |
| 6163 | + this.primIndex = primIndex; | |
| 6164 | + }; | |
| 6165 | + | |
| 6166 | + Selection.prototype.primary = function () { return this.ranges[this.primIndex] }; | |
| 6167 | + | |
| 6168 | + Selection.prototype.equals = function (other) { | |
| 6169 | + if (other == this) { return true } | |
| 6170 | + if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false } | |
| 6171 | + for (var i = 0; i < this.ranges.length; i++) { | |
| 6172 | + var here = this.ranges[i], there = other.ranges[i]; | |
| 6173 | + if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false } | |
| 6174 | + } | |
| 6175 | + return true | |
| 6176 | + }; | |
| 6177 | + | |
| 6178 | + Selection.prototype.deepCopy = function () { | |
| 6179 | + var out = []; | |
| 6180 | + for (var i = 0; i < this.ranges.length; i++) | |
| 6181 | + { out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head)); } | |
| 6182 | + return new Selection(out, this.primIndex) | |
| 6183 | + }; | |
| 6184 | + | |
| 6185 | + Selection.prototype.somethingSelected = function () { | |
| 6186 | + for (var i = 0; i < this.ranges.length; i++) | |
| 6187 | + { if (!this.ranges[i].empty()) { return true } } | |
| 6188 | + return false | |
| 6189 | + }; | |
| 6190 | + | |
| 6191 | + Selection.prototype.contains = function (pos, end) { | |
| 6192 | + if (!end) { end = pos; } | |
| 6193 | + for (var i = 0; i < this.ranges.length; i++) { | |
| 6194 | + var range = this.ranges[i]; | |
| 6195 | + if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0) | |
| 6196 | + { return i } | |
| 6197 | + } | |
| 6198 | + return -1 | |
| 6199 | + }; | |
| 6200 | + | |
| 6201 | + var Range = function(anchor, head) { | |
| 6202 | + this.anchor = anchor; this.head = head; | |
| 6203 | + }; | |
| 6204 | + | |
| 6205 | + Range.prototype.from = function () { return minPos(this.anchor, this.head) }; | |
| 6206 | + Range.prototype.to = function () { return maxPos(this.anchor, this.head) }; | |
| 6207 | + Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch }; | |
| 6208 | + | |
| 6209 | + // Take an unsorted, potentially overlapping set of ranges, and | |
| 6210 | + // build a selection out of it. 'Consumes' ranges array (modifying | |
| 6211 | + // it). | |
| 6212 | + function normalizeSelection(cm, ranges, primIndex) { | |
| 6213 | + var mayTouch = cm && cm.options.selectionsMayTouch; | |
| 6214 | + var prim = ranges[primIndex]; | |
| 6215 | + ranges.sort(function (a, b) { return cmp(a.from(), b.from()); }); | |
| 6216 | + primIndex = indexOf(ranges, prim); | |
| 6217 | + for (var i = 1; i < ranges.length; i++) { | |
| 6218 | + var cur = ranges[i], prev = ranges[i - 1]; | |
| 6219 | + var diff = cmp(prev.to(), cur.from()); | |
| 6220 | + if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) { | |
| 6221 | + var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to()); | |
| 6222 | + var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head; | |
| 6223 | + if (i <= primIndex) { --primIndex; } | |
| 6224 | + ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to)); | |
| 6225 | + } | |
| 6226 | + } | |
| 6227 | + return new Selection(ranges, primIndex) | |
| 6228 | + } | |
| 6229 | + | |
| 6230 | + function simpleSelection(anchor, head) { | |
| 6231 | + return new Selection([new Range(anchor, head || anchor)], 0) | |
| 6232 | + } | |
| 6233 | + | |
| 6234 | + // Compute the position of the end of a change (its 'to' property | |
| 6235 | + // refers to the pre-change end). | |
| 6236 | + function changeEnd(change) { | |
| 6237 | + if (!change.text) { return change.to } | |
| 6238 | + return Pos(change.from.line + change.text.length - 1, | |
| 6239 | + lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0)) | |
| 6240 | + } | |
| 6241 | + | |
| 6242 | + // Adjust a position to refer to the post-change position of the | |
| 6243 | + // same text, or the end of the change if the change covers it. | |
| 6244 | + function adjustForChange(pos, change) { | |
| 6245 | + if (cmp(pos, change.from) < 0) { return pos } | |
| 6246 | + if (cmp(pos, change.to) <= 0) { return changeEnd(change) } | |
| 6247 | + | |
| 6248 | + var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch; | |
| 6249 | + if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch; } | |
| 6250 | + return Pos(line, ch) | |
| 6251 | + } | |
| 6252 | + | |
| 6253 | + function computeSelAfterChange(doc, change) { | |
| 6254 | + var out = []; | |
| 6255 | + for (var i = 0; i < doc.sel.ranges.length; i++) { | |
| 6256 | + var range = doc.sel.ranges[i]; | |
| 6257 | + out.push(new Range(adjustForChange(range.anchor, change), | |
| 6258 | + adjustForChange(range.head, change))); | |
| 6259 | + } | |
| 6260 | + return normalizeSelection(doc.cm, out, doc.sel.primIndex) | |
| 6261 | + } | |
| 6262 | + | |
| 6263 | + function offsetPos(pos, old, nw) { | |
| 6264 | + if (pos.line == old.line) | |
| 6265 | + { return Pos(nw.line, pos.ch - old.ch + nw.ch) } | |
| 6266 | + else | |
| 6267 | + { return Pos(nw.line + (pos.line - old.line), pos.ch) } | |
| 6268 | + } | |
| 6269 | + | |
| 6270 | + // Used by replaceSelections to allow moving the selection to the | |
| 6271 | + // start or around the replaced test. Hint may be "start" or "around". | |
| 6272 | + function computeReplacedSel(doc, changes, hint) { | |
| 6273 | + var out = []; | |
| 6274 | + var oldPrev = Pos(doc.first, 0), newPrev = oldPrev; | |
| 6275 | + for (var i = 0; i < changes.length; i++) { | |
| 6276 | + var change = changes[i]; | |
| 6277 | + var from = offsetPos(change.from, oldPrev, newPrev); | |
| 6278 | + var to = offsetPos(changeEnd(change), oldPrev, newPrev); | |
| 6279 | + oldPrev = change.to; | |
| 6280 | + newPrev = to; | |
| 6281 | + if (hint == "around") { | |
| 6282 | + var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0; | |
| 6283 | + out[i] = new Range(inv ? to : from, inv ? from : to); | |
| 6284 | + } else { | |
| 6285 | + out[i] = new Range(from, from); | |
| 6286 | + } | |
| 6287 | + } | |
| 6288 | + return new Selection(out, doc.sel.primIndex) | |
| 6289 | + } | |
| 6290 | + | |
| 6291 | + // Used to get the editor into a consistent state again when options change. | |
| 6292 | + | |
| 6293 | + function loadMode(cm) { | |
| 6294 | + cm.doc.mode = getMode(cm.options, cm.doc.modeOption); | |
| 6295 | + resetModeState(cm); | |
| 6296 | + } | |
| 6297 | + | |
| 6298 | + function resetModeState(cm) { | |
| 6299 | + cm.doc.iter(function (line) { | |
| 6300 | + if (line.stateAfter) { line.stateAfter = null; } | |
| 6301 | + if (line.styles) { line.styles = null; } | |
| 6302 | + }); | |
| 6303 | + cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first; | |
| 6304 | + startWorker(cm, 100); | |
| 6305 | + cm.state.modeGen++; | |
| 6306 | + if (cm.curOp) { regChange(cm); } | |
| 6307 | + } | |
| 6308 | + | |
| 6309 | + // DOCUMENT DATA STRUCTURE | |
| 6310 | + | |
| 6311 | + // By default, updates that start and end at the beginning of a line | |
| 6312 | + // are treated specially, in order to make the association of line | |
| 6313 | + // widgets and marker elements with the text behave more intuitive. | |
| 6314 | + function isWholeLineUpdate(doc, change) { | |
| 6315 | + return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" && | |
| 6316 | + (!doc.cm || doc.cm.options.wholeLineUpdateBefore) | |
| 6317 | + } | |
| 6318 | + | |
| 6319 | + // Perform a change on the document data structure. | |
| 6320 | + function updateDoc(doc, change, markedSpans, estimateHeight) { | |
| 6321 | + function spansFor(n) {return markedSpans ? markedSpans[n] : null} | |
| 6322 | + function update(line, text, spans) { | |
| 6323 | + updateLine(line, text, spans, estimateHeight); | |
| 6324 | + signalLater(line, "change", line, change); | |
| 6325 | + } | |
| 6326 | + function linesFor(start, end) { | |
| 6327 | + var result = []; | |
| 6328 | + for (var i = start; i < end; ++i) | |
| 6329 | + { result.push(new Line(text[i], spansFor(i), estimateHeight)); } | |
| 6330 | + return result | |
| 6331 | + } | |
| 6332 | + | |
| 6333 | + var from = change.from, to = change.to, text = change.text; | |
| 6334 | + var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line); | |
| 6335 | + var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line; | |
| 6336 | + | |
| 6337 | + // Adjust the line structure | |
| 6338 | + if (change.full) { | |
| 6339 | + doc.insert(0, linesFor(0, text.length)); | |
| 6340 | + doc.remove(text.length, doc.size - text.length); | |
| 6341 | + } else if (isWholeLineUpdate(doc, change)) { | |
| 6342 | + // This is a whole-line replace. Treated specially to make | |
| 6343 | + // sure line objects move the way they are supposed to. | |
| 6344 | + var added = linesFor(0, text.length - 1); | |
| 6345 | + update(lastLine, lastLine.text, lastSpans); | |
| 6346 | + if (nlines) { doc.remove(from.line, nlines); } | |
| 6347 | + if (added.length) { doc.insert(from.line, added); } | |
| 6348 | + } else if (firstLine == lastLine) { | |
| 6349 | + if (text.length == 1) { | |
| 6350 | + update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans); | |
| 6351 | + } else { | |
| 6352 | + var added$1 = linesFor(1, text.length - 1); | |
| 6353 | + added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight)); | |
| 6354 | + update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)); | |
| 6355 | + doc.insert(from.line + 1, added$1); | |
| 6356 | + } | |
| 6357 | + } else if (text.length == 1) { | |
| 6358 | + update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0)); | |
| 6359 | + doc.remove(from.line + 1, nlines); | |
| 6360 | + } else { | |
| 6361 | + update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)); | |
| 6362 | + update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans); | |
| 6363 | + var added$2 = linesFor(1, text.length - 1); | |
| 6364 | + if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); } | |
| 6365 | + doc.insert(from.line + 1, added$2); | |
| 6366 | + } | |
| 6367 | + | |
| 6368 | + signalLater(doc, "change", doc, change); | |
| 6369 | + } | |
| 6370 | + | |
| 6371 | + // Call f for all linked documents. | |
| 6372 | + function linkedDocs(doc, f, sharedHistOnly) { | |
| 6373 | + function propagate(doc, skip, sharedHist) { | |
| 6374 | + if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) { | |
| 6375 | + var rel = doc.linked[i]; | |
| 6376 | + if (rel.doc == skip) { continue } | |
| 6377 | + var shared = sharedHist && rel.sharedHist; | |
| 6378 | + if (sharedHistOnly && !shared) { continue } | |
| 6379 | + f(rel.doc, shared); | |
| 6380 | + propagate(rel.doc, doc, shared); | |
| 6381 | + } } | |
| 6382 | + } | |
| 6383 | + propagate(doc, null, true); | |
| 6384 | + } | |
| 6385 | + | |
| 6386 | + // Attach a document to an editor. | |
| 6387 | + function attachDoc(cm, doc) { | |
| 6388 | + if (doc.cm) { throw new Error("This document is already in use.") } | |
| 6389 | + cm.doc = doc; | |
| 6390 | + doc.cm = cm; | |
| 6391 | + estimateLineHeights(cm); | |
| 6392 | + loadMode(cm); | |
| 6393 | + setDirectionClass(cm); | |
| 6394 | + if (!cm.options.lineWrapping) { findMaxLine(cm); } | |
| 6395 | + cm.options.mode = doc.modeOption; | |
| 6396 | + regChange(cm); | |
| 6397 | + } | |
| 6398 | + | |
| 6399 | + function setDirectionClass(cm) { | |
| 6400 | + (cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl"); | |
| 6401 | + } | |
| 6402 | + | |
| 6403 | + function directionChanged(cm) { | |
| 6404 | + runInOp(cm, function () { | |
| 6405 | + setDirectionClass(cm); | |
| 6406 | + regChange(cm); | |
| 6407 | + }); | |
| 6408 | + } | |
| 6409 | + | |
| 6410 | + function History(prev) { | |
| 6411 | + // Arrays of change events and selections. Doing something adds an | |
| 6412 | + // event to done and clears undo. Undoing moves events from done | |
| 6413 | + // to undone, redoing moves them in the other direction. | |
| 6414 | + this.done = []; this.undone = []; | |
| 6415 | + this.undoDepth = prev ? prev.undoDepth : Infinity; | |
| 6416 | + // Used to track when changes can be merged into a single undo | |
| 6417 | + // event | |
| 6418 | + this.lastModTime = this.lastSelTime = 0; | |
| 6419 | + this.lastOp = this.lastSelOp = null; | |
| 6420 | + this.lastOrigin = this.lastSelOrigin = null; | |
| 6421 | + // Used by the isClean() method | |
| 6422 | + this.generation = this.maxGeneration = prev ? prev.maxGeneration : 1; | |
| 6423 | + } | |
| 6424 | + | |
| 6425 | + // Create a history change event from an updateDoc-style change | |
| 6426 | + // object. | |
| 6427 | + function historyChangeFromChange(doc, change) { | |
| 6428 | + var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)}; | |
| 6429 | + attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); | |
| 6430 | + linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true); | |
| 6431 | + return histChange | |
| 6432 | + } | |
| 6433 | + | |
| 6434 | + // Pop all selection events off the end of a history array. Stop at | |
| 6435 | + // a change event. | |
| 6436 | + function clearSelectionEvents(array) { | |
| 6437 | + while (array.length) { | |
| 6438 | + var last = lst(array); | |
| 6439 | + if (last.ranges) { array.pop(); } | |
| 6440 | + else { break } | |
| 6441 | + } | |
| 6442 | + } | |
| 6443 | + | |
| 6444 | + // Find the top change event in the history. Pop off selection | |
| 6445 | + // events that are in the way. | |
| 6446 | + function lastChangeEvent(hist, force) { | |
| 6447 | + if (force) { | |
| 6448 | + clearSelectionEvents(hist.done); | |
| 6449 | + return lst(hist.done) | |
| 6450 | + } else if (hist.done.length && !lst(hist.done).ranges) { | |
| 6451 | + return lst(hist.done) | |
| 6452 | + } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) { | |
| 6453 | + hist.done.pop(); | |
| 6454 | + return lst(hist.done) | |
| 6455 | + } | |
| 6456 | + } | |
| 6457 | + | |
| 6458 | + // Register a change in the history. Merges changes that are within | |
| 6459 | + // a single operation, or are close together with an origin that | |
| 6460 | + // allows merging (starting with "+") into a single event. | |
| 6461 | + function addChangeToHistory(doc, change, selAfter, opId) { | |
| 6462 | + var hist = doc.history; | |
| 6463 | + hist.undone.length = 0; | |
| 6464 | + var time = +new Date, cur; | |
| 6465 | + var last; | |
| 6466 | + | |
| 6467 | + if ((hist.lastOp == opId || | |
| 6468 | + hist.lastOrigin == change.origin && change.origin && | |
| 6469 | + ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) || | |
| 6470 | + change.origin.charAt(0) == "*")) && | |
| 6471 | + (cur = lastChangeEvent(hist, hist.lastOp == opId))) { | |
| 6472 | + // Merge this change into the last event | |
| 6473 | + last = lst(cur.changes); | |
| 6474 | + if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) { | |
| 6475 | + // Optimized case for simple insertion -- don't want to add | |
| 6476 | + // new changesets for every character typed | |
| 6477 | + last.to = changeEnd(change); | |
| 6478 | + } else { | |
| 6479 | + // Add new sub-event | |
| 6480 | + cur.changes.push(historyChangeFromChange(doc, change)); | |
| 6481 | + } | |
| 6482 | + } else { | |
| 6483 | + // Can not be merged, start a new event. | |
| 6484 | + var before = lst(hist.done); | |
| 6485 | + if (!before || !before.ranges) | |
| 6486 | + { pushSelectionToHistory(doc.sel, hist.done); } | |
| 6487 | + cur = {changes: [historyChangeFromChange(doc, change)], | |
| 6488 | + generation: hist.generation}; | |
| 6489 | + hist.done.push(cur); | |
| 6490 | + while (hist.done.length > hist.undoDepth) { | |
| 6491 | + hist.done.shift(); | |
| 6492 | + if (!hist.done[0].ranges) { hist.done.shift(); } | |
| 6493 | + } | |
| 6494 | + } | |
| 6495 | + hist.done.push(selAfter); | |
| 6496 | + hist.generation = ++hist.maxGeneration; | |
| 6497 | + hist.lastModTime = hist.lastSelTime = time; | |
| 6498 | + hist.lastOp = hist.lastSelOp = opId; | |
| 6499 | + hist.lastOrigin = hist.lastSelOrigin = change.origin; | |
| 6500 | + | |
| 6501 | + if (!last) { signal(doc, "historyAdded"); } | |
| 6502 | + } | |
| 6503 | + | |
| 6504 | + function selectionEventCanBeMerged(doc, origin, prev, sel) { | |
| 6505 | + var ch = origin.charAt(0); | |
| 6506 | + return ch == "*" || | |
| 6507 | + ch == "+" && | |
| 6508 | + prev.ranges.length == sel.ranges.length && | |
| 6509 | + prev.somethingSelected() == sel.somethingSelected() && | |
| 6510 | + new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500) | |
| 6511 | + } | |
| 6512 | + | |
| 6513 | + // Called whenever the selection changes, sets the new selection as | |
| 6514 | + // the pending selection in the history, and pushes the old pending | |
| 6515 | + // selection into the 'done' array when it was significantly | |
| 6516 | + // different (in number of selected ranges, emptiness, or time). | |
| 6517 | + function addSelectionToHistory(doc, sel, opId, options) { | |
| 6518 | + var hist = doc.history, origin = options && options.origin; | |
| 6519 | + | |
| 6520 | + // A new event is started when the previous origin does not match | |
| 6521 | + // the current, or the origins don't allow matching. Origins | |
| 6522 | + // starting with * are always merged, those starting with + are | |
| 6523 | + // merged when similar and close together in time. | |
| 6524 | + if (opId == hist.lastSelOp || | |
| 6525 | + (origin && hist.lastSelOrigin == origin && | |
| 6526 | + (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin || | |
| 6527 | + selectionEventCanBeMerged(doc, origin, lst(hist.done), sel)))) | |
| 6528 | + { hist.done[hist.done.length - 1] = sel; } | |
| 6529 | + else | |
| 6530 | + { pushSelectionToHistory(sel, hist.done); } | |
| 6531 | + | |
| 6532 | + hist.lastSelTime = +new Date; | |
| 6533 | + hist.lastSelOrigin = origin; | |
| 6534 | + hist.lastSelOp = opId; | |
| 6535 | + if (options && options.clearRedo !== false) | |
| 6536 | + { clearSelectionEvents(hist.undone); } | |
| 6537 | + } | |
| 6538 | + | |
| 6539 | + function pushSelectionToHistory(sel, dest) { | |
| 6540 | + var top = lst(dest); | |
| 6541 | + if (!(top && top.ranges && top.equals(sel))) | |
| 6542 | + { dest.push(sel); } | |
| 6543 | + } | |
| 6544 | + | |
| 6545 | + // Used to store marked span information in the history. | |
| 6546 | + function attachLocalSpans(doc, change, from, to) { | |
| 6547 | + var existing = change["spans_" + doc.id], n = 0; | |
| 6548 | + doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) { | |
| 6549 | + if (line.markedSpans) | |
| 6550 | + { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans; } | |
| 6551 | + ++n; | |
| 6552 | + }); | |
| 6553 | + } | |
| 6554 | + | |
| 6555 | + // When un/re-doing restores text containing marked spans, those | |
| 6556 | + // that have been explicitly cleared should not be restored. | |
| 6557 | + function removeClearedSpans(spans) { | |
| 6558 | + if (!spans) { return null } | |
| 6559 | + var out; | |
| 6560 | + for (var i = 0; i < spans.length; ++i) { | |
| 6561 | + if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i); } } | |
| 6562 | + else if (out) { out.push(spans[i]); } | |
| 6563 | + } | |
| 6564 | + return !out ? spans : out.length ? out : null | |
| 6565 | + } | |
| 6566 | + | |
| 6567 | + // Retrieve and filter the old marked spans stored in a change event. | |
| 6568 | + function getOldSpans(doc, change) { | |
| 6569 | + var found = change["spans_" + doc.id]; | |
| 6570 | + if (!found) { return null } | |
| 6571 | + var nw = []; | |
| 6572 | + for (var i = 0; i < change.text.length; ++i) | |
| 6573 | + { nw.push(removeClearedSpans(found[i])); } | |
| 6574 | + return nw | |
| 6575 | + } | |
| 6576 | + | |
| 6577 | + // Used for un/re-doing changes from the history. Combines the | |
| 6578 | + // result of computing the existing spans with the set of spans that | |
| 6579 | + // existed in the history (so that deleting around a span and then | |
| 6580 | + // undoing brings back the span). | |
| 6581 | + function mergeOldSpans(doc, change) { | |
| 6582 | + var old = getOldSpans(doc, change); | |
| 6583 | + var stretched = stretchSpansOverChange(doc, change); | |
| 6584 | + if (!old) { return stretched } | |
| 6585 | + if (!stretched) { return old } | |
| 6586 | + | |
| 6587 | + for (var i = 0; i < old.length; ++i) { | |
| 6588 | + var oldCur = old[i], stretchCur = stretched[i]; | |
| 6589 | + if (oldCur && stretchCur) { | |
| 6590 | + spans: for (var j = 0; j < stretchCur.length; ++j) { | |
| 6591 | + var span = stretchCur[j]; | |
| 6592 | + for (var k = 0; k < oldCur.length; ++k) | |
| 6593 | + { if (oldCur[k].marker == span.marker) { continue spans } } | |
| 6594 | + oldCur.push(span); | |
| 6595 | + } | |
| 6596 | + } else if (stretchCur) { | |
| 6597 | + old[i] = stretchCur; | |
| 6598 | + } | |
| 6599 | + } | |
| 6600 | + return old | |
| 6601 | + } | |
| 6602 | + | |
| 6603 | + // Used both to provide a JSON-safe object in .getHistory, and, when | |
| 6604 | + // detaching a document, to split the history in two | |
| 6605 | + function copyHistoryArray(events, newGroup, instantiateSel) { | |
| 6606 | + var copy = []; | |
| 6607 | + for (var i = 0; i < events.length; ++i) { | |
| 6608 | + var event = events[i]; | |
| 6609 | + if (event.ranges) { | |
| 6610 | + copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event); | |
| 6611 | + continue | |
| 6612 | + } | |
| 6613 | + var changes = event.changes, newChanges = []; | |
| 6614 | + copy.push({changes: newChanges}); | |
| 6615 | + for (var j = 0; j < changes.length; ++j) { | |
| 6616 | + var change = changes[j], m = (void 0); | |
| 6617 | + newChanges.push({from: change.from, to: change.to, text: change.text}); | |
| 6618 | + if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) { | |
| 6619 | + if (indexOf(newGroup, Number(m[1])) > -1) { | |
| 6620 | + lst(newChanges)[prop] = change[prop]; | |
| 6621 | + delete change[prop]; | |
| 6622 | + } | |
| 6623 | + } } } | |
| 6624 | + } | |
| 6625 | + } | |
| 6626 | + return copy | |
| 6627 | + } | |
| 6628 | + | |
| 6629 | + // The 'scroll' parameter given to many of these indicated whether | |
| 6630 | + // the new cursor position should be scrolled into view after | |
| 6631 | + // modifying the selection. | |
| 6632 | + | |
| 6633 | + // If shift is held or the extend flag is set, extends a range to | |
| 6634 | + // include a given position (and optionally a second position). | |
| 6635 | + // Otherwise, simply returns the range between the given positions. | |
| 6636 | + // Used for cursor motion and such. | |
| 6637 | + function extendRange(range, head, other, extend) { | |
| 6638 | + if (extend) { | |
| 6639 | + var anchor = range.anchor; | |
| 6640 | + if (other) { | |
| 6641 | + var posBefore = cmp(head, anchor) < 0; | |
| 6642 | + if (posBefore != (cmp(other, anchor) < 0)) { | |
| 6643 | + anchor = head; | |
| 6644 | + head = other; | |
| 6645 | + } else if (posBefore != (cmp(head, other) < 0)) { | |
| 6646 | + head = other; | |
| 6647 | + } | |
| 6648 | + } | |
| 6649 | + return new Range(anchor, head) | |
| 6650 | + } else { | |
| 6651 | + return new Range(other || head, head) | |
| 6652 | + } | |
| 6653 | + } | |
| 6654 | + | |
| 6655 | + // Extend the primary selection range, discard the rest. | |
| 6656 | + function extendSelection(doc, head, other, options, extend) { | |
| 6657 | + if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend); } | |
| 6658 | + setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options); | |
| 6659 | + } | |
| 6660 | + | |
| 6661 | + // Extend all selections (pos is an array of selections with length | |
| 6662 | + // equal the number of selections) | |
| 6663 | + function extendSelections(doc, heads, options) { | |
| 6664 | + var out = []; | |
| 6665 | + var extend = doc.cm && (doc.cm.display.shift || doc.extend); | |
| 6666 | + for (var i = 0; i < doc.sel.ranges.length; i++) | |
| 6667 | + { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend); } | |
| 6668 | + var newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex); | |
| 6669 | + setSelection(doc, newSel, options); | |
| 6670 | + } | |
| 6671 | + | |
| 6672 | + // Updates a single range in the selection. | |
| 6673 | + function replaceOneSelection(doc, i, range, options) { | |
| 6674 | + var ranges = doc.sel.ranges.slice(0); | |
| 6675 | + ranges[i] = range; | |
| 6676 | + setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options); | |
| 6677 | + } | |
| 6678 | + | |
| 6679 | + // Reset the selection to a single range. | |
| 6680 | + function setSimpleSelection(doc, anchor, head, options) { | |
| 6681 | + setSelection(doc, simpleSelection(anchor, head), options); | |
| 6682 | + } | |
| 6683 | + | |
| 6684 | + // Give beforeSelectionChange handlers a change to influence a | |
| 6685 | + // selection update. | |
| 6686 | + function filterSelectionChange(doc, sel, options) { | |
| 6687 | + var obj = { | |
| 6688 | + ranges: sel.ranges, | |
| 6689 | + update: function(ranges) { | |
| 6690 | + this.ranges = []; | |
| 6691 | + for (var i = 0; i < ranges.length; i++) | |
| 6692 | + { this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor), | |
| 6693 | + clipPos(doc, ranges[i].head)); } | |
| 6694 | + }, | |
| 6695 | + origin: options && options.origin | |
| 6696 | + }; | |
| 6697 | + signal(doc, "beforeSelectionChange", doc, obj); | |
| 6698 | + if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj); } | |
| 6699 | + if (obj.ranges != sel.ranges) { return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1) } | |
| 6700 | + else { return sel } | |
| 6701 | + } | |
| 6702 | + | |
| 6703 | + function setSelectionReplaceHistory(doc, sel, options) { | |
| 6704 | + var done = doc.history.done, last = lst(done); | |
| 6705 | + if (last && last.ranges) { | |
| 6706 | + done[done.length - 1] = sel; | |
| 6707 | + setSelectionNoUndo(doc, sel, options); | |
| 6708 | + } else { | |
| 6709 | + setSelection(doc, sel, options); | |
| 6710 | + } | |
| 6711 | + } | |
| 6712 | + | |
| 6713 | + // Set a new selection. | |
| 6714 | + function setSelection(doc, sel, options) { | |
| 6715 | + setSelectionNoUndo(doc, sel, options); | |
| 6716 | + addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options); | |
| 6717 | + } | |
| 6718 | + | |
| 6719 | + function setSelectionNoUndo(doc, sel, options) { | |
| 6720 | + if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange")) | |
| 6721 | + { sel = filterSelectionChange(doc, sel, options); } | |
| 6722 | + | |
| 6723 | + var bias = options && options.bias || | |
| 6724 | + (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1); | |
| 6725 | + setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true)); | |
| 6726 | + | |
| 6727 | + if (!(options && options.scroll === false) && doc.cm && doc.cm.getOption("readOnly") != "nocursor") | |
| 6728 | + { ensureCursorVisible(doc.cm); } | |
| 6729 | + } | |
| 6730 | + | |
| 6731 | + function setSelectionInner(doc, sel) { | |
| 6732 | + if (sel.equals(doc.sel)) { return } | |
| 6733 | + | |
| 6734 | + doc.sel = sel; | |
| 6735 | + | |
| 6736 | + if (doc.cm) { | |
| 6737 | + doc.cm.curOp.updateInput = 1; | |
| 6738 | + doc.cm.curOp.selectionChanged = true; | |
| 6739 | + signalCursorActivity(doc.cm); | |
| 6740 | + } | |
| 6741 | + signalLater(doc, "cursorActivity", doc); | |
| 6742 | + } | |
| 6743 | + | |
| 6744 | + // Verify that the selection does not partially select any atomic | |
| 6745 | + // marked ranges. | |
| 6746 | + function reCheckSelection(doc) { | |
| 6747 | + setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false)); | |
| 6748 | + } | |
| 6749 | + | |
| 6750 | + // Return a selection that does not partially select any atomic | |
| 6751 | + // ranges. | |
| 6752 | + function skipAtomicInSelection(doc, sel, bias, mayClear) { | |
| 6753 | + var out; | |
| 6754 | + for (var i = 0; i < sel.ranges.length; i++) { | |
| 6755 | + var range = sel.ranges[i]; | |
| 6756 | + var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]; | |
| 6757 | + var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear); | |
| 6758 | + var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear); | |
| 6759 | + if (out || newAnchor != range.anchor || newHead != range.head) { | |
| 6760 | + if (!out) { out = sel.ranges.slice(0, i); } | |
| 6761 | + out[i] = new Range(newAnchor, newHead); | |
| 6762 | + } | |
| 6763 | + } | |
| 6764 | + return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel | |
| 6765 | + } | |
| 6766 | + | |
| 6767 | + function skipAtomicInner(doc, pos, oldPos, dir, mayClear) { | |
| 6768 | + var line = getLine(doc, pos.line); | |
| 6769 | + if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) { | |
| 6770 | + var sp = line.markedSpans[i], m = sp.marker; | |
| 6771 | + | |
| 6772 | + // Determine if we should prevent the cursor being placed to the left/right of an atomic marker | |
| 6773 | + // Historically this was determined using the inclusiveLeft/Right option, but the new way to control it | |
| 6774 | + // is with selectLeft/Right | |
| 6775 | + var preventCursorLeft = ("selectLeft" in m) ? !m.selectLeft : m.inclusiveLeft; | |
| 6776 | + var preventCursorRight = ("selectRight" in m) ? !m.selectRight : m.inclusiveRight; | |
| 6777 | + | |
| 6778 | + if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) && | |
| 6779 | + (sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) { | |
| 6780 | + if (mayClear) { | |
| 6781 | + signal(m, "beforeCursorEnter"); | |
| 6782 | + if (m.explicitlyCleared) { | |
| 6783 | + if (!line.markedSpans) { break } | |
| 6784 | + else {--i; continue} | |
| 6785 | + } | |
| 6786 | + } | |
| 6787 | + if (!m.atomic) { continue } | |
| 6788 | + | |
| 6789 | + if (oldPos) { | |
| 6790 | + var near = m.find(dir < 0 ? 1 : -1), diff = (void 0); | |
| 6791 | + if (dir < 0 ? preventCursorRight : preventCursorLeft) | |
| 6792 | + { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null); } | |
| 6793 | + if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0)) | |
| 6794 | + { return skipAtomicInner(doc, near, pos, dir, mayClear) } | |
| 6795 | + } | |
| 6796 | + | |
| 6797 | + var far = m.find(dir < 0 ? -1 : 1); | |
| 6798 | + if (dir < 0 ? preventCursorLeft : preventCursorRight) | |
| 6799 | + { far = movePos(doc, far, dir, far.line == pos.line ? line : null); } | |
| 6800 | + return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null | |
| 6801 | + } | |
| 6802 | + } } | |
| 6803 | + return pos | |
| 6804 | + } | |
| 6805 | + | |
| 6806 | + // Ensure a given position is not inside an atomic range. | |
| 6807 | + function skipAtomic(doc, pos, oldPos, bias, mayClear) { | |
| 6808 | + var dir = bias || 1; | |
| 6809 | + var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) || | |
| 6810 | + (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) || | |
| 6811 | + skipAtomicInner(doc, pos, oldPos, -dir, mayClear) || | |
| 6812 | + (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true)); | |
| 6813 | + if (!found) { | |
| 6814 | + doc.cantEdit = true; | |
| 6815 | + return Pos(doc.first, 0) | |
| 6816 | + } | |
| 6817 | + return found | |
| 6818 | + } | |
| 6819 | + | |
| 6820 | + function movePos(doc, pos, dir, line) { | |
| 6821 | + if (dir < 0 && pos.ch == 0) { | |
| 6822 | + if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) } | |
| 6823 | + else { return null } | |
| 6824 | + } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) { | |
| 6825 | + if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) } | |
| 6826 | + else { return null } | |
| 6827 | + } else { | |
| 6828 | + return new Pos(pos.line, pos.ch + dir) | |
| 6829 | + } | |
| 6830 | + } | |
| 6831 | + | |
| 6832 | + function selectAll(cm) { | |
| 6833 | + cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll); | |
| 6834 | + } | |
| 6835 | + | |
| 6836 | + // UPDATING | |
| 6837 | + | |
| 6838 | + // Allow "beforeChange" event handlers to influence a change | |
| 6839 | + function filterChange(doc, change, update) { | |
| 6840 | + var obj = { | |
| 6841 | + canceled: false, | |
| 6842 | + from: change.from, | |
| 6843 | + to: change.to, | |
| 6844 | + text: change.text, | |
| 6845 | + origin: change.origin, | |
| 6846 | + cancel: function () { return obj.canceled = true; } | |
| 6847 | + }; | |
| 6848 | + if (update) { obj.update = function (from, to, text, origin) { | |
| 6849 | + if (from) { obj.from = clipPos(doc, from); } | |
| 6850 | + if (to) { obj.to = clipPos(doc, to); } | |
| 6851 | + if (text) { obj.text = text; } | |
| 6852 | + if (origin !== undefined) { obj.origin = origin; } | |
| 6853 | + }; } | |
| 6854 | + signal(doc, "beforeChange", doc, obj); | |
| 6855 | + if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); } | |
| 6856 | + | |
| 6857 | + if (obj.canceled) { | |
| 6858 | + if (doc.cm) { doc.cm.curOp.updateInput = 2; } | |
| 6859 | + return null | |
| 6860 | + } | |
| 6861 | + return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin} | |
| 6862 | + } | |
| 6863 | + | |
| 6864 | + // Apply a change to a document, and add it to the document's | |
| 6865 | + // history, and propagating it to all linked documents. | |
| 6866 | + function makeChange(doc, change, ignoreReadOnly) { | |
| 6867 | + if (doc.cm) { | |
| 6868 | + if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) } | |
| 6869 | + if (doc.cm.state.suppressEdits) { return } | |
| 6870 | + } | |
| 6871 | + | |
| 6872 | + if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) { | |
| 6873 | + change = filterChange(doc, change, true); | |
| 6874 | + if (!change) { return } | |
| 6875 | + } | |
| 6876 | + | |
| 6877 | + // Possibly split or suppress the update based on the presence | |
| 6878 | + // of read-only spans in its range. | |
| 6879 | + var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to); | |
| 6880 | + if (split) { | |
| 6881 | + for (var i = split.length - 1; i >= 0; --i) | |
| 6882 | + { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}); } | |
| 6883 | + } else { | |
| 6884 | + makeChangeInner(doc, change); | |
| 6885 | + } | |
| 6886 | + } | |
| 6887 | + | |
| 6888 | + function makeChangeInner(doc, change) { | |
| 6889 | + if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return } | |
| 6890 | + var selAfter = computeSelAfterChange(doc, change); | |
| 6891 | + addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN); | |
| 6892 | + | |
| 6893 | + makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change)); | |
| 6894 | + var rebased = []; | |
| 6895 | + | |
| 6896 | + linkedDocs(doc, function (doc, sharedHist) { | |
| 6897 | + if (!sharedHist && indexOf(rebased, doc.history) == -1) { | |
| 6898 | + rebaseHist(doc.history, change); | |
| 6899 | + rebased.push(doc.history); | |
| 6900 | + } | |
| 6901 | + makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change)); | |
| 6902 | + }); | |
| 6903 | + } | |
| 6904 | + | |
| 6905 | + // Revert a change stored in a document's history. | |
| 6906 | + function makeChangeFromHistory(doc, type, allowSelectionOnly) { | |
| 6907 | + var suppress = doc.cm && doc.cm.state.suppressEdits; | |
| 6908 | + if (suppress && !allowSelectionOnly) { return } | |
| 6909 | + | |
| 6910 | + var hist = doc.history, event, selAfter = doc.sel; | |
| 6911 | + var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done; | |
| 6912 | + | |
| 6913 | + // Verify that there is a useable event (so that ctrl-z won't | |
| 6914 | + // needlessly clear selection events) | |
| 6915 | + var i = 0; | |
| 6916 | + for (; i < source.length; i++) { | |
| 6917 | + event = source[i]; | |
| 6918 | + if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges) | |
| 6919 | + { break } | |
| 6920 | + } | |
| 6921 | + if (i == source.length) { return } | |
| 6922 | + hist.lastOrigin = hist.lastSelOrigin = null; | |
| 6923 | + | |
| 6924 | + for (;;) { | |
| 6925 | + event = source.pop(); | |
| 6926 | + if (event.ranges) { | |
| 6927 | + pushSelectionToHistory(event, dest); | |
| 6928 | + if (allowSelectionOnly && !event.equals(doc.sel)) { | |
| 6929 | + setSelection(doc, event, {clearRedo: false}); | |
| 6930 | + return | |
| 6931 | + } | |
| 6932 | + selAfter = event; | |
| 6933 | + } else if (suppress) { | |
| 6934 | + source.push(event); | |
| 6935 | + return | |
| 6936 | + } else { break } | |
| 6937 | + } | |
| 6938 | + | |
| 6939 | + // Build up a reverse change object to add to the opposite history | |
| 6940 | + // stack (redo when undoing, and vice versa). | |
| 6941 | + var antiChanges = []; | |
| 6942 | + pushSelectionToHistory(selAfter, dest); | |
| 6943 | + dest.push({changes: antiChanges, generation: hist.generation}); | |
| 6944 | + hist.generation = event.generation || ++hist.maxGeneration; | |
| 6945 | + | |
| 6946 | + var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange"); | |
| 6947 | + | |
| 6948 | + var loop = function ( i ) { | |
| 6949 | + var change = event.changes[i]; | |
| 6950 | + change.origin = type; | |
| 6951 | + if (filter && !filterChange(doc, change, false)) { | |
| 6952 | + source.length = 0; | |
| 6953 | + return {} | |
| 6954 | + } | |
| 6955 | + | |
| 6956 | + antiChanges.push(historyChangeFromChange(doc, change)); | |
| 6957 | + | |
| 6958 | + var after = i ? computeSelAfterChange(doc, change) : lst(source); | |
| 6959 | + makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change)); | |
| 6960 | + if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}); } | |
| 6961 | + var rebased = []; | |
| 6962 | + | |
| 6963 | + // Propagate to the linked documents | |
| 6964 | + linkedDocs(doc, function (doc, sharedHist) { | |
| 6965 | + if (!sharedHist && indexOf(rebased, doc.history) == -1) { | |
| 6966 | + rebaseHist(doc.history, change); | |
| 6967 | + rebased.push(doc.history); | |
| 6968 | + } | |
| 6969 | + makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change)); | |
| 6970 | + }); | |
| 6971 | + }; | |
| 6972 | + | |
| 6973 | + for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) { | |
| 6974 | + var returned = loop( i$1 ); | |
| 6975 | + | |
| 6976 | + if ( returned ) return returned.v; | |
| 6977 | + } | |
| 6978 | + } | |
| 6979 | + | |
| 6980 | + // Sub-views need their line numbers shifted when text is added | |
| 6981 | + // above or below them in the parent document. | |
| 6982 | + function shiftDoc(doc, distance) { | |
| 6983 | + if (distance == 0) { return } | |
| 6984 | + doc.first += distance; | |
| 6985 | + doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range( | |
| 6986 | + Pos(range.anchor.line + distance, range.anchor.ch), | |
| 6987 | + Pos(range.head.line + distance, range.head.ch) | |
| 6988 | + ); }), doc.sel.primIndex); | |
| 6989 | + if (doc.cm) { | |
| 6990 | + regChange(doc.cm, doc.first, doc.first - distance, distance); | |
| 6991 | + for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++) | |
| 6992 | + { regLineChange(doc.cm, l, "gutter"); } | |
| 6993 | + } | |
| 6994 | + } | |
| 6995 | + | |
| 6996 | + // More lower-level change function, handling only a single document | |
| 6997 | + // (not linked ones). | |
| 6998 | + function makeChangeSingleDoc(doc, change, selAfter, spans) { | |
| 6999 | + if (doc.cm && !doc.cm.curOp) | |
| 7000 | + { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) } | |
| 7001 | + | |
| 7002 | + if (change.to.line < doc.first) { | |
| 7003 | + shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line)); | |
| 7004 | + return | |
| 7005 | + } | |
| 7006 | + if (change.from.line > doc.lastLine()) { return } | |
| 7007 | + | |
| 7008 | + // Clip the change to the size of this doc | |
| 7009 | + if (change.from.line < doc.first) { | |
| 7010 | + var shift = change.text.length - 1 - (doc.first - change.from.line); | |
| 7011 | + shiftDoc(doc, shift); | |
| 7012 | + change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch), | |
| 7013 | + text: [lst(change.text)], origin: change.origin}; | |
| 7014 | + } | |
| 7015 | + var last = doc.lastLine(); | |
| 7016 | + if (change.to.line > last) { | |
| 7017 | + change = {from: change.from, to: Pos(last, getLine(doc, last).text.length), | |
| 7018 | + text: [change.text[0]], origin: change.origin}; | |
| 7019 | + } | |
| 7020 | + | |
| 7021 | + change.removed = getBetween(doc, change.from, change.to); | |
| 7022 | + | |
| 7023 | + if (!selAfter) { selAfter = computeSelAfterChange(doc, change); } | |
| 7024 | + if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans); } | |
| 7025 | + else { updateDoc(doc, change, spans); } | |
| 7026 | + setSelectionNoUndo(doc, selAfter, sel_dontScroll); | |
| 7027 | + | |
| 7028 | + if (doc.cantEdit && skipAtomic(doc, Pos(doc.firstLine(), 0))) | |
| 7029 | + { doc.cantEdit = false; } | |
| 7030 | + } | |
| 7031 | + | |
| 7032 | + // Handle the interaction of a change to a document with the editor | |
| 7033 | + // that this document is part of. | |
| 7034 | + function makeChangeSingleDocInEditor(cm, change, spans) { | |
| 7035 | + var doc = cm.doc, display = cm.display, from = change.from, to = change.to; | |
| 7036 | + | |
| 7037 | + var recomputeMaxLength = false, checkWidthStart = from.line; | |
| 7038 | + if (!cm.options.lineWrapping) { | |
| 7039 | + checkWidthStart = lineNo(visualLine(getLine(doc, from.line))); | |
| 7040 | + doc.iter(checkWidthStart, to.line + 1, function (line) { | |
| 7041 | + if (line == display.maxLine) { | |
| 7042 | + recomputeMaxLength = true; | |
| 7043 | + return true | |
| 7044 | + } | |
| 7045 | + }); | |
| 7046 | + } | |
| 7047 | + | |
| 7048 | + if (doc.sel.contains(change.from, change.to) > -1) | |
| 7049 | + { signalCursorActivity(cm); } | |
| 7050 | + | |
| 7051 | + updateDoc(doc, change, spans, estimateHeight(cm)); | |
| 7052 | + | |
| 7053 | + if (!cm.options.lineWrapping) { | |
| 7054 | + doc.iter(checkWidthStart, from.line + change.text.length, function (line) { | |
| 7055 | + var len = lineLength(line); | |
| 7056 | + if (len > display.maxLineLength) { | |
| 7057 | + display.maxLine = line; | |
| 7058 | + display.maxLineLength = len; | |
| 7059 | + display.maxLineChanged = true; | |
| 7060 | + recomputeMaxLength = false; | |
| 7061 | + } | |
| 7062 | + }); | |
| 7063 | + if (recomputeMaxLength) { cm.curOp.updateMaxLine = true; } | |
| 7064 | + } | |
| 7065 | + | |
| 7066 | + retreatFrontier(doc, from.line); | |
| 7067 | + startWorker(cm, 400); | |
| 7068 | + | |
| 7069 | + var lendiff = change.text.length - (to.line - from.line) - 1; | |
| 7070 | + // Remember that these lines changed, for updating the display | |
| 7071 | + if (change.full) | |
| 7072 | + { regChange(cm); } | |
| 7073 | + else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change)) | |
| 7074 | + { regLineChange(cm, from.line, "text"); } | |
| 7075 | + else | |
| 7076 | + { regChange(cm, from.line, to.line + 1, lendiff); } | |
| 7077 | + | |
| 7078 | + var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change"); | |
| 7079 | + if (changeHandler || changesHandler) { | |
| 7080 | + var obj = { | |
| 7081 | + from: from, to: to, | |
| 7082 | + text: change.text, | |
| 7083 | + removed: change.removed, | |
| 7084 | + origin: change.origin | |
| 7085 | + }; | |
| 7086 | + if (changeHandler) { signalLater(cm, "change", cm, obj); } | |
| 7087 | + if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj); } | |
| 7088 | + } | |
| 7089 | + cm.display.selForContextMenu = null; | |
| 7090 | + } | |
| 7091 | + | |
| 7092 | + function replaceRange(doc, code, from, to, origin) { | |
| 7093 | + var assign; | |
| 7094 | + | |
| 7095 | + if (!to) { to = from; } | |
| 7096 | + if (cmp(to, from) < 0) { (assign = [to, from], from = assign[0], to = assign[1]); } | |
| 7097 | + if (typeof code == "string") { code = doc.splitLines(code); } | |
| 7098 | + makeChange(doc, {from: from, to: to, text: code, origin: origin}); | |
| 7099 | + } | |
| 7100 | + | |
| 7101 | + // Rebasing/resetting history to deal with externally-sourced changes | |
| 7102 | + | |
| 7103 | + function rebaseHistSelSingle(pos, from, to, diff) { | |
| 7104 | + if (to < pos.line) { | |
| 7105 | + pos.line += diff; | |
| 7106 | + } else if (from < pos.line) { | |
| 7107 | + pos.line = from; | |
| 7108 | + pos.ch = 0; | |
| 7109 | + } | |
| 7110 | + } | |
| 7111 | + | |
| 7112 | + // Tries to rebase an array of history events given a change in the | |
| 7113 | + // document. If the change touches the same lines as the event, the | |
| 7114 | + // event, and everything 'behind' it, is discarded. If the change is | |
| 7115 | + // before the event, the event's positions are updated. Uses a | |
| 7116 | + // copy-on-write scheme for the positions, to avoid having to | |
| 7117 | + // reallocate them all on every rebase, but also avoid problems with | |
| 7118 | + // shared position objects being unsafely updated. | |
| 7119 | + function rebaseHistArray(array, from, to, diff) { | |
| 7120 | + for (var i = 0; i < array.length; ++i) { | |
| 7121 | + var sub = array[i], ok = true; | |
| 7122 | + if (sub.ranges) { | |
| 7123 | + if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; } | |
| 7124 | + for (var j = 0; j < sub.ranges.length; j++) { | |
| 7125 | + rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff); | |
| 7126 | + rebaseHistSelSingle(sub.ranges[j].head, from, to, diff); | |
| 7127 | + } | |
| 7128 | + continue | |
| 7129 | + } | |
| 7130 | + for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) { | |
| 7131 | + var cur = sub.changes[j$1]; | |
| 7132 | + if (to < cur.from.line) { | |
| 7133 | + cur.from = Pos(cur.from.line + diff, cur.from.ch); | |
| 7134 | + cur.to = Pos(cur.to.line + diff, cur.to.ch); | |
| 7135 | + } else if (from <= cur.to.line) { | |
| 7136 | + ok = false; | |
| 7137 | + break | |
| 7138 | + } | |
| 7139 | + } | |
| 7140 | + if (!ok) { | |
| 7141 | + array.splice(0, i + 1); | |
| 7142 | + i = 0; | |
| 7143 | + } | |
| 7144 | + } | |
| 7145 | + } | |
| 7146 | + | |
| 7147 | + function rebaseHist(hist, change) { | |
| 7148 | + var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1; | |
| 7149 | + rebaseHistArray(hist.done, from, to, diff); | |
| 7150 | + rebaseHistArray(hist.undone, from, to, diff); | |
| 7151 | + } | |
| 7152 | + | |
| 7153 | + // Utility for applying a change to a line by handle or number, | |
| 7154 | + // returning the number and optionally registering the line as | |
| 7155 | + // changed. | |
| 7156 | + function changeLine(doc, handle, changeType, op) { | |
| 7157 | + var no = handle, line = handle; | |
| 7158 | + if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)); } | |
| 7159 | + else { no = lineNo(handle); } | |
| 7160 | + if (no == null) { return null } | |
| 7161 | + if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType); } | |
| 7162 | + return line | |
| 7163 | + } | |
| 7164 | + | |
| 7165 | + // The document is represented as a BTree consisting of leaves, with | |
| 7166 | + // chunk of lines in them, and branches, with up to ten leaves or | |
| 7167 | + // other branch nodes below them. The top node is always a branch | |
| 7168 | + // node, and is the document object itself (meaning it has | |
| 7169 | + // additional methods and properties). | |
| 7170 | + // | |
| 7171 | + // All nodes have parent links. The tree is used both to go from | |
| 7172 | + // line numbers to line objects, and to go from objects to numbers. | |
| 7173 | + // It also indexes by height, and is used to convert between height | |
| 7174 | + // and line object, and to find the total height of the document. | |
| 7175 | + // | |
| 7176 | + // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html | |
| 7177 | + | |
| 7178 | + function LeafChunk(lines) { | |
| 7179 | + this.lines = lines; | |
| 7180 | + this.parent = null; | |
| 7181 | + var height = 0; | |
| 7182 | + for (var i = 0; i < lines.length; ++i) { | |
| 7183 | + lines[i].parent = this; | |
| 7184 | + height += lines[i].height; | |
| 7185 | + } | |
| 7186 | + this.height = height; | |
| 7187 | + } | |
| 7188 | + | |
| 7189 | + LeafChunk.prototype = { | |
| 7190 | + chunkSize: function() { return this.lines.length }, | |
| 7191 | + | |
| 7192 | + // Remove the n lines at offset 'at'. | |
| 7193 | + removeInner: function(at, n) { | |
| 7194 | + for (var i = at, e = at + n; i < e; ++i) { | |
| 7195 | + var line = this.lines[i]; | |
| 7196 | + this.height -= line.height; | |
| 7197 | + cleanUpLine(line); | |
| 7198 | + signalLater(line, "delete"); | |
| 7199 | + } | |
| 7200 | + this.lines.splice(at, n); | |
| 7201 | + }, | |
| 7202 | + | |
| 7203 | + // Helper used to collapse a small branch into a single leaf. | |
| 7204 | + collapse: function(lines) { | |
| 7205 | + lines.push.apply(lines, this.lines); | |
| 7206 | + }, | |
| 7207 | + | |
| 7208 | + // Insert the given array of lines at offset 'at', count them as | |
| 7209 | + // having the given height. | |
| 7210 | + insertInner: function(at, lines, height) { | |
| 7211 | + this.height += height; | |
| 7212 | + this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at)); | |
| 7213 | + for (var i = 0; i < lines.length; ++i) { lines[i].parent = this; } | |
| 7214 | + }, | |
| 7215 | + | |
| 7216 | + // Used to iterate over a part of the tree. | |
| 7217 | + iterN: function(at, n, op) { | |
| 7218 | + for (var e = at + n; at < e; ++at) | |
| 7219 | + { if (op(this.lines[at])) { return true } } | |
| 7220 | + } | |
| 7221 | + }; | |
| 7222 | + | |
| 7223 | + function BranchChunk(children) { | |
| 7224 | + this.children = children; | |
| 7225 | + var size = 0, height = 0; | |
| 7226 | + for (var i = 0; i < children.length; ++i) { | |
| 7227 | + var ch = children[i]; | |
| 7228 | + size += ch.chunkSize(); height += ch.height; | |
| 7229 | + ch.parent = this; | |
| 7230 | + } | |
| 7231 | + this.size = size; | |
| 7232 | + this.height = height; | |
| 7233 | + this.parent = null; | |
| 7234 | + } | |
| 7235 | + | |
| 7236 | + BranchChunk.prototype = { | |
| 7237 | + chunkSize: function() { return this.size }, | |
| 7238 | + | |
| 7239 | + removeInner: function(at, n) { | |
| 7240 | + this.size -= n; | |
| 7241 | + for (var i = 0; i < this.children.length; ++i) { | |
| 7242 | + var child = this.children[i], sz = child.chunkSize(); | |
| 7243 | + if (at < sz) { | |
| 7244 | + var rm = Math.min(n, sz - at), oldHeight = child.height; | |
| 7245 | + child.removeInner(at, rm); | |
| 7246 | + this.height -= oldHeight - child.height; | |
| 7247 | + if (sz == rm) { this.children.splice(i--, 1); child.parent = null; } | |
| 7248 | + if ((n -= rm) == 0) { break } | |
| 7249 | + at = 0; | |
| 7250 | + } else { at -= sz; } | |
| 7251 | + } | |
| 7252 | + // If the result is smaller than 25 lines, ensure that it is a | |
| 7253 | + // single leaf node. | |
| 7254 | + if (this.size - n < 25 && | |
| 7255 | + (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) { | |
| 7256 | + var lines = []; | |
| 7257 | + this.collapse(lines); | |
| 7258 | + this.children = [new LeafChunk(lines)]; | |
| 7259 | + this.children[0].parent = this; | |
| 7260 | + } | |
| 7261 | + }, | |
| 7262 | + | |
| 7263 | + collapse: function(lines) { | |
| 7264 | + for (var i = 0; i < this.children.length; ++i) { this.children[i].collapse(lines); } | |
| 7265 | + }, | |
| 7266 | + | |
| 7267 | + insertInner: function(at, lines, height) { | |
| 7268 | + this.size += lines.length; | |
| 7269 | + this.height += height; | |
| 7270 | + for (var i = 0; i < this.children.length; ++i) { | |
| 7271 | + var child = this.children[i], sz = child.chunkSize(); | |
| 7272 | + if (at <= sz) { | |
| 7273 | + child.insertInner(at, lines, height); | |
| 7274 | + if (child.lines && child.lines.length > 50) { | |
| 7275 | + // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced. | |
| 7276 | + // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest. | |
| 7277 | + var remaining = child.lines.length % 25 + 25; | |
| 7278 | + for (var pos = remaining; pos < child.lines.length;) { | |
| 7279 | + var leaf = new LeafChunk(child.lines.slice(pos, pos += 25)); | |
| 7280 | + child.height -= leaf.height; | |
| 7281 | + this.children.splice(++i, 0, leaf); | |
| 7282 | + leaf.parent = this; | |
| 7283 | + } | |
| 7284 | + child.lines = child.lines.slice(0, remaining); | |
| 7285 | + this.maybeSpill(); | |
| 7286 | + } | |
| 7287 | + break | |
| 7288 | + } | |
| 7289 | + at -= sz; | |
| 7290 | + } | |
| 7291 | + }, | |
| 7292 | + | |
| 7293 | + // When a node has grown, check whether it should be split. | |
| 7294 | + maybeSpill: function() { | |
| 7295 | + if (this.children.length <= 10) { return } | |
| 7296 | + var me = this; | |
| 7297 | + do { | |
| 7298 | + var spilled = me.children.splice(me.children.length - 5, 5); | |
| 7299 | + var sibling = new BranchChunk(spilled); | |
| 7300 | + if (!me.parent) { // Become the parent node | |
| 7301 | + var copy = new BranchChunk(me.children); | |
| 7302 | + copy.parent = me; | |
| 7303 | + me.children = [copy, sibling]; | |
| 7304 | + me = copy; | |
| 7305 | + } else { | |
| 7306 | + me.size -= sibling.size; | |
| 7307 | + me.height -= sibling.height; | |
| 7308 | + var myIndex = indexOf(me.parent.children, me); | |
| 7309 | + me.parent.children.splice(myIndex + 1, 0, sibling); | |
| 7310 | + } | |
| 7311 | + sibling.parent = me.parent; | |
| 7312 | + } while (me.children.length > 10) | |
| 7313 | + me.parent.maybeSpill(); | |
| 7314 | + }, | |
| 7315 | + | |
| 7316 | + iterN: function(at, n, op) { | |
| 7317 | + for (var i = 0; i < this.children.length; ++i) { | |
| 7318 | + var child = this.children[i], sz = child.chunkSize(); | |
| 7319 | + if (at < sz) { | |
| 7320 | + var used = Math.min(n, sz - at); | |
| 7321 | + if (child.iterN(at, used, op)) { return true } | |
| 7322 | + if ((n -= used) == 0) { break } | |
| 7323 | + at = 0; | |
| 7324 | + } else { at -= sz; } | |
| 7325 | + } | |
| 7326 | + } | |
| 7327 | + }; | |
| 7328 | + | |
| 7329 | + // Line widgets are block elements displayed above or below a line. | |
| 7330 | + | |
| 7331 | + var LineWidget = function(doc, node, options) { | |
| 7332 | + if (options) { for (var opt in options) { if (options.hasOwnProperty(opt)) | |
| 7333 | + { this[opt] = options[opt]; } } } | |
| 7334 | + this.doc = doc; | |
| 7335 | + this.node = node; | |
| 7336 | + }; | |
| 7337 | + | |
| 7338 | + LineWidget.prototype.clear = function () { | |
| 7339 | + var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line); | |
| 7340 | + if (no == null || !ws) { return } | |
| 7341 | + for (var i = 0; i < ws.length; ++i) { if (ws[i] == this) { ws.splice(i--, 1); } } | |
| 7342 | + if (!ws.length) { line.widgets = null; } | |
| 7343 | + var height = widgetHeight(this); | |
| 7344 | + updateLineHeight(line, Math.max(0, line.height - height)); | |
| 7345 | + if (cm) { | |
| 7346 | + runInOp(cm, function () { | |
| 7347 | + adjustScrollWhenAboveVisible(cm, line, -height); | |
| 7348 | + regLineChange(cm, no, "widget"); | |
| 7349 | + }); | |
| 7350 | + signalLater(cm, "lineWidgetCleared", cm, this, no); | |
| 7351 | + } | |
| 7352 | + }; | |
| 7353 | + | |
| 7354 | + LineWidget.prototype.changed = function () { | |
| 7355 | + var this$1 = this; | |
| 7356 | + | |
| 7357 | + var oldH = this.height, cm = this.doc.cm, line = this.line; | |
| 7358 | + this.height = null; | |
| 7359 | + var diff = widgetHeight(this) - oldH; | |
| 7360 | + if (!diff) { return } | |
| 7361 | + if (!lineIsHidden(this.doc, line)) { updateLineHeight(line, line.height + diff); } | |
| 7362 | + if (cm) { | |
| 7363 | + runInOp(cm, function () { | |
| 7364 | + cm.curOp.forceUpdate = true; | |
| 7365 | + adjustScrollWhenAboveVisible(cm, line, diff); | |
| 7366 | + signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line)); | |
| 7367 | + }); | |
| 7368 | + } | |
| 7369 | + }; | |
| 7370 | + eventMixin(LineWidget); | |
| 7371 | + | |
| 7372 | + function adjustScrollWhenAboveVisible(cm, line, diff) { | |
| 7373 | + if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop)) | |
| 7374 | + { addToScrollTop(cm, diff); } | |
| 7375 | + } | |
| 7376 | + | |
| 7377 | + function addLineWidget(doc, handle, node, options) { | |
| 7378 | + var widget = new LineWidget(doc, node, options); | |
| 7379 | + var cm = doc.cm; | |
| 7380 | + if (cm && widget.noHScroll) { cm.display.alignWidgets = true; } | |
| 7381 | + changeLine(doc, handle, "widget", function (line) { | |
| 7382 | + var widgets = line.widgets || (line.widgets = []); | |
| 7383 | + if (widget.insertAt == null) { widgets.push(widget); } | |
| 7384 | + else { widgets.splice(Math.min(widgets.length, Math.max(0, widget.insertAt)), 0, widget); } | |
| 7385 | + widget.line = line; | |
| 7386 | + if (cm && !lineIsHidden(doc, line)) { | |
| 7387 | + var aboveVisible = heightAtLine(line) < doc.scrollTop; | |
| 7388 | + updateLineHeight(line, line.height + widgetHeight(widget)); | |
| 7389 | + if (aboveVisible) { addToScrollTop(cm, widget.height); } | |
| 7390 | + cm.curOp.forceUpdate = true; | |
| 7391 | + } | |
| 7392 | + return true | |
| 7393 | + }); | |
| 7394 | + if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)); } | |
| 7395 | + return widget | |
| 7396 | + } | |
| 7397 | + | |
| 7398 | + // TEXTMARKERS | |
| 7399 | + | |
| 7400 | + // Created with markText and setBookmark methods. A TextMarker is a | |
| 7401 | + // handle that can be used to clear or find a marked position in the | |
| 7402 | + // document. Line objects hold arrays (markedSpans) containing | |
| 7403 | + // {from, to, marker} object pointing to such marker objects, and | |
| 7404 | + // indicating that such a marker is present on that line. Multiple | |
| 7405 | + // lines may point to the same marker when it spans across lines. | |
| 7406 | + // The spans will have null for their from/to properties when the | |
| 7407 | + // marker continues beyond the start/end of the line. Markers have | |
| 7408 | + // links back to the lines they currently touch. | |
| 7409 | + | |
| 7410 | + // Collapsed markers have unique ids, in order to be able to order | |
| 7411 | + // them, which is needed for uniquely determining an outer marker | |
| 7412 | + // when they overlap (they may nest, but not partially overlap). | |
| 7413 | + var nextMarkerId = 0; | |
| 7414 | + | |
| 7415 | + var TextMarker = function(doc, type) { | |
| 7416 | + this.lines = []; | |
| 7417 | + this.type = type; | |
| 7418 | + this.doc = doc; | |
| 7419 | + this.id = ++nextMarkerId; | |
| 7420 | + }; | |
| 7421 | + | |
| 7422 | + // Clear the marker. | |
| 7423 | + TextMarker.prototype.clear = function () { | |
| 7424 | + if (this.explicitlyCleared) { return } | |
| 7425 | + var cm = this.doc.cm, withOp = cm && !cm.curOp; | |
| 7426 | + if (withOp) { startOperation(cm); } | |
| 7427 | + if (hasHandler(this, "clear")) { | |
| 7428 | + var found = this.find(); | |
| 7429 | + if (found) { signalLater(this, "clear", found.from, found.to); } | |
| 7430 | + } | |
| 7431 | + var min = null, max = null; | |
| 7432 | + for (var i = 0; i < this.lines.length; ++i) { | |
| 7433 | + var line = this.lines[i]; | |
| 7434 | + var span = getMarkedSpanFor(line.markedSpans, this); | |
| 7435 | + if (cm && !this.collapsed) { regLineChange(cm, lineNo(line), "text"); } | |
| 7436 | + else if (cm) { | |
| 7437 | + if (span.to != null) { max = lineNo(line); } | |
| 7438 | + if (span.from != null) { min = lineNo(line); } | |
| 7439 | + } | |
| 7440 | + line.markedSpans = removeMarkedSpan(line.markedSpans, span); | |
| 7441 | + if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm) | |
| 7442 | + { updateLineHeight(line, textHeight(cm.display)); } | |
| 7443 | + } | |
| 7444 | + if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) { | |
| 7445 | + var visual = visualLine(this.lines[i$1]), len = lineLength(visual); | |
| 7446 | + if (len > cm.display.maxLineLength) { | |
| 7447 | + cm.display.maxLine = visual; | |
| 7448 | + cm.display.maxLineLength = len; | |
| 7449 | + cm.display.maxLineChanged = true; | |
| 7450 | + } | |
| 7451 | + } } | |
| 7452 | + | |
| 7453 | + if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1); } | |
| 7454 | + this.lines.length = 0; | |
| 7455 | + this.explicitlyCleared = true; | |
| 7456 | + if (this.atomic && this.doc.cantEdit) { | |
| 7457 | + this.doc.cantEdit = false; | |
| 7458 | + if (cm) { reCheckSelection(cm.doc); } | |
| 7459 | + } | |
| 7460 | + if (cm) { signalLater(cm, "markerCleared", cm, this, min, max); } | |
| 7461 | + if (withOp) { endOperation(cm); } | |
| 7462 | + if (this.parent) { this.parent.clear(); } | |
| 7463 | + }; | |
| 7464 | + | |
| 7465 | + // Find the position of the marker in the document. Returns a {from, | |
| 7466 | + // to} object by default. Side can be passed to get a specific side | |
| 7467 | + // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the | |
| 7468 | + // Pos objects returned contain a line object, rather than a line | |
| 7469 | + // number (used to prevent looking up the same line twice). | |
| 7470 | + TextMarker.prototype.find = function (side, lineObj) { | |
| 7471 | + if (side == null && this.type == "bookmark") { side = 1; } | |
| 7472 | + var from, to; | |
| 7473 | + for (var i = 0; i < this.lines.length; ++i) { | |
| 7474 | + var line = this.lines[i]; | |
| 7475 | + var span = getMarkedSpanFor(line.markedSpans, this); | |
| 7476 | + if (span.from != null) { | |
| 7477 | + from = Pos(lineObj ? line : lineNo(line), span.from); | |
| 7478 | + if (side == -1) { return from } | |
| 7479 | + } | |
| 7480 | + if (span.to != null) { | |
| 7481 | + to = Pos(lineObj ? line : lineNo(line), span.to); | |
| 7482 | + if (side == 1) { return to } | |
| 7483 | + } | |
| 7484 | + } | |
| 7485 | + return from && {from: from, to: to} | |
| 7486 | + }; | |
| 7487 | + | |
| 7488 | + // Signals that the marker's widget changed, and surrounding layout | |
| 7489 | + // should be recomputed. | |
| 7490 | + TextMarker.prototype.changed = function () { | |
| 7491 | + var this$1 = this; | |
| 7492 | + | |
| 7493 | + var pos = this.find(-1, true), widget = this, cm = this.doc.cm; | |
| 7494 | + if (!pos || !cm) { return } | |
| 7495 | + runInOp(cm, function () { | |
| 7496 | + var line = pos.line, lineN = lineNo(pos.line); | |
| 7497 | + var view = findViewForLine(cm, lineN); | |
| 7498 | + if (view) { | |
| 7499 | + clearLineMeasurementCacheFor(view); | |
| 7500 | + cm.curOp.selectionChanged = cm.curOp.forceUpdate = true; | |
| 7501 | + } | |
| 7502 | + cm.curOp.updateMaxLine = true; | |
| 7503 | + if (!lineIsHidden(widget.doc, line) && widget.height != null) { | |
| 7504 | + var oldHeight = widget.height; | |
| 7505 | + widget.height = null; | |
| 7506 | + var dHeight = widgetHeight(widget) - oldHeight; | |
| 7507 | + if (dHeight) | |
| 7508 | + { updateLineHeight(line, line.height + dHeight); } | |
| 7509 | + } | |
| 7510 | + signalLater(cm, "markerChanged", cm, this$1); | |
| 7511 | + }); | |
| 7512 | + }; | |
| 7513 | + | |
| 7514 | + TextMarker.prototype.attachLine = function (line) { | |
| 7515 | + if (!this.lines.length && this.doc.cm) { | |
| 7516 | + var op = this.doc.cm.curOp; | |
| 7517 | + if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1) | |
| 7518 | + { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this); } | |
| 7519 | + } | |
| 7520 | + this.lines.push(line); | |
| 7521 | + }; | |
| 7522 | + | |
| 7523 | + TextMarker.prototype.detachLine = function (line) { | |
| 7524 | + this.lines.splice(indexOf(this.lines, line), 1); | |
| 7525 | + if (!this.lines.length && this.doc.cm) { | |
| 7526 | + var op = this.doc.cm.curOp | |
| 7527 | + ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this); | |
| 7528 | + } | |
| 7529 | + }; | |
| 7530 | + eventMixin(TextMarker); | |
| 7531 | + | |
| 7532 | + // Create a marker, wire it up to the right lines, and | |
| 7533 | + function markText(doc, from, to, options, type) { | |
| 7534 | + // Shared markers (across linked documents) are handled separately | |
| 7535 | + // (markTextShared will call out to this again, once per | |
| 7536 | + // document). | |
| 7537 | + if (options && options.shared) { return markTextShared(doc, from, to, options, type) } | |
| 7538 | + // Ensure we are in an operation. | |
| 7539 | + if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) } | |
| 7540 | + | |
| 7541 | + var marker = new TextMarker(doc, type), diff = cmp(from, to); | |
| 7542 | + if (options) { copyObj(options, marker, false); } | |
| 7543 | + // Don't connect empty markers unless clearWhenEmpty is false | |
| 7544 | + if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false) | |
| 7545 | + { return marker } | |
| 7546 | + if (marker.replacedWith) { | |
| 7547 | + // Showing up as a widget implies collapsed (widget replaces text) | |
| 7548 | + marker.collapsed = true; | |
| 7549 | + marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget"); | |
| 7550 | + if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); } | |
| 7551 | + if (options.insertLeft) { marker.widgetNode.insertLeft = true; } | |
| 7552 | + } | |
| 7553 | + if (marker.collapsed) { | |
| 7554 | + if (conflictingCollapsedRange(doc, from.line, from, to, marker) || | |
| 7555 | + from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker)) | |
| 7556 | + { throw new Error("Inserting collapsed marker partially overlapping an existing one") } | |
| 7557 | + seeCollapsedSpans(); | |
| 7558 | + } | |
| 7559 | + | |
| 7560 | + if (marker.addToHistory) | |
| 7561 | + { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); } | |
| 7562 | + | |
| 7563 | + var curLine = from.line, cm = doc.cm, updateMaxLine; | |
| 7564 | + doc.iter(curLine, to.line + 1, function (line) { | |
| 7565 | + if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine) | |
| 7566 | + { updateMaxLine = true; } | |
| 7567 | + if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); } | |
| 7568 | + addMarkedSpan(line, new MarkedSpan(marker, | |
| 7569 | + curLine == from.line ? from.ch : null, | |
| 7570 | + curLine == to.line ? to.ch : null)); | |
| 7571 | + ++curLine; | |
| 7572 | + }); | |
| 7573 | + // lineIsHidden depends on the presence of the spans, so needs a second pass | |
| 7574 | + if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) { | |
| 7575 | + if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); } | |
| 7576 | + }); } | |
| 7577 | + | |
| 7578 | + if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); } | |
| 7579 | + | |
| 7580 | + if (marker.readOnly) { | |
| 7581 | + seeReadOnlySpans(); | |
| 7582 | + if (doc.history.done.length || doc.history.undone.length) | |
| 7583 | + { doc.clearHistory(); } | |
| 7584 | + } | |
| 7585 | + if (marker.collapsed) { | |
| 7586 | + marker.id = ++nextMarkerId; | |
| 7587 | + marker.atomic = true; | |
| 7588 | + } | |
| 7589 | + if (cm) { | |
| 7590 | + // Sync editor state | |
| 7591 | + if (updateMaxLine) { cm.curOp.updateMaxLine = true; } | |
| 7592 | + if (marker.collapsed) | |
| 7593 | + { regChange(cm, from.line, to.line + 1); } | |
| 7594 | + else if (marker.className || marker.startStyle || marker.endStyle || marker.css || | |
| 7595 | + marker.attributes || marker.title) | |
| 7596 | + { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text"); } } | |
| 7597 | + if (marker.atomic) { reCheckSelection(cm.doc); } | |
| 7598 | + signalLater(cm, "markerAdded", cm, marker); | |
| 7599 | + } | |
| 7600 | + return marker | |
| 7601 | + } | |
| 7602 | + | |
| 7603 | + // SHARED TEXTMARKERS | |
| 7604 | + | |
| 7605 | + // A shared marker spans multiple linked documents. It is | |
| 7606 | + // implemented as a meta-marker-object controlling multiple normal | |
| 7607 | + // markers. | |
| 7608 | + var SharedTextMarker = function(markers, primary) { | |
| 7609 | + this.markers = markers; | |
| 7610 | + this.primary = primary; | |
| 7611 | + for (var i = 0; i < markers.length; ++i) | |
| 7612 | + { markers[i].parent = this; } | |
| 7613 | + }; | |
| 7614 | + | |
| 7615 | + SharedTextMarker.prototype.clear = function () { | |
| 7616 | + if (this.explicitlyCleared) { return } | |
| 7617 | + this.explicitlyCleared = true; | |
| 7618 | + for (var i = 0; i < this.markers.length; ++i) | |
| 7619 | + { this.markers[i].clear(); } | |
| 7620 | + signalLater(this, "clear"); | |
| 7621 | + }; | |
| 7622 | + | |
| 7623 | + SharedTextMarker.prototype.find = function (side, lineObj) { | |
| 7624 | + return this.primary.find(side, lineObj) | |
| 7625 | + }; | |
| 7626 | + eventMixin(SharedTextMarker); | |
| 7627 | + | |
| 7628 | + function markTextShared(doc, from, to, options, type) { | |
| 7629 | + options = copyObj(options); | |
| 7630 | + options.shared = false; | |
| 7631 | + var markers = [markText(doc, from, to, options, type)], primary = markers[0]; | |
| 7632 | + var widget = options.widgetNode; | |
| 7633 | + linkedDocs(doc, function (doc) { | |
| 7634 | + if (widget) { options.widgetNode = widget.cloneNode(true); } | |
| 7635 | + markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type)); | |
| 7636 | + for (var i = 0; i < doc.linked.length; ++i) | |
| 7637 | + { if (doc.linked[i].isParent) { return } } | |
| 7638 | + primary = lst(markers); | |
| 7639 | + }); | |
| 7640 | + return new SharedTextMarker(markers, primary) | |
| 7641 | + } | |
| 7642 | + | |
| 7643 | + function findSharedMarkers(doc) { | |
| 7644 | + return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; }) | |
| 7645 | + } | |
| 7646 | + | |
| 7647 | + function copySharedMarkers(doc, markers) { | |
| 7648 | + for (var i = 0; i < markers.length; i++) { | |
| 7649 | + var marker = markers[i], pos = marker.find(); | |
| 7650 | + var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to); | |
| 7651 | + if (cmp(mFrom, mTo)) { | |
| 7652 | + var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type); | |
| 7653 | + marker.markers.push(subMark); | |
| 7654 | + subMark.parent = marker; | |
| 7655 | + } | |
| 7656 | + } | |
| 7657 | + } | |
| 7658 | + | |
| 7659 | + function detachSharedMarkers(markers) { | |
| 7660 | + var loop = function ( i ) { | |
| 7661 | + var marker = markers[i], linked = [marker.primary.doc]; | |
| 7662 | + linkedDocs(marker.primary.doc, function (d) { return linked.push(d); }); | |
| 7663 | + for (var j = 0; j < marker.markers.length; j++) { | |
| 7664 | + var subMarker = marker.markers[j]; | |
| 7665 | + if (indexOf(linked, subMarker.doc) == -1) { | |
| 7666 | + subMarker.parent = null; | |
| 7667 | + marker.markers.splice(j--, 1); | |
| 7668 | + } | |
| 7669 | + } | |
| 7670 | + }; | |
| 7671 | + | |
| 7672 | + for (var i = 0; i < markers.length; i++) loop( i ); | |
| 7673 | + } | |
| 7674 | + | |
| 7675 | + var nextDocId = 0; | |
| 7676 | + var Doc = function(text, mode, firstLine, lineSep, direction) { | |
| 7677 | + if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) } | |
| 7678 | + if (firstLine == null) { firstLine = 0; } | |
| 7679 | + | |
| 7680 | + BranchChunk.call(this, [new LeafChunk([new Line("", null)])]); | |
| 7681 | + this.first = firstLine; | |
| 7682 | + this.scrollTop = this.scrollLeft = 0; | |
| 7683 | + this.cantEdit = false; | |
| 7684 | + this.cleanGeneration = 1; | |
| 7685 | + this.modeFrontier = this.highlightFrontier = firstLine; | |
| 7686 | + var start = Pos(firstLine, 0); | |
| 7687 | + this.sel = simpleSelection(start); | |
| 7688 | + this.history = new History(null); | |
| 7689 | + this.id = ++nextDocId; | |
| 7690 | + this.modeOption = mode; | |
| 7691 | + this.lineSep = lineSep; | |
| 7692 | + this.direction = (direction == "rtl") ? "rtl" : "ltr"; | |
| 7693 | + this.extend = false; | |
| 7694 | + | |
| 7695 | + if (typeof text == "string") { text = this.splitLines(text); } | |
| 7696 | + updateDoc(this, {from: start, to: start, text: text}); | |
| 7697 | + setSelection(this, simpleSelection(start), sel_dontScroll); | |
| 7698 | + }; | |
| 7699 | + | |
| 7700 | + Doc.prototype = createObj(BranchChunk.prototype, { | |
| 7701 | + constructor: Doc, | |
| 7702 | + // Iterate over the document. Supports two forms -- with only one | |
| 7703 | + // argument, it calls that for each line in the document. With | |
| 7704 | + // three, it iterates over the range given by the first two (with | |
| 7705 | + // the second being non-inclusive). | |
| 7706 | + iter: function(from, to, op) { | |
| 7707 | + if (op) { this.iterN(from - this.first, to - from, op); } | |
| 7708 | + else { this.iterN(this.first, this.first + this.size, from); } | |
| 7709 | + }, | |
| 7710 | + | |
| 7711 | + // Non-public interface for adding and removing lines. | |
| 7712 | + insert: function(at, lines) { | |
| 7713 | + var height = 0; | |
| 7714 | + for (var i = 0; i < lines.length; ++i) { height += lines[i].height; } | |
| 7715 | + this.insertInner(at - this.first, lines, height); | |
| 7716 | + }, | |
| 7717 | + remove: function(at, n) { this.removeInner(at - this.first, n); }, | |
| 7718 | + | |
| 7719 | + // From here, the methods are part of the public interface. Most | |
| 7720 | + // are also available from CodeMirror (editor) instances. | |
| 7721 | + | |
| 7722 | + getValue: function(lineSep) { | |
| 7723 | + var lines = getLines(this, this.first, this.first + this.size); | |
| 7724 | + if (lineSep === false) { return lines } | |
| 7725 | + return lines.join(lineSep || this.lineSeparator()) | |
| 7726 | + }, | |
| 7727 | + setValue: docMethodOp(function(code) { | |
| 7728 | + var top = Pos(this.first, 0), last = this.first + this.size - 1; | |
| 7729 | + makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length), | |
| 7730 | + text: this.splitLines(code), origin: "setValue", full: true}, true); | |
| 7731 | + if (this.cm) { scrollToCoords(this.cm, 0, 0); } | |
| 7732 | + setSelection(this, simpleSelection(top), sel_dontScroll); | |
| 7733 | + }), | |
| 7734 | + replaceRange: function(code, from, to, origin) { | |
| 7735 | + from = clipPos(this, from); | |
| 7736 | + to = to ? clipPos(this, to) : from; | |
| 7737 | + replaceRange(this, code, from, to, origin); | |
| 7738 | + }, | |
| 7739 | + getRange: function(from, to, lineSep) { | |
| 7740 | + var lines = getBetween(this, clipPos(this, from), clipPos(this, to)); | |
| 7741 | + if (lineSep === false) { return lines } | |
| 7742 | + return lines.join(lineSep || this.lineSeparator()) | |
| 7743 | + }, | |
| 7744 | + | |
| 7745 | + getLine: function(line) {var l = this.getLineHandle(line); return l && l.text}, | |
| 7746 | + | |
| 7747 | + getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }}, | |
| 7748 | + getLineNumber: function(line) {return lineNo(line)}, | |
| 7749 | + | |
| 7750 | + getLineHandleVisualStart: function(line) { | |
| 7751 | + if (typeof line == "number") { line = getLine(this, line); } | |
| 7752 | + return visualLine(line) | |
| 7753 | + }, | |
| 7754 | + | |
| 7755 | + lineCount: function() {return this.size}, | |
| 7756 | + firstLine: function() {return this.first}, | |
| 7757 | + lastLine: function() {return this.first + this.size - 1}, | |
| 7758 | + | |
| 7759 | + clipPos: function(pos) {return clipPos(this, pos)}, | |
| 7760 | + | |
| 7761 | + getCursor: function(start) { | |
| 7762 | + var range = this.sel.primary(), pos; | |
| 7763 | + if (start == null || start == "head") { pos = range.head; } | |
| 7764 | + else if (start == "anchor") { pos = range.anchor; } | |
| 7765 | + else if (start == "end" || start == "to" || start === false) { pos = range.to(); } | |
| 7766 | + else { pos = range.from(); } | |
| 7767 | + return pos | |
| 7768 | + }, | |
| 7769 | + listSelections: function() { return this.sel.ranges }, | |
| 7770 | + somethingSelected: function() {return this.sel.somethingSelected()}, | |
| 7771 | + | |
| 7772 | + setCursor: docMethodOp(function(line, ch, options) { | |
| 7773 | + setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options); | |
| 7774 | + }), | |
| 7775 | + setSelection: docMethodOp(function(anchor, head, options) { | |
| 7776 | + setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options); | |
| 7777 | + }), | |
| 7778 | + extendSelection: docMethodOp(function(head, other, options) { | |
| 7779 | + extendSelection(this, clipPos(this, head), other && clipPos(this, other), options); | |
| 7780 | + }), | |
| 7781 | + extendSelections: docMethodOp(function(heads, options) { | |
| 7782 | + extendSelections(this, clipPosArray(this, heads), options); | |
| 7783 | + }), | |
| 7784 | + extendSelectionsBy: docMethodOp(function(f, options) { | |
| 7785 | + var heads = map(this.sel.ranges, f); | |
| 7786 | + extendSelections(this, clipPosArray(this, heads), options); | |
| 7787 | + }), | |
| 7788 | + setSelections: docMethodOp(function(ranges, primary, options) { | |
| 7789 | + if (!ranges.length) { return } | |
| 7790 | + var out = []; | |
| 7791 | + for (var i = 0; i < ranges.length; i++) | |
| 7792 | + { out[i] = new Range(clipPos(this, ranges[i].anchor), | |
| 7793 | + clipPos(this, ranges[i].head || ranges[i].anchor)); } | |
| 7794 | + if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex); } | |
| 7795 | + setSelection(this, normalizeSelection(this.cm, out, primary), options); | |
| 7796 | + }), | |
| 7797 | + addSelection: docMethodOp(function(anchor, head, options) { | |
| 7798 | + var ranges = this.sel.ranges.slice(0); | |
| 7799 | + ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor))); | |
| 7800 | + setSelection(this, normalizeSelection(this.cm, ranges, ranges.length - 1), options); | |
| 7801 | + }), | |
| 7802 | + | |
| 7803 | + getSelection: function(lineSep) { | |
| 7804 | + var ranges = this.sel.ranges, lines; | |
| 7805 | + for (var i = 0; i < ranges.length; i++) { | |
| 7806 | + var sel = getBetween(this, ranges[i].from(), ranges[i].to()); | |
| 7807 | + lines = lines ? lines.concat(sel) : sel; | |
| 7808 | + } | |
| 7809 | + if (lineSep === false) { return lines } | |
| 7810 | + else { return lines.join(lineSep || this.lineSeparator()) } | |
| 7811 | + }, | |
| 7812 | + getSelections: function(lineSep) { | |
| 7813 | + var parts = [], ranges = this.sel.ranges; | |
| 7814 | + for (var i = 0; i < ranges.length; i++) { | |
| 7815 | + var sel = getBetween(this, ranges[i].from(), ranges[i].to()); | |
| 7816 | + if (lineSep !== false) { sel = sel.join(lineSep || this.lineSeparator()); } | |
| 7817 | + parts[i] = sel; | |
| 7818 | + } | |
| 7819 | + return parts | |
| 7820 | + }, | |
| 7821 | + replaceSelection: function(code, collapse, origin) { | |
| 7822 | + var dup = []; | |
| 7823 | + for (var i = 0; i < this.sel.ranges.length; i++) | |
| 7824 | + { dup[i] = code; } | |
| 7825 | + this.replaceSelections(dup, collapse, origin || "+input"); | |
| 7826 | + }, | |
| 7827 | + replaceSelections: docMethodOp(function(code, collapse, origin) { | |
| 7828 | + var changes = [], sel = this.sel; | |
| 7829 | + for (var i = 0; i < sel.ranges.length; i++) { | |
| 7830 | + var range = sel.ranges[i]; | |
| 7831 | + changes[i] = {from: range.from(), to: range.to(), text: this.splitLines(code[i]), origin: origin}; | |
| 7832 | + } | |
| 7833 | + var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse); | |
| 7834 | + for (var i$1 = changes.length - 1; i$1 >= 0; i$1--) | |
| 7835 | + { makeChange(this, changes[i$1]); } | |
| 7836 | + if (newSel) { setSelectionReplaceHistory(this, newSel); } | |
| 7837 | + else if (this.cm) { ensureCursorVisible(this.cm); } | |
| 7838 | + }), | |
| 7839 | + undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}), | |
| 7840 | + redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}), | |
| 7841 | + undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}), | |
| 7842 | + redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}), | |
| 7843 | + | |
| 7844 | + setExtending: function(val) {this.extend = val;}, | |
| 7845 | + getExtending: function() {return this.extend}, | |
| 7846 | + | |
| 7847 | + historySize: function() { | |
| 7848 | + var hist = this.history, done = 0, undone = 0; | |
| 7849 | + for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done; } } | |
| 7850 | + for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone; } } | |
| 7851 | + return {undo: done, redo: undone} | |
| 7852 | + }, | |
| 7853 | + clearHistory: function() { | |
| 7854 | + var this$1 = this; | |
| 7855 | + | |
| 7856 | + this.history = new History(this.history); | |
| 7857 | + linkedDocs(this, function (doc) { return doc.history = this$1.history; }, true); | |
| 7858 | + }, | |
| 7859 | + | |
| 7860 | + markClean: function() { | |
| 7861 | + this.cleanGeneration = this.changeGeneration(true); | |
| 7862 | + }, | |
| 7863 | + changeGeneration: function(forceSplit) { | |
| 7864 | + if (forceSplit) | |
| 7865 | + { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null; } | |
| 7866 | + return this.history.generation | |
| 7867 | + }, | |
| 7868 | + isClean: function (gen) { | |
| 7869 | + return this.history.generation == (gen || this.cleanGeneration) | |
| 7870 | + }, | |
| 7871 | + | |
| 7872 | + getHistory: function() { | |
| 7873 | + return {done: copyHistoryArray(this.history.done), | |
| 7874 | + undone: copyHistoryArray(this.history.undone)} | |
| 7875 | + }, | |
| 7876 | + setHistory: function(histData) { | |
| 7877 | + var hist = this.history = new History(this.history); | |
| 7878 | + hist.done = copyHistoryArray(histData.done.slice(0), null, true); | |
| 7879 | + hist.undone = copyHistoryArray(histData.undone.slice(0), null, true); | |
| 7880 | + }, | |
| 7881 | + | |
| 7882 | + setGutterMarker: docMethodOp(function(line, gutterID, value) { | |
| 7883 | + return changeLine(this, line, "gutter", function (line) { | |
| 7884 | + var markers = line.gutterMarkers || (line.gutterMarkers = {}); | |
| 7885 | + markers[gutterID] = value; | |
| 7886 | + if (!value && isEmpty(markers)) { line.gutterMarkers = null; } | |
| 7887 | + return true | |
| 7888 | + }) | |
| 7889 | + }), | |
| 7890 | + | |
| 7891 | + clearGutter: docMethodOp(function(gutterID) { | |
| 7892 | + var this$1 = this; | |
| 7893 | + | |
| 7894 | + this.iter(function (line) { | |
| 7895 | + if (line.gutterMarkers && line.gutterMarkers[gutterID]) { | |
| 7896 | + changeLine(this$1, line, "gutter", function () { | |
| 7897 | + line.gutterMarkers[gutterID] = null; | |
| 7898 | + if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null; } | |
| 7899 | + return true | |
| 7900 | + }); | |
| 7901 | + } | |
| 7902 | + }); | |
| 7903 | + }), | |
| 7904 | + | |
| 7905 | + lineInfo: function(line) { | |
| 7906 | + var n; | |
| 7907 | + if (typeof line == "number") { | |
| 7908 | + if (!isLine(this, line)) { return null } | |
| 7909 | + n = line; | |
| 7910 | + line = getLine(this, line); | |
| 7911 | + if (!line) { return null } | |
| 7912 | + } else { | |
| 7913 | + n = lineNo(line); | |
| 7914 | + if (n == null) { return null } | |
| 7915 | + } | |
| 7916 | + return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers, | |
| 7917 | + textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass, | |
| 7918 | + widgets: line.widgets} | |
| 7919 | + }, | |
| 7920 | + | |
| 7921 | + addLineClass: docMethodOp(function(handle, where, cls) { | |
| 7922 | + return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) { | |
| 7923 | + var prop = where == "text" ? "textClass" | |
| 7924 | + : where == "background" ? "bgClass" | |
| 7925 | + : where == "gutter" ? "gutterClass" : "wrapClass"; | |
| 7926 | + if (!line[prop]) { line[prop] = cls; } | |
| 7927 | + else if (classTest(cls).test(line[prop])) { return false } | |
| 7928 | + else { line[prop] += " " + cls; } | |
| 7929 | + return true | |
| 7930 | + }) | |
| 7931 | + }), | |
| 7932 | + removeLineClass: docMethodOp(function(handle, where, cls) { | |
| 7933 | + return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) { | |
| 7934 | + var prop = where == "text" ? "textClass" | |
| 7935 | + : where == "background" ? "bgClass" | |
| 7936 | + : where == "gutter" ? "gutterClass" : "wrapClass"; | |
| 7937 | + var cur = line[prop]; | |
| 7938 | + if (!cur) { return false } | |
| 7939 | + else if (cls == null) { line[prop] = null; } | |
| 7940 | + else { | |
| 7941 | + var found = cur.match(classTest(cls)); | |
| 7942 | + if (!found) { return false } | |
| 7943 | + var end = found.index + found[0].length; | |
| 7944 | + line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null; | |
| 7945 | + } | |
| 7946 | + return true | |
| 7947 | + }) | |
| 7948 | + }), | |
| 7949 | + | |
| 7950 | + addLineWidget: docMethodOp(function(handle, node, options) { | |
| 7951 | + return addLineWidget(this, handle, node, options) | |
| 7952 | + }), | |
| 7953 | + removeLineWidget: function(widget) { widget.clear(); }, | |
| 7954 | + | |
| 7955 | + markText: function(from, to, options) { | |
| 7956 | + return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range") | |
| 7957 | + }, | |
| 7958 | + setBookmark: function(pos, options) { | |
| 7959 | + var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options), | |
| 7960 | + insertLeft: options && options.insertLeft, | |
| 7961 | + clearWhenEmpty: false, shared: options && options.shared, | |
| 7962 | + handleMouseEvents: options && options.handleMouseEvents}; | |
| 7963 | + pos = clipPos(this, pos); | |
| 7964 | + return markText(this, pos, pos, realOpts, "bookmark") | |
| 7965 | + }, | |
| 7966 | + findMarksAt: function(pos) { | |
| 7967 | + pos = clipPos(this, pos); | |
| 7968 | + var markers = [], spans = getLine(this, pos.line).markedSpans; | |
| 7969 | + if (spans) { for (var i = 0; i < spans.length; ++i) { | |
| 7970 | + var span = spans[i]; | |
| 7971 | + if ((span.from == null || span.from <= pos.ch) && | |
| 7972 | + (span.to == null || span.to >= pos.ch)) | |
| 7973 | + { markers.push(span.marker.parent || span.marker); } | |
| 7974 | + } } | |
| 7975 | + return markers | |
| 7976 | + }, | |
| 7977 | + findMarks: function(from, to, filter) { | |
| 7978 | + from = clipPos(this, from); to = clipPos(this, to); | |
| 7979 | + var found = [], lineNo = from.line; | |
| 7980 | + this.iter(from.line, to.line + 1, function (line) { | |
| 7981 | + var spans = line.markedSpans; | |
| 7982 | + if (spans) { for (var i = 0; i < spans.length; i++) { | |
| 7983 | + var span = spans[i]; | |
| 7984 | + if (!(span.to != null && lineNo == from.line && from.ch >= span.to || | |
| 7985 | + span.from == null && lineNo != from.line || | |
| 7986 | + span.from != null && lineNo == to.line && span.from >= to.ch) && | |
| 7987 | + (!filter || filter(span.marker))) | |
| 7988 | + { found.push(span.marker.parent || span.marker); } | |
| 7989 | + } } | |
| 7990 | + ++lineNo; | |
| 7991 | + }); | |
| 7992 | + return found | |
| 7993 | + }, | |
| 7994 | + getAllMarks: function() { | |
| 7995 | + var markers = []; | |
| 7996 | + this.iter(function (line) { | |
| 7997 | + var sps = line.markedSpans; | |
| 7998 | + if (sps) { for (var i = 0; i < sps.length; ++i) | |
| 7999 | + { if (sps[i].from != null) { markers.push(sps[i].marker); } } } | |
| 8000 | + }); | |
| 8001 | + return markers | |
| 8002 | + }, | |
| 8003 | + | |
| 8004 | + posFromIndex: function(off) { | |
| 8005 | + var ch, lineNo = this.first, sepSize = this.lineSeparator().length; | |
| 8006 | + this.iter(function (line) { | |
| 8007 | + var sz = line.text.length + sepSize; | |
| 8008 | + if (sz > off) { ch = off; return true } | |
| 8009 | + off -= sz; | |
| 8010 | + ++lineNo; | |
| 8011 | + }); | |
| 8012 | + return clipPos(this, Pos(lineNo, ch)) | |
| 8013 | + }, | |
| 8014 | + indexFromPos: function (coords) { | |
| 8015 | + coords = clipPos(this, coords); | |
| 8016 | + var index = coords.ch; | |
| 8017 | + if (coords.line < this.first || coords.ch < 0) { return 0 } | |
| 8018 | + var sepSize = this.lineSeparator().length; | |
| 8019 | + this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value | |
| 8020 | + index += line.text.length + sepSize; | |
| 8021 | + }); | |
| 8022 | + return index | |
| 8023 | + }, | |
| 8024 | + | |
| 8025 | + copy: function(copyHistory) { | |
| 8026 | + var doc = new Doc(getLines(this, this.first, this.first + this.size), | |
| 8027 | + this.modeOption, this.first, this.lineSep, this.direction); | |
| 8028 | + doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft; | |
| 8029 | + doc.sel = this.sel; | |
| 8030 | + doc.extend = false; | |
| 8031 | + if (copyHistory) { | |
| 8032 | + doc.history.undoDepth = this.history.undoDepth; | |
| 8033 | + doc.setHistory(this.getHistory()); | |
| 8034 | + } | |
| 8035 | + return doc | |
| 8036 | + }, | |
| 8037 | + | |
| 8038 | + linkedDoc: function(options) { | |
| 8039 | + if (!options) { options = {}; } | |
| 8040 | + var from = this.first, to = this.first + this.size; | |
| 8041 | + if (options.from != null && options.from > from) { from = options.from; } | |
| 8042 | + if (options.to != null && options.to < to) { to = options.to; } | |
| 8043 | + var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction); | |
| 8044 | + if (options.sharedHist) { copy.history = this.history | |
| 8045 | + ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist}); | |
| 8046 | + copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}]; | |
| 8047 | + copySharedMarkers(copy, findSharedMarkers(this)); | |
| 8048 | + return copy | |
| 8049 | + }, | |
| 8050 | + unlinkDoc: function(other) { | |
| 8051 | + if (other instanceof CodeMirror) { other = other.doc; } | |
| 8052 | + if (this.linked) { for (var i = 0; i < this.linked.length; ++i) { | |
| 8053 | + var link = this.linked[i]; | |
| 8054 | + if (link.doc != other) { continue } | |
| 8055 | + this.linked.splice(i, 1); | |
| 8056 | + other.unlinkDoc(this); | |
| 8057 | + detachSharedMarkers(findSharedMarkers(this)); | |
| 8058 | + break | |
| 8059 | + } } | |
| 8060 | + // If the histories were shared, split them again | |
| 8061 | + if (other.history == this.history) { | |
| 8062 | + var splitIds = [other.id]; | |
| 8063 | + linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true); | |
| 8064 | + other.history = new History(null); | |
| 8065 | + other.history.done = copyHistoryArray(this.history.done, splitIds); | |
| 8066 | + other.history.undone = copyHistoryArray(this.history.undone, splitIds); | |
| 8067 | + } | |
| 8068 | + }, | |
| 8069 | + iterLinkedDocs: function(f) {linkedDocs(this, f);}, | |
| 8070 | + | |
| 8071 | + getMode: function() {return this.mode}, | |
| 8072 | + getEditor: function() {return this.cm}, | |
| 8073 | + | |
| 8074 | + splitLines: function(str) { | |
| 8075 | + if (this.lineSep) { return str.split(this.lineSep) } | |
| 8076 | + return splitLinesAuto(str) | |
| 8077 | + }, | |
| 8078 | + lineSeparator: function() { return this.lineSep || "\n" }, | |
| 8079 | + | |
| 8080 | + setDirection: docMethodOp(function (dir) { | |
| 8081 | + if (dir != "rtl") { dir = "ltr"; } | |
| 8082 | + if (dir == this.direction) { return } | |
| 8083 | + this.direction = dir; | |
| 8084 | + this.iter(function (line) { return line.order = null; }); | |
| 8085 | + if (this.cm) { directionChanged(this.cm); } | |
| 8086 | + }) | |
| 8087 | + }); | |
| 8088 | + | |
| 8089 | + // Public alias. | |
| 8090 | + Doc.prototype.eachLine = Doc.prototype.iter; | |
| 8091 | + | |
| 8092 | + // Kludge to work around strange IE behavior where it'll sometimes | |
| 8093 | + // re-fire a series of drag-related events right after the drop (#1551) | |
| 8094 | + var lastDrop = 0; | |
| 8095 | + | |
| 8096 | + function onDrop(e) { | |
| 8097 | + var cm = this; | |
| 8098 | + clearDragCursor(cm); | |
| 8099 | + if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) | |
| 8100 | + { return } | |
| 8101 | + e_preventDefault(e); | |
| 8102 | + if (ie) { lastDrop = +new Date; } | |
| 8103 | + var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files; | |
| 8104 | + if (!pos || cm.isReadOnly()) { return } | |
| 8105 | + // Might be a file drop, in which case we simply extract the text | |
| 8106 | + // and insert it. | |
| 8107 | + if (files && files.length && window.FileReader && window.File) { | |
| 8108 | + var n = files.length, text = Array(n), read = 0; | |
| 8109 | + var markAsReadAndPasteIfAllFilesAreRead = function () { | |
| 8110 | + if (++read == n) { | |
| 8111 | + operation(cm, function () { | |
| 8112 | + pos = clipPos(cm.doc, pos); | |
| 8113 | + var change = {from: pos, to: pos, | |
| 8114 | + text: cm.doc.splitLines( | |
| 8115 | + text.filter(function (t) { return t != null; }).join(cm.doc.lineSeparator())), | |
| 8116 | + origin: "paste"}; | |
| 8117 | + makeChange(cm.doc, change); | |
| 8118 | + setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change)))); | |
| 8119 | + })(); | |
| 8120 | + } | |
| 8121 | + }; | |
| 8122 | + var readTextFromFile = function (file, i) { | |
| 8123 | + if (cm.options.allowDropFileTypes && | |
| 8124 | + indexOf(cm.options.allowDropFileTypes, file.type) == -1) { | |
| 8125 | + markAsReadAndPasteIfAllFilesAreRead(); | |
| 8126 | + return | |
| 8127 | + } | |
| 8128 | + var reader = new FileReader; | |
| 8129 | + reader.onerror = function () { return markAsReadAndPasteIfAllFilesAreRead(); }; | |
| 8130 | + reader.onload = function () { | |
| 8131 | + var content = reader.result; | |
| 8132 | + if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { | |
| 8133 | + markAsReadAndPasteIfAllFilesAreRead(); | |
| 8134 | + return | |
| 8135 | + } | |
| 8136 | + text[i] = content; | |
| 8137 | + markAsReadAndPasteIfAllFilesAreRead(); | |
| 8138 | + }; | |
| 8139 | + reader.readAsText(file); | |
| 8140 | + }; | |
| 8141 | + for (var i = 0; i < files.length; i++) { readTextFromFile(files[i], i); } | |
| 8142 | + } else { // Normal drop | |
| 8143 | + // Don't do a replace if the drop happened inside of the selected text. | |
| 8144 | + if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) { | |
| 8145 | + cm.state.draggingText(e); | |
| 8146 | + // Ensure the editor is re-focused | |
| 8147 | + setTimeout(function () { return cm.display.input.focus(); }, 20); | |
| 8148 | + return | |
| 8149 | + } | |
| 8150 | + try { | |
| 8151 | + var text$1 = e.dataTransfer.getData("Text"); | |
| 8152 | + if (text$1) { | |
| 8153 | + var selected; | |
| 8154 | + if (cm.state.draggingText && !cm.state.draggingText.copy) | |
| 8155 | + { selected = cm.listSelections(); } | |
| 8156 | + setSelectionNoUndo(cm.doc, simpleSelection(pos, pos)); | |
| 8157 | + if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1) | |
| 8158 | + { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag"); } } | |
| 8159 | + cm.replaceSelection(text$1, "around", "paste"); | |
| 8160 | + cm.display.input.focus(); | |
| 8161 | + } | |
| 8162 | + } | |
| 8163 | + catch(e$1){} | |
| 8164 | + } | |
| 8165 | + } | |
| 8166 | + | |
| 8167 | + function onDragStart(cm, e) { | |
| 8168 | + if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return } | |
| 8169 | + if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return } | |
| 8170 | + | |
| 8171 | + e.dataTransfer.setData("Text", cm.getSelection()); | |
| 8172 | + e.dataTransfer.effectAllowed = "copyMove"; | |
| 8173 | + | |
| 8174 | + // Use dummy image instead of default browsers image. | |
| 8175 | + // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there. | |
| 8176 | + if (e.dataTransfer.setDragImage && !safari) { | |
| 8177 | + var img = elt("img", null, null, "position: fixed; left: 0; top: 0;"); | |
| 8178 | + img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="; | |
| 8179 | + if (presto) { | |
| 8180 | + img.width = img.height = 1; | |
| 8181 | + cm.display.wrapper.appendChild(img); | |
| 8182 | + // Force a relayout, or Opera won't use our image for some obscure reason | |
| 8183 | + img._top = img.offsetTop; | |
| 8184 | + } | |
| 8185 | + e.dataTransfer.setDragImage(img, 0, 0); | |
| 8186 | + if (presto) { img.parentNode.removeChild(img); } | |
| 8187 | + } | |
| 8188 | + } | |
| 8189 | + | |
| 8190 | + function onDragOver(cm, e) { | |
| 8191 | + var pos = posFromMouse(cm, e); | |
| 8192 | + if (!pos) { return } | |
| 8193 | + var frag = document.createDocumentFragment(); | |
| 8194 | + drawSelectionCursor(cm, pos, frag); | |
| 8195 | + if (!cm.display.dragCursor) { | |
| 8196 | + cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors"); | |
| 8197 | + cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv); | |
| 8198 | + } | |
| 8199 | + removeChildrenAndAdd(cm.display.dragCursor, frag); | |
| 8200 | + } | |
| 8201 | + | |
| 8202 | + function clearDragCursor(cm) { | |
| 8203 | + if (cm.display.dragCursor) { | |
| 8204 | + cm.display.lineSpace.removeChild(cm.display.dragCursor); | |
| 8205 | + cm.display.dragCursor = null; | |
| 8206 | + } | |
| 8207 | + } | |
| 8208 | + | |
| 8209 | + // These must be handled carefully, because naively registering a | |
| 8210 | + // handler for each editor will cause the editors to never be | |
| 8211 | + // garbage collected. | |
| 8212 | + | |
| 8213 | + function forEachCodeMirror(f) { | |
| 8214 | + if (!document.getElementsByClassName) { return } | |
| 8215 | + var byClass = document.getElementsByClassName("CodeMirror"), editors = []; | |
| 8216 | + for (var i = 0; i < byClass.length; i++) { | |
| 8217 | + var cm = byClass[i].CodeMirror; | |
| 8218 | + if (cm) { editors.push(cm); } | |
| 8219 | + } | |
| 8220 | + if (editors.length) { editors[0].operation(function () { | |
| 8221 | + for (var i = 0; i < editors.length; i++) { f(editors[i]); } | |
| 8222 | + }); } | |
| 8223 | + } | |
| 8224 | + | |
| 8225 | + var globalsRegistered = false; | |
| 8226 | + function ensureGlobalHandlers() { | |
| 8227 | + if (globalsRegistered) { return } | |
| 8228 | + registerGlobalHandlers(); | |
| 8229 | + globalsRegistered = true; | |
| 8230 | + } | |
| 8231 | + function registerGlobalHandlers() { | |
| 8232 | + // When the window resizes, we need to refresh active editors. | |
| 8233 | + var resizeTimer; | |
| 8234 | + on(window, "resize", function () { | |
| 8235 | + if (resizeTimer == null) { resizeTimer = setTimeout(function () { | |
| 8236 | + resizeTimer = null; | |
| 8237 | + forEachCodeMirror(onResize); | |
| 8238 | + }, 100); } | |
| 8239 | + }); | |
| 8240 | + // When the window loses focus, we want to show the editor as blurred | |
| 8241 | + on(window, "blur", function () { return forEachCodeMirror(onBlur); }); | |
| 8242 | + } | |
| 8243 | + // Called when the window resizes | |
| 8244 | + function onResize(cm) { | |
| 8245 | + var d = cm.display; | |
| 8246 | + // Might be a text scaling operation, clear size caches. | |
| 8247 | + d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null; | |
| 8248 | + d.scrollbarsClipped = false; | |
| 8249 | + cm.setSize(); | |
| 8250 | + } | |
| 8251 | + | |
| 8252 | + var keyNames = { | |
| 8253 | + 3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt", | |
| 8254 | + 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", | |
| 8255 | + 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert", | |
| 8256 | + 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod", | |
| 8257 | + 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 145: "ScrollLock", | |
| 8258 | + 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", | |
| 8259 | + 221: "]", 222: "'", 224: "Mod", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete", | |
| 8260 | + 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert" | |
| 8261 | + }; | |
| 8262 | + | |
| 8263 | + // Number keys | |
| 8264 | + for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i); } | |
| 8265 | + // Alphabetic keys | |
| 8266 | + for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1); } | |
| 8267 | + // Function keys | |
| 8268 | + for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2; } | |
| 8269 | + | |
| 8270 | + var keyMap = {}; | |
| 8271 | + | |
| 8272 | + keyMap.basic = { | |
| 8273 | + "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown", | |
| 8274 | + "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown", | |
| 8275 | + "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore", | |
| 8276 | + "Tab": "defaultTab", "Shift-Tab": "indentAuto", | |
| 8277 | + "Enter": "newlineAndIndent", "Insert": "toggleOverwrite", | |
| 8278 | + "Esc": "singleSelection" | |
| 8279 | + }; | |
| 8280 | + // Note that the save and find-related commands aren't defined by | |
| 8281 | + // default. User code or addons can define them. Unknown commands | |
| 8282 | + // are simply ignored. | |
| 8283 | + keyMap.pcDefault = { | |
| 8284 | + "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo", | |
| 8285 | + "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown", | |
| 8286 | + "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd", | |
| 8287 | + "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find", | |
| 8288 | + "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll", | |
| 8289 | + "Ctrl-[": "indentLess", "Ctrl-]": "indentMore", | |
| 8290 | + "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection", | |
| 8291 | + "fallthrough": "basic" | |
| 8292 | + }; | |
| 8293 | + // Very basic readline/emacs-style bindings, which are standard on Mac. | |
| 8294 | + keyMap.emacsy = { | |
| 8295 | + "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown", | |
| 8296 | + "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd", "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", | |
| 8297 | + "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", | |
| 8298 | + "Ctrl-T": "transposeChars", "Ctrl-O": "openLine" | |
| 8299 | + }; | |
| 8300 | + keyMap.macDefault = { | |
| 8301 | + "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo", | |
| 8302 | + "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft", | |
| 8303 | + "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore", | |
| 8304 | + "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find", | |
| 8305 | + "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll", | |
| 8306 | + "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight", | |
| 8307 | + "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd", | |
| 8308 | + "fallthrough": ["basic", "emacsy"] | |
| 8309 | + }; | |
| 8310 | + keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault; | |
| 8311 | + | |
| 8312 | + // KEYMAP DISPATCH | |
| 8313 | + | |
| 8314 | + function normalizeKeyName(name) { | |
| 8315 | + var parts = name.split(/-(?!$)/); | |
| 8316 | + name = parts[parts.length - 1]; | |
| 8317 | + var alt, ctrl, shift, cmd; | |
| 8318 | + for (var i = 0; i < parts.length - 1; i++) { | |
| 8319 | + var mod = parts[i]; | |
| 8320 | + if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true; } | |
| 8321 | + else if (/^a(lt)?$/i.test(mod)) { alt = true; } | |
| 8322 | + else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; } | |
| 8323 | + else if (/^s(hift)?$/i.test(mod)) { shift = true; } | |
| 8324 | + else { throw new Error("Unrecognized modifier name: " + mod) } | |
| 8325 | + } | |
| 8326 | + if (alt) { name = "Alt-" + name; } | |
| 8327 | + if (ctrl) { name = "Ctrl-" + name; } | |
| 8328 | + if (cmd) { name = "Cmd-" + name; } | |
| 8329 | + if (shift) { name = "Shift-" + name; } | |
| 8330 | + return name | |
| 8331 | + } | |
| 8332 | + | |
| 8333 | + // This is a kludge to keep keymaps mostly working as raw objects | |
| 8334 | + // (backwards compatibility) while at the same time support features | |
| 8335 | + // like normalization and multi-stroke key bindings. It compiles a | |
| 8336 | + // new normalized keymap, and then updates the old object to reflect | |
| 8337 | + // this. | |
| 8338 | + function normalizeKeyMap(keymap) { | |
| 8339 | + var copy = {}; | |
| 8340 | + for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) { | |
| 8341 | + var value = keymap[keyname]; | |
| 8342 | + if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue } | |
| 8343 | + if (value == "...") { delete keymap[keyname]; continue } | |
| 8344 | + | |
| 8345 | + var keys = map(keyname.split(" "), normalizeKeyName); | |
| 8346 | + for (var i = 0; i < keys.length; i++) { | |
| 8347 | + var val = (void 0), name = (void 0); | |
| 8348 | + if (i == keys.length - 1) { | |
| 8349 | + name = keys.join(" "); | |
| 8350 | + val = value; | |
| 8351 | + } else { | |
| 8352 | + name = keys.slice(0, i + 1).join(" "); | |
| 8353 | + val = "..."; | |
| 8354 | + } | |
| 8355 | + var prev = copy[name]; | |
| 8356 | + if (!prev) { copy[name] = val; } | |
| 8357 | + else if (prev != val) { throw new Error("Inconsistent bindings for " + name) } | |
| 8358 | + } | |
| 8359 | + delete keymap[keyname]; | |
| 8360 | + } } | |
| 8361 | + for (var prop in copy) { keymap[prop] = copy[prop]; } | |
| 8362 | + return keymap | |
| 8363 | + } | |
| 8364 | + | |
| 8365 | + function lookupKey(key, map, handle, context) { | |
| 8366 | + map = getKeyMap(map); | |
| 8367 | + var found = map.call ? map.call(key, context) : map[key]; | |
| 8368 | + if (found === false) { return "nothing" } | |
| 8369 | + if (found === "...") { return "multi" } | |
| 8370 | + if (found != null && handle(found)) { return "handled" } | |
| 8371 | + | |
| 8372 | + if (map.fallthrough) { | |
| 8373 | + if (Object.prototype.toString.call(map.fallthrough) != "[object Array]") | |
| 8374 | + { return lookupKey(key, map.fallthrough, handle, context) } | |
| 8375 | + for (var i = 0; i < map.fallthrough.length; i++) { | |
| 8376 | + var result = lookupKey(key, map.fallthrough[i], handle, context); | |
| 8377 | + if (result) { return result } | |
| 8378 | + } | |
| 8379 | + } | |
| 8380 | + } | |
| 8381 | + | |
| 8382 | + // Modifier key presses don't count as 'real' key presses for the | |
| 8383 | + // purpose of keymap fallthrough. | |
| 8384 | + function isModifierKey(value) { | |
| 8385 | + var name = typeof value == "string" ? value : keyNames[value.keyCode]; | |
| 8386 | + return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod" | |
| 8387 | + } | |
| 8388 | + | |
| 8389 | + function addModifierNames(name, event, noShift) { | |
| 8390 | + var base = name; | |
| 8391 | + if (event.altKey && base != "Alt") { name = "Alt-" + name; } | |
| 8392 | + if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name; } | |
| 8393 | + if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Mod") { name = "Cmd-" + name; } | |
| 8394 | + if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name; } | |
| 8395 | + return name | |
| 8396 | + } | |
| 8397 | + | |
| 8398 | + // Look up the name of a key as indicated by an event object. | |
| 8399 | + function keyName(event, noShift) { | |
| 8400 | + if (presto && event.keyCode == 34 && event["char"]) { return false } | |
| 8401 | + var name = keyNames[event.keyCode]; | |
| 8402 | + if (name == null || event.altGraphKey) { return false } | |
| 8403 | + // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause, | |
| 8404 | + // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+) | |
| 8405 | + if (event.keyCode == 3 && event.code) { name = event.code; } | |
| 8406 | + return addModifierNames(name, event, noShift) | |
| 8407 | + } | |
| 8408 | + | |
| 8409 | + function getKeyMap(val) { | |
| 8410 | + return typeof val == "string" ? keyMap[val] : val | |
| 8411 | + } | |
| 8412 | + | |
| 8413 | + // Helper for deleting text near the selection(s), used to implement | |
| 8414 | + // backspace, delete, and similar functionality. | |
| 8415 | + function deleteNearSelection(cm, compute) { | |
| 8416 | + var ranges = cm.doc.sel.ranges, kill = []; | |
| 8417 | + // Build up a set of ranges to kill first, merging overlapping | |
| 8418 | + // ranges. | |
| 8419 | + for (var i = 0; i < ranges.length; i++) { | |
| 8420 | + var toKill = compute(ranges[i]); | |
| 8421 | + while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) { | |
| 8422 | + var replaced = kill.pop(); | |
| 8423 | + if (cmp(replaced.from, toKill.from) < 0) { | |
| 8424 | + toKill.from = replaced.from; | |
| 8425 | + break | |
| 8426 | + } | |
| 8427 | + } | |
| 8428 | + kill.push(toKill); | |
| 8429 | + } | |
| 8430 | + // Next, remove those actual ranges. | |
| 8431 | + runInOp(cm, function () { | |
| 8432 | + for (var i = kill.length - 1; i >= 0; i--) | |
| 8433 | + { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete"); } | |
| 8434 | + ensureCursorVisible(cm); | |
| 8435 | + }); | |
| 8436 | + } | |
| 8437 | + | |
| 8438 | + function moveCharLogically(line, ch, dir) { | |
| 8439 | + var target = skipExtendingChars(line.text, ch + dir, dir); | |
| 8440 | + return target < 0 || target > line.text.length ? null : target | |
| 8441 | + } | |
| 8442 | + | |
| 8443 | + function moveLogically(line, start, dir) { | |
| 8444 | + var ch = moveCharLogically(line, start.ch, dir); | |
| 8445 | + return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before") | |
| 8446 | + } | |
| 8447 | + | |
| 8448 | + function endOfLine(visually, cm, lineObj, lineNo, dir) { | |
| 8449 | + if (visually) { | |
| 8450 | + if (cm.doc.direction == "rtl") { dir = -dir; } | |
| 8451 | + var order = getOrder(lineObj, cm.doc.direction); | |
| 8452 | + if (order) { | |
| 8453 | + var part = dir < 0 ? lst(order) : order[0]; | |
| 8454 | + var moveInStorageOrder = (dir < 0) == (part.level == 1); | |
| 8455 | + var sticky = moveInStorageOrder ? "after" : "before"; | |
| 8456 | + var ch; | |
| 8457 | + // With a wrapped rtl chunk (possibly spanning multiple bidi parts), | |
| 8458 | + // it could be that the last bidi part is not on the last visual line, | |
| 8459 | + // since visual lines contain content order-consecutive chunks. | |
| 8460 | + // Thus, in rtl, we are looking for the first (content-order) character | |
| 8461 | + // in the rtl chunk that is on the last line (that is, the same line | |
| 8462 | + // as the last (content-order) character). | |
| 8463 | + if (part.level > 0 || cm.doc.direction == "rtl") { | |
| 8464 | + var prep = prepareMeasureForLine(cm, lineObj); | |
| 8465 | + ch = dir < 0 ? lineObj.text.length - 1 : 0; | |
| 8466 | + var targetTop = measureCharPrepared(cm, prep, ch).top; | |
| 8467 | + ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch); | |
| 8468 | + if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1); } | |
| 8469 | + } else { ch = dir < 0 ? part.to : part.from; } | |
| 8470 | + return new Pos(lineNo, ch, sticky) | |
| 8471 | + } | |
| 8472 | + } | |
| 8473 | + return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after") | |
| 8474 | + } | |
| 8475 | + | |
| 8476 | + function moveVisually(cm, line, start, dir) { | |
| 8477 | + var bidi = getOrder(line, cm.doc.direction); | |
| 8478 | + if (!bidi) { return moveLogically(line, start, dir) } | |
| 8479 | + if (start.ch >= line.text.length) { | |
| 8480 | + start.ch = line.text.length; | |
| 8481 | + start.sticky = "before"; | |
| 8482 | + } else if (start.ch <= 0) { | |
| 8483 | + start.ch = 0; | |
| 8484 | + start.sticky = "after"; | |
| 8485 | + } | |
| 8486 | + var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos]; | |
| 8487 | + if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) { | |
| 8488 | + // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines, | |
| 8489 | + // nothing interesting happens. | |
| 8490 | + return moveLogically(line, start, dir) | |
| 8491 | + } | |
| 8492 | + | |
| 8493 | + var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); }; | |
| 8494 | + var prep; | |
| 8495 | + var getWrappedLineExtent = function (ch) { | |
| 8496 | + if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} } | |
| 8497 | + prep = prep || prepareMeasureForLine(cm, line); | |
| 8498 | + return wrappedLineExtentChar(cm, line, prep, ch) | |
| 8499 | + }; | |
| 8500 | + var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch); | |
| 8501 | + | |
| 8502 | + if (cm.doc.direction == "rtl" || part.level == 1) { | |
| 8503 | + var moveInStorageOrder = (part.level == 1) == (dir < 0); | |
| 8504 | + var ch = mv(start, moveInStorageOrder ? 1 : -1); | |
| 8505 | + if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) { | |
| 8506 | + // Case 2: We move within an rtl part or in an rtl editor on the same visual line | |
| 8507 | + var sticky = moveInStorageOrder ? "before" : "after"; | |
| 8508 | + return new Pos(start.line, ch, sticky) | |
| 8509 | + } | |
| 8510 | + } | |
| 8511 | + | |
| 8512 | + // Case 3: Could not move within this bidi part in this visual line, so leave | |
| 8513 | + // the current bidi part | |
| 8514 | + | |
| 8515 | + var searchInVisualLine = function (partPos, dir, wrappedLineExtent) { | |
| 8516 | + var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder | |
| 8517 | + ? new Pos(start.line, mv(ch, 1), "before") | |
| 8518 | + : new Pos(start.line, ch, "after"); }; | |
| 8519 | + | |
| 8520 | + for (; partPos >= 0 && partPos < bidi.length; partPos += dir) { | |
| 8521 | + var part = bidi[partPos]; | |
| 8522 | + var moveInStorageOrder = (dir > 0) == (part.level != 1); | |
| 8523 | + var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1); | |
| 8524 | + if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) } | |
| 8525 | + ch = moveInStorageOrder ? part.from : mv(part.to, -1); | |
| 8526 | + if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) } | |
| 8527 | + } | |
| 8528 | + }; | |
| 8529 | + | |
| 8530 | + // Case 3a: Look for other bidi parts on the same visual line | |
| 8531 | + var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent); | |
| 8532 | + if (res) { return res } | |
| 8533 | + | |
| 8534 | + // Case 3b: Look for other bidi parts on the next visual line | |
| 8535 | + var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1); | |
| 8536 | + if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) { | |
| 8537 | + res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh)); | |
| 8538 | + if (res) { return res } | |
| 8539 | + } | |
| 8540 | + | |
| 8541 | + // Case 4: Nowhere to move | |
| 8542 | + return null | |
| 8543 | + } | |
| 8544 | + | |
| 8545 | + // Commands are parameter-less actions that can be performed on an | |
| 8546 | + // editor, mostly used for keybindings. | |
| 8547 | + var commands = { | |
| 8548 | + selectAll: selectAll, | |
| 8549 | + singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); }, | |
| 8550 | + killLine: function (cm) { return deleteNearSelection(cm, function (range) { | |
| 8551 | + if (range.empty()) { | |
| 8552 | + var len = getLine(cm.doc, range.head.line).text.length; | |
| 8553 | + if (range.head.ch == len && range.head.line < cm.lastLine()) | |
| 8554 | + { return {from: range.head, to: Pos(range.head.line + 1, 0)} } | |
| 8555 | + else | |
| 8556 | + { return {from: range.head, to: Pos(range.head.line, len)} } | |
| 8557 | + } else { | |
| 8558 | + return {from: range.from(), to: range.to()} | |
| 8559 | + } | |
| 8560 | + }); }, | |
| 8561 | + deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({ | |
| 8562 | + from: Pos(range.from().line, 0), | |
| 8563 | + to: clipPos(cm.doc, Pos(range.to().line + 1, 0)) | |
| 8564 | + }); }); }, | |
| 8565 | + delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({ | |
| 8566 | + from: Pos(range.from().line, 0), to: range.from() | |
| 8567 | + }); }); }, | |
| 8568 | + delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { | |
| 8569 | + var top = cm.charCoords(range.head, "div").top + 5; | |
| 8570 | + var leftPos = cm.coordsChar({left: 0, top: top}, "div"); | |
| 8571 | + return {from: leftPos, to: range.from()} | |
| 8572 | + }); }, | |
| 8573 | + delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) { | |
| 8574 | + var top = cm.charCoords(range.head, "div").top + 5; | |
| 8575 | + var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div"); | |
| 8576 | + return {from: range.from(), to: rightPos } | |
| 8577 | + }); }, | |
| 8578 | + undo: function (cm) { return cm.undo(); }, | |
| 8579 | + redo: function (cm) { return cm.redo(); }, | |
| 8580 | + undoSelection: function (cm) { return cm.undoSelection(); }, | |
| 8581 | + redoSelection: function (cm) { return cm.redoSelection(); }, | |
| 8582 | + goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); }, | |
| 8583 | + goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); }, | |
| 8584 | + goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); }, | |
| 8585 | + {origin: "+move", bias: 1} | |
| 8586 | + ); }, | |
| 8587 | + goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); }, | |
| 8588 | + {origin: "+move", bias: 1} | |
| 8589 | + ); }, | |
| 8590 | + goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); }, | |
| 8591 | + {origin: "+move", bias: -1} | |
| 8592 | + ); }, | |
| 8593 | + goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) { | |
| 8594 | + var top = cm.cursorCoords(range.head, "div").top + 5; | |
| 8595 | + return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div") | |
| 8596 | + }, sel_move); }, | |
| 8597 | + goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) { | |
| 8598 | + var top = cm.cursorCoords(range.head, "div").top + 5; | |
| 8599 | + return cm.coordsChar({left: 0, top: top}, "div") | |
| 8600 | + }, sel_move); }, | |
| 8601 | + goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) { | |
| 8602 | + var top = cm.cursorCoords(range.head, "div").top + 5; | |
| 8603 | + var pos = cm.coordsChar({left: 0, top: top}, "div"); | |
| 8604 | + if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) } | |
| 8605 | + return pos | |
| 8606 | + }, sel_move); }, | |
| 8607 | + goLineUp: function (cm) { return cm.moveV(-1, "line"); }, | |
| 8608 | + goLineDown: function (cm) { return cm.moveV(1, "line"); }, | |
| 8609 | + goPageUp: function (cm) { return cm.moveV(-1, "page"); }, | |
| 8610 | + goPageDown: function (cm) { return cm.moveV(1, "page"); }, | |
| 8611 | + goCharLeft: function (cm) { return cm.moveH(-1, "char"); }, | |
| 8612 | + goCharRight: function (cm) { return cm.moveH(1, "char"); }, | |
| 8613 | + goColumnLeft: function (cm) { return cm.moveH(-1, "column"); }, | |
| 8614 | + goColumnRight: function (cm) { return cm.moveH(1, "column"); }, | |
| 8615 | + goWordLeft: function (cm) { return cm.moveH(-1, "word"); }, | |
| 8616 | + goGroupRight: function (cm) { return cm.moveH(1, "group"); }, | |
| 8617 | + goGroupLeft: function (cm) { return cm.moveH(-1, "group"); }, | |
| 8618 | + goWordRight: function (cm) { return cm.moveH(1, "word"); }, | |
| 8619 | + delCharBefore: function (cm) { return cm.deleteH(-1, "codepoint"); }, | |
| 8620 | + delCharAfter: function (cm) { return cm.deleteH(1, "char"); }, | |
| 8621 | + delWordBefore: function (cm) { return cm.deleteH(-1, "word"); }, | |
| 8622 | + delWordAfter: function (cm) { return cm.deleteH(1, "word"); }, | |
| 8623 | + delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); }, | |
| 8624 | + delGroupAfter: function (cm) { return cm.deleteH(1, "group"); }, | |
| 8625 | + indentAuto: function (cm) { return cm.indentSelection("smart"); }, | |
| 8626 | + indentMore: function (cm) { return cm.indentSelection("add"); }, | |
| 8627 | + indentLess: function (cm) { return cm.indentSelection("subtract"); }, | |
| 8628 | + insertTab: function (cm) { return cm.replaceSelection("\t"); }, | |
| 8629 | + insertSoftTab: function (cm) { | |
| 8630 | + var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize; | |
| 8631 | + for (var i = 0; i < ranges.length; i++) { | |
| 8632 | + var pos = ranges[i].from(); | |
| 8633 | + var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize); | |
| 8634 | + spaces.push(spaceStr(tabSize - col % tabSize)); | |
| 8635 | + } | |
| 8636 | + cm.replaceSelections(spaces); | |
| 8637 | + }, | |
| 8638 | + defaultTab: function (cm) { | |
| 8639 | + if (cm.somethingSelected()) { cm.indentSelection("add"); } | |
| 8640 | + else { cm.execCommand("insertTab"); } | |
| 8641 | + }, | |
| 8642 | + // Swap the two chars left and right of each selection's head. | |
| 8643 | + // Move cursor behind the two swapped characters afterwards. | |
| 8644 | + // | |
| 8645 | + // Doesn't consider line feeds a character. | |
| 8646 | + // Doesn't scan more than one line above to find a character. | |
| 8647 | + // Doesn't do anything on an empty line. | |
| 8648 | + // Doesn't do anything with non-empty selections. | |
| 8649 | + transposeChars: function (cm) { return runInOp(cm, function () { | |
| 8650 | + var ranges = cm.listSelections(), newSel = []; | |
| 8651 | + for (var i = 0; i < ranges.length; i++) { | |
| 8652 | + if (!ranges[i].empty()) { continue } | |
| 8653 | + var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text; | |
| 8654 | + if (line) { | |
| 8655 | + if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1); } | |
| 8656 | + if (cur.ch > 0) { | |
| 8657 | + cur = new Pos(cur.line, cur.ch + 1); | |
| 8658 | + cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2), | |
| 8659 | + Pos(cur.line, cur.ch - 2), cur, "+transpose"); | |
| 8660 | + } else if (cur.line > cm.doc.first) { | |
| 8661 | + var prev = getLine(cm.doc, cur.line - 1).text; | |
| 8662 | + if (prev) { | |
| 8663 | + cur = new Pos(cur.line, 1); | |
| 8664 | + cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() + | |
| 8665 | + prev.charAt(prev.length - 1), | |
| 8666 | + Pos(cur.line - 1, prev.length - 1), cur, "+transpose"); | |
| 8667 | + } | |
| 8668 | + } | |
| 8669 | + } | |
| 8670 | + newSel.push(new Range(cur, cur)); | |
| 8671 | + } | |
| 8672 | + cm.setSelections(newSel); | |
| 8673 | + }); }, | |
| 8674 | + newlineAndIndent: function (cm) { return runInOp(cm, function () { | |
| 8675 | + var sels = cm.listSelections(); | |
| 8676 | + for (var i = sels.length - 1; i >= 0; i--) | |
| 8677 | + { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input"); } | |
| 8678 | + sels = cm.listSelections(); | |
| 8679 | + for (var i$1 = 0; i$1 < sels.length; i$1++) | |
| 8680 | + { cm.indentLine(sels[i$1].from().line, null, true); } | |
| 8681 | + ensureCursorVisible(cm); | |
| 8682 | + }); }, | |
| 8683 | + openLine: function (cm) { return cm.replaceSelection("\n", "start"); }, | |
| 8684 | + toggleOverwrite: function (cm) { return cm.toggleOverwrite(); } | |
| 8685 | + }; | |
| 8686 | + | |
| 8687 | + | |
| 8688 | + function lineStart(cm, lineN) { | |
| 8689 | + var line = getLine(cm.doc, lineN); | |
| 8690 | + var visual = visualLine(line); | |
| 8691 | + if (visual != line) { lineN = lineNo(visual); } | |
| 8692 | + return endOfLine(true, cm, visual, lineN, 1) | |
| 8693 | + } | |
| 8694 | + function lineEnd(cm, lineN) { | |
| 8695 | + var line = getLine(cm.doc, lineN); | |
| 8696 | + var visual = visualLineEnd(line); | |
| 8697 | + if (visual != line) { lineN = lineNo(visual); } | |
| 8698 | + return endOfLine(true, cm, line, lineN, -1) | |
| 8699 | + } | |
| 8700 | + function lineStartSmart(cm, pos) { | |
| 8701 | + var start = lineStart(cm, pos.line); | |
| 8702 | + var line = getLine(cm.doc, start.line); | |
| 8703 | + var order = getOrder(line, cm.doc.direction); | |
| 8704 | + if (!order || order[0].level == 0) { | |
| 8705 | + var firstNonWS = Math.max(start.ch, line.text.search(/\S/)); | |
| 8706 | + var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch; | |
| 8707 | + return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky) | |
| 8708 | + } | |
| 8709 | + return start | |
| 8710 | + } | |
| 8711 | + | |
| 8712 | + // Run a handler that was bound to a key. | |
| 8713 | + function doHandleBinding(cm, bound, dropShift) { | |
| 8714 | + if (typeof bound == "string") { | |
| 8715 | + bound = commands[bound]; | |
| 8716 | + if (!bound) { return false } | |
| 8717 | + } | |
| 8718 | + // Ensure previous input has been read, so that the handler sees a | |
| 8719 | + // consistent view of the document | |
| 8720 | + cm.display.input.ensurePolled(); | |
| 8721 | + var prevShift = cm.display.shift, done = false; | |
| 8722 | + try { | |
| 8723 | + if (cm.isReadOnly()) { cm.state.suppressEdits = true; } | |
| 8724 | + if (dropShift) { cm.display.shift = false; } | |
| 8725 | + done = bound(cm) != Pass; | |
| 8726 | + } finally { | |
| 8727 | + cm.display.shift = prevShift; | |
| 8728 | + cm.state.suppressEdits = false; | |
| 8729 | + } | |
| 8730 | + return done | |
| 8731 | + } | |
| 8732 | + | |
| 8733 | + function lookupKeyForEditor(cm, name, handle) { | |
| 8734 | + for (var i = 0; i < cm.state.keyMaps.length; i++) { | |
| 8735 | + var result = lookupKey(name, cm.state.keyMaps[i], handle, cm); | |
| 8736 | + if (result) { return result } | |
| 8737 | + } | |
| 8738 | + return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm)) | |
| 8739 | + || lookupKey(name, cm.options.keyMap, handle, cm) | |
| 8740 | + } | |
| 8741 | + | |
| 8742 | + // Note that, despite the name, this function is also used to check | |
| 8743 | + // for bound mouse clicks. | |
| 8744 | + | |
| 8745 | + var stopSeq = new Delayed; | |
| 8746 | + | |
| 8747 | + function dispatchKey(cm, name, e, handle) { | |
| 8748 | + var seq = cm.state.keySeq; | |
| 8749 | + if (seq) { | |
| 8750 | + if (isModifierKey(name)) { return "handled" } | |
| 8751 | + if (/\'$/.test(name)) | |
| 8752 | + { cm.state.keySeq = null; } | |
| 8753 | + else | |
| 8754 | + { stopSeq.set(50, function () { | |
| 8755 | + if (cm.state.keySeq == seq) { | |
| 8756 | + cm.state.keySeq = null; | |
| 8757 | + cm.display.input.reset(); | |
| 8758 | + } | |
| 8759 | + }); } | |
| 8760 | + if (dispatchKeyInner(cm, seq + " " + name, e, handle)) { return true } | |
| 8761 | + } | |
| 8762 | + return dispatchKeyInner(cm, name, e, handle) | |
| 8763 | + } | |
| 8764 | + | |
| 8765 | + function dispatchKeyInner(cm, name, e, handle) { | |
| 8766 | + var result = lookupKeyForEditor(cm, name, handle); | |
| 8767 | + | |
| 8768 | + if (result == "multi") | |
| 8769 | + { cm.state.keySeq = name; } | |
| 8770 | + if (result == "handled") | |
| 8771 | + { signalLater(cm, "keyHandled", cm, name, e); } | |
| 8772 | + | |
| 8773 | + if (result == "handled" || result == "multi") { | |
| 8774 | + e_preventDefault(e); | |
| 8775 | + restartBlink(cm); | |
| 8776 | + } | |
| 8777 | + | |
| 8778 | + return !!result | |
| 8779 | + } | |
| 8780 | + | |
| 8781 | + // Handle a key from the keydown event. | |
| 8782 | + function handleKeyBinding(cm, e) { | |
| 8783 | + var name = keyName(e, true); | |
| 8784 | + if (!name) { return false } | |
| 8785 | + | |
| 8786 | + if (e.shiftKey && !cm.state.keySeq) { | |
| 8787 | + // First try to resolve full name (including 'Shift-'). Failing | |
| 8788 | + // that, see if there is a cursor-motion command (starting with | |
| 8789 | + // 'go') bound to the keyname without 'Shift-'. | |
| 8790 | + return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); }) | |
| 8791 | + || dispatchKey(cm, name, e, function (b) { | |
| 8792 | + if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion) | |
| 8793 | + { return doHandleBinding(cm, b) } | |
| 8794 | + }) | |
| 8795 | + } else { | |
| 8796 | + return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); }) | |
| 8797 | + } | |
| 8798 | + } | |
| 8799 | + | |
| 8800 | + // Handle a key from the keypress event | |
| 8801 | + function handleCharBinding(cm, e, ch) { | |
| 8802 | + return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); }) | |
| 8803 | + } | |
| 8804 | + | |
| 8805 | + var lastStoppedKey = null; | |
| 8806 | + function onKeyDown(e) { | |
| 8807 | + var cm = this; | |
| 8808 | + if (e.target && e.target != cm.display.input.getField()) { return } | |
| 8809 | + cm.curOp.focus = activeElt(); | |
| 8810 | + if (signalDOMEvent(cm, e)) { return } | |
| 8811 | + // IE does strange things with escape. | |
| 8812 | + if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; } | |
| 8813 | + var code = e.keyCode; | |
| 8814 | + cm.display.shift = code == 16 || e.shiftKey; | |
| 8815 | + var handled = handleKeyBinding(cm, e); | |
| 8816 | + if (presto) { | |
| 8817 | + lastStoppedKey = handled ? code : null; | |
| 8818 | + // Opera has no cut event... we try to at least catch the key combo | |
| 8819 | + if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey)) | |
| 8820 | + { cm.replaceSelection("", null, "cut"); } | |
| 8821 | + } | |
| 8822 | + if (gecko && !mac && !handled && code == 46 && e.shiftKey && !e.ctrlKey && document.execCommand) | |
| 8823 | + { document.execCommand("cut"); } | |
| 8824 | + | |
| 8825 | + // Turn mouse into crosshair when Alt is held on Mac. | |
| 8826 | + if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className)) | |
| 8827 | + { showCrossHair(cm); } | |
| 8828 | + } | |
| 8829 | + | |
| 8830 | + function showCrossHair(cm) { | |
| 8831 | + var lineDiv = cm.display.lineDiv; | |
| 8832 | + addClass(lineDiv, "CodeMirror-crosshair"); | |
| 8833 | + | |
| 8834 | + function up(e) { | |
| 8835 | + if (e.keyCode == 18 || !e.altKey) { | |
| 8836 | + rmClass(lineDiv, "CodeMirror-crosshair"); | |
| 8837 | + off(document, "keyup", up); | |
| 8838 | + off(document, "mouseover", up); | |
| 8839 | + } | |
| 8840 | + } | |
| 8841 | + on(document, "keyup", up); | |
| 8842 | + on(document, "mouseover", up); | |
| 8843 | + } | |
| 8844 | + | |
| 8845 | + function onKeyUp(e) { | |
| 8846 | + if (e.keyCode == 16) { this.doc.sel.shift = false; } | |
| 8847 | + signalDOMEvent(this, e); | |
| 8848 | + } | |
| 8849 | + | |
| 8850 | + function onKeyPress(e) { | |
| 8851 | + var cm = this; | |
| 8852 | + if (e.target && e.target != cm.display.input.getField()) { return } | |
| 8853 | + if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return } | |
| 8854 | + var keyCode = e.keyCode, charCode = e.charCode; | |
| 8855 | + if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return} | |
| 8856 | + if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return } | |
| 8857 | + var ch = String.fromCharCode(charCode == null ? keyCode : charCode); | |
| 8858 | + // Some browsers fire keypress events for backspace | |
| 8859 | + if (ch == "\x08") { return } | |
| 8860 | + if (handleCharBinding(cm, e, ch)) { return } | |
| 8861 | + cm.display.input.onKeyPress(e); | |
| 8862 | + } | |
| 8863 | + | |
| 8864 | + var DOUBLECLICK_DELAY = 400; | |
| 8865 | + | |
| 8866 | + var PastClick = function(time, pos, button) { | |
| 8867 | + this.time = time; | |
| 8868 | + this.pos = pos; | |
| 8869 | + this.button = button; | |
| 8870 | + }; | |
| 8871 | + | |
| 8872 | + PastClick.prototype.compare = function (time, pos, button) { | |
| 8873 | + return this.time + DOUBLECLICK_DELAY > time && | |
| 8874 | + cmp(pos, this.pos) == 0 && button == this.button | |
| 8875 | + }; | |
| 8876 | + | |
| 8877 | + var lastClick, lastDoubleClick; | |
| 8878 | + function clickRepeat(pos, button) { | |
| 8879 | + var now = +new Date; | |
| 8880 | + if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) { | |
| 8881 | + lastClick = lastDoubleClick = null; | |
| 8882 | + return "triple" | |
| 8883 | + } else if (lastClick && lastClick.compare(now, pos, button)) { | |
| 8884 | + lastDoubleClick = new PastClick(now, pos, button); | |
| 8885 | + lastClick = null; | |
| 8886 | + return "double" | |
| 8887 | + } else { | |
| 8888 | + lastClick = new PastClick(now, pos, button); | |
| 8889 | + lastDoubleClick = null; | |
| 8890 | + return "single" | |
| 8891 | + } | |
| 8892 | + } | |
| 8893 | + | |
| 8894 | + // A mouse down can be a single click, double click, triple click, | |
| 8895 | + // start of selection drag, start of text drag, new cursor | |
| 8896 | + // (ctrl-click), rectangle drag (alt-drag), or xwin | |
| 8897 | + // middle-click-paste. Or it might be a click on something we should | |
| 8898 | + // not interfere with, such as a scrollbar or widget. | |
| 8899 | + function onMouseDown(e) { | |
| 8900 | + var cm = this, display = cm.display; | |
| 8901 | + if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return } | |
| 8902 | + display.input.ensurePolled(); | |
| 8903 | + display.shift = e.shiftKey; | |
| 8904 | + | |
| 8905 | + if (eventInWidget(display, e)) { | |
| 8906 | + if (!webkit) { | |
| 8907 | + // Briefly turn off draggability, to allow widgets to do | |
| 8908 | + // normal dragging things. | |
| 8909 | + display.scroller.draggable = false; | |
| 8910 | + setTimeout(function () { return display.scroller.draggable = true; }, 100); | |
| 8911 | + } | |
| 8912 | + return | |
| 8913 | + } | |
| 8914 | + if (clickInGutter(cm, e)) { return } | |
| 8915 | + var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single"; | |
| 8916 | + window.focus(); | |
| 8917 | + | |
| 8918 | + // #3261: make sure, that we're not starting a second selection | |
| 8919 | + if (button == 1 && cm.state.selectingText) | |
| 8920 | + { cm.state.selectingText(e); } | |
| 8921 | + | |
| 8922 | + if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return } | |
| 8923 | + | |
| 8924 | + if (button == 1) { | |
| 8925 | + if (pos) { leftButtonDown(cm, pos, repeat, e); } | |
| 8926 | + else if (e_target(e) == display.scroller) { e_preventDefault(e); } | |
| 8927 | + } else if (button == 2) { | |
| 8928 | + if (pos) { extendSelection(cm.doc, pos); } | |
| 8929 | + setTimeout(function () { return display.input.focus(); }, 20); | |
| 8930 | + } else if (button == 3) { | |
| 8931 | + if (captureRightClick) { cm.display.input.onContextMenu(e); } | |
| 8932 | + else { delayBlurEvent(cm); } | |
| 8933 | + } | |
| 8934 | + } | |
| 8935 | + | |
| 8936 | + function handleMappedButton(cm, button, pos, repeat, event) { | |
| 8937 | + var name = "Click"; | |
| 8938 | + if (repeat == "double") { name = "Double" + name; } | |
| 8939 | + else if (repeat == "triple") { name = "Triple" + name; } | |
| 8940 | + name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name; | |
| 8941 | + | |
| 8942 | + return dispatchKey(cm, addModifierNames(name, event), event, function (bound) { | |
| 8943 | + if (typeof bound == "string") { bound = commands[bound]; } | |
| 8944 | + if (!bound) { return false } | |
| 8945 | + var done = false; | |
| 8946 | + try { | |
| 8947 | + if (cm.isReadOnly()) { cm.state.suppressEdits = true; } | |
| 8948 | + done = bound(cm, pos) != Pass; | |
| 8949 | + } finally { | |
| 8950 | + cm.state.suppressEdits = false; | |
| 8951 | + } | |
| 8952 | + return done | |
| 8953 | + }) | |
| 8954 | + } | |
| 8955 | + | |
| 8956 | + function configureMouse(cm, repeat, event) { | |
| 8957 | + var option = cm.getOption("configureMouse"); | |
| 8958 | + var value = option ? option(cm, repeat, event) : {}; | |
| 8959 | + if (value.unit == null) { | |
| 8960 | + var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey; | |
| 8961 | + value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line"; | |
| 8962 | + } | |
| 8963 | + if (value.extend == null || cm.doc.extend) { value.extend = cm.doc.extend || event.shiftKey; } | |
| 8964 | + if (value.addNew == null) { value.addNew = mac ? event.metaKey : event.ctrlKey; } | |
| 8965 | + if (value.moveOnDrag == null) { value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey); } | |
| 8966 | + return value | |
| 8967 | + } | |
| 8968 | + | |
| 8969 | + function leftButtonDown(cm, pos, repeat, event) { | |
| 8970 | + if (ie) { setTimeout(bind(ensureFocus, cm), 0); } | |
| 8971 | + else { cm.curOp.focus = activeElt(); } | |
| 8972 | + | |
| 8973 | + var behavior = configureMouse(cm, repeat, event); | |
| 8974 | + | |
| 8975 | + var sel = cm.doc.sel, contained; | |
| 8976 | + if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() && | |
| 8977 | + repeat == "single" && (contained = sel.contains(pos)) > -1 && | |
| 8978 | + (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) && | |
| 8979 | + (cmp(contained.to(), pos) > 0 || pos.xRel < 0)) | |
| 8980 | + { leftButtonStartDrag(cm, event, pos, behavior); } | |
| 8981 | + else | |
| 8982 | + { leftButtonSelect(cm, event, pos, behavior); } | |
| 8983 | + } | |
| 8984 | + | |
| 8985 | + // Start a text drag. When it ends, see if any dragging actually | |
| 8986 | + // happen, and treat as a click if it didn't. | |
| 8987 | + function leftButtonStartDrag(cm, event, pos, behavior) { | |
| 8988 | + var display = cm.display, moved = false; | |
| 8989 | + var dragEnd = operation(cm, function (e) { | |
| 8990 | + if (webkit) { display.scroller.draggable = false; } | |
| 8991 | + cm.state.draggingText = false; | |
| 8992 | + if (cm.state.delayingBlurEvent) { | |
| 8993 | + if (cm.hasFocus()) { cm.state.delayingBlurEvent = false; } | |
| 8994 | + else { delayBlurEvent(cm); } | |
| 8995 | + } | |
| 8996 | + off(display.wrapper.ownerDocument, "mouseup", dragEnd); | |
| 8997 | + off(display.wrapper.ownerDocument, "mousemove", mouseMove); | |
| 8998 | + off(display.scroller, "dragstart", dragStart); | |
| 8999 | + off(display.scroller, "drop", dragEnd); | |
| 9000 | + if (!moved) { | |
| 9001 | + e_preventDefault(e); | |
| 9002 | + if (!behavior.addNew) | |
| 9003 | + { extendSelection(cm.doc, pos, null, null, behavior.extend); } | |
| 9004 | + // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081) | |
| 9005 | + if ((webkit && !safari) || ie && ie_version == 9) | |
| 9006 | + { setTimeout(function () {display.wrapper.ownerDocument.body.focus({preventScroll: true}); display.input.focus();}, 20); } | |
| 9007 | + else | |
| 9008 | + { display.input.focus(); } | |
| 9009 | + } | |
| 9010 | + }); | |
| 9011 | + var mouseMove = function(e2) { | |
| 9012 | + moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10; | |
| 9013 | + }; | |
| 9014 | + var dragStart = function () { return moved = true; }; | |
| 9015 | + // Let the drag handler handle this. | |
| 9016 | + if (webkit) { display.scroller.draggable = true; } | |
| 9017 | + cm.state.draggingText = dragEnd; | |
| 9018 | + dragEnd.copy = !behavior.moveOnDrag; | |
| 9019 | + on(display.wrapper.ownerDocument, "mouseup", dragEnd); | |
| 9020 | + on(display.wrapper.ownerDocument, "mousemove", mouseMove); | |
| 9021 | + on(display.scroller, "dragstart", dragStart); | |
| 9022 | + on(display.scroller, "drop", dragEnd); | |
| 9023 | + | |
| 9024 | + cm.state.delayingBlurEvent = true; | |
| 9025 | + setTimeout(function () { return display.input.focus(); }, 20); | |
| 9026 | + // IE's approach to draggable | |
| 9027 | + if (display.scroller.dragDrop) { display.scroller.dragDrop(); } | |
| 9028 | + } | |
| 9029 | + | |
| 9030 | + function rangeForUnit(cm, pos, unit) { | |
| 9031 | + if (unit == "char") { return new Range(pos, pos) } | |
| 9032 | + if (unit == "word") { return cm.findWordAt(pos) } | |
| 9033 | + if (unit == "line") { return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) } | |
| 9034 | + var result = unit(cm, pos); | |
| 9035 | + return new Range(result.from, result.to) | |
| 9036 | + } | |
| 9037 | + | |
| 9038 | + // Normal selection, as opposed to text dragging. | |
| 9039 | + function leftButtonSelect(cm, event, start, behavior) { | |
| 9040 | + if (ie) { delayBlurEvent(cm); } | |
| 9041 | + var display = cm.display, doc = cm.doc; | |
| 9042 | + e_preventDefault(event); | |
| 9043 | + | |
| 9044 | + var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges; | |
| 9045 | + if (behavior.addNew && !behavior.extend) { | |
| 9046 | + ourIndex = doc.sel.contains(start); | |
| 9047 | + if (ourIndex > -1) | |
| 9048 | + { ourRange = ranges[ourIndex]; } | |
| 9049 | + else | |
| 9050 | + { ourRange = new Range(start, start); } | |
| 9051 | + } else { | |
| 9052 | + ourRange = doc.sel.primary(); | |
| 9053 | + ourIndex = doc.sel.primIndex; | |
| 9054 | + } | |
| 9055 | + | |
| 9056 | + if (behavior.unit == "rectangle") { | |
| 9057 | + if (!behavior.addNew) { ourRange = new Range(start, start); } | |
| 9058 | + start = posFromMouse(cm, event, true, true); | |
| 9059 | + ourIndex = -1; | |
| 9060 | + } else { | |
| 9061 | + var range = rangeForUnit(cm, start, behavior.unit); | |
| 9062 | + if (behavior.extend) | |
| 9063 | + { ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend); } | |
| 9064 | + else | |
| 9065 | + { ourRange = range; } | |
| 9066 | + } | |
| 9067 | + | |
| 9068 | + if (!behavior.addNew) { | |
| 9069 | + ourIndex = 0; | |
| 9070 | + setSelection(doc, new Selection([ourRange], 0), sel_mouse); | |
| 9071 | + startSel = doc.sel; | |
| 9072 | + } else if (ourIndex == -1) { | |
| 9073 | + ourIndex = ranges.length; | |
| 9074 | + setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex), | |
| 9075 | + {scroll: false, origin: "*mouse"}); | |
| 9076 | + } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) { | |
| 9077 | + setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), | |
| 9078 | + {scroll: false, origin: "*mouse"}); | |
| 9079 | + startSel = doc.sel; | |
| 9080 | + } else { | |
| 9081 | + replaceOneSelection(doc, ourIndex, ourRange, sel_mouse); | |
| 9082 | + } | |
| 9083 | + | |
| 9084 | + var lastPos = start; | |
| 9085 | + function extendTo(pos) { | |
| 9086 | + if (cmp(lastPos, pos) == 0) { return } | |
| 9087 | + lastPos = pos; | |
| 9088 | + | |
| 9089 | + if (behavior.unit == "rectangle") { | |
| 9090 | + var ranges = [], tabSize = cm.options.tabSize; | |
| 9091 | + var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize); | |
| 9092 | + var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize); | |
| 9093 | + var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol); | |
| 9094 | + for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); | |
| 9095 | + line <= end; line++) { | |
| 9096 | + var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize); | |
| 9097 | + if (left == right) | |
| 9098 | + { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); } | |
| 9099 | + else if (text.length > leftPos) | |
| 9100 | + { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); } | |
| 9101 | + } | |
| 9102 | + if (!ranges.length) { ranges.push(new Range(start, start)); } | |
| 9103 | + setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), | |
| 9104 | + {origin: "*mouse", scroll: false}); | |
| 9105 | + cm.scrollIntoView(pos); | |
| 9106 | + } else { | |
| 9107 | + var oldRange = ourRange; | |
| 9108 | + var range = rangeForUnit(cm, pos, behavior.unit); | |
| 9109 | + var anchor = oldRange.anchor, head; | |
| 9110 | + if (cmp(range.anchor, anchor) > 0) { | |
| 9111 | + head = range.head; | |
| 9112 | + anchor = minPos(oldRange.from(), range.anchor); | |
| 9113 | + } else { | |
| 9114 | + head = range.anchor; | |
| 9115 | + anchor = maxPos(oldRange.to(), range.head); | |
| 9116 | + } | |
| 9117 | + var ranges$1 = startSel.ranges.slice(0); | |
| 9118 | + ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head)); | |
| 9119 | + setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse); | |
| 9120 | + } | |
| 9121 | + } | |
| 9122 | + | |
| 9123 | + var editorSize = display.wrapper.getBoundingClientRect(); | |
| 9124 | + // Used to ensure timeout re-tries don't fire when another extend | |
| 9125 | + // happened in the meantime (clearTimeout isn't reliable -- at | |
| 9126 | + // least on Chrome, the timeouts still happen even when cleared, | |
| 9127 | + // if the clear happens after their scheduled firing time). | |
| 9128 | + var counter = 0; | |
| 9129 | + | |
| 9130 | + function extend(e) { | |
| 9131 | + var curCount = ++counter; | |
| 9132 | + var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle"); | |
| 9133 | + if (!cur) { return } | |
| 9134 | + if (cmp(cur, lastPos) != 0) { | |
| 9135 | + cm.curOp.focus = activeElt(); | |
| 9136 | + extendTo(cur); | |
| 9137 | + var visible = visibleLines(display, doc); | |
| 9138 | + if (cur.line >= visible.to || cur.line < visible.from) | |
| 9139 | + { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); } | |
| 9140 | + } else { | |
| 9141 | + var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0; | |
| 9142 | + if (outside) { setTimeout(operation(cm, function () { | |
| 9143 | + if (counter != curCount) { return } | |
| 9144 | + display.scroller.scrollTop += outside; | |
| 9145 | + extend(e); | |
| 9146 | + }), 50); } | |
| 9147 | + } | |
| 9148 | + } | |
| 9149 | + | |
| 9150 | + function done(e) { | |
| 9151 | + cm.state.selectingText = false; | |
| 9152 | + counter = Infinity; | |
| 9153 | + // If e is null or undefined we interpret this as someone trying | |
| 9154 | + // to explicitly cancel the selection rather than the user | |
| 9155 | + // letting go of the mouse button. | |
| 9156 | + if (e) { | |
| 9157 | + e_preventDefault(e); | |
| 9158 | + display.input.focus(); | |
| 9159 | + } | |
| 9160 | + off(display.wrapper.ownerDocument, "mousemove", move); | |
| 9161 | + off(display.wrapper.ownerDocument, "mouseup", up); | |
| 9162 | + doc.history.lastSelOrigin = null; | |
| 9163 | + } | |
| 9164 | + | |
| 9165 | + var move = operation(cm, function (e) { | |
| 9166 | + if (e.buttons === 0 || !e_button(e)) { done(e); } | |
| 9167 | + else { extend(e); } | |
| 9168 | + }); | |
| 9169 | + var up = operation(cm, done); | |
| 9170 | + cm.state.selectingText = up; | |
| 9171 | + on(display.wrapper.ownerDocument, "mousemove", move); | |
| 9172 | + on(display.wrapper.ownerDocument, "mouseup", up); | |
| 9173 | + } | |
| 9174 | + | |
| 9175 | + // Used when mouse-selecting to adjust the anchor to the proper side | |
| 9176 | + // of a bidi jump depending on the visual position of the head. | |
| 9177 | + function bidiSimplify(cm, range) { | |
| 9178 | + var anchor = range.anchor; | |
| 9179 | + var head = range.head; | |
| 9180 | + var anchorLine = getLine(cm.doc, anchor.line); | |
| 9181 | + if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range } | |
| 9182 | + var order = getOrder(anchorLine); | |
| 9183 | + if (!order) { return range } | |
| 9184 | + var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index]; | |
| 9185 | + if (part.from != anchor.ch && part.to != anchor.ch) { return range } | |
| 9186 | + var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1); | |
| 9187 | + if (boundary == 0 || boundary == order.length) { return range } | |
| 9188 | + | |
| 9189 | + // Compute the relative visual position of the head compared to the | |
| 9190 | + // anchor (<0 is to the left, >0 to the right) | |
| 9191 | + var leftSide; | |
| 9192 | + if (head.line != anchor.line) { | |
| 9193 | + leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0; | |
| 9194 | + } else { | |
| 9195 | + var headIndex = getBidiPartAt(order, head.ch, head.sticky); | |
| 9196 | + var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1); | |
| 9197 | + if (headIndex == boundary - 1 || headIndex == boundary) | |
| 9198 | + { leftSide = dir < 0; } | |
| 9199 | + else | |
| 9200 | + { leftSide = dir > 0; } | |
| 9201 | + } | |
| 9202 | + | |
| 9203 | + var usePart = order[boundary + (leftSide ? -1 : 0)]; | |
| 9204 | + var from = leftSide == (usePart.level == 1); | |
| 9205 | + var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before"; | |
| 9206 | + return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head) | |
| 9207 | + } | |
| 9208 | + | |
| 9209 | + | |
| 9210 | + // Determines whether an event happened in the gutter, and fires the | |
| 9211 | + // handlers for the corresponding event. | |
| 9212 | + function gutterEvent(cm, e, type, prevent) { | |
| 9213 | + var mX, mY; | |
| 9214 | + if (e.touches) { | |
| 9215 | + mX = e.touches[0].clientX; | |
| 9216 | + mY = e.touches[0].clientY; | |
| 9217 | + } else { | |
| 9218 | + try { mX = e.clientX; mY = e.clientY; } | |
| 9219 | + catch(e$1) { return false } | |
| 9220 | + } | |
| 9221 | + if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false } | |
| 9222 | + if (prevent) { e_preventDefault(e); } | |
| 9223 | + | |
| 9224 | + var display = cm.display; | |
| 9225 | + var lineBox = display.lineDiv.getBoundingClientRect(); | |
| 9226 | + | |
| 9227 | + if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) } | |
| 9228 | + mY -= lineBox.top - display.viewOffset; | |
| 9229 | + | |
| 9230 | + for (var i = 0; i < cm.display.gutterSpecs.length; ++i) { | |
| 9231 | + var g = display.gutters.childNodes[i]; | |
| 9232 | + if (g && g.getBoundingClientRect().right >= mX) { | |
| 9233 | + var line = lineAtHeight(cm.doc, mY); | |
| 9234 | + var gutter = cm.display.gutterSpecs[i]; | |
| 9235 | + signal(cm, type, cm, line, gutter.className, e); | |
| 9236 | + return e_defaultPrevented(e) | |
| 9237 | + } | |
| 9238 | + } | |
| 9239 | + } | |
| 9240 | + | |
| 9241 | + function clickInGutter(cm, e) { | |
| 9242 | + return gutterEvent(cm, e, "gutterClick", true) | |
| 9243 | + } | |
| 9244 | + | |
| 9245 | + // CONTEXT MENU HANDLING | |
| 9246 | + | |
| 9247 | + // To make the context menu work, we need to briefly unhide the | |
| 9248 | + // textarea (making it as unobtrusive as possible) to let the | |
| 9249 | + // right-click take effect on it. | |
| 9250 | + function onContextMenu(cm, e) { | |
| 9251 | + if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return } | |
| 9252 | + if (signalDOMEvent(cm, e, "contextmenu")) { return } | |
| 9253 | + if (!captureRightClick) { cm.display.input.onContextMenu(e); } | |
| 9254 | + } | |
| 9255 | + | |
| 9256 | + function contextMenuInGutter(cm, e) { | |
| 9257 | + if (!hasHandler(cm, "gutterContextMenu")) { return false } | |
| 9258 | + return gutterEvent(cm, e, "gutterContextMenu", false) | |
| 9259 | + } | |
| 9260 | + | |
| 9261 | + function themeChanged(cm) { | |
| 9262 | + cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") + | |
| 9263 | + cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-"); | |
| 9264 | + clearCaches(cm); | |
| 9265 | + } | |
| 9266 | + | |
| 9267 | + var Init = {toString: function(){return "CodeMirror.Init"}}; | |
| 9268 | + | |
| 9269 | + var defaults = {}; | |
| 9270 | + var optionHandlers = {}; | |
| 9271 | + | |
| 9272 | + function defineOptions(CodeMirror) { | |
| 9273 | + var optionHandlers = CodeMirror.optionHandlers; | |
| 9274 | + | |
| 9275 | + function option(name, deflt, handle, notOnInit) { | |
| 9276 | + CodeMirror.defaults[name] = deflt; | |
| 9277 | + if (handle) { optionHandlers[name] = | |
| 9278 | + notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old); }} : handle; } | |
| 9279 | + } | |
| 9280 | + | |
| 9281 | + CodeMirror.defineOption = option; | |
| 9282 | + | |
| 9283 | + // Passed to option handlers when there is no old value. | |
| 9284 | + CodeMirror.Init = Init; | |
| 9285 | + | |
| 9286 | + // These two are, on init, called from the constructor because they | |
| 9287 | + // have to be initialized before the editor can start at all. | |
| 9288 | + option("value", "", function (cm, val) { return cm.setValue(val); }, true); | |
| 9289 | + option("mode", null, function (cm, val) { | |
| 9290 | + cm.doc.modeOption = val; | |
| 9291 | + loadMode(cm); | |
| 9292 | + }, true); | |
| 9293 | + | |
| 9294 | + option("indentUnit", 2, loadMode, true); | |
| 9295 | + option("indentWithTabs", false); | |
| 9296 | + option("smartIndent", true); | |
| 9297 | + option("tabSize", 4, function (cm) { | |
| 9298 | + resetModeState(cm); | |
| 9299 | + clearCaches(cm); | |
| 9300 | + regChange(cm); | |
| 9301 | + }, true); | |
| 9302 | + | |
| 9303 | + option("lineSeparator", null, function (cm, val) { | |
| 9304 | + cm.doc.lineSep = val; | |
| 9305 | + if (!val) { return } | |
| 9306 | + var newBreaks = [], lineNo = cm.doc.first; | |
| 9307 | + cm.doc.iter(function (line) { | |
| 9308 | + for (var pos = 0;;) { | |
| 9309 | + var found = line.text.indexOf(val, pos); | |
| 9310 | + if (found == -1) { break } | |
| 9311 | + pos = found + val.length; | |
| 9312 | + newBreaks.push(Pos(lineNo, found)); | |
| 9313 | + } | |
| 9314 | + lineNo++; | |
| 9315 | + }); | |
| 9316 | + for (var i = newBreaks.length - 1; i >= 0; i--) | |
| 9317 | + { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); } | |
| 9318 | + }); | |
| 9319 | + option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g, function (cm, val, old) { | |
| 9320 | + cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g"); | |
| 9321 | + if (old != Init) { cm.refresh(); } | |
| 9322 | + }); | |
| 9323 | + option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true); | |
| 9324 | + option("electricChars", true); | |
| 9325 | + option("inputStyle", mobile ? "contenteditable" : "textarea", function () { | |
| 9326 | + throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME | |
| 9327 | + }, true); | |
| 9328 | + option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true); | |
| 9329 | + option("autocorrect", false, function (cm, val) { return cm.getInputField().autocorrect = val; }, true); | |
| 9330 | + option("autocapitalize", false, function (cm, val) { return cm.getInputField().autocapitalize = val; }, true); | |
| 9331 | + option("rtlMoveVisually", !windows); | |
| 9332 | + option("wholeLineUpdateBefore", true); | |
| 9333 | + | |
| 9334 | + option("theme", "default", function (cm) { | |
| 9335 | + themeChanged(cm); | |
| 9336 | + updateGutters(cm); | |
| 9337 | + }, true); | |
| 9338 | + option("keyMap", "default", function (cm, val, old) { | |
| 9339 | + var next = getKeyMap(val); | |
| 9340 | + var prev = old != Init && getKeyMap(old); | |
| 9341 | + if (prev && prev.detach) { prev.detach(cm, next); } | |
| 9342 | + if (next.attach) { next.attach(cm, prev || null); } | |
| 9343 | + }); | |
| 9344 | + option("extraKeys", null); | |
| 9345 | + option("configureMouse", null); | |
| 9346 | + | |
| 9347 | + option("lineWrapping", false, wrappingChanged, true); | |
| 9348 | + option("gutters", [], function (cm, val) { | |
| 9349 | + cm.display.gutterSpecs = getGutters(val, cm.options.lineNumbers); | |
| 9350 | + updateGutters(cm); | |
| 9351 | + }, true); | |
| 9352 | + option("fixedGutter", true, function (cm, val) { | |
| 9353 | + cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"; | |
| 9354 | + cm.refresh(); | |
| 9355 | + }, true); | |
| 9356 | + option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true); | |
| 9357 | + option("scrollbarStyle", "native", function (cm) { | |
| 9358 | + initScrollbars(cm); | |
| 9359 | + updateScrollbars(cm); | |
| 9360 | + cm.display.scrollbars.setScrollTop(cm.doc.scrollTop); | |
| 9361 | + cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft); | |
| 9362 | + }, true); | |
| 9363 | + option("lineNumbers", false, function (cm, val) { | |
| 9364 | + cm.display.gutterSpecs = getGutters(cm.options.gutters, val); | |
| 9365 | + updateGutters(cm); | |
| 9366 | + }, true); | |
| 9367 | + option("firstLineNumber", 1, updateGutters, true); | |
| 9368 | + option("lineNumberFormatter", function (integer) { return integer; }, updateGutters, true); | |
| 9369 | + option("showCursorWhenSelecting", false, updateSelection, true); | |
| 9370 | + | |
| 9371 | + option("resetSelectionOnContextMenu", true); | |
| 9372 | + option("lineWiseCopyCut", true); | |
| 9373 | + option("pasteLinesPerSelection", true); | |
| 9374 | + option("selectionsMayTouch", false); | |
| 9375 | + | |
| 9376 | + option("readOnly", false, function (cm, val) { | |
| 9377 | + if (val == "nocursor") { | |
| 9378 | + onBlur(cm); | |
| 9379 | + cm.display.input.blur(); | |
| 9380 | + } | |
| 9381 | + cm.display.input.readOnlyChanged(val); | |
| 9382 | + }); | |
| 9383 | + | |
| 9384 | + option("screenReaderLabel", null, function (cm, val) { | |
| 9385 | + val = (val === '') ? null : val; | |
| 9386 | + cm.display.input.screenReaderLabelChanged(val); | |
| 9387 | + }); | |
| 9388 | + | |
| 9389 | + option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset(); }}, true); | |
| 9390 | + option("dragDrop", true, dragDropChanged); | |
| 9391 | + option("allowDropFileTypes", null); | |
| 9392 | + | |
| 9393 | + option("cursorBlinkRate", 530); | |
| 9394 | + option("cursorScrollMargin", 0); | |
| 9395 | + option("cursorHeight", 1, updateSelection, true); | |
| 9396 | + option("singleCursorHeightPerLine", true, updateSelection, true); | |
| 9397 | + option("workTime", 100); | |
| 9398 | + option("workDelay", 100); | |
| 9399 | + option("flattenSpans", true, resetModeState, true); | |
| 9400 | + option("addModeClass", false, resetModeState, true); | |
| 9401 | + option("pollInterval", 100); | |
| 9402 | + option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; }); | |
| 9403 | + option("historyEventDelay", 1250); | |
| 9404 | + option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true); | |
| 9405 | + option("maxHighlightLength", 10000, resetModeState, true); | |
| 9406 | + option("moveInputWithCursor", true, function (cm, val) { | |
| 9407 | + if (!val) { cm.display.input.resetPosition(); } | |
| 9408 | + }); | |
| 9409 | + | |
| 9410 | + option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; }); | |
| 9411 | + option("autofocus", null); | |
| 9412 | + option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true); | |
| 9413 | + option("phrases", null); | |
| 9414 | + } | |
| 9415 | + | |
| 9416 | + function dragDropChanged(cm, value, old) { | |
| 9417 | + var wasOn = old && old != Init; | |
| 9418 | + if (!value != !wasOn) { | |
| 9419 | + var funcs = cm.display.dragFunctions; | |
| 9420 | + var toggle = value ? on : off; | |
| 9421 | + toggle(cm.display.scroller, "dragstart", funcs.start); | |
| 9422 | + toggle(cm.display.scroller, "dragenter", funcs.enter); | |
| 9423 | + toggle(cm.display.scroller, "dragover", funcs.over); | |
| 9424 | + toggle(cm.display.scroller, "dragleave", funcs.leave); | |
| 9425 | + toggle(cm.display.scroller, "drop", funcs.drop); | |
| 9426 | + } | |
| 9427 | + } | |
| 9428 | + | |
| 9429 | + function wrappingChanged(cm) { | |
| 9430 | + if (cm.options.lineWrapping) { | |
| 9431 | + addClass(cm.display.wrapper, "CodeMirror-wrap"); | |
| 9432 | + cm.display.sizer.style.minWidth = ""; | |
| 9433 | + cm.display.sizerWidth = null; | |
| 9434 | + } else { | |
| 9435 | + rmClass(cm.display.wrapper, "CodeMirror-wrap"); | |
| 9436 | + findMaxLine(cm); | |
| 9437 | + } | |
| 9438 | + estimateLineHeights(cm); | |
| 9439 | + regChange(cm); | |
| 9440 | + clearCaches(cm); | |
| 9441 | + setTimeout(function () { return updateScrollbars(cm); }, 100); | |
| 9442 | + } | |
| 9443 | + | |
| 9444 | + // A CodeMirror instance represents an editor. This is the object | |
| 9445 | + // that user code is usually dealing with. | |
| 9446 | + | |
| 9447 | + function CodeMirror(place, options) { | |
| 9448 | + var this$1 = this; | |
| 9449 | + | |
| 9450 | + if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) } | |
| 9451 | + | |
| 9452 | + this.options = options = options ? copyObj(options) : {}; | |
| 9453 | + // Determine effective options based on given values and defaults. | |
| 9454 | + copyObj(defaults, options, false); | |
| 9455 | + | |
| 9456 | + var doc = options.value; | |
| 9457 | + if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction); } | |
| 9458 | + else if (options.mode) { doc.modeOption = options.mode; } | |
| 9459 | + this.doc = doc; | |
| 9460 | + | |
| 9461 | + var input = new CodeMirror.inputStyles[options.inputStyle](this); | |
| 9462 | + var display = this.display = new Display(place, doc, input, options); | |
| 9463 | + display.wrapper.CodeMirror = this; | |
| 9464 | + themeChanged(this); | |
| 9465 | + if (options.lineWrapping) | |
| 9466 | + { this.display.wrapper.className += " CodeMirror-wrap"; } | |
| 9467 | + initScrollbars(this); | |
| 9468 | + | |
| 9469 | + this.state = { | |
| 9470 | + keyMaps: [], // stores maps added by addKeyMap | |
| 9471 | + overlays: [], // highlighting overlays, as added by addOverlay | |
| 9472 | + modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info | |
| 9473 | + overwrite: false, | |
| 9474 | + delayingBlurEvent: false, | |
| 9475 | + focused: false, | |
| 9476 | + suppressEdits: false, // used to disable editing during key handlers when in readOnly mode | |
| 9477 | + pasteIncoming: -1, cutIncoming: -1, // help recognize paste/cut edits in input.poll | |
| 9478 | + selectingText: false, | |
| 9479 | + draggingText: false, | |
| 9480 | + highlight: new Delayed(), // stores highlight worker timeout | |
| 9481 | + keySeq: null, // Unfinished key sequence | |
| 9482 | + specialChars: null | |
| 9483 | + }; | |
| 9484 | + | |
| 9485 | + if (options.autofocus && !mobile) { display.input.focus(); } | |
| 9486 | + | |
| 9487 | + // Override magic textarea content restore that IE sometimes does | |
| 9488 | + // on our hidden textarea on reload | |
| 9489 | + if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20); } | |
| 9490 | + | |
| 9491 | + registerEventHandlers(this); | |
| 9492 | + ensureGlobalHandlers(); | |
| 9493 | + | |
| 9494 | + startOperation(this); | |
| 9495 | + this.curOp.forceUpdate = true; | |
| 9496 | + attachDoc(this, doc); | |
| 9497 | + | |
| 9498 | + if ((options.autofocus && !mobile) || this.hasFocus()) | |
| 9499 | + { setTimeout(function () { | |
| 9500 | + if (this$1.hasFocus() && !this$1.state.focused) { onFocus(this$1); } | |
| 9501 | + }, 20); } | |
| 9502 | + else | |
| 9503 | + { onBlur(this); } | |
| 9504 | + | |
| 9505 | + for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt)) | |
| 9506 | + { optionHandlers[opt](this, options[opt], Init); } } | |
| 9507 | + maybeUpdateLineNumberWidth(this); | |
| 9508 | + if (options.finishInit) { options.finishInit(this); } | |
| 9509 | + for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this); } | |
| 9510 | + endOperation(this); | |
| 9511 | + // Suppress optimizelegibility in Webkit, since it breaks text | |
| 9512 | + // measuring on line wrapping boundaries. | |
| 9513 | + if (webkit && options.lineWrapping && | |
| 9514 | + getComputedStyle(display.lineDiv).textRendering == "optimizelegibility") | |
| 9515 | + { display.lineDiv.style.textRendering = "auto"; } | |
| 9516 | + } | |
| 9517 | + | |
| 9518 | + // The default configuration options. | |
| 9519 | + CodeMirror.defaults = defaults; | |
| 9520 | + // Functions to run when options are changed. | |
| 9521 | + CodeMirror.optionHandlers = optionHandlers; | |
| 9522 | + | |
| 9523 | + // Attach the necessary event handlers when initializing the editor | |
| 9524 | + function registerEventHandlers(cm) { | |
| 9525 | + var d = cm.display; | |
| 9526 | + on(d.scroller, "mousedown", operation(cm, onMouseDown)); | |
| 9527 | + // Older IE's will not fire a second mousedown for a double click | |
| 9528 | + if (ie && ie_version < 11) | |
| 9529 | + { on(d.scroller, "dblclick", operation(cm, function (e) { | |
| 9530 | + if (signalDOMEvent(cm, e)) { return } | |
| 9531 | + var pos = posFromMouse(cm, e); | |
| 9532 | + if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return } | |
| 9533 | + e_preventDefault(e); | |
| 9534 | + var word = cm.findWordAt(pos); | |
| 9535 | + extendSelection(cm.doc, word.anchor, word.head); | |
| 9536 | + })); } | |
| 9537 | + else | |
| 9538 | + { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); } | |
| 9539 | + // Some browsers fire contextmenu *after* opening the menu, at | |
| 9540 | + // which point we can't mess with it anymore. Context menu is | |
| 9541 | + // handled in onMouseDown for these browsers. | |
| 9542 | + on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); }); | |
| 9543 | + on(d.input.getField(), "contextmenu", function (e) { | |
| 9544 | + if (!d.scroller.contains(e.target)) { onContextMenu(cm, e); } | |
| 9545 | + }); | |
| 9546 | + | |
| 9547 | + // Used to suppress mouse event handling when a touch happens | |
| 9548 | + var touchFinished, prevTouch = {end: 0}; | |
| 9549 | + function finishTouch() { | |
| 9550 | + if (d.activeTouch) { | |
| 9551 | + touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000); | |
| 9552 | + prevTouch = d.activeTouch; | |
| 9553 | + prevTouch.end = +new Date; | |
| 9554 | + } | |
| 9555 | + } | |
| 9556 | + function isMouseLikeTouchEvent(e) { | |
| 9557 | + if (e.touches.length != 1) { return false } | |
| 9558 | + var touch = e.touches[0]; | |
| 9559 | + return touch.radiusX <= 1 && touch.radiusY <= 1 | |
| 9560 | + } | |
| 9561 | + function farAway(touch, other) { | |
| 9562 | + if (other.left == null) { return true } | |
| 9563 | + var dx = other.left - touch.left, dy = other.top - touch.top; | |
| 9564 | + return dx * dx + dy * dy > 20 * 20 | |
| 9565 | + } | |
| 9566 | + on(d.scroller, "touchstart", function (e) { | |
| 9567 | + if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) { | |
| 9568 | + d.input.ensurePolled(); | |
| 9569 | + clearTimeout(touchFinished); | |
| 9570 | + var now = +new Date; | |
| 9571 | + d.activeTouch = {start: now, moved: false, | |
| 9572 | + prev: now - prevTouch.end <= 300 ? prevTouch : null}; | |
| 9573 | + if (e.touches.length == 1) { | |
| 9574 | + d.activeTouch.left = e.touches[0].pageX; | |
| 9575 | + d.activeTouch.top = e.touches[0].pageY; | |
| 9576 | + } | |
| 9577 | + } | |
| 9578 | + }); | |
| 9579 | + on(d.scroller, "touchmove", function () { | |
| 9580 | + if (d.activeTouch) { d.activeTouch.moved = true; } | |
| 9581 | + }); | |
| 9582 | + on(d.scroller, "touchend", function (e) { | |
| 9583 | + var touch = d.activeTouch; | |
| 9584 | + if (touch && !eventInWidget(d, e) && touch.left != null && | |
| 9585 | + !touch.moved && new Date - touch.start < 300) { | |
| 9586 | + var pos = cm.coordsChar(d.activeTouch, "page"), range; | |
| 9587 | + if (!touch.prev || farAway(touch, touch.prev)) // Single tap | |
| 9588 | + { range = new Range(pos, pos); } | |
| 9589 | + else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap | |
| 9590 | + { range = cm.findWordAt(pos); } | |
| 9591 | + else // Triple tap | |
| 9592 | + { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); } | |
| 9593 | + cm.setSelection(range.anchor, range.head); | |
| 9594 | + cm.focus(); | |
| 9595 | + e_preventDefault(e); | |
| 9596 | + } | |
| 9597 | + finishTouch(); | |
| 9598 | + }); | |
| 9599 | + on(d.scroller, "touchcancel", finishTouch); | |
| 9600 | + | |
| 9601 | + // Sync scrolling between fake scrollbars and real scrollable | |
| 9602 | + // area, ensure viewport is updated when scrolling. | |
| 9603 | + on(d.scroller, "scroll", function () { | |
| 9604 | + if (d.scroller.clientHeight) { | |
| 9605 | + updateScrollTop(cm, d.scroller.scrollTop); | |
| 9606 | + setScrollLeft(cm, d.scroller.scrollLeft, true); | |
| 9607 | + signal(cm, "scroll", cm); | |
| 9608 | + } | |
| 9609 | + }); | |
| 9610 | + | |
| 9611 | + // Listen to wheel events in order to try and update the viewport on time. | |
| 9612 | + on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); }); | |
| 9613 | + on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); }); | |
| 9614 | + | |
| 9615 | + // Prevent wrapper from ever scrolling | |
| 9616 | + on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; }); | |
| 9617 | + | |
| 9618 | + d.dragFunctions = { | |
| 9619 | + enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e); }}, | |
| 9620 | + over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }}, | |
| 9621 | + start: function (e) { return onDragStart(cm, e); }, | |
| 9622 | + drop: operation(cm, onDrop), | |
| 9623 | + leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }} | |
| 9624 | + }; | |
| 9625 | + | |
| 9626 | + var inp = d.input.getField(); | |
| 9627 | + on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); }); | |
| 9628 | + on(inp, "keydown", operation(cm, onKeyDown)); | |
| 9629 | + on(inp, "keypress", operation(cm, onKeyPress)); | |
| 9630 | + on(inp, "focus", function (e) { return onFocus(cm, e); }); | |
| 9631 | + on(inp, "blur", function (e) { return onBlur(cm, e); }); | |
| 9632 | + } | |
| 9633 | + | |
| 9634 | + var initHooks = []; | |
| 9635 | + CodeMirror.defineInitHook = function (f) { return initHooks.push(f); }; | |
| 9636 | + | |
| 9637 | + // Indent the given line. The how parameter can be "smart", | |
| 9638 | + // "add"/null, "subtract", or "prev". When aggressive is false | |
| 9639 | + // (typically set to true for forced single-line indents), empty | |
| 9640 | + // lines are not indented, and places where the mode returns Pass | |
| 9641 | + // are left alone. | |
| 9642 | + function indentLine(cm, n, how, aggressive) { | |
| 9643 | + var doc = cm.doc, state; | |
| 9644 | + if (how == null) { how = "add"; } | |
| 9645 | + if (how == "smart") { | |
| 9646 | + // Fall back to "prev" when the mode doesn't have an indentation | |
| 9647 | + // method. | |
| 9648 | + if (!doc.mode.indent) { how = "prev"; } | |
| 9649 | + else { state = getContextBefore(cm, n).state; } | |
| 9650 | + } | |
| 9651 | + | |
| 9652 | + var tabSize = cm.options.tabSize; | |
| 9653 | + var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize); | |
| 9654 | + if (line.stateAfter) { line.stateAfter = null; } | |
| 9655 | + var curSpaceString = line.text.match(/^\s*/)[0], indentation; | |
| 9656 | + if (!aggressive && !/\S/.test(line.text)) { | |
| 9657 | + indentation = 0; | |
| 9658 | + how = "not"; | |
| 9659 | + } else if (how == "smart") { | |
| 9660 | + indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text); | |
| 9661 | + if (indentation == Pass || indentation > 150) { | |
| 9662 | + if (!aggressive) { return } | |
| 9663 | + how = "prev"; | |
| 9664 | + } | |
| 9665 | + } | |
| 9666 | + if (how == "prev") { | |
| 9667 | + if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); } | |
| 9668 | + else { indentation = 0; } | |
| 9669 | + } else if (how == "add") { | |
| 9670 | + indentation = curSpace + cm.options.indentUnit; | |
| 9671 | + } else if (how == "subtract") { | |
| 9672 | + indentation = curSpace - cm.options.indentUnit; | |
| 9673 | + } else if (typeof how == "number") { | |
| 9674 | + indentation = curSpace + how; | |
| 9675 | + } | |
| 9676 | + indentation = Math.max(0, indentation); | |
| 9677 | + | |
| 9678 | + var indentString = "", pos = 0; | |
| 9679 | + if (cm.options.indentWithTabs) | |
| 9680 | + { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} } | |
| 9681 | + if (pos < indentation) { indentString += spaceStr(indentation - pos); } | |
| 9682 | + | |
| 9683 | + if (indentString != curSpaceString) { | |
| 9684 | + replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input"); | |
| 9685 | + line.stateAfter = null; | |
| 9686 | + return true | |
| 9687 | + } else { | |
| 9688 | + // Ensure that, if the cursor was in the whitespace at the start | |
| 9689 | + // of the line, it is moved to the end of that space. | |
| 9690 | + for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) { | |
| 9691 | + var range = doc.sel.ranges[i$1]; | |
| 9692 | + if (range.head.line == n && range.head.ch < curSpaceString.length) { | |
| 9693 | + var pos$1 = Pos(n, curSpaceString.length); | |
| 9694 | + replaceOneSelection(doc, i$1, new Range(pos$1, pos$1)); | |
| 9695 | + break | |
| 9696 | + } | |
| 9697 | + } | |
| 9698 | + } | |
| 9699 | + } | |
| 9700 | + | |
| 9701 | + // This will be set to a {lineWise: bool, text: [string]} object, so | |
| 9702 | + // that, when pasting, we know what kind of selections the copied | |
| 9703 | + // text was made out of. | |
| 9704 | + var lastCopied = null; | |
| 9705 | + | |
| 9706 | + function setLastCopied(newLastCopied) { | |
| 9707 | + lastCopied = newLastCopied; | |
| 9708 | + } | |
| 9709 | + | |
| 9710 | + function applyTextInput(cm, inserted, deleted, sel, origin) { | |
| 9711 | + var doc = cm.doc; | |
| 9712 | + cm.display.shift = false; | |
| 9713 | + if (!sel) { sel = doc.sel; } | |
| 9714 | + | |
| 9715 | + var recent = +new Date - 200; | |
| 9716 | + var paste = origin == "paste" || cm.state.pasteIncoming > recent; | |
| 9717 | + var textLines = splitLinesAuto(inserted), multiPaste = null; | |
| 9718 | + // When pasting N lines into N selections, insert one line per selection | |
| 9719 | + if (paste && sel.ranges.length > 1) { | |
| 9720 | + if (lastCopied && lastCopied.text.join("\n") == inserted) { | |
| 9721 | + if (sel.ranges.length % lastCopied.text.length == 0) { | |
| 9722 | + multiPaste = []; | |
| 9723 | + for (var i = 0; i < lastCopied.text.length; i++) | |
| 9724 | + { multiPaste.push(doc.splitLines(lastCopied.text[i])); } | |
| 9725 | + } | |
| 9726 | + } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) { | |
| 9727 | + multiPaste = map(textLines, function (l) { return [l]; }); | |
| 9728 | + } | |
| 9729 | + } | |
| 9730 | + | |
| 9731 | + var updateInput = cm.curOp.updateInput; | |
| 9732 | + // Normal behavior is to insert the new text into every selection | |
| 9733 | + for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) { | |
| 9734 | + var range = sel.ranges[i$1]; | |
| 9735 | + var from = range.from(), to = range.to(); | |
| 9736 | + if (range.empty()) { | |
| 9737 | + if (deleted && deleted > 0) // Handle deletion | |
| 9738 | + { from = Pos(from.line, from.ch - deleted); } | |
| 9739 | + else if (cm.state.overwrite && !paste) // Handle overwrite | |
| 9740 | + { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); } | |
| 9741 | + else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == textLines.join("\n")) | |
| 9742 | + { from = to = Pos(from.line, 0); } | |
| 9743 | + } | |
| 9744 | + var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines, | |
| 9745 | + origin: origin || (paste ? "paste" : cm.state.cutIncoming > recent ? "cut" : "+input")}; | |
| 9746 | + makeChange(cm.doc, changeEvent); | |
| 9747 | + signalLater(cm, "inputRead", cm, changeEvent); | |
| 9748 | + } | |
| 9749 | + if (inserted && !paste) | |
| 9750 | + { triggerElectric(cm, inserted); } | |
| 9751 | + | |
| 9752 | + ensureCursorVisible(cm); | |
| 9753 | + if (cm.curOp.updateInput < 2) { cm.curOp.updateInput = updateInput; } | |
| 9754 | + cm.curOp.typing = true; | |
| 9755 | + cm.state.pasteIncoming = cm.state.cutIncoming = -1; | |
| 9756 | + } | |
| 9757 | + | |
| 9758 | + function handlePaste(e, cm) { | |
| 9759 | + var pasted = e.clipboardData && e.clipboardData.getData("Text"); | |
| 9760 | + if (pasted) { | |
| 9761 | + e.preventDefault(); | |
| 9762 | + if (!cm.isReadOnly() && !cm.options.disableInput) | |
| 9763 | + { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }); } | |
| 9764 | + return true | |
| 9765 | + } | |
| 9766 | + } | |
| 9767 | + | |
| 9768 | + function triggerElectric(cm, inserted) { | |
| 9769 | + // When an 'electric' character is inserted, immediately trigger a reindent | |
| 9770 | + if (!cm.options.electricChars || !cm.options.smartIndent) { return } | |
| 9771 | + var sel = cm.doc.sel; | |
| 9772 | + | |
| 9773 | + for (var i = sel.ranges.length - 1; i >= 0; i--) { | |
| 9774 | + var range = sel.ranges[i]; | |
| 9775 | + if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) { continue } | |
| 9776 | + var mode = cm.getModeAt(range.head); | |
| 9777 | + var indented = false; | |
| 9778 | + if (mode.electricChars) { | |
| 9779 | + for (var j = 0; j < mode.electricChars.length; j++) | |
| 9780 | + { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) { | |
| 9781 | + indented = indentLine(cm, range.head.line, "smart"); | |
| 9782 | + break | |
| 9783 | + } } | |
| 9784 | + } else if (mode.electricInput) { | |
| 9785 | + if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch))) | |
| 9786 | + { indented = indentLine(cm, range.head.line, "smart"); } | |
| 9787 | + } | |
| 9788 | + if (indented) { signalLater(cm, "electricInput", cm, range.head.line); } | |
| 9789 | + } | |
| 9790 | + } | |
| 9791 | + | |
| 9792 | + function copyableRanges(cm) { | |
| 9793 | + var text = [], ranges = []; | |
| 9794 | + for (var i = 0; i < cm.doc.sel.ranges.length; i++) { | |
| 9795 | + var line = cm.doc.sel.ranges[i].head.line; | |
| 9796 | + var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)}; | |
| 9797 | + ranges.push(lineRange); | |
| 9798 | + text.push(cm.getRange(lineRange.anchor, lineRange.head)); | |
| 9799 | + } | |
| 9800 | + return {text: text, ranges: ranges} | |
| 9801 | + } | |
| 9802 | + | |
| 9803 | + function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) { | |
| 9804 | + field.setAttribute("autocorrect", autocorrect ? "" : "off"); | |
| 9805 | + field.setAttribute("autocapitalize", autocapitalize ? "" : "off"); | |
| 9806 | + field.setAttribute("spellcheck", !!spellcheck); | |
| 9807 | + } | |
| 9808 | + | |
| 9809 | + function hiddenTextarea() { | |
| 9810 | + var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none"); | |
| 9811 | + var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;"); | |
| 9812 | + // The textarea is kept positioned near the cursor to prevent the | |
| 9813 | + // fact that it'll be scrolled into view on input from scrolling | |
| 9814 | + // our fake cursor out of view. On webkit, when wrap=off, paste is | |
| 9815 | + // very slow. So make the area wide instead. | |
| 9816 | + if (webkit) { te.style.width = "1000px"; } | |
| 9817 | + else { te.setAttribute("wrap", "off"); } | |
| 9818 | + // If border: 0; -- iOS fails to open keyboard (issue #1287) | |
| 9819 | + if (ios) { te.style.border = "1px solid black"; } | |
| 9820 | + disableBrowserMagic(te); | |
| 9821 | + return div | |
| 9822 | + } | |
| 9823 | + | |
| 9824 | + // The publicly visible API. Note that methodOp(f) means | |
| 9825 | + // 'wrap f in an operation, performed on its `this` parameter'. | |
| 9826 | + | |
| 9827 | + // This is not the complete set of editor methods. Most of the | |
| 9828 | + // methods defined on the Doc type are also injected into | |
| 9829 | + // CodeMirror.prototype, for backwards compatibility and | |
| 9830 | + // convenience. | |
| 9831 | + | |
| 9832 | + function addEditorMethods(CodeMirror) { | |
| 9833 | + var optionHandlers = CodeMirror.optionHandlers; | |
| 9834 | + | |
| 9835 | + var helpers = CodeMirror.helpers = {}; | |
| 9836 | + | |
| 9837 | + CodeMirror.prototype = { | |
| 9838 | + constructor: CodeMirror, | |
| 9839 | + focus: function(){window.focus(); this.display.input.focus();}, | |
| 9840 | + | |
| 9841 | + setOption: function(option, value) { | |
| 9842 | + var options = this.options, old = options[option]; | |
| 9843 | + if (options[option] == value && option != "mode") { return } | |
| 9844 | + options[option] = value; | |
| 9845 | + if (optionHandlers.hasOwnProperty(option)) | |
| 9846 | + { operation(this, optionHandlers[option])(this, value, old); } | |
| 9847 | + signal(this, "optionChange", this, option); | |
| 9848 | + }, | |
| 9849 | + | |
| 9850 | + getOption: function(option) {return this.options[option]}, | |
| 9851 | + getDoc: function() {return this.doc}, | |
| 9852 | + | |
| 9853 | + addKeyMap: function(map, bottom) { | |
| 9854 | + this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map)); | |
| 9855 | + }, | |
| 9856 | + removeKeyMap: function(map) { | |
| 9857 | + var maps = this.state.keyMaps; | |
| 9858 | + for (var i = 0; i < maps.length; ++i) | |
| 9859 | + { if (maps[i] == map || maps[i].name == map) { | |
| 9860 | + maps.splice(i, 1); | |
| 9861 | + return true | |
| 9862 | + } } | |
| 9863 | + }, | |
| 9864 | + | |
| 9865 | + addOverlay: methodOp(function(spec, options) { | |
| 9866 | + var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec); | |
| 9867 | + if (mode.startState) { throw new Error("Overlays may not be stateful.") } | |
| 9868 | + insertSorted(this.state.overlays, | |
| 9869 | + {mode: mode, modeSpec: spec, opaque: options && options.opaque, | |
| 9870 | + priority: (options && options.priority) || 0}, | |
| 9871 | + function (overlay) { return overlay.priority; }); | |
| 9872 | + this.state.modeGen++; | |
| 9873 | + regChange(this); | |
| 9874 | + }), | |
| 9875 | + removeOverlay: methodOp(function(spec) { | |
| 9876 | + var overlays = this.state.overlays; | |
| 9877 | + for (var i = 0; i < overlays.length; ++i) { | |
| 9878 | + var cur = overlays[i].modeSpec; | |
| 9879 | + if (cur == spec || typeof spec == "string" && cur.name == spec) { | |
| 9880 | + overlays.splice(i, 1); | |
| 9881 | + this.state.modeGen++; | |
| 9882 | + regChange(this); | |
| 9883 | + return | |
| 9884 | + } | |
| 9885 | + } | |
| 9886 | + }), | |
| 9887 | + | |
| 9888 | + indentLine: methodOp(function(n, dir, aggressive) { | |
| 9889 | + if (typeof dir != "string" && typeof dir != "number") { | |
| 9890 | + if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev"; } | |
| 9891 | + else { dir = dir ? "add" : "subtract"; } | |
| 9892 | + } | |
| 9893 | + if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive); } | |
| 9894 | + }), | |
| 9895 | + indentSelection: methodOp(function(how) { | |
| 9896 | + var ranges = this.doc.sel.ranges, end = -1; | |
| 9897 | + for (var i = 0; i < ranges.length; i++) { | |
| 9898 | + var range = ranges[i]; | |
| 9899 | + if (!range.empty()) { | |
| 9900 | + var from = range.from(), to = range.to(); | |
| 9901 | + var start = Math.max(end, from.line); | |
| 9902 | + end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1; | |
| 9903 | + for (var j = start; j < end; ++j) | |
| 9904 | + { indentLine(this, j, how); } | |
| 9905 | + var newRanges = this.doc.sel.ranges; | |
| 9906 | + if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0) | |
| 9907 | + { replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll); } | |
| 9908 | + } else if (range.head.line > end) { | |
| 9909 | + indentLine(this, range.head.line, how, true); | |
| 9910 | + end = range.head.line; | |
| 9911 | + if (i == this.doc.sel.primIndex) { ensureCursorVisible(this); } | |
| 9912 | + } | |
| 9913 | + } | |
| 9914 | + }), | |
| 9915 | + | |
| 9916 | + // Fetch the parser token for a given character. Useful for hacks | |
| 9917 | + // that want to inspect the mode state (say, for completion). | |
| 9918 | + getTokenAt: function(pos, precise) { | |
| 9919 | + return takeToken(this, pos, precise) | |
| 9920 | + }, | |
| 9921 | + | |
| 9922 | + getLineTokens: function(line, precise) { | |
| 9923 | + return takeToken(this, Pos(line), precise, true) | |
| 9924 | + }, | |
| 9925 | + | |
| 9926 | + getTokenTypeAt: function(pos) { | |
| 9927 | + pos = clipPos(this.doc, pos); | |
| 9928 | + var styles = getLineStyles(this, getLine(this.doc, pos.line)); | |
| 9929 | + var before = 0, after = (styles.length - 1) / 2, ch = pos.ch; | |
| 9930 | + var type; | |
| 9931 | + if (ch == 0) { type = styles[2]; } | |
| 9932 | + else { for (;;) { | |
| 9933 | + var mid = (before + after) >> 1; | |
| 9934 | + if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid; } | |
| 9935 | + else if (styles[mid * 2 + 1] < ch) { before = mid + 1; } | |
| 9936 | + else { type = styles[mid * 2 + 2]; break } | |
| 9937 | + } } | |
| 9938 | + var cut = type ? type.indexOf("overlay ") : -1; | |
| 9939 | + return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1) | |
| 9940 | + }, | |
| 9941 | + | |
| 9942 | + getModeAt: function(pos) { | |
| 9943 | + var mode = this.doc.mode; | |
| 9944 | + if (!mode.innerMode) { return mode } | |
| 9945 | + return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode | |
| 9946 | + }, | |
| 9947 | + | |
| 9948 | + getHelper: function(pos, type) { | |
| 9949 | + return this.getHelpers(pos, type)[0] | |
| 9950 | + }, | |
| 9951 | + | |
| 9952 | + getHelpers: function(pos, type) { | |
| 9953 | + var found = []; | |
| 9954 | + if (!helpers.hasOwnProperty(type)) { return found } | |
| 9955 | + var help = helpers[type], mode = this.getModeAt(pos); | |
| 9956 | + if (typeof mode[type] == "string") { | |
| 9957 | + if (help[mode[type]]) { found.push(help[mode[type]]); } | |
| 9958 | + } else if (mode[type]) { | |
| 9959 | + for (var i = 0; i < mode[type].length; i++) { | |
| 9960 | + var val = help[mode[type][i]]; | |
| 9961 | + if (val) { found.push(val); } | |
| 9962 | + } | |
| 9963 | + } else if (mode.helperType && help[mode.helperType]) { | |
| 9964 | + found.push(help[mode.helperType]); | |
| 9965 | + } else if (help[mode.name]) { | |
| 9966 | + found.push(help[mode.name]); | |
| 9967 | + } | |
| 9968 | + for (var i$1 = 0; i$1 < help._global.length; i$1++) { | |
| 9969 | + var cur = help._global[i$1]; | |
| 9970 | + if (cur.pred(mode, this) && indexOf(found, cur.val) == -1) | |
| 9971 | + { found.push(cur.val); } | |
| 9972 | + } | |
| 9973 | + return found | |
| 9974 | + }, | |
| 9975 | + | |
| 9976 | + getStateAfter: function(line, precise) { | |
| 9977 | + var doc = this.doc; | |
| 9978 | + line = clipLine(doc, line == null ? doc.first + doc.size - 1: line); | |
| 9979 | + return getContextBefore(this, line + 1, precise).state | |
| 9980 | + }, | |
| 9981 | + | |
| 9982 | + cursorCoords: function(start, mode) { | |
| 9983 | + var pos, range = this.doc.sel.primary(); | |
| 9984 | + if (start == null) { pos = range.head; } | |
| 9985 | + else if (typeof start == "object") { pos = clipPos(this.doc, start); } | |
| 9986 | + else { pos = start ? range.from() : range.to(); } | |
| 9987 | + return cursorCoords(this, pos, mode || "page") | |
| 9988 | + }, | |
| 9989 | + | |
| 9990 | + charCoords: function(pos, mode) { | |
| 9991 | + return charCoords(this, clipPos(this.doc, pos), mode || "page") | |
| 9992 | + }, | |
| 9993 | + | |
| 9994 | + coordsChar: function(coords, mode) { | |
| 9995 | + coords = fromCoordSystem(this, coords, mode || "page"); | |
| 9996 | + return coordsChar(this, coords.left, coords.top) | |
| 9997 | + }, | |
| 9998 | + | |
| 9999 | + lineAtHeight: function(height, mode) { | |
| 10000 | + height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top; | |
| 10001 | + return lineAtHeight(this.doc, height + this.display.viewOffset) | |
| 10002 | + }, | |
| 10003 | + heightAtLine: function(line, mode, includeWidgets) { | |
| 10004 | + var end = false, lineObj; | |
| 10005 | + if (typeof line == "number") { | |
| 10006 | + var last = this.doc.first + this.doc.size - 1; | |
| 10007 | + if (line < this.doc.first) { line = this.doc.first; } | |
| 10008 | + else if (line > last) { line = last; end = true; } | |
| 10009 | + lineObj = getLine(this.doc, line); | |
| 10010 | + } else { | |
| 10011 | + lineObj = line; | |
| 10012 | + } | |
| 10013 | + return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top + | |
| 10014 | + (end ? this.doc.height - heightAtLine(lineObj) : 0) | |
| 10015 | + }, | |
| 10016 | + | |
| 10017 | + defaultTextHeight: function() { return textHeight(this.display) }, | |
| 10018 | + defaultCharWidth: function() { return charWidth(this.display) }, | |
| 10019 | + | |
| 10020 | + getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}}, | |
| 10021 | + | |
| 10022 | + addWidget: function(pos, node, scroll, vert, horiz) { | |
| 10023 | + var display = this.display; | |
| 10024 | + pos = cursorCoords(this, clipPos(this.doc, pos)); | |
| 10025 | + var top = pos.bottom, left = pos.left; | |
| 10026 | + node.style.position = "absolute"; | |
| 10027 | + node.setAttribute("cm-ignore-events", "true"); | |
| 10028 | + this.display.input.setUneditable(node); | |
| 10029 | + display.sizer.appendChild(node); | |
| 10030 | + if (vert == "over") { | |
| 10031 | + top = pos.top; | |
| 10032 | + } else if (vert == "above" || vert == "near") { | |
| 10033 | + var vspace = Math.max(display.wrapper.clientHeight, this.doc.height), | |
| 10034 | + hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth); | |
| 10035 | + // Default to positioning above (if specified and possible); otherwise default to positioning below | |
| 10036 | + if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight) | |
| 10037 | + { top = pos.top - node.offsetHeight; } | |
| 10038 | + else if (pos.bottom + node.offsetHeight <= vspace) | |
| 10039 | + { top = pos.bottom; } | |
| 10040 | + if (left + node.offsetWidth > hspace) | |
| 10041 | + { left = hspace - node.offsetWidth; } | |
| 10042 | + } | |
| 10043 | + node.style.top = top + "px"; | |
| 10044 | + node.style.left = node.style.right = ""; | |
| 10045 | + if (horiz == "right") { | |
| 10046 | + left = display.sizer.clientWidth - node.offsetWidth; | |
| 10047 | + node.style.right = "0px"; | |
| 10048 | + } else { | |
| 10049 | + if (horiz == "left") { left = 0; } | |
| 10050 | + else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2; } | |
| 10051 | + node.style.left = left + "px"; | |
| 10052 | + } | |
| 10053 | + if (scroll) | |
| 10054 | + { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}); } | |
| 10055 | + }, | |
| 10056 | + | |
| 10057 | + triggerOnKeyDown: methodOp(onKeyDown), | |
| 10058 | + triggerOnKeyPress: methodOp(onKeyPress), | |
| 10059 | + triggerOnKeyUp: onKeyUp, | |
| 10060 | + triggerOnMouseDown: methodOp(onMouseDown), | |
| 10061 | + | |
| 10062 | + execCommand: function(cmd) { | |
| 10063 | + if (commands.hasOwnProperty(cmd)) | |
| 10064 | + { return commands[cmd].call(null, this) } | |
| 10065 | + }, | |
| 10066 | + | |
| 10067 | + triggerElectric: methodOp(function(text) { triggerElectric(this, text); }), | |
| 10068 | + | |
| 10069 | + findPosH: function(from, amount, unit, visually) { | |
| 10070 | + var dir = 1; | |
| 10071 | + if (amount < 0) { dir = -1; amount = -amount; } | |
| 10072 | + var cur = clipPos(this.doc, from); | |
| 10073 | + for (var i = 0; i < amount; ++i) { | |
| 10074 | + cur = findPosH(this.doc, cur, dir, unit, visually); | |
| 10075 | + if (cur.hitSide) { break } | |
| 10076 | + } | |
| 10077 | + return cur | |
| 10078 | + }, | |
| 10079 | + | |
| 10080 | + moveH: methodOp(function(dir, unit) { | |
| 10081 | + var this$1 = this; | |
| 10082 | + | |
| 10083 | + this.extendSelectionsBy(function (range) { | |
| 10084 | + if (this$1.display.shift || this$1.doc.extend || range.empty()) | |
| 10085 | + { return findPosH(this$1.doc, range.head, dir, unit, this$1.options.rtlMoveVisually) } | |
| 10086 | + else | |
| 10087 | + { return dir < 0 ? range.from() : range.to() } | |
| 10088 | + }, sel_move); | |
| 10089 | + }), | |
| 10090 | + | |
| 10091 | + deleteH: methodOp(function(dir, unit) { | |
| 10092 | + var sel = this.doc.sel, doc = this.doc; | |
| 10093 | + if (sel.somethingSelected()) | |
| 10094 | + { doc.replaceSelection("", null, "+delete"); } | |
| 10095 | + else | |
| 10096 | + { deleteNearSelection(this, function (range) { | |
| 10097 | + var other = findPosH(doc, range.head, dir, unit, false); | |
| 10098 | + return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other} | |
| 10099 | + }); } | |
| 10100 | + }), | |
| 10101 | + | |
| 10102 | + findPosV: function(from, amount, unit, goalColumn) { | |
| 10103 | + var dir = 1, x = goalColumn; | |
| 10104 | + if (amount < 0) { dir = -1; amount = -amount; } | |
| 10105 | + var cur = clipPos(this.doc, from); | |
| 10106 | + for (var i = 0; i < amount; ++i) { | |
| 10107 | + var coords = cursorCoords(this, cur, "div"); | |
| 10108 | + if (x == null) { x = coords.left; } | |
| 10109 | + else { coords.left = x; } | |
| 10110 | + cur = findPosV(this, coords, dir, unit); | |
| 10111 | + if (cur.hitSide) { break } | |
| 10112 | + } | |
| 10113 | + return cur | |
| 10114 | + }, | |
| 10115 | + | |
| 10116 | + moveV: methodOp(function(dir, unit) { | |
| 10117 | + var this$1 = this; | |
| 10118 | + | |
| 10119 | + var doc = this.doc, goals = []; | |
| 10120 | + var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected(); | |
| 10121 | + doc.extendSelectionsBy(function (range) { | |
| 10122 | + if (collapse) | |
| 10123 | + { return dir < 0 ? range.from() : range.to() } | |
| 10124 | + var headPos = cursorCoords(this$1, range.head, "div"); | |
| 10125 | + if (range.goalColumn != null) { headPos.left = range.goalColumn; } | |
| 10126 | + goals.push(headPos.left); | |
| 10127 | + var pos = findPosV(this$1, headPos, dir, unit); | |
| 10128 | + if (unit == "page" && range == doc.sel.primary()) | |
| 10129 | + { addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top); } | |
| 10130 | + return pos | |
| 10131 | + }, sel_move); | |
| 10132 | + if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++) | |
| 10133 | + { doc.sel.ranges[i].goalColumn = goals[i]; } } | |
| 10134 | + }), | |
| 10135 | + | |
| 10136 | + // Find the word at the given position (as returned by coordsChar). | |
| 10137 | + findWordAt: function(pos) { | |
| 10138 | + var doc = this.doc, line = getLine(doc, pos.line).text; | |
| 10139 | + var start = pos.ch, end = pos.ch; | |
| 10140 | + if (line) { | |
| 10141 | + var helper = this.getHelper(pos, "wordChars"); | |
| 10142 | + if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end; } | |
| 10143 | + var startChar = line.charAt(start); | |
| 10144 | + var check = isWordChar(startChar, helper) | |
| 10145 | + ? function (ch) { return isWordChar(ch, helper); } | |
| 10146 | + : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); } | |
| 10147 | + : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); }; | |
| 10148 | + while (start > 0 && check(line.charAt(start - 1))) { --start; } | |
| 10149 | + while (end < line.length && check(line.charAt(end))) { ++end; } | |
| 10150 | + } | |
| 10151 | + return new Range(Pos(pos.line, start), Pos(pos.line, end)) | |
| 10152 | + }, | |
| 10153 | + | |
| 10154 | + toggleOverwrite: function(value) { | |
| 10155 | + if (value != null && value == this.state.overwrite) { return } | |
| 10156 | + if (this.state.overwrite = !this.state.overwrite) | |
| 10157 | + { addClass(this.display.cursorDiv, "CodeMirror-overwrite"); } | |
| 10158 | + else | |
| 10159 | + { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); } | |
| 10160 | + | |
| 10161 | + signal(this, "overwriteToggle", this, this.state.overwrite); | |
| 10162 | + }, | |
| 10163 | + hasFocus: function() { return this.display.input.getField() == activeElt() }, | |
| 10164 | + isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) }, | |
| 10165 | + | |
| 10166 | + scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }), | |
| 10167 | + getScrollInfo: function() { | |
| 10168 | + var scroller = this.display.scroller; | |
| 10169 | + return {left: scroller.scrollLeft, top: scroller.scrollTop, | |
| 10170 | + height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight, | |
| 10171 | + width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth, | |
| 10172 | + clientHeight: displayHeight(this), clientWidth: displayWidth(this)} | |
| 10173 | + }, | |
| 10174 | + | |
| 10175 | + scrollIntoView: methodOp(function(range, margin) { | |
| 10176 | + if (range == null) { | |
| 10177 | + range = {from: this.doc.sel.primary().head, to: null}; | |
| 10178 | + if (margin == null) { margin = this.options.cursorScrollMargin; } | |
| 10179 | + } else if (typeof range == "number") { | |
| 10180 | + range = {from: Pos(range, 0), to: null}; | |
| 10181 | + } else if (range.from == null) { | |
| 10182 | + range = {from: range, to: null}; | |
| 10183 | + } | |
| 10184 | + if (!range.to) { range.to = range.from; } | |
| 10185 | + range.margin = margin || 0; | |
| 10186 | + | |
| 10187 | + if (range.from.line != null) { | |
| 10188 | + scrollToRange(this, range); | |
| 10189 | + } else { | |
| 10190 | + scrollToCoordsRange(this, range.from, range.to, range.margin); | |
| 10191 | + } | |
| 10192 | + }), | |
| 10193 | + | |
| 10194 | + setSize: methodOp(function(width, height) { | |
| 10195 | + var this$1 = this; | |
| 10196 | + | |
| 10197 | + var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; }; | |
| 10198 | + if (width != null) { this.display.wrapper.style.width = interpret(width); } | |
| 10199 | + if (height != null) { this.display.wrapper.style.height = interpret(height); } | |
| 10200 | + if (this.options.lineWrapping) { clearLineMeasurementCache(this); } | |
| 10201 | + var lineNo = this.display.viewFrom; | |
| 10202 | + this.doc.iter(lineNo, this.display.viewTo, function (line) { | |
| 10203 | + if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) | |
| 10204 | + { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo, "widget"); break } } } | |
| 10205 | + ++lineNo; | |
| 10206 | + }); | |
| 10207 | + this.curOp.forceUpdate = true; | |
| 10208 | + signal(this, "refresh", this); | |
| 10209 | + }), | |
| 10210 | + | |
| 10211 | + operation: function(f){return runInOp(this, f)}, | |
| 10212 | + startOperation: function(){return startOperation(this)}, | |
| 10213 | + endOperation: function(){return endOperation(this)}, | |
| 10214 | + | |
| 10215 | + refresh: methodOp(function() { | |
| 10216 | + var oldHeight = this.display.cachedTextHeight; | |
| 10217 | + regChange(this); | |
| 10218 | + this.curOp.forceUpdate = true; | |
| 10219 | + clearCaches(this); | |
| 10220 | + scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop); | |
| 10221 | + updateGutterSpace(this.display); | |
| 10222 | + if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5 || this.options.lineWrapping) | |
| 10223 | + { estimateLineHeights(this); } | |
| 10224 | + signal(this, "refresh", this); | |
| 10225 | + }), | |
| 10226 | + | |
| 10227 | + swapDoc: methodOp(function(doc) { | |
| 10228 | + var old = this.doc; | |
| 10229 | + old.cm = null; | |
| 10230 | + // Cancel the current text selection if any (#5821) | |
| 10231 | + if (this.state.selectingText) { this.state.selectingText(); } | |
| 10232 | + attachDoc(this, doc); | |
| 10233 | + clearCaches(this); | |
| 10234 | + this.display.input.reset(); | |
| 10235 | + scrollToCoords(this, doc.scrollLeft, doc.scrollTop); | |
| 10236 | + this.curOp.forceScroll = true; | |
| 10237 | + signalLater(this, "swapDoc", this, old); | |
| 10238 | + return old | |
| 10239 | + }), | |
| 10240 | + | |
| 10241 | + phrase: function(phraseText) { | |
| 10242 | + var phrases = this.options.phrases; | |
| 10243 | + return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText | |
| 10244 | + }, | |
| 10245 | + | |
| 10246 | + getInputField: function(){return this.display.input.getField()}, | |
| 10247 | + getWrapperElement: function(){return this.display.wrapper}, | |
| 10248 | + getScrollerElement: function(){return this.display.scroller}, | |
| 10249 | + getGutterElement: function(){return this.display.gutters} | |
| 10250 | + }; | |
| 10251 | + eventMixin(CodeMirror); | |
| 10252 | + | |
| 10253 | + CodeMirror.registerHelper = function(type, name, value) { | |
| 10254 | + if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []}; } | |
| 10255 | + helpers[type][name] = value; | |
| 10256 | + }; | |
| 10257 | + CodeMirror.registerGlobalHelper = function(type, name, predicate, value) { | |
| 10258 | + CodeMirror.registerHelper(type, name, value); | |
| 10259 | + helpers[type]._global.push({pred: predicate, val: value}); | |
| 10260 | + }; | |
| 10261 | + } | |
| 10262 | + | |
| 10263 | + // Used for horizontal relative motion. Dir is -1 or 1 (left or | |
| 10264 | + // right), unit can be "codepoint", "char", "column" (like char, but | |
| 10265 | + // doesn't cross line boundaries), "word" (across next word), or | |
| 10266 | + // "group" (to the start of next group of word or | |
| 10267 | + // non-word-non-whitespace chars). The visually param controls | |
| 10268 | + // whether, in right-to-left text, direction 1 means to move towards | |
| 10269 | + // the next index in the string, or towards the character to the right | |
| 10270 | + // of the current position. The resulting position will have a | |
| 10271 | + // hitSide=true property if it reached the end of the document. | |
| 10272 | + function findPosH(doc, pos, dir, unit, visually) { | |
| 10273 | + var oldPos = pos; | |
| 10274 | + var origDir = dir; | |
| 10275 | + var lineObj = getLine(doc, pos.line); | |
| 10276 | + var lineDir = visually && doc.direction == "rtl" ? -dir : dir; | |
| 10277 | + function findNextLine() { | |
| 10278 | + var l = pos.line + lineDir; | |
| 10279 | + if (l < doc.first || l >= doc.first + doc.size) { return false } | |
| 10280 | + pos = new Pos(l, pos.ch, pos.sticky); | |
| 10281 | + return lineObj = getLine(doc, l) | |
| 10282 | + } | |
| 10283 | + function moveOnce(boundToLine) { | |
| 10284 | + var next; | |
| 10285 | + if (unit == "codepoint") { | |
| 10286 | + var ch = lineObj.text.charCodeAt(pos.ch + (dir > 0 ? 0 : -1)); | |
| 10287 | + if (isNaN(ch)) { | |
| 10288 | + next = null; | |
| 10289 | + } else { | |
| 10290 | + var astral = dir > 0 ? ch >= 0xD800 && ch < 0xDC00 : ch >= 0xDC00 && ch < 0xDFFF; | |
| 10291 | + next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (astral ? 2 : 1))), -dir); | |
| 10292 | + } | |
| 10293 | + } else if (visually) { | |
| 10294 | + next = moveVisually(doc.cm, lineObj, pos, dir); | |
| 10295 | + } else { | |
| 10296 | + next = moveLogically(lineObj, pos, dir); | |
| 10297 | + } | |
| 10298 | + if (next == null) { | |
| 10299 | + if (!boundToLine && findNextLine()) | |
| 10300 | + { pos = endOfLine(visually, doc.cm, lineObj, pos.line, lineDir); } | |
| 10301 | + else | |
| 10302 | + { return false } | |
| 10303 | + } else { | |
| 10304 | + pos = next; | |
| 10305 | + } | |
| 10306 | + return true | |
| 10307 | + } | |
| 10308 | + | |
| 10309 | + if (unit == "char" || unit == "codepoint") { | |
| 10310 | + moveOnce(); | |
| 10311 | + } else if (unit == "column") { | |
| 10312 | + moveOnce(true); | |
| 10313 | + } else if (unit == "word" || unit == "group") { | |
| 10314 | + var sawType = null, group = unit == "group"; | |
| 10315 | + var helper = doc.cm && doc.cm.getHelper(pos, "wordChars"); | |
| 10316 | + for (var first = true;; first = false) { | |
| 10317 | + if (dir < 0 && !moveOnce(!first)) { break } | |
| 10318 | + var cur = lineObj.text.charAt(pos.ch) || "\n"; | |
| 10319 | + var type = isWordChar(cur, helper) ? "w" | |
| 10320 | + : group && cur == "\n" ? "n" | |
| 10321 | + : !group || /\s/.test(cur) ? null | |
| 10322 | + : "p"; | |
| 10323 | + if (group && !first && !type) { type = "s"; } | |
| 10324 | + if (sawType && sawType != type) { | |
| 10325 | + if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";} | |
| 10326 | + break | |
| 10327 | + } | |
| 10328 | + | |
| 10329 | + if (type) { sawType = type; } | |
| 10330 | + if (dir > 0 && !moveOnce(!first)) { break } | |
| 10331 | + } | |
| 10332 | + } | |
| 10333 | + var result = skipAtomic(doc, pos, oldPos, origDir, true); | |
| 10334 | + if (equalCursorPos(oldPos, result)) { result.hitSide = true; } | |
| 10335 | + return result | |
| 10336 | + } | |
| 10337 | + | |
| 10338 | + // For relative vertical movement. Dir may be -1 or 1. Unit can be | |
| 10339 | + // "page" or "line". The resulting position will have a hitSide=true | |
| 10340 | + // property if it reached the end of the document. | |
| 10341 | + function findPosV(cm, pos, dir, unit) { | |
| 10342 | + var doc = cm.doc, x = pos.left, y; | |
| 10343 | + if (unit == "page") { | |
| 10344 | + var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight); | |
| 10345 | + var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3); | |
| 10346 | + y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount; | |
| 10347 | + | |
| 10348 | + } else if (unit == "line") { | |
| 10349 | + y = dir > 0 ? pos.bottom + 3 : pos.top - 3; | |
| 10350 | + } | |
| 10351 | + var target; | |
| 10352 | + for (;;) { | |
| 10353 | + target = coordsChar(cm, x, y); | |
| 10354 | + if (!target.outside) { break } | |
| 10355 | + if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break } | |
| 10356 | + y += dir * 5; | |
| 10357 | + } | |
| 10358 | + return target | |
| 10359 | + } | |
| 10360 | + | |
| 10361 | + // CONTENTEDITABLE INPUT STYLE | |
| 10362 | + | |
| 10363 | + var ContentEditableInput = function(cm) { | |
| 10364 | + this.cm = cm; | |
| 10365 | + this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null; | |
| 10366 | + this.polling = new Delayed(); | |
| 10367 | + this.composing = null; | |
| 10368 | + this.gracePeriod = false; | |
| 10369 | + this.readDOMTimeout = null; | |
| 10370 | + }; | |
| 10371 | + | |
| 10372 | + ContentEditableInput.prototype.init = function (display) { | |
| 10373 | + var this$1 = this; | |
| 10374 | + | |
| 10375 | + var input = this, cm = input.cm; | |
| 10376 | + var div = input.div = display.lineDiv; | |
| 10377 | + div.contentEditable = true; | |
| 10378 | + disableBrowserMagic(div, cm.options.spellcheck, cm.options.autocorrect, cm.options.autocapitalize); | |
| 10379 | + | |
| 10380 | + function belongsToInput(e) { | |
| 10381 | + for (var t = e.target; t; t = t.parentNode) { | |
| 10382 | + if (t == div) { return true } | |
| 10383 | + if (/\bCodeMirror-(?:line)?widget\b/.test(t.className)) { break } | |
| 10384 | + } | |
| 10385 | + return false | |
| 10386 | + } | |
| 10387 | + | |
| 10388 | + on(div, "paste", function (e) { | |
| 10389 | + if (!belongsToInput(e) || signalDOMEvent(cm, e) || handlePaste(e, cm)) { return } | |
| 10390 | + // IE doesn't fire input events, so we schedule a read for the pasted content in this way | |
| 10391 | + if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20); } | |
| 10392 | + }); | |
| 10393 | + | |
| 10394 | + on(div, "compositionstart", function (e) { | |
| 10395 | + this$1.composing = {data: e.data, done: false}; | |
| 10396 | + }); | |
| 10397 | + on(div, "compositionupdate", function (e) { | |
| 10398 | + if (!this$1.composing) { this$1.composing = {data: e.data, done: false}; } | |
| 10399 | + }); | |
| 10400 | + on(div, "compositionend", function (e) { | |
| 10401 | + if (this$1.composing) { | |
| 10402 | + if (e.data != this$1.composing.data) { this$1.readFromDOMSoon(); } | |
| 10403 | + this$1.composing.done = true; | |
| 10404 | + } | |
| 10405 | + }); | |
| 10406 | + | |
| 10407 | + on(div, "touchstart", function () { return input.forceCompositionEnd(); }); | |
| 10408 | + | |
| 10409 | + on(div, "input", function () { | |
| 10410 | + if (!this$1.composing) { this$1.readFromDOMSoon(); } | |
| 10411 | + }); | |
| 10412 | + | |
| 10413 | + function onCopyCut(e) { | |
| 10414 | + if (!belongsToInput(e) || signalDOMEvent(cm, e)) { return } | |
| 10415 | + if (cm.somethingSelected()) { | |
| 10416 | + setLastCopied({lineWise: false, text: cm.getSelections()}); | |
| 10417 | + if (e.type == "cut") { cm.replaceSelection("", null, "cut"); } | |
| 10418 | + } else if (!cm.options.lineWiseCopyCut) { | |
| 10419 | + return | |
| 10420 | + } else { | |
| 10421 | + var ranges = copyableRanges(cm); | |
| 10422 | + setLastCopied({lineWise: true, text: ranges.text}); | |
| 10423 | + if (e.type == "cut") { | |
| 10424 | + cm.operation(function () { | |
| 10425 | + cm.setSelections(ranges.ranges, 0, sel_dontScroll); | |
| 10426 | + cm.replaceSelection("", null, "cut"); | |
| 10427 | + }); | |
| 10428 | + } | |
| 10429 | + } | |
| 10430 | + if (e.clipboardData) { | |
| 10431 | + e.clipboardData.clearData(); | |
| 10432 | + var content = lastCopied.text.join("\n"); | |
| 10433 | + // iOS exposes the clipboard API, but seems to discard content inserted into it | |
| 10434 | + e.clipboardData.setData("Text", content); | |
| 10435 | + if (e.clipboardData.getData("Text") == content) { | |
| 10436 | + e.preventDefault(); | |
| 10437 | + return | |
| 10438 | + } | |
| 10439 | + } | |
| 10440 | + // Old-fashioned briefly-focus-a-textarea hack | |
| 10441 | + var kludge = hiddenTextarea(), te = kludge.firstChild; | |
| 10442 | + cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild); | |
| 10443 | + te.value = lastCopied.text.join("\n"); | |
| 10444 | + var hadFocus = activeElt(); | |
| 10445 | + selectInput(te); | |
| 10446 | + setTimeout(function () { | |
| 10447 | + cm.display.lineSpace.removeChild(kludge); | |
| 10448 | + hadFocus.focus(); | |
| 10449 | + if (hadFocus == div) { input.showPrimarySelection(); } | |
| 10450 | + }, 50); | |
| 10451 | + } | |
| 10452 | + on(div, "copy", onCopyCut); | |
| 10453 | + on(div, "cut", onCopyCut); | |
| 10454 | + }; | |
| 10455 | + | |
| 10456 | + ContentEditableInput.prototype.screenReaderLabelChanged = function (label) { | |
| 10457 | + // Label for screenreaders, accessibility | |
| 10458 | + if(label) { | |
| 10459 | + this.div.setAttribute('aria-label', label); | |
| 10460 | + } else { | |
| 10461 | + this.div.removeAttribute('aria-label'); | |
| 10462 | + } | |
| 10463 | + }; | |
| 10464 | + | |
| 10465 | + ContentEditableInput.prototype.prepareSelection = function () { | |
| 10466 | + var result = prepareSelection(this.cm, false); | |
| 10467 | + result.focus = activeElt() == this.div; | |
| 10468 | + return result | |
| 10469 | + }; | |
| 10470 | + | |
| 10471 | + ContentEditableInput.prototype.showSelection = function (info, takeFocus) { | |
| 10472 | + if (!info || !this.cm.display.view.length) { return } | |
| 10473 | + if (info.focus || takeFocus) { this.showPrimarySelection(); } | |
| 10474 | + this.showMultipleSelections(info); | |
| 10475 | + }; | |
| 10476 | + | |
| 10477 | + ContentEditableInput.prototype.getSelection = function () { | |
| 10478 | + return this.cm.display.wrapper.ownerDocument.getSelection() | |
| 10479 | + }; | |
| 10480 | + | |
| 10481 | + ContentEditableInput.prototype.showPrimarySelection = function () { | |
| 10482 | + var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary(); | |
| 10483 | + var from = prim.from(), to = prim.to(); | |
| 10484 | + | |
| 10485 | + if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) { | |
| 10486 | + sel.removeAllRanges(); | |
| 10487 | + return | |
| 10488 | + } | |
| 10489 | + | |
| 10490 | + var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset); | |
| 10491 | + var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset); | |
| 10492 | + if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad && | |
| 10493 | + cmp(minPos(curAnchor, curFocus), from) == 0 && | |
| 10494 | + cmp(maxPos(curAnchor, curFocus), to) == 0) | |
| 10495 | + { return } | |
| 10496 | + | |
| 10497 | + var view = cm.display.view; | |
| 10498 | + var start = (from.line >= cm.display.viewFrom && posToDOM(cm, from)) || | |
| 10499 | + {node: view[0].measure.map[2], offset: 0}; | |
| 10500 | + var end = to.line < cm.display.viewTo && posToDOM(cm, to); | |
| 10501 | + if (!end) { | |
| 10502 | + var measure = view[view.length - 1].measure; | |
| 10503 | + var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map; | |
| 10504 | + end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]}; | |
| 10505 | + } | |
| 10506 | + | |
| 10507 | + if (!start || !end) { | |
| 10508 | + sel.removeAllRanges(); | |
| 10509 | + return | |
| 10510 | + } | |
| 10511 | + | |
| 10512 | + var old = sel.rangeCount && sel.getRangeAt(0), rng; | |
| 10513 | + try { rng = range(start.node, start.offset, end.offset, end.node); } | |
| 10514 | + catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible | |
| 10515 | + if (rng) { | |
| 10516 | + if (!gecko && cm.state.focused) { | |
| 10517 | + sel.collapse(start.node, start.offset); | |
| 10518 | + if (!rng.collapsed) { | |
| 10519 | + sel.removeAllRanges(); | |
| 10520 | + sel.addRange(rng); | |
| 10521 | + } | |
| 10522 | + } else { | |
| 10523 | + sel.removeAllRanges(); | |
| 10524 | + sel.addRange(rng); | |
| 10525 | + } | |
| 10526 | + if (old && sel.anchorNode == null) { sel.addRange(old); } | |
| 10527 | + else if (gecko) { this.startGracePeriod(); } | |
| 10528 | + } | |
| 10529 | + this.rememberSelection(); | |
| 10530 | + }; | |
| 10531 | + | |
| 10532 | + ContentEditableInput.prototype.startGracePeriod = function () { | |
| 10533 | + var this$1 = this; | |
| 10534 | + | |
| 10535 | + clearTimeout(this.gracePeriod); | |
| 10536 | + this.gracePeriod = setTimeout(function () { | |
| 10537 | + this$1.gracePeriod = false; | |
| 10538 | + if (this$1.selectionChanged()) | |
| 10539 | + { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }); } | |
| 10540 | + }, 20); | |
| 10541 | + }; | |
| 10542 | + | |
| 10543 | + ContentEditableInput.prototype.showMultipleSelections = function (info) { | |
| 10544 | + removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors); | |
| 10545 | + removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection); | |
| 10546 | + }; | |
| 10547 | + | |
| 10548 | + ContentEditableInput.prototype.rememberSelection = function () { | |
| 10549 | + var sel = this.getSelection(); | |
| 10550 | + this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset; | |
| 10551 | + this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset; | |
| 10552 | + }; | |
| 10553 | + | |
| 10554 | + ContentEditableInput.prototype.selectionInEditor = function () { | |
| 10555 | + var sel = this.getSelection(); | |
| 10556 | + if (!sel.rangeCount) { return false } | |
| 10557 | + var node = sel.getRangeAt(0).commonAncestorContainer; | |
| 10558 | + return contains(this.div, node) | |
| 10559 | + }; | |
| 10560 | + | |
| 10561 | + ContentEditableInput.prototype.focus = function () { | |
| 10562 | + if (this.cm.options.readOnly != "nocursor") { | |
| 10563 | + if (!this.selectionInEditor() || activeElt() != this.div) | |
| 10564 | + { this.showSelection(this.prepareSelection(), true); } | |
| 10565 | + this.div.focus(); | |
| 10566 | + } | |
| 10567 | + }; | |
| 10568 | + ContentEditableInput.prototype.blur = function () { this.div.blur(); }; | |
| 10569 | + ContentEditableInput.prototype.getField = function () { return this.div }; | |
| 10570 | + | |
| 10571 | + ContentEditableInput.prototype.supportsTouch = function () { return true }; | |
| 10572 | + | |
| 10573 | + ContentEditableInput.prototype.receivedFocus = function () { | |
| 10574 | + var input = this; | |
| 10575 | + if (this.selectionInEditor()) | |
| 10576 | + { this.pollSelection(); } | |
| 10577 | + else | |
| 10578 | + { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }); } | |
| 10579 | + | |
| 10580 | + function poll() { | |
| 10581 | + if (input.cm.state.focused) { | |
| 10582 | + input.pollSelection(); | |
| 10583 | + input.polling.set(input.cm.options.pollInterval, poll); | |
| 10584 | + } | |
| 10585 | + } | |
| 10586 | + this.polling.set(this.cm.options.pollInterval, poll); | |
| 10587 | + }; | |
| 10588 | + | |
| 10589 | + ContentEditableInput.prototype.selectionChanged = function () { | |
| 10590 | + var sel = this.getSelection(); | |
| 10591 | + return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset || | |
| 10592 | + sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset | |
| 10593 | + }; | |
| 10594 | + | |
| 10595 | + ContentEditableInput.prototype.pollSelection = function () { | |
| 10596 | + if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return } | |
| 10597 | + var sel = this.getSelection(), cm = this.cm; | |
| 10598 | + // On Android Chrome (version 56, at least), backspacing into an | |
| 10599 | + // uneditable block element will put the cursor in that element, | |
| 10600 | + // and then, because it's not editable, hide the virtual keyboard. | |
| 10601 | + // Because Android doesn't allow us to actually detect backspace | |
| 10602 | + // presses in a sane way, this code checks for when that happens | |
| 10603 | + // and simulates a backspace press in this case. | |
| 10604 | + if (android && chrome && this.cm.display.gutterSpecs.length && isInGutter(sel.anchorNode)) { | |
| 10605 | + this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs}); | |
| 10606 | + this.blur(); | |
| 10607 | + this.focus(); | |
| 10608 | + return | |
| 10609 | + } | |
| 10610 | + if (this.composing) { return } | |
| 10611 | + this.rememberSelection(); | |
| 10612 | + var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset); | |
| 10613 | + var head = domToPos(cm, sel.focusNode, sel.focusOffset); | |
| 10614 | + if (anchor && head) { runInOp(cm, function () { | |
| 10615 | + setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll); | |
| 10616 | + if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true; } | |
| 10617 | + }); } | |
| 10618 | + }; | |
| 10619 | + | |
| 10620 | + ContentEditableInput.prototype.pollContent = function () { | |
| 10621 | + if (this.readDOMTimeout != null) { | |
| 10622 | + clearTimeout(this.readDOMTimeout); | |
| 10623 | + this.readDOMTimeout = null; | |
| 10624 | + } | |
| 10625 | + | |
| 10626 | + var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary(); | |
| 10627 | + var from = sel.from(), to = sel.to(); | |
| 10628 | + if (from.ch == 0 && from.line > cm.firstLine()) | |
| 10629 | + { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length); } | |
| 10630 | + if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine()) | |
| 10631 | + { to = Pos(to.line + 1, 0); } | |
| 10632 | + if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false } | |
| 10633 | + | |
| 10634 | + var fromIndex, fromLine, fromNode; | |
| 10635 | + if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) { | |
| 10636 | + fromLine = lineNo(display.view[0].line); | |
| 10637 | + fromNode = display.view[0].node; | |
| 10638 | + } else { | |
| 10639 | + fromLine = lineNo(display.view[fromIndex].line); | |
| 10640 | + fromNode = display.view[fromIndex - 1].node.nextSibling; | |
| 10641 | + } | |
| 10642 | + var toIndex = findViewIndex(cm, to.line); | |
| 10643 | + var toLine, toNode; | |
| 10644 | + if (toIndex == display.view.length - 1) { | |
| 10645 | + toLine = display.viewTo - 1; | |
| 10646 | + toNode = display.lineDiv.lastChild; | |
| 10647 | + } else { | |
| 10648 | + toLine = lineNo(display.view[toIndex + 1].line) - 1; | |
| 10649 | + toNode = display.view[toIndex + 1].node.previousSibling; | |
| 10650 | + } | |
| 10651 | + | |
| 10652 | + if (!fromNode) { return false } | |
| 10653 | + var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine)); | |
| 10654 | + var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length)); | |
| 10655 | + while (newText.length > 1 && oldText.length > 1) { | |
| 10656 | + if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; } | |
| 10657 | + else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; } | |
| 10658 | + else { break } | |
| 10659 | + } | |
| 10660 | + | |
| 10661 | + var cutFront = 0, cutEnd = 0; | |
| 10662 | + var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length); | |
| 10663 | + while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront)) | |
| 10664 | + { ++cutFront; } | |
| 10665 | + var newBot = lst(newText), oldBot = lst(oldText); | |
| 10666 | + var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0), | |
| 10667 | + oldBot.length - (oldText.length == 1 ? cutFront : 0)); | |
| 10668 | + while (cutEnd < maxCutEnd && | |
| 10669 | + newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) | |
| 10670 | + { ++cutEnd; } | |
| 10671 | + // Try to move start of change to start of selection if ambiguous | |
| 10672 | + if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) { | |
| 10673 | + while (cutFront && cutFront > from.ch && | |
| 10674 | + newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) { | |
| 10675 | + cutFront--; | |
| 10676 | + cutEnd++; | |
| 10677 | + } | |
| 10678 | + } | |
| 10679 | + | |
| 10680 | + newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, ""); | |
| 10681 | + newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, ""); | |
| 10682 | + | |
| 10683 | + var chFrom = Pos(fromLine, cutFront); | |
| 10684 | + var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0); | |
| 10685 | + if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) { | |
| 10686 | + replaceRange(cm.doc, newText, chFrom, chTo, "+input"); | |
| 10687 | + return true | |
| 10688 | + } | |
| 10689 | + }; | |
| 10690 | + | |
| 10691 | + ContentEditableInput.prototype.ensurePolled = function () { | |
| 10692 | + this.forceCompositionEnd(); | |
| 10693 | + }; | |
| 10694 | + ContentEditableInput.prototype.reset = function () { | |
| 10695 | + this.forceCompositionEnd(); | |
| 10696 | + }; | |
| 10697 | + ContentEditableInput.prototype.forceCompositionEnd = function () { | |
| 10698 | + if (!this.composing) { return } | |
| 10699 | + clearTimeout(this.readDOMTimeout); | |
| 10700 | + this.composing = null; | |
| 10701 | + this.updateFromDOM(); | |
| 10702 | + this.div.blur(); | |
| 10703 | + this.div.focus(); | |
| 10704 | + }; | |
| 10705 | + ContentEditableInput.prototype.readFromDOMSoon = function () { | |
| 10706 | + var this$1 = this; | |
| 10707 | + | |
| 10708 | + if (this.readDOMTimeout != null) { return } | |
| 10709 | + this.readDOMTimeout = setTimeout(function () { | |
| 10710 | + this$1.readDOMTimeout = null; | |
| 10711 | + if (this$1.composing) { | |
| 10712 | + if (this$1.composing.done) { this$1.composing = null; } | |
| 10713 | + else { return } | |
| 10714 | + } | |
| 10715 | + this$1.updateFromDOM(); | |
| 10716 | + }, 80); | |
| 10717 | + }; | |
| 10718 | + | |
| 10719 | + ContentEditableInput.prototype.updateFromDOM = function () { | |
| 10720 | + var this$1 = this; | |
| 10721 | + | |
| 10722 | + if (this.cm.isReadOnly() || !this.pollContent()) | |
| 10723 | + { runInOp(this.cm, function () { return regChange(this$1.cm); }); } | |
| 10724 | + }; | |
| 10725 | + | |
| 10726 | + ContentEditableInput.prototype.setUneditable = function (node) { | |
| 10727 | + node.contentEditable = "false"; | |
| 10728 | + }; | |
| 10729 | + | |
| 10730 | + ContentEditableInput.prototype.onKeyPress = function (e) { | |
| 10731 | + if (e.charCode == 0 || this.composing) { return } | |
| 10732 | + e.preventDefault(); | |
| 10733 | + if (!this.cm.isReadOnly()) | |
| 10734 | + { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); } | |
| 10735 | + }; | |
| 10736 | + | |
| 10737 | + ContentEditableInput.prototype.readOnlyChanged = function (val) { | |
| 10738 | + this.div.contentEditable = String(val != "nocursor"); | |
| 10739 | + }; | |
| 10740 | + | |
| 10741 | + ContentEditableInput.prototype.onContextMenu = function () {}; | |
| 10742 | + ContentEditableInput.prototype.resetPosition = function () {}; | |
| 10743 | + | |
| 10744 | + ContentEditableInput.prototype.needsContentAttribute = true; | |
| 10745 | + | |
| 10746 | + function posToDOM(cm, pos) { | |
| 10747 | + var view = findViewForLine(cm, pos.line); | |
| 10748 | + if (!view || view.hidden) { return null } | |
| 10749 | + var line = getLine(cm.doc, pos.line); | |
| 10750 | + var info = mapFromLineView(view, line, pos.line); | |
| 10751 | + | |
| 10752 | + var order = getOrder(line, cm.doc.direction), side = "left"; | |
| 10753 | + if (order) { | |
| 10754 | + var partPos = getBidiPartAt(order, pos.ch); | |
| 10755 | + side = partPos % 2 ? "right" : "left"; | |
| 10756 | + } | |
| 10757 | + var result = nodeAndOffsetInLineMap(info.map, pos.ch, side); | |
| 10758 | + result.offset = result.collapse == "right" ? result.end : result.start; | |
| 10759 | + return result | |
| 10760 | + } | |
| 10761 | + | |
| 10762 | + function isInGutter(node) { | |
| 10763 | + for (var scan = node; scan; scan = scan.parentNode) | |
| 10764 | + { if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } } | |
| 10765 | + return false | |
| 10766 | + } | |
| 10767 | + | |
| 10768 | + function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos } | |
| 10769 | + | |
| 10770 | + function domTextBetween(cm, from, to, fromLine, toLine) { | |
| 10771 | + var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false; | |
| 10772 | + function recognizeMarker(id) { return function (marker) { return marker.id == id; } } | |
| 10773 | + function close() { | |
| 10774 | + if (closing) { | |
| 10775 | + text += lineSep; | |
| 10776 | + if (extraLinebreak) { text += lineSep; } | |
| 10777 | + closing = extraLinebreak = false; | |
| 10778 | + } | |
| 10779 | + } | |
| 10780 | + function addText(str) { | |
| 10781 | + if (str) { | |
| 10782 | + close(); | |
| 10783 | + text += str; | |
| 10784 | + } | |
| 10785 | + } | |
| 10786 | + function walk(node) { | |
| 10787 | + if (node.nodeType == 1) { | |
| 10788 | + var cmText = node.getAttribute("cm-text"); | |
| 10789 | + if (cmText) { | |
| 10790 | + addText(cmText); | |
| 10791 | + return | |
| 10792 | + } | |
| 10793 | + var markerID = node.getAttribute("cm-marker"), range; | |
| 10794 | + if (markerID) { | |
| 10795 | + var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID)); | |
| 10796 | + if (found.length && (range = found[0].find(0))) | |
| 10797 | + { addText(getBetween(cm.doc, range.from, range.to).join(lineSep)); } | |
| 10798 | + return | |
| 10799 | + } | |
| 10800 | + if (node.getAttribute("contenteditable") == "false") { return } | |
| 10801 | + var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName); | |
| 10802 | + if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return } | |
| 10803 | + | |
| 10804 | + if (isBlock) { close(); } | |
| 10805 | + for (var i = 0; i < node.childNodes.length; i++) | |
| 10806 | + { walk(node.childNodes[i]); } | |
| 10807 | + | |
| 10808 | + if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true; } | |
| 10809 | + if (isBlock) { closing = true; } | |
| 10810 | + } else if (node.nodeType == 3) { | |
| 10811 | + addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " ")); | |
| 10812 | + } | |
| 10813 | + } | |
| 10814 | + for (;;) { | |
| 10815 | + walk(from); | |
| 10816 | + if (from == to) { break } | |
| 10817 | + from = from.nextSibling; | |
| 10818 | + extraLinebreak = false; | |
| 10819 | + } | |
| 10820 | + return text | |
| 10821 | + } | |
| 10822 | + | |
| 10823 | + function domToPos(cm, node, offset) { | |
| 10824 | + var lineNode; | |
| 10825 | + if (node == cm.display.lineDiv) { | |
| 10826 | + lineNode = cm.display.lineDiv.childNodes[offset]; | |
| 10827 | + if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) } | |
| 10828 | + node = null; offset = 0; | |
| 10829 | + } else { | |
| 10830 | + for (lineNode = node;; lineNode = lineNode.parentNode) { | |
| 10831 | + if (!lineNode || lineNode == cm.display.lineDiv) { return null } | |
| 10832 | + if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break } | |
| 10833 | + } | |
| 10834 | + } | |
| 10835 | + for (var i = 0; i < cm.display.view.length; i++) { | |
| 10836 | + var lineView = cm.display.view[i]; | |
| 10837 | + if (lineView.node == lineNode) | |
| 10838 | + { return locateNodeInLineView(lineView, node, offset) } | |
| 10839 | + } | |
| 10840 | + } | |
| 10841 | + | |
| 10842 | + function locateNodeInLineView(lineView, node, offset) { | |
| 10843 | + var wrapper = lineView.text.firstChild, bad = false; | |
| 10844 | + if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) } | |
| 10845 | + if (node == wrapper) { | |
| 10846 | + bad = true; | |
| 10847 | + node = wrapper.childNodes[offset]; | |
| 10848 | + offset = 0; | |
| 10849 | + if (!node) { | |
| 10850 | + var line = lineView.rest ? lst(lineView.rest) : lineView.line; | |
| 10851 | + return badPos(Pos(lineNo(line), line.text.length), bad) | |
| 10852 | + } | |
| 10853 | + } | |
| 10854 | + | |
| 10855 | + var textNode = node.nodeType == 3 ? node : null, topNode = node; | |
| 10856 | + if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) { | |
| 10857 | + textNode = node.firstChild; | |
| 10858 | + if (offset) { offset = textNode.nodeValue.length; } | |
| 10859 | + } | |
| 10860 | + while (topNode.parentNode != wrapper) { topNode = topNode.parentNode; } | |
| 10861 | + var measure = lineView.measure, maps = measure.maps; | |
| 10862 | + | |
| 10863 | + function find(textNode, topNode, offset) { | |
| 10864 | + for (var i = -1; i < (maps ? maps.length : 0); i++) { | |
| 10865 | + var map = i < 0 ? measure.map : maps[i]; | |
| 10866 | + for (var j = 0; j < map.length; j += 3) { | |
| 10867 | + var curNode = map[j + 2]; | |
| 10868 | + if (curNode == textNode || curNode == topNode) { | |
| 10869 | + var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]); | |
| 10870 | + var ch = map[j] + offset; | |
| 10871 | + if (offset < 0 || curNode != textNode) { ch = map[j + (offset ? 1 : 0)]; } | |
| 10872 | + return Pos(line, ch) | |
| 10873 | + } | |
| 10874 | + } | |
| 10875 | + } | |
| 10876 | + } | |
| 10877 | + var found = find(textNode, topNode, offset); | |
| 10878 | + if (found) { return badPos(found, bad) } | |
| 10879 | + | |
| 10880 | + // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems | |
| 10881 | + for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) { | |
| 10882 | + found = find(after, after.firstChild, 0); | |
| 10883 | + if (found) | |
| 10884 | + { return badPos(Pos(found.line, found.ch - dist), bad) } | |
| 10885 | + else | |
| 10886 | + { dist += after.textContent.length; } | |
| 10887 | + } | |
| 10888 | + for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) { | |
| 10889 | + found = find(before, before.firstChild, -1); | |
| 10890 | + if (found) | |
| 10891 | + { return badPos(Pos(found.line, found.ch + dist$1), bad) } | |
| 10892 | + else | |
| 10893 | + { dist$1 += before.textContent.length; } | |
| 10894 | + } | |
| 10895 | + } | |
| 10896 | + | |
| 10897 | + // TEXTAREA INPUT STYLE | |
| 10898 | + | |
| 10899 | + var TextareaInput = function(cm) { | |
| 10900 | + this.cm = cm; | |
| 10901 | + // See input.poll and input.reset | |
| 10902 | + this.prevInput = ""; | |
| 10903 | + | |
| 10904 | + // Flag that indicates whether we expect input to appear real soon | |
| 10905 | + // now (after some event like 'keypress' or 'input') and are | |
| 10906 | + // polling intensively. | |
| 10907 | + this.pollingFast = false; | |
| 10908 | + // Self-resetting timeout for the poller | |
| 10909 | + this.polling = new Delayed(); | |
| 10910 | + // Used to work around IE issue with selection being forgotten when focus moves away from textarea | |
| 10911 | + this.hasSelection = false; | |
| 10912 | + this.composing = null; | |
| 10913 | + }; | |
| 10914 | + | |
| 10915 | + TextareaInput.prototype.init = function (display) { | |
| 10916 | + var this$1 = this; | |
| 10917 | + | |
| 10918 | + var input = this, cm = this.cm; | |
| 10919 | + this.createField(display); | |
| 10920 | + var te = this.textarea; | |
| 10921 | + | |
| 10922 | + display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild); | |
| 10923 | + | |
| 10924 | + // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore) | |
| 10925 | + if (ios) { te.style.width = "0px"; } | |
| 10926 | + | |
| 10927 | + on(te, "input", function () { | |
| 10928 | + if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null; } | |
| 10929 | + input.poll(); | |
| 10930 | + }); | |
| 10931 | + | |
| 10932 | + on(te, "paste", function (e) { | |
| 10933 | + if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return } | |
| 10934 | + | |
| 10935 | + cm.state.pasteIncoming = +new Date; | |
| 10936 | + input.fastPoll(); | |
| 10937 | + }); | |
| 10938 | + | |
| 10939 | + function prepareCopyCut(e) { | |
| 10940 | + if (signalDOMEvent(cm, e)) { return } | |
| 10941 | + if (cm.somethingSelected()) { | |
| 10942 | + setLastCopied({lineWise: false, text: cm.getSelections()}); | |
| 10943 | + } else if (!cm.options.lineWiseCopyCut) { | |
| 10944 | + return | |
| 10945 | + } else { | |
| 10946 | + var ranges = copyableRanges(cm); | |
| 10947 | + setLastCopied({lineWise: true, text: ranges.text}); | |
| 10948 | + if (e.type == "cut") { | |
| 10949 | + cm.setSelections(ranges.ranges, null, sel_dontScroll); | |
| 10950 | + } else { | |
| 10951 | + input.prevInput = ""; | |
| 10952 | + te.value = ranges.text.join("\n"); | |
| 10953 | + selectInput(te); | |
| 10954 | + } | |
| 10955 | + } | |
| 10956 | + if (e.type == "cut") { cm.state.cutIncoming = +new Date; } | |
| 10957 | + } | |
| 10958 | + on(te, "cut", prepareCopyCut); | |
| 10959 | + on(te, "copy", prepareCopyCut); | |
| 10960 | + | |
| 10961 | + on(display.scroller, "paste", function (e) { | |
| 10962 | + if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return } | |
| 10963 | + if (!te.dispatchEvent) { | |
| 10964 | + cm.state.pasteIncoming = +new Date; | |
| 10965 | + input.focus(); | |
| 10966 | + return | |
| 10967 | + } | |
| 10968 | + | |
| 10969 | + // Pass the `paste` event to the textarea so it's handled by its event listener. | |
| 10970 | + var event = new Event("paste"); | |
| 10971 | + event.clipboardData = e.clipboardData; | |
| 10972 | + te.dispatchEvent(event); | |
| 10973 | + }); | |
| 10974 | + | |
| 10975 | + // Prevent normal selection in the editor (we handle our own) | |
| 10976 | + on(display.lineSpace, "selectstart", function (e) { | |
| 10977 | + if (!eventInWidget(display, e)) { e_preventDefault(e); } | |
| 10978 | + }); | |
| 10979 | + | |
| 10980 | + on(te, "compositionstart", function () { | |
| 10981 | + var start = cm.getCursor("from"); | |
| 10982 | + if (input.composing) { input.composing.range.clear(); } | |
| 10983 | + input.composing = { | |
| 10984 | + start: start, | |
| 10985 | + range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"}) | |
| 10986 | + }; | |
| 10987 | + }); | |
| 10988 | + on(te, "compositionend", function () { | |
| 10989 | + if (input.composing) { | |
| 10990 | + input.poll(); | |
| 10991 | + input.composing.range.clear(); | |
| 10992 | + input.composing = null; | |
| 10993 | + } | |
| 10994 | + }); | |
| 10995 | + }; | |
| 10996 | + | |
| 10997 | + TextareaInput.prototype.createField = function (_display) { | |
| 10998 | + // Wraps and hides input textarea | |
| 10999 | + this.wrapper = hiddenTextarea(); | |
| 11000 | + // The semihidden textarea that is focused when the editor is | |
| 11001 | + // focused, and receives input. | |
| 11002 | + this.textarea = this.wrapper.firstChild; | |
| 11003 | + }; | |
| 11004 | + | |
| 11005 | + TextareaInput.prototype.screenReaderLabelChanged = function (label) { | |
| 11006 | + // Label for screenreaders, accessibility | |
| 11007 | + if(label) { | |
| 11008 | + this.textarea.setAttribute('aria-label', label); | |
| 11009 | + } else { | |
| 11010 | + this.textarea.removeAttribute('aria-label'); | |
| 11011 | + } | |
| 11012 | + }; | |
| 11013 | + | |
| 11014 | + TextareaInput.prototype.prepareSelection = function () { | |
| 11015 | + // Redraw the selection and/or cursor | |
| 11016 | + var cm = this.cm, display = cm.display, doc = cm.doc; | |
| 11017 | + var result = prepareSelection(cm); | |
| 11018 | + | |
| 11019 | + // Move the hidden textarea near the cursor to prevent scrolling artifacts | |
| 11020 | + if (cm.options.moveInputWithCursor) { | |
| 11021 | + var headPos = cursorCoords(cm, doc.sel.primary().head, "div"); | |
| 11022 | + var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect(); | |
| 11023 | + result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10, | |
| 11024 | + headPos.top + lineOff.top - wrapOff.top)); | |
| 11025 | + result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10, | |
| 11026 | + headPos.left + lineOff.left - wrapOff.left)); | |
| 11027 | + } | |
| 11028 | + | |
| 11029 | + return result | |
| 11030 | + }; | |
| 11031 | + | |
| 11032 | + TextareaInput.prototype.showSelection = function (drawn) { | |
| 11033 | + var cm = this.cm, display = cm.display; | |
| 11034 | + removeChildrenAndAdd(display.cursorDiv, drawn.cursors); | |
| 11035 | + removeChildrenAndAdd(display.selectionDiv, drawn.selection); | |
| 11036 | + if (drawn.teTop != null) { | |
| 11037 | + this.wrapper.style.top = drawn.teTop + "px"; | |
| 11038 | + this.wrapper.style.left = drawn.teLeft + "px"; | |
| 11039 | + } | |
| 11040 | + }; | |
| 11041 | + | |
| 11042 | + // Reset the input to correspond to the selection (or to be empty, | |
| 11043 | + // when not typing and nothing is selected) | |
| 11044 | + TextareaInput.prototype.reset = function (typing) { | |
| 11045 | + if (this.contextMenuPending || this.composing) { return } | |
| 11046 | + var cm = this.cm; | |
| 11047 | + if (cm.somethingSelected()) { | |
| 11048 | + this.prevInput = ""; | |
| 11049 | + var content = cm.getSelection(); | |
| 11050 | + this.textarea.value = content; | |
| 11051 | + if (cm.state.focused) { selectInput(this.textarea); } | |
| 11052 | + if (ie && ie_version >= 9) { this.hasSelection = content; } | |
| 11053 | + } else if (!typing) { | |
| 11054 | + this.prevInput = this.textarea.value = ""; | |
| 11055 | + if (ie && ie_version >= 9) { this.hasSelection = null; } | |
| 11056 | + } | |
| 11057 | + }; | |
| 11058 | + | |
| 11059 | + TextareaInput.prototype.getField = function () { return this.textarea }; | |
| 11060 | + | |
| 11061 | + TextareaInput.prototype.supportsTouch = function () { return false }; | |
| 11062 | + | |
| 11063 | + TextareaInput.prototype.focus = function () { | |
| 11064 | + if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) { | |
| 11065 | + try { this.textarea.focus(); } | |
| 11066 | + catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM | |
| 11067 | + } | |
| 11068 | + }; | |
| 11069 | + | |
| 11070 | + TextareaInput.prototype.blur = function () { this.textarea.blur(); }; | |
| 11071 | + | |
| 11072 | + TextareaInput.prototype.resetPosition = function () { | |
| 11073 | + this.wrapper.style.top = this.wrapper.style.left = 0; | |
| 11074 | + }; | |
| 11075 | + | |
| 11076 | + TextareaInput.prototype.receivedFocus = function () { this.slowPoll(); }; | |
| 11077 | + | |
| 11078 | + // Poll for input changes, using the normal rate of polling. This | |
| 11079 | + // runs as long as the editor is focused. | |
| 11080 | + TextareaInput.prototype.slowPoll = function () { | |
| 11081 | + var this$1 = this; | |
| 11082 | + | |
| 11083 | + if (this.pollingFast) { return } | |
| 11084 | + this.polling.set(this.cm.options.pollInterval, function () { | |
| 11085 | + this$1.poll(); | |
| 11086 | + if (this$1.cm.state.focused) { this$1.slowPoll(); } | |
| 11087 | + }); | |
| 11088 | + }; | |
| 11089 | + | |
| 11090 | + // When an event has just come in that is likely to add or change | |
| 11091 | + // something in the input textarea, we poll faster, to ensure that | |
| 11092 | + // the change appears on the screen quickly. | |
| 11093 | + TextareaInput.prototype.fastPoll = function () { | |
| 11094 | + var missed = false, input = this; | |
| 11095 | + input.pollingFast = true; | |
| 11096 | + function p() { | |
| 11097 | + var changed = input.poll(); | |
| 11098 | + if (!changed && !missed) {missed = true; input.polling.set(60, p);} | |
| 11099 | + else {input.pollingFast = false; input.slowPoll();} | |
| 11100 | + } | |
| 11101 | + input.polling.set(20, p); | |
| 11102 | + }; | |
| 11103 | + | |
| 11104 | + // Read input from the textarea, and update the document to match. | |
| 11105 | + // When something is selected, it is present in the textarea, and | |
| 11106 | + // selected (unless it is huge, in which case a placeholder is | |
| 11107 | + // used). When nothing is selected, the cursor sits after previously | |
| 11108 | + // seen text (can be empty), which is stored in prevInput (we must | |
| 11109 | + // not reset the textarea when typing, because that breaks IME). | |
| 11110 | + TextareaInput.prototype.poll = function () { | |
| 11111 | + var this$1 = this; | |
| 11112 | + | |
| 11113 | + var cm = this.cm, input = this.textarea, prevInput = this.prevInput; | |
| 11114 | + // Since this is called a *lot*, try to bail out as cheaply as | |
| 11115 | + // possible when it is clear that nothing happened. hasSelection | |
| 11116 | + // will be the case when there is a lot of text in the textarea, | |
| 11117 | + // in which case reading its value would be expensive. | |
| 11118 | + if (this.contextMenuPending || !cm.state.focused || | |
| 11119 | + (hasSelection(input) && !prevInput && !this.composing) || | |
| 11120 | + cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq) | |
| 11121 | + { return false } | |
| 11122 | + | |
| 11123 | + var text = input.value; | |
| 11124 | + // If nothing changed, bail. | |
| 11125 | + if (text == prevInput && !cm.somethingSelected()) { return false } | |
| 11126 | + // Work around nonsensical selection resetting in IE9/10, and | |
| 11127 | + // inexplicable appearance of private area unicode characters on | |
| 11128 | + // some key combos in Mac (#2689). | |
| 11129 | + if (ie && ie_version >= 9 && this.hasSelection === text || | |
| 11130 | + mac && /[\uf700-\uf7ff]/.test(text)) { | |
| 11131 | + cm.display.input.reset(); | |
| 11132 | + return false | |
| 11133 | + } | |
| 11134 | + | |
| 11135 | + if (cm.doc.sel == cm.display.selForContextMenu) { | |
| 11136 | + var first = text.charCodeAt(0); | |
| 11137 | + if (first == 0x200b && !prevInput) { prevInput = "\u200b"; } | |
| 11138 | + if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") } | |
| 11139 | + } | |
| 11140 | + // Find the part of the input that is actually new | |
| 11141 | + var same = 0, l = Math.min(prevInput.length, text.length); | |
| 11142 | + while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same; } | |
| 11143 | + | |
| 11144 | + runInOp(cm, function () { | |
| 11145 | + applyTextInput(cm, text.slice(same), prevInput.length - same, | |
| 11146 | + null, this$1.composing ? "*compose" : null); | |
| 11147 | + | |
| 11148 | + // Don't leave long text in the textarea, since it makes further polling slow | |
| 11149 | + if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = ""; } | |
| 11150 | + else { this$1.prevInput = text; } | |
| 11151 | + | |
| 11152 | + if (this$1.composing) { | |
| 11153 | + this$1.composing.range.clear(); | |
| 11154 | + this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"), | |
| 11155 | + {className: "CodeMirror-composing"}); | |
| 11156 | + } | |
| 11157 | + }); | |
| 11158 | + return true | |
| 11159 | + }; | |
| 11160 | + | |
| 11161 | + TextareaInput.prototype.ensurePolled = function () { | |
| 11162 | + if (this.pollingFast && this.poll()) { this.pollingFast = false; } | |
| 11163 | + }; | |
| 11164 | + | |
| 11165 | + TextareaInput.prototype.onKeyPress = function () { | |
| 11166 | + if (ie && ie_version >= 9) { this.hasSelection = null; } | |
| 11167 | + this.fastPoll(); | |
| 11168 | + }; | |
| 11169 | + | |
| 11170 | + TextareaInput.prototype.onContextMenu = function (e) { | |
| 11171 | + var input = this, cm = input.cm, display = cm.display, te = input.textarea; | |
| 11172 | + if (input.contextMenuPending) { input.contextMenuPending(); } | |
| 11173 | + var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop; | |
| 11174 | + if (!pos || presto) { return } // Opera is difficult. | |
| 11175 | + | |
| 11176 | + // Reset the current text selection only if the click is done outside of the selection | |
| 11177 | + // and 'resetSelectionOnContextMenu' option is true. | |
| 11178 | + var reset = cm.options.resetSelectionOnContextMenu; | |
| 11179 | + if (reset && cm.doc.sel.contains(pos) == -1) | |
| 11180 | + { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); } | |
| 11181 | + | |
| 11182 | + var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText; | |
| 11183 | + var wrapperBox = input.wrapper.offsetParent.getBoundingClientRect(); | |
| 11184 | + input.wrapper.style.cssText = "position: static"; | |
| 11185 | + te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);"; | |
| 11186 | + var oldScrollY; | |
| 11187 | + if (webkit) { oldScrollY = window.scrollY; } // Work around Chrome issue (#2712) | |
| 11188 | + display.input.focus(); | |
| 11189 | + if (webkit) { window.scrollTo(null, oldScrollY); } | |
| 11190 | + display.input.reset(); | |
| 11191 | + // Adds "Select all" to context menu in FF | |
| 11192 | + if (!cm.somethingSelected()) { te.value = input.prevInput = " "; } | |
| 11193 | + input.contextMenuPending = rehide; | |
| 11194 | + display.selForContextMenu = cm.doc.sel; | |
| 11195 | + clearTimeout(display.detectingSelectAll); | |
| 11196 | + | |
| 11197 | + // Select-all will be greyed out if there's nothing to select, so | |
| 11198 | + // this adds a zero-width space so that we can later check whether | |
| 11199 | + // it got selected. | |
| 11200 | + function prepareSelectAllHack() { | |
| 11201 | + if (te.selectionStart != null) { | |
| 11202 | + var selected = cm.somethingSelected(); | |
| 11203 | + var extval = "\u200b" + (selected ? te.value : ""); | |
| 11204 | + te.value = "\u21da"; // Used to catch context-menu undo | |
| 11205 | + te.value = extval; | |
| 11206 | + input.prevInput = selected ? "" : "\u200b"; | |
| 11207 | + te.selectionStart = 1; te.selectionEnd = extval.length; | |
| 11208 | + // Re-set this, in case some other handler touched the | |
| 11209 | + // selection in the meantime. | |
| 11210 | + display.selForContextMenu = cm.doc.sel; | |
| 11211 | + } | |
| 11212 | + } | |
| 11213 | + function rehide() { | |
| 11214 | + if (input.contextMenuPending != rehide) { return } | |
| 11215 | + input.contextMenuPending = false; | |
| 11216 | + input.wrapper.style.cssText = oldWrapperCSS; | |
| 11217 | + te.style.cssText = oldCSS; | |
| 11218 | + if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos); } | |
| 11219 | + | |
| 11220 | + // Try to detect the user choosing select-all | |
| 11221 | + if (te.selectionStart != null) { | |
| 11222 | + if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack(); } | |
| 11223 | + var i = 0, poll = function () { | |
| 11224 | + if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 && | |
| 11225 | + te.selectionEnd > 0 && input.prevInput == "\u200b") { | |
| 11226 | + operation(cm, selectAll)(cm); | |
| 11227 | + } else if (i++ < 10) { | |
| 11228 | + display.detectingSelectAll = setTimeout(poll, 500); | |
| 11229 | + } else { | |
| 11230 | + display.selForContextMenu = null; | |
| 11231 | + display.input.reset(); | |
| 11232 | + } | |
| 11233 | + }; | |
| 11234 | + display.detectingSelectAll = setTimeout(poll, 200); | |
| 11235 | + } | |
| 11236 | + } | |
| 11237 | + | |
| 11238 | + if (ie && ie_version >= 9) { prepareSelectAllHack(); } | |
| 11239 | + if (captureRightClick) { | |
| 11240 | + e_stop(e); | |
| 11241 | + var mouseup = function () { | |
| 11242 | + off(window, "mouseup", mouseup); | |
| 11243 | + setTimeout(rehide, 20); | |
| 11244 | + }; | |
| 11245 | + on(window, "mouseup", mouseup); | |
| 11246 | + } else { | |
| 11247 | + setTimeout(rehide, 50); | |
| 11248 | + } | |
| 11249 | + }; | |
| 11250 | + | |
| 11251 | + TextareaInput.prototype.readOnlyChanged = function (val) { | |
| 11252 | + if (!val) { this.reset(); } | |
| 11253 | + this.textarea.disabled = val == "nocursor"; | |
| 11254 | + this.textarea.readOnly = !!val; | |
| 11255 | + }; | |
| 11256 | + | |
| 11257 | + TextareaInput.prototype.setUneditable = function () {}; | |
| 11258 | + | |
| 11259 | + TextareaInput.prototype.needsContentAttribute = false; | |
| 11260 | + | |
| 11261 | + function fromTextArea(textarea, options) { | |
| 11262 | + options = options ? copyObj(options) : {}; | |
| 11263 | + options.value = textarea.value; | |
| 11264 | + if (!options.tabindex && textarea.tabIndex) | |
| 11265 | + { options.tabindex = textarea.tabIndex; } | |
| 11266 | + if (!options.placeholder && textarea.placeholder) | |
| 11267 | + { options.placeholder = textarea.placeholder; } | |
| 11268 | + // Set autofocus to true if this textarea is focused, or if it has | |
| 11269 | + // autofocus and no other element is focused. | |
| 11270 | + if (options.autofocus == null) { | |
| 11271 | + var hasFocus = activeElt(); | |
| 11272 | + options.autofocus = hasFocus == textarea || | |
| 11273 | + textarea.getAttribute("autofocus") != null && hasFocus == document.body; | |
| 11274 | + } | |
| 11275 | + | |
| 11276 | + function save() {textarea.value = cm.getValue();} | |
| 11277 | + | |
| 11278 | + var realSubmit; | |
| 11279 | + if (textarea.form) { | |
| 11280 | + on(textarea.form, "submit", save); | |
| 11281 | + // Deplorable hack to make the submit method do the right thing. | |
| 11282 | + if (!options.leaveSubmitMethodAlone) { | |
| 11283 | + var form = textarea.form; | |
| 11284 | + realSubmit = form.submit; | |
| 11285 | + try { | |
| 11286 | + var wrappedSubmit = form.submit = function () { | |
| 11287 | + save(); | |
| 11288 | + form.submit = realSubmit; | |
| 11289 | + form.submit(); | |
| 11290 | + form.submit = wrappedSubmit; | |
| 11291 | + }; | |
| 11292 | + } catch(e) {} | |
| 11293 | + } | |
| 11294 | + } | |
| 11295 | + | |
| 11296 | + options.finishInit = function (cm) { | |
| 11297 | + cm.save = save; | |
| 11298 | + cm.getTextArea = function () { return textarea; }; | |
| 11299 | + cm.toTextArea = function () { | |
| 11300 | + cm.toTextArea = isNaN; // Prevent this from being ran twice | |
| 11301 | + save(); | |
| 11302 | + textarea.parentNode.removeChild(cm.getWrapperElement()); | |
| 11303 | + textarea.style.display = ""; | |
| 11304 | + if (textarea.form) { | |
| 11305 | + off(textarea.form, "submit", save); | |
| 11306 | + if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == "function") | |
| 11307 | + { textarea.form.submit = realSubmit; } | |
| 11308 | + } | |
| 11309 | + }; | |
| 11310 | + }; | |
| 11311 | + | |
| 11312 | + textarea.style.display = "none"; | |
| 11313 | + var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); }, | |
| 11314 | + options); | |
| 11315 | + return cm | |
| 11316 | + } | |
| 11317 | + | |
| 11318 | + function addLegacyProps(CodeMirror) { | |
| 11319 | + CodeMirror.off = off; | |
| 11320 | + CodeMirror.on = on; | |
| 11321 | + CodeMirror.wheelEventPixels = wheelEventPixels; | |
| 11322 | + CodeMirror.Doc = Doc; | |
| 11323 | + CodeMirror.splitLines = splitLinesAuto; | |
| 11324 | + CodeMirror.countColumn = countColumn; | |
| 11325 | + CodeMirror.findColumn = findColumn; | |
| 11326 | + CodeMirror.isWordChar = isWordCharBasic; | |
| 11327 | + CodeMirror.Pass = Pass; | |
| 11328 | + CodeMirror.signal = signal; | |
| 11329 | + CodeMirror.Line = Line; | |
| 11330 | + CodeMirror.changeEnd = changeEnd; | |
| 11331 | + CodeMirror.scrollbarModel = scrollbarModel; | |
| 11332 | + CodeMirror.Pos = Pos; | |
| 11333 | + CodeMirror.cmpPos = cmp; | |
| 11334 | + CodeMirror.modes = modes; | |
| 11335 | + CodeMirror.mimeModes = mimeModes; | |
| 11336 | + CodeMirror.resolveMode = resolveMode; | |
| 11337 | + CodeMirror.getMode = getMode; | |
| 11338 | + CodeMirror.modeExtensions = modeExtensions; | |
| 11339 | + CodeMirror.extendMode = extendMode; | |
| 11340 | + CodeMirror.copyState = copyState; | |
| 11341 | + CodeMirror.startState = startState; | |
| 11342 | + CodeMirror.innerMode = innerMode; | |
| 11343 | + CodeMirror.commands = commands; | |
| 11344 | + CodeMirror.keyMap = keyMap; | |
| 11345 | + CodeMirror.keyName = keyName; | |
| 11346 | + CodeMirror.isModifierKey = isModifierKey; | |
| 11347 | + CodeMirror.lookupKey = lookupKey; | |
| 11348 | + CodeMirror.normalizeKeyMap = normalizeKeyMap; | |
| 11349 | + CodeMirror.StringStream = StringStream; | |
| 11350 | + CodeMirror.SharedTextMarker = SharedTextMarker; | |
| 11351 | + CodeMirror.TextMarker = TextMarker; | |
| 11352 | + CodeMirror.LineWidget = LineWidget; | |
| 11353 | + CodeMirror.e_preventDefault = e_preventDefault; | |
| 11354 | + CodeMirror.e_stopPropagation = e_stopPropagation; | |
| 11355 | + CodeMirror.e_stop = e_stop; | |
| 11356 | + CodeMirror.addClass = addClass; | |
| 11357 | + CodeMirror.contains = contains; | |
| 11358 | + CodeMirror.rmClass = rmClass; | |
| 11359 | + CodeMirror.keyNames = keyNames; | |
| 11360 | + } | |
| 11361 | + | |
| 11362 | + // EDITOR CONSTRUCTOR | |
| 11363 | + | |
| 11364 | + defineOptions(CodeMirror); | |
| 11365 | + | |
| 11366 | + addEditorMethods(CodeMirror); | |
| 11367 | + | |
| 11368 | + // Set up methods on CodeMirror's prototype to redirect to the editor's document. | |
| 11369 | + var dontDelegate = "iter insert remove copy getEditor constructor".split(" "); | |
| 11370 | + for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0) | |
| 11371 | + { CodeMirror.prototype[prop] = (function(method) { | |
| 11372 | + return function() {return method.apply(this.doc, arguments)} | |
| 11373 | + })(Doc.prototype[prop]); } } | |
| 11374 | + | |
| 11375 | + eventMixin(Doc); | |
| 11376 | + CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}; | |
| 11377 | + | |
| 11378 | + // Extra arguments are stored as the mode's dependencies, which is | |
| 11379 | + // used by (legacy) mechanisms like loadmode.js to automatically | |
| 11380 | + // load a mode. (Preferred mechanism is the require/define calls.) | |
| 11381 | + CodeMirror.defineMode = function(name/*, mode, …*/) { | |
| 11382 | + if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name; } | |
| 11383 | + defineMode.apply(this, arguments); | |
| 11384 | + }; | |
| 11385 | + | |
| 11386 | + CodeMirror.defineMIME = defineMIME; | |
| 11387 | + | |
| 11388 | + // Minimal default mode. | |
| 11389 | + CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); }); | |
| 11390 | + CodeMirror.defineMIME("text/plain", "null"); | |
| 11391 | + | |
| 11392 | + // EXTENSIONS | |
| 11393 | + | |
| 11394 | + CodeMirror.defineExtension = function (name, func) { | |
| 11395 | + CodeMirror.prototype[name] = func; | |
| 11396 | + }; | |
| 11397 | + CodeMirror.defineDocExtension = function (name, func) { | |
| 11398 | + Doc.prototype[name] = func; | |
| 11399 | + }; | |
| 11400 | + | |
| 11401 | + CodeMirror.fromTextArea = fromTextArea; | |
| 11402 | + | |
| 11403 | + addLegacyProps(CodeMirror); | |
| 11404 | + | |
| 11405 | + CodeMirror.version = "5.61.0"; | |
| 11406 | + | |
| 11407 | + return CodeMirror; | |
| 11408 | + | |
| 11409 | +}))); | |
| 11410 | + | |
| 11411 | +},{}],15:[function(require,module,exports){ | |
| 11412 | +// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
| 11413 | +// Distributed under an MIT license: https://codemirror.net/LICENSE | |
| 11414 | + | |
| 11415 | +(function(mod) { | |
| 11416 | + if (typeof exports == "object" && typeof module == "object") // CommonJS | |
| 11417 | + mod(require("../../lib/codemirror")); | |
| 11418 | + else if (typeof define == "function" && define.amd) // AMD | |
| 11419 | + define(["../../lib/codemirror"], mod); | |
| 11420 | + else // Plain browser env | |
| 11421 | + mod(CodeMirror); | |
| 11422 | +})(function(CodeMirror) { | |
| 11423 | +"use strict"; | |
| 11424 | + | |
| 11425 | +CodeMirror.defineMode("css", function(config, parserConfig) { | |
| 11426 | + var inline = parserConfig.inline | |
| 11427 | + if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css"); | |
| 11428 | + | |
| 11429 | + var indentUnit = config.indentUnit, | |
| 11430 | + tokenHooks = parserConfig.tokenHooks, | |
| 11431 | + documentTypes = parserConfig.documentTypes || {}, | |
| 11432 | + mediaTypes = parserConfig.mediaTypes || {}, | |
| 11433 | + mediaFeatures = parserConfig.mediaFeatures || {}, | |
| 11434 | + mediaValueKeywords = parserConfig.mediaValueKeywords || {}, | |
| 11435 | + propertyKeywords = parserConfig.propertyKeywords || {}, | |
| 11436 | + nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {}, | |
| 11437 | + fontProperties = parserConfig.fontProperties || {}, | |
| 11438 | + counterDescriptors = parserConfig.counterDescriptors || {}, | |
| 11439 | + colorKeywords = parserConfig.colorKeywords || {}, | |
| 11440 | + valueKeywords = parserConfig.valueKeywords || {}, | |
| 11441 | + allowNested = parserConfig.allowNested, | |
| 11442 | + lineComment = parserConfig.lineComment, | |
| 11443 | + supportsAtComponent = parserConfig.supportsAtComponent === true, | |
| 11444 | + highlightNonStandardPropertyKeywords = config.highlightNonStandardPropertyKeywords !== false; | |
| 11445 | + | |
| 11446 | + var type, override; | |
| 11447 | + function ret(style, tp) { type = tp; return style; } | |
| 11448 | + | |
| 11449 | + // Tokenizers | |
| 11450 | + | |
| 11451 | + function tokenBase(stream, state) { | |
| 11452 | + var ch = stream.next(); | |
| 11453 | + if (tokenHooks[ch]) { | |
| 11454 | + var result = tokenHooks[ch](stream, state); | |
| 11455 | + if (result !== false) return result; | |
| 11456 | + } | |
| 11457 | + if (ch == "@") { | |
| 11458 | + stream.eatWhile(/[\w\\\-]/); | |
| 11459 | + return ret("def", stream.current()); | |
| 11460 | + } else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) { | |
| 11461 | + return ret(null, "compare"); | |
| 11462 | + } else if (ch == "\"" || ch == "'") { | |
| 11463 | + state.tokenize = tokenString(ch); | |
| 11464 | + return state.tokenize(stream, state); | |
| 11465 | + } else if (ch == "#") { | |
| 11466 | + stream.eatWhile(/[\w\\\-]/); | |
| 11467 | + return ret("atom", "hash"); | |
| 11468 | + } else if (ch == "!") { | |
| 11469 | + stream.match(/^\s*\w*/); | |
| 11470 | + return ret("keyword", "important"); | |
| 11471 | + } else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) { | |
| 11472 | + stream.eatWhile(/[\w.%]/); | |
| 11473 | + return ret("number", "unit"); | |
| 11474 | + } else if (ch === "-") { | |
| 11475 | + if (/[\d.]/.test(stream.peek())) { | |
| 11476 | + stream.eatWhile(/[\w.%]/); | |
| 11477 | + return ret("number", "unit"); | |
| 11478 | + } else if (stream.match(/^-[\w\\\-]*/)) { | |
| 11479 | + stream.eatWhile(/[\w\\\-]/); | |
| 11480 | + if (stream.match(/^\s*:/, false)) | |
| 11481 | + return ret("variable-2", "variable-definition"); | |
| 11482 | + return ret("variable-2", "variable"); | |
| 11483 | + } else if (stream.match(/^\w+-/)) { | |
| 11484 | + return ret("meta", "meta"); | |
| 11485 | + } | |
| 11486 | + } else if (/[,+>*\/]/.test(ch)) { | |
| 11487 | + return ret(null, "select-op"); | |
| 11488 | + } else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) { | |
| 11489 | + return ret("qualifier", "qualifier"); | |
| 11490 | + } else if (/[:;{}\[\]\(\)]/.test(ch)) { | |
| 11491 | + return ret(null, ch); | |
| 11492 | + } else if (stream.match(/^[\w-.]+(?=\()/)) { | |
| 11493 | + if (/^(url(-prefix)?|domain|regexp)$/i.test(stream.current())) { | |
| 11494 | + state.tokenize = tokenParenthesized; | |
| 11495 | + } | |
| 11496 | + return ret("variable callee", "variable"); | |
| 11497 | + } else if (/[\w\\\-]/.test(ch)) { | |
| 11498 | + stream.eatWhile(/[\w\\\-]/); | |
| 11499 | + return ret("property", "word"); | |
| 11500 | + } else { | |
| 11501 | + return ret(null, null); | |
| 11502 | + } | |
| 11503 | + } | |
| 11504 | + | |
| 11505 | + function tokenString(quote) { | |
| 11506 | + return function(stream, state) { | |
| 11507 | + var escaped = false, ch; | |
| 11508 | + while ((ch = stream.next()) != null) { | |
| 11509 | + if (ch == quote && !escaped) { | |
| 11510 | + if (quote == ")") stream.backUp(1); | |
| 11511 | + break; | |
| 11512 | + } | |
| 11513 | + escaped = !escaped && ch == "\\"; | |
| 11514 | + } | |
| 11515 | + if (ch == quote || !escaped && quote != ")") state.tokenize = null; | |
| 11516 | + return ret("string", "string"); | |
| 11517 | + }; | |
| 11518 | + } | |
| 11519 | + | |
| 11520 | + function tokenParenthesized(stream, state) { | |
| 11521 | + stream.next(); // Must be '(' | |
| 11522 | + if (!stream.match(/^\s*[\"\')]/, false)) | |
| 11523 | + state.tokenize = tokenString(")"); | |
| 11524 | + else | |
| 11525 | + state.tokenize = null; | |
| 11526 | + return ret(null, "("); | |
| 11527 | + } | |
| 11528 | + | |
| 11529 | + // Context management | |
| 11530 | + | |
| 11531 | + function Context(type, indent, prev) { | |
| 11532 | + this.type = type; | |
| 11533 | + this.indent = indent; | |
| 11534 | + this.prev = prev; | |
| 11535 | + } | |
| 11536 | + | |
| 11537 | + function pushContext(state, stream, type, indent) { | |
| 11538 | + state.context = new Context(type, stream.indentation() + (indent === false ? 0 : indentUnit), state.context); | |
| 11539 | + return type; | |
| 11540 | + } | |
| 11541 | + | |
| 11542 | + function popContext(state) { | |
| 11543 | + if (state.context.prev) | |
| 11544 | + state.context = state.context.prev; | |
| 11545 | + return state.context.type; | |
| 11546 | + } | |
| 11547 | + | |
| 11548 | + function pass(type, stream, state) { | |
| 11549 | + return states[state.context.type](type, stream, state); | |
| 11550 | + } | |
| 11551 | + function popAndPass(type, stream, state, n) { | |
| 11552 | + for (var i = n || 1; i > 0; i--) | |
| 11553 | + state.context = state.context.prev; | |
| 11554 | + return pass(type, stream, state); | |
| 11555 | + } | |
| 11556 | + | |
| 11557 | + // Parser | |
| 11558 | + | |
| 11559 | + function wordAsValue(stream) { | |
| 11560 | + var word = stream.current().toLowerCase(); | |
| 11561 | + if (valueKeywords.hasOwnProperty(word)) | |
| 11562 | + override = "atom"; | |
| 11563 | + else if (colorKeywords.hasOwnProperty(word)) | |
| 11564 | + override = "keyword"; | |
| 11565 | + else | |
| 11566 | + override = "variable"; | |
| 11567 | + } | |
| 11568 | + | |
| 11569 | + var states = {}; | |
| 11570 | + | |
| 11571 | + states.top = function(type, stream, state) { | |
| 11572 | + if (type == "{") { | |
| 11573 | + return pushContext(state, stream, "block"); | |
| 11574 | + } else if (type == "}" && state.context.prev) { | |
| 11575 | + return popContext(state); | |
| 11576 | + } else if (supportsAtComponent && /@component/i.test(type)) { | |
| 11577 | + return pushContext(state, stream, "atComponentBlock"); | |
| 11578 | + } else if (/^@(-moz-)?document$/i.test(type)) { | |
| 11579 | + return pushContext(state, stream, "documentTypes"); | |
| 11580 | + } else if (/^@(media|supports|(-moz-)?document|import)$/i.test(type)) { | |
| 11581 | + return pushContext(state, stream, "atBlock"); | |
| 11582 | + } else if (/^@(font-face|counter-style)/i.test(type)) { | |
| 11583 | + state.stateArg = type; | |
| 11584 | + return "restricted_atBlock_before"; | |
| 11585 | + } else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/i.test(type)) { | |
| 11586 | + return "keyframes"; | |
| 11587 | + } else if (type && type.charAt(0) == "@") { | |
| 11588 | + return pushContext(state, stream, "at"); | |
| 11589 | + } else if (type == "hash") { | |
| 11590 | + override = "builtin"; | |
| 11591 | + } else if (type == "word") { | |
| 11592 | + override = "tag"; | |
| 11593 | + } else if (type == "variable-definition") { | |
| 11594 | + return "maybeprop"; | |
| 11595 | + } else if (type == "interpolation") { | |
| 11596 | + return pushContext(state, stream, "interpolation"); | |
| 11597 | + } else if (type == ":") { | |
| 11598 | + return "pseudo"; | |
| 11599 | + } else if (allowNested && type == "(") { | |
| 11600 | + return pushContext(state, stream, "parens"); | |
| 11601 | + } | |
| 11602 | + return state.context.type; | |
| 11603 | + }; | |
| 11604 | + | |
| 11605 | + states.block = function(type, stream, state) { | |
| 11606 | + if (type == "word") { | |
| 11607 | + var word = stream.current().toLowerCase(); | |
| 11608 | + if (propertyKeywords.hasOwnProperty(word)) { | |
| 11609 | + override = "property"; | |
| 11610 | + return "maybeprop"; | |
| 11611 | + } else if (nonStandardPropertyKeywords.hasOwnProperty(word)) { | |
| 11612 | + override = highlightNonStandardPropertyKeywords ? "string-2" : "property"; | |
| 11613 | + return "maybeprop"; | |
| 11614 | + } else if (allowNested) { | |
| 11615 | + override = stream.match(/^\s*:(?:\s|$)/, false) ? "property" : "tag"; | |
| 11616 | + return "block"; | |
| 11617 | + } else { | |
| 11618 | + override += " error"; | |
| 11619 | + return "maybeprop"; | |
| 11620 | + } | |
| 11621 | + } else if (type == "meta") { | |
| 11622 | + return "block"; | |
| 11623 | + } else if (!allowNested && (type == "hash" || type == "qualifier")) { | |
| 11624 | + override = "error"; | |
| 11625 | + return "block"; | |
| 11626 | + } else { | |
| 11627 | + return states.top(type, stream, state); | |
| 11628 | + } | |
| 11629 | + }; | |
| 11630 | + | |
| 11631 | + states.maybeprop = function(type, stream, state) { | |
| 11632 | + if (type == ":") return pushContext(state, stream, "prop"); | |
| 11633 | + return pass(type, stream, state); | |
| 11634 | + }; | |
| 11635 | + | |
| 11636 | + states.prop = function(type, stream, state) { | |
| 11637 | + if (type == ";") return popContext(state); | |
| 11638 | + if (type == "{" && allowNested) return pushContext(state, stream, "propBlock"); | |
| 11639 | + if (type == "}" || type == "{") return popAndPass(type, stream, state); | |
| 11640 | + if (type == "(") return pushContext(state, stream, "parens"); | |
| 11641 | + | |
| 11642 | + if (type == "hash" && !/^#([0-9a-fA-f]{3,4}|[0-9a-fA-f]{6}|[0-9a-fA-f]{8})$/.test(stream.current())) { | |
| 11643 | + override += " error"; | |
| 11644 | + } else if (type == "word") { | |
| 11645 | + wordAsValue(stream); | |
| 11646 | + } else if (type == "interpolation") { | |
| 11647 | + return pushContext(state, stream, "interpolation"); | |
| 11648 | + } | |
| 11649 | + return "prop"; | |
| 11650 | + }; | |
| 11651 | + | |
| 11652 | + states.propBlock = function(type, _stream, state) { | |
| 11653 | + if (type == "}") return popContext(state); | |
| 11654 | + if (type == "word") { override = "property"; return "maybeprop"; } | |
| 11655 | + return state.context.type; | |
| 11656 | + }; | |
| 11657 | + | |
| 11658 | + states.parens = function(type, stream, state) { | |
| 11659 | + if (type == "{" || type == "}") return popAndPass(type, stream, state); | |
| 11660 | + if (type == ")") return popContext(state); | |
| 11661 | + if (type == "(") return pushContext(state, stream, "parens"); | |
| 11662 | + if (type == "interpolation") return pushContext(state, stream, "interpolation"); | |
| 11663 | + if (type == "word") wordAsValue(stream); | |
| 11664 | + return "parens"; | |
| 11665 | + }; | |
| 11666 | + | |
| 11667 | + states.pseudo = function(type, stream, state) { | |
| 11668 | + if (type == "meta") return "pseudo"; | |
| 11669 | + | |
| 11670 | + if (type == "word") { | |
| 11671 | + override = "variable-3"; | |
| 11672 | + return state.context.type; | |
| 11673 | + } | |
| 11674 | + return pass(type, stream, state); | |
| 11675 | + }; | |
| 11676 | + | |
| 11677 | + states.documentTypes = function(type, stream, state) { | |
| 11678 | + if (type == "word" && documentTypes.hasOwnProperty(stream.current())) { | |
| 11679 | + override = "tag"; | |
| 11680 | + return state.context.type; | |
| 11681 | + } else { | |
| 11682 | + return states.atBlock(type, stream, state); | |
| 11683 | + } | |
| 11684 | + }; | |
| 11685 | + | |
| 11686 | + states.atBlock = function(type, stream, state) { | |
| 11687 | + if (type == "(") return pushContext(state, stream, "atBlock_parens"); | |
| 11688 | + if (type == "}" || type == ";") return popAndPass(type, stream, state); | |
| 11689 | + if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top"); | |
| 11690 | + | |
| 11691 | + if (type == "interpolation") return pushContext(state, stream, "interpolation"); | |
| 11692 | + | |
| 11693 | + if (type == "word") { | |
| 11694 | + var word = stream.current().toLowerCase(); | |
| 11695 | + if (word == "only" || word == "not" || word == "and" || word == "or") | |
| 11696 | + override = "keyword"; | |
| 11697 | + else if (mediaTypes.hasOwnProperty(word)) | |
| 11698 | + override = "attribute"; | |
| 11699 | + else if (mediaFeatures.hasOwnProperty(word)) | |
| 11700 | + override = "property"; | |
| 11701 | + else if (mediaValueKeywords.hasOwnProperty(word)) | |
| 11702 | + override = "keyword"; | |
| 11703 | + else if (propertyKeywords.hasOwnProperty(word)) | |
| 11704 | + override = "property"; | |
| 11705 | + else if (nonStandardPropertyKeywords.hasOwnProperty(word)) | |
| 11706 | + override = highlightNonStandardPropertyKeywords ? "string-2" : "property"; | |
| 11707 | + else if (valueKeywords.hasOwnProperty(word)) | |
| 11708 | + override = "atom"; | |
| 11709 | + else if (colorKeywords.hasOwnProperty(word)) | |
| 11710 | + override = "keyword"; | |
| 11711 | + else | |
| 11712 | + override = "error"; | |
| 11713 | + } | |
| 11714 | + return state.context.type; | |
| 11715 | + }; | |
| 11716 | + | |
| 11717 | + states.atComponentBlock = function(type, stream, state) { | |
| 11718 | + if (type == "}") | |
| 11719 | + return popAndPass(type, stream, state); | |
| 11720 | + if (type == "{") | |
| 11721 | + return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top", false); | |
| 11722 | + if (type == "word") | |
| 11723 | + override = "error"; | |
| 11724 | + return state.context.type; | |
| 11725 | + }; | |
| 11726 | + | |
| 11727 | + states.atBlock_parens = function(type, stream, state) { | |
| 11728 | + if (type == ")") return popContext(state); | |
| 11729 | + if (type == "{" || type == "}") return popAndPass(type, stream, state, 2); | |
| 11730 | + return states.atBlock(type, stream, state); | |
| 11731 | + }; | |
| 11732 | + | |
| 11733 | + states.restricted_atBlock_before = function(type, stream, state) { | |
| 11734 | + if (type == "{") | |
| 11735 | + return pushContext(state, stream, "restricted_atBlock"); | |
| 11736 | + if (type == "word" && state.stateArg == "@counter-style") { | |
| 11737 | + override = "variable"; | |
| 11738 | + return "restricted_atBlock_before"; | |
| 11739 | + } | |
| 11740 | + return pass(type, stream, state); | |
| 11741 | + }; | |
| 11742 | + | |
| 11743 | + states.restricted_atBlock = function(type, stream, state) { | |
| 11744 | + if (type == "}") { | |
| 11745 | + state.stateArg = null; | |
| 11746 | + return popContext(state); | |
| 11747 | + } | |
| 11748 | + if (type == "word") { | |
| 11749 | + if ((state.stateArg == "@font-face" && !fontProperties.hasOwnProperty(stream.current().toLowerCase())) || | |
| 11750 | + (state.stateArg == "@counter-style" && !counterDescriptors.hasOwnProperty(stream.current().toLowerCase()))) | |
| 11751 | + override = "error"; | |
| 11752 | + else | |
| 11753 | + override = "property"; | |
| 11754 | + return "maybeprop"; | |
| 11755 | + } | |
| 11756 | + return "restricted_atBlock"; | |
| 11757 | + }; | |
| 11758 | + | |
| 11759 | + states.keyframes = function(type, stream, state) { | |
| 11760 | + if (type == "word") { override = "variable"; return "keyframes"; } | |
| 11761 | + if (type == "{") return pushContext(state, stream, "top"); | |
| 11762 | + return pass(type, stream, state); | |
| 11763 | + }; | |
| 11764 | + | |
| 11765 | + states.at = function(type, stream, state) { | |
| 11766 | + if (type == ";") return popContext(state); | |
| 11767 | + if (type == "{" || type == "}") return popAndPass(type, stream, state); | |
| 11768 | + if (type == "word") override = "tag"; | |
| 11769 | + else if (type == "hash") override = "builtin"; | |
| 11770 | + return "at"; | |
| 11771 | + }; | |
| 11772 | + | |
| 11773 | + states.interpolation = function(type, stream, state) { | |
| 11774 | + if (type == "}") return popContext(state); | |
| 11775 | + if (type == "{" || type == ";") return popAndPass(type, stream, state); | |
| 11776 | + if (type == "word") override = "variable"; | |
| 11777 | + else if (type != "variable" && type != "(" && type != ")") override = "error"; | |
| 11778 | + return "interpolation"; | |
| 11779 | + }; | |
| 11780 | + | |
| 11781 | + return { | |
| 11782 | + startState: function(base) { | |
| 11783 | + return {tokenize: null, | |
| 11784 | + state: inline ? "block" : "top", | |
| 11785 | + stateArg: null, | |
| 11786 | + context: new Context(inline ? "block" : "top", base || 0, null)}; | |
| 11787 | + }, | |
| 11788 | + | |
| 11789 | + token: function(stream, state) { | |
| 11790 | + if (!state.tokenize && stream.eatSpace()) return null; | |
| 11791 | + var style = (state.tokenize || tokenBase)(stream, state); | |
| 11792 | + if (style && typeof style == "object") { | |
| 11793 | + type = style[1]; | |
| 11794 | + style = style[0]; | |
| 11795 | + } | |
| 11796 | + override = style; | |
| 11797 | + if (type != "comment") | |
| 11798 | + state.state = states[state.state](type, stream, state); | |
| 11799 | + return override; | |
| 11800 | + }, | |
| 11801 | + | |
| 11802 | + indent: function(state, textAfter) { | |
| 11803 | + var cx = state.context, ch = textAfter && textAfter.charAt(0); | |
| 11804 | + var indent = cx.indent; | |
| 11805 | + if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev; | |
| 11806 | + if (cx.prev) { | |
| 11807 | + if (ch == "}" && (cx.type == "block" || cx.type == "top" || | |
| 11808 | + cx.type == "interpolation" || cx.type == "restricted_atBlock")) { | |
| 11809 | + // Resume indentation from parent context. | |
| 11810 | + cx = cx.prev; | |
| 11811 | + indent = cx.indent; | |
| 11812 | + } else if (ch == ")" && (cx.type == "parens" || cx.type == "atBlock_parens") || | |
| 11813 | + ch == "{" && (cx.type == "at" || cx.type == "atBlock")) { | |
| 11814 | + // Dedent relative to current context. | |
| 11815 | + indent = Math.max(0, cx.indent - indentUnit); | |
| 11816 | + } | |
| 11817 | + } | |
| 11818 | + return indent; | |
| 11819 | + }, | |
| 11820 | + | |
| 11821 | + electricChars: "}", | |
| 11822 | + blockCommentStart: "/*", | |
| 11823 | + blockCommentEnd: "*/", | |
| 11824 | + blockCommentContinue: " * ", | |
| 11825 | + lineComment: lineComment, | |
| 11826 | + fold: "brace" | |
| 11827 | + }; | |
| 11828 | +}); | |
| 11829 | + | |
| 11830 | + function keySet(array) { | |
| 11831 | + var keys = {}; | |
| 11832 | + for (var i = 0; i < array.length; ++i) { | |
| 11833 | + keys[array[i].toLowerCase()] = true; | |
| 11834 | + } | |
| 11835 | + return keys; | |
| 11836 | + } | |
| 11837 | + | |
| 11838 | + var documentTypes_ = [ | |
| 11839 | + "domain", "regexp", "url", "url-prefix" | |
| 11840 | + ], documentTypes = keySet(documentTypes_); | |
| 11841 | + | |
| 11842 | + var mediaTypes_ = [ | |
| 11843 | + "all", "aural", "braille", "handheld", "print", "projection", "screen", | |
| 11844 | + "tty", "tv", "embossed" | |
| 11845 | + ], mediaTypes = keySet(mediaTypes_); | |
| 11846 | + | |
| 11847 | + var mediaFeatures_ = [ | |
| 11848 | + "width", "min-width", "max-width", "height", "min-height", "max-height", | |
| 11849 | + "device-width", "min-device-width", "max-device-width", "device-height", | |
| 11850 | + "min-device-height", "max-device-height", "aspect-ratio", | |
| 11851 | + "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio", | |
| 11852 | + "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color", | |
| 11853 | + "max-color", "color-index", "min-color-index", "max-color-index", | |
| 11854 | + "monochrome", "min-monochrome", "max-monochrome", "resolution", | |
| 11855 | + "min-resolution", "max-resolution", "scan", "grid", "orientation", | |
| 11856 | + "device-pixel-ratio", "min-device-pixel-ratio", "max-device-pixel-ratio", | |
| 11857 | + "pointer", "any-pointer", "hover", "any-hover", "prefers-color-scheme" | |
| 11858 | + ], mediaFeatures = keySet(mediaFeatures_); | |
| 11859 | + | |
| 11860 | + var mediaValueKeywords_ = [ | |
| 11861 | + "landscape", "portrait", "none", "coarse", "fine", "on-demand", "hover", | |
| 11862 | + "interlace", "progressive", | |
| 11863 | + "dark", "light" | |
| 11864 | + ], mediaValueKeywords = keySet(mediaValueKeywords_); | |
| 11865 | + | |
| 11866 | + var propertyKeywords_ = [ | |
| 11867 | + "align-content", "align-items", "align-self", "alignment-adjust", | |
| 11868 | + "alignment-baseline", "all", "anchor-point", "animation", "animation-delay", | |
| 11869 | + "animation-direction", "animation-duration", "animation-fill-mode", | |
| 11870 | + "animation-iteration-count", "animation-name", "animation-play-state", | |
| 11871 | + "animation-timing-function", "appearance", "azimuth", "backdrop-filter", | |
| 11872 | + "backface-visibility", "background", "background-attachment", | |
| 11873 | + "background-blend-mode", "background-clip", "background-color", | |
| 11874 | + "background-image", "background-origin", "background-position", | |
| 11875 | + "background-position-x", "background-position-y", "background-repeat", | |
| 11876 | + "background-size", "baseline-shift", "binding", "bleed", "block-size", | |
| 11877 | + "bookmark-label", "bookmark-level", "bookmark-state", "bookmark-target", | |
| 11878 | + "border", "border-bottom", "border-bottom-color", "border-bottom-left-radius", | |
| 11879 | + "border-bottom-right-radius", "border-bottom-style", "border-bottom-width", | |
| 11880 | + "border-collapse", "border-color", "border-image", "border-image-outset", | |
| 11881 | + "border-image-repeat", "border-image-slice", "border-image-source", | |
| 11882 | + "border-image-width", "border-left", "border-left-color", "border-left-style", | |
| 11883 | + "border-left-width", "border-radius", "border-right", "border-right-color", | |
| 11884 | + "border-right-style", "border-right-width", "border-spacing", "border-style", | |
| 11885 | + "border-top", "border-top-color", "border-top-left-radius", | |
| 11886 | + "border-top-right-radius", "border-top-style", "border-top-width", | |
| 11887 | + "border-width", "bottom", "box-decoration-break", "box-shadow", "box-sizing", | |
| 11888 | + "break-after", "break-before", "break-inside", "caption-side", "caret-color", | |
| 11889 | + "clear", "clip", "color", "color-profile", "column-count", "column-fill", | |
| 11890 | + "column-gap", "column-rule", "column-rule-color", "column-rule-style", | |
| 11891 | + "column-rule-width", "column-span", "column-width", "columns", "contain", | |
| 11892 | + "content", "counter-increment", "counter-reset", "crop", "cue", "cue-after", | |
| 11893 | + "cue-before", "cursor", "direction", "display", "dominant-baseline", | |
| 11894 | + "drop-initial-after-adjust", "drop-initial-after-align", | |
| 11895 | + "drop-initial-before-adjust", "drop-initial-before-align", "drop-initial-size", | |
| 11896 | + "drop-initial-value", "elevation", "empty-cells", "fit", "fit-position", | |
| 11897 | + "flex", "flex-basis", "flex-direction", "flex-flow", "flex-grow", | |
| 11898 | + "flex-shrink", "flex-wrap", "float", "float-offset", "flow-from", "flow-into", | |
| 11899 | + "font", "font-family", "font-feature-settings", "font-kerning", | |
| 11900 | + "font-language-override", "font-optical-sizing", "font-size", | |
| 11901 | + "font-size-adjust", "font-stretch", "font-style", "font-synthesis", | |
| 11902 | + "font-variant", "font-variant-alternates", "font-variant-caps", | |
| 11903 | + "font-variant-east-asian", "font-variant-ligatures", "font-variant-numeric", | |
| 11904 | + "font-variant-position", "font-variation-settings", "font-weight", "gap", | |
| 11905 | + "grid", "grid-area", "grid-auto-columns", "grid-auto-flow", "grid-auto-rows", | |
| 11906 | + "grid-column", "grid-column-end", "grid-column-gap", "grid-column-start", | |
| 11907 | + "grid-gap", "grid-row", "grid-row-end", "grid-row-gap", "grid-row-start", | |
| 11908 | + "grid-template", "grid-template-areas", "grid-template-columns", | |
| 11909 | + "grid-template-rows", "hanging-punctuation", "height", "hyphens", "icon", | |
| 11910 | + "image-orientation", "image-rendering", "image-resolution", "inline-box-align", | |
| 11911 | + "inset", "inset-block", "inset-block-end", "inset-block-start", "inset-inline", | |
| 11912 | + "inset-inline-end", "inset-inline-start", "isolation", "justify-content", | |
| 11913 | + "justify-items", "justify-self", "left", "letter-spacing", "line-break", | |
| 11914 | + "line-height", "line-height-step", "line-stacking", "line-stacking-ruby", | |
| 11915 | + "line-stacking-shift", "line-stacking-strategy", "list-style", | |
| 11916 | + "list-style-image", "list-style-position", "list-style-type", "margin", | |
| 11917 | + "margin-bottom", "margin-left", "margin-right", "margin-top", "marks", | |
| 11918 | + "marquee-direction", "marquee-loop", "marquee-play-count", "marquee-speed", | |
| 11919 | + "marquee-style", "mask-clip", "mask-composite", "mask-image", "mask-mode", | |
| 11920 | + "mask-origin", "mask-position", "mask-repeat", "mask-size","mask-type", | |
| 11921 | + "max-block-size", "max-height", "max-inline-size", | |
| 11922 | + "max-width", "min-block-size", "min-height", "min-inline-size", "min-width", | |
| 11923 | + "mix-blend-mode", "move-to", "nav-down", "nav-index", "nav-left", "nav-right", | |
| 11924 | + "nav-up", "object-fit", "object-position", "offset", "offset-anchor", | |
| 11925 | + "offset-distance", "offset-path", "offset-position", "offset-rotate", | |
| 11926 | + "opacity", "order", "orphans", "outline", "outline-color", "outline-offset", | |
| 11927 | + "outline-style", "outline-width", "overflow", "overflow-style", | |
| 11928 | + "overflow-wrap", "overflow-x", "overflow-y", "padding", "padding-bottom", | |
| 11929 | + "padding-left", "padding-right", "padding-top", "page", "page-break-after", | |
| 11930 | + "page-break-before", "page-break-inside", "page-policy", "pause", | |
| 11931 | + "pause-after", "pause-before", "perspective", "perspective-origin", "pitch", | |
| 11932 | + "pitch-range", "place-content", "place-items", "place-self", "play-during", | |
| 11933 | + "position", "presentation-level", "punctuation-trim", "quotes", | |
| 11934 | + "region-break-after", "region-break-before", "region-break-inside", | |
| 11935 | + "region-fragment", "rendering-intent", "resize", "rest", "rest-after", | |
| 11936 | + "rest-before", "richness", "right", "rotate", "rotation", "rotation-point", | |
| 11937 | + "row-gap", "ruby-align", "ruby-overhang", "ruby-position", "ruby-span", | |
| 11938 | + "scale", "scroll-behavior", "scroll-margin", "scroll-margin-block", | |
| 11939 | + "scroll-margin-block-end", "scroll-margin-block-start", "scroll-margin-bottom", | |
| 11940 | + "scroll-margin-inline", "scroll-margin-inline-end", | |
| 11941 | + "scroll-margin-inline-start", "scroll-margin-left", "scroll-margin-right", | |
| 11942 | + "scroll-margin-top", "scroll-padding", "scroll-padding-block", | |
| 11943 | + "scroll-padding-block-end", "scroll-padding-block-start", | |
| 11944 | + "scroll-padding-bottom", "scroll-padding-inline", "scroll-padding-inline-end", | |
| 11945 | + "scroll-padding-inline-start", "scroll-padding-left", "scroll-padding-right", | |
| 11946 | + "scroll-padding-top", "scroll-snap-align", "scroll-snap-type", | |
| 11947 | + "shape-image-threshold", "shape-inside", "shape-margin", "shape-outside", | |
| 11948 | + "size", "speak", "speak-as", "speak-header", "speak-numeral", | |
| 11949 | + "speak-punctuation", "speech-rate", "stress", "string-set", "tab-size", | |
| 11950 | + "table-layout", "target", "target-name", "target-new", "target-position", | |
| 11951 | + "text-align", "text-align-last", "text-combine-upright", "text-decoration", | |
| 11952 | + "text-decoration-color", "text-decoration-line", "text-decoration-skip", | |
| 11953 | + "text-decoration-skip-ink", "text-decoration-style", "text-emphasis", | |
| 11954 | + "text-emphasis-color", "text-emphasis-position", "text-emphasis-style", | |
| 11955 | + "text-height", "text-indent", "text-justify", "text-orientation", | |
| 11956 | + "text-outline", "text-overflow", "text-rendering", "text-shadow", | |
| 11957 | + "text-size-adjust", "text-space-collapse", "text-transform", | |
| 11958 | + "text-underline-position", "text-wrap", "top", "touch-action", "transform", "transform-origin", | |
| 11959 | + "transform-style", "transition", "transition-delay", "transition-duration", | |
| 11960 | + "transition-property", "transition-timing-function", "translate", | |
| 11961 | + "unicode-bidi", "user-select", "vertical-align", "visibility", "voice-balance", | |
| 11962 | + "voice-duration", "voice-family", "voice-pitch", "voice-range", "voice-rate", | |
| 11963 | + "voice-stress", "voice-volume", "volume", "white-space", "widows", "width", | |
| 11964 | + "will-change", "word-break", "word-spacing", "word-wrap", "writing-mode", "z-index", | |
| 11965 | + // SVG-specific | |
| 11966 | + "clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color", | |
| 11967 | + "flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events", | |
| 11968 | + "color-interpolation", "color-interpolation-filters", | |
| 11969 | + "color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering", | |
| 11970 | + "marker", "marker-end", "marker-mid", "marker-start", "paint-order", "shape-rendering", "stroke", | |
| 11971 | + "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", | |
| 11972 | + "stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering", | |
| 11973 | + "baseline-shift", "dominant-baseline", "glyph-orientation-horizontal", | |
| 11974 | + "glyph-orientation-vertical", "text-anchor", "writing-mode", | |
| 11975 | + ], propertyKeywords = keySet(propertyKeywords_); | |
| 11976 | + | |
| 11977 | + var nonStandardPropertyKeywords_ = [ | |
| 11978 | + "border-block", "border-block-color", "border-block-end", | |
| 11979 | + "border-block-end-color", "border-block-end-style", "border-block-end-width", | |
| 11980 | + "border-block-start", "border-block-start-color", "border-block-start-style", | |
| 11981 | + "border-block-start-width", "border-block-style", "border-block-width", | |
| 11982 | + "border-inline", "border-inline-color", "border-inline-end", | |
| 11983 | + "border-inline-end-color", "border-inline-end-style", | |
| 11984 | + "border-inline-end-width", "border-inline-start", "border-inline-start-color", | |
| 11985 | + "border-inline-start-style", "border-inline-start-width", | |
| 11986 | + "border-inline-style", "border-inline-width", "margin-block", | |
| 11987 | + "margin-block-end", "margin-block-start", "margin-inline", "margin-inline-end", | |
| 11988 | + "margin-inline-start", "padding-block", "padding-block-end", | |
| 11989 | + "padding-block-start", "padding-inline", "padding-inline-end", | |
| 11990 | + "padding-inline-start", "scroll-snap-stop", "scrollbar-3d-light-color", | |
| 11991 | + "scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color", | |
| 11992 | + "scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color", | |
| 11993 | + "scrollbar-track-color", "searchfield-cancel-button", "searchfield-decoration", | |
| 11994 | + "searchfield-results-button", "searchfield-results-decoration", "shape-inside", "zoom" | |
| 11995 | + ], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_); | |
| 11996 | + | |
| 11997 | + var fontProperties_ = [ | |
| 11998 | + "font-display", "font-family", "src", "unicode-range", "font-variant", | |
| 11999 | + "font-feature-settings", "font-stretch", "font-weight", "font-style" | |
| 12000 | + ], fontProperties = keySet(fontProperties_); | |
| 12001 | + | |
| 12002 | + var counterDescriptors_ = [ | |
| 12003 | + "additive-symbols", "fallback", "negative", "pad", "prefix", "range", | |
| 12004 | + "speak-as", "suffix", "symbols", "system" | |
| 12005 | + ], counterDescriptors = keySet(counterDescriptors_); | |
| 12006 | + | |
| 12007 | + var colorKeywords_ = [ | |
| 12008 | + "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", | |
| 12009 | + "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", | |
| 12010 | + "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", | |
| 12011 | + "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", | |
| 12012 | + "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", | |
| 12013 | + "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", | |
| 12014 | + "darkslateblue", "darkslategray", "darkturquoise", "darkviolet", | |
| 12015 | + "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick", | |
| 12016 | + "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", | |
| 12017 | + "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew", | |
| 12018 | + "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", | |
| 12019 | + "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", | |
| 12020 | + "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink", | |
| 12021 | + "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", | |
| 12022 | + "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", | |
| 12023 | + "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", | |
| 12024 | + "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", | |
| 12025 | + "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", | |
| 12026 | + "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", | |
| 12027 | + "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", | |
| 12028 | + "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", | |
| 12029 | + "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", | |
| 12030 | + "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", | |
| 12031 | + "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan", | |
| 12032 | + "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", | |
| 12033 | + "whitesmoke", "yellow", "yellowgreen" | |
| 12034 | + ], colorKeywords = keySet(colorKeywords_); | |
| 12035 | + | |
| 12036 | + var valueKeywords_ = [ | |
| 12037 | + "above", "absolute", "activeborder", "additive", "activecaption", "afar", | |
| 12038 | + "after-white-space", "ahead", "alias", "all", "all-scroll", "alphabetic", "alternate", | |
| 12039 | + "always", "amharic", "amharic-abegede", "antialiased", "appworkspace", | |
| 12040 | + "arabic-indic", "armenian", "asterisks", "attr", "auto", "auto-flow", "avoid", "avoid-column", "avoid-page", | |
| 12041 | + "avoid-region", "axis-pan", "background", "backwards", "baseline", "below", "bidi-override", "binary", | |
| 12042 | + "bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box", | |
| 12043 | + "both", "bottom", "break", "break-all", "break-word", "bullets", "button", "button-bevel", | |
| 12044 | + "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "calc", "cambodian", | |
| 12045 | + "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret", | |
| 12046 | + "cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch", | |
| 12047 | + "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote", | |
| 12048 | + "col-resize", "collapse", "color", "color-burn", "color-dodge", "column", "column-reverse", | |
| 12049 | + "compact", "condensed", "contain", "content", "contents", | |
| 12050 | + "content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop", | |
| 12051 | + "cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal", | |
| 12052 | + "decimal-leading-zero", "default", "default-button", "dense", "destination-atop", | |
| 12053 | + "destination-in", "destination-out", "destination-over", "devanagari", "difference", | |
| 12054 | + "disc", "discard", "disclosure-closed", "disclosure-open", "document", | |
| 12055 | + "dot-dash", "dot-dot-dash", | |
| 12056 | + "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", | |
| 12057 | + "element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede", | |
| 12058 | + "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er", | |
| 12059 | + "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er", | |
| 12060 | + "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et", | |
| 12061 | + "ethiopic-halehame-gez", "ethiopic-halehame-om-et", | |
| 12062 | + "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et", | |
| 12063 | + "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig", | |
| 12064 | + "ethiopic-numeric", "ew-resize", "exclusion", "expanded", "extends", "extra-condensed", | |
| 12065 | + "extra-expanded", "fantasy", "fast", "fill", "fill-box", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes", | |
| 12066 | + "forwards", "from", "geometricPrecision", "georgian", "graytext", "grid", "groove", | |
| 12067 | + "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hard-light", "hebrew", | |
| 12068 | + "help", "hidden", "hide", "higher", "highlight", "highlighttext", | |
| 12069 | + "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "hue", "icon", "ignore", | |
| 12070 | + "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", | |
| 12071 | + "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis", | |
| 12072 | + "inline-block", "inline-flex", "inline-grid", "inline-table", "inset", "inside", "intrinsic", "invert", | |
| 12073 | + "italic", "japanese-formal", "japanese-informal", "justify", "kannada", | |
| 12074 | + "katakana", "katakana-iroha", "keep-all", "khmer", | |
| 12075 | + "korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal", | |
| 12076 | + "landscape", "lao", "large", "larger", "left", "level", "lighter", "lighten", | |
| 12077 | + "line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem", | |
| 12078 | + "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", | |
| 12079 | + "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian", | |
| 12080 | + "lower-roman", "lowercase", "ltr", "luminosity", "malayalam", "manipulation", "match", "matrix", "matrix3d", | |
| 12081 | + "media-controls-background", "media-current-time-display", | |
| 12082 | + "media-fullscreen-button", "media-mute-button", "media-play-button", | |
| 12083 | + "media-return-to-realtime-button", "media-rewind-button", | |
| 12084 | + "media-seek-back-button", "media-seek-forward-button", "media-slider", | |
| 12085 | + "media-sliderthumb", "media-time-remaining-display", "media-volume-slider", | |
| 12086 | + "media-volume-slider-container", "media-volume-sliderthumb", "medium", | |
| 12087 | + "menu", "menulist", "menulist-button", "menulist-text", | |
| 12088 | + "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", | |
| 12089 | + "mix", "mongolian", "monospace", "move", "multiple", "multiple_mask_images", "multiply", "myanmar", "n-resize", | |
| 12090 | + "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", | |
| 12091 | + "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap", | |
| 12092 | + "ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "opacity", "open-quote", | |
| 12093 | + "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset", | |
| 12094 | + "outside", "outside-shape", "overlay", "overline", "padding", "padding-box", | |
| 12095 | + "painted", "page", "paused", "persian", "perspective", "pinch-zoom", "plus-darker", "plus-lighter", | |
| 12096 | + "pointer", "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", | |
| 12097 | + "progress", "push-button", "radial-gradient", "radio", "read-only", | |
| 12098 | + "read-write", "read-write-plaintext-only", "rectangle", "region", | |
| 12099 | + "relative", "repeat", "repeating-linear-gradient", | |
| 12100 | + "repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse", | |
| 12101 | + "rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY", | |
| 12102 | + "rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running", | |
| 12103 | + "s-resize", "sans-serif", "saturation", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "screen", | |
| 12104 | + "scroll", "scrollbar", "scroll-position", "se-resize", "searchfield", | |
| 12105 | + "searchfield-cancel-button", "searchfield-decoration", | |
| 12106 | + "searchfield-results-button", "searchfield-results-decoration", "self-start", "self-end", | |
| 12107 | + "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama", | |
| 12108 | + "simp-chinese-formal", "simp-chinese-informal", "single", | |
| 12109 | + "skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal", | |
| 12110 | + "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow", | |
| 12111 | + "small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "somali", | |
| 12112 | + "source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "space-evenly", "spell-out", "square", | |
| 12113 | + "square-button", "start", "static", "status-bar", "stretch", "stroke", "stroke-box", "sub", | |
| 12114 | + "subpixel-antialiased", "svg_masks", "super", "sw-resize", "symbolic", "symbols", "system-ui", "table", | |
| 12115 | + "table-caption", "table-cell", "table-column", "table-column-group", | |
| 12116 | + "table-footer-group", "table-header-group", "table-row", "table-row-group", | |
| 12117 | + "tamil", | |
| 12118 | + "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai", | |
| 12119 | + "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight", | |
| 12120 | + "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er", | |
| 12121 | + "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top", | |
| 12122 | + "trad-chinese-formal", "trad-chinese-informal", "transform", | |
| 12123 | + "translate", "translate3d", "translateX", "translateY", "translateZ", | |
| 12124 | + "transparent", "ultra-condensed", "ultra-expanded", "underline", "unidirectional-pan", "unset", "up", | |
| 12125 | + "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal", | |
| 12126 | + "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", | |
| 12127 | + "var", "vertical", "vertical-text", "view-box", "visible", "visibleFill", "visiblePainted", | |
| 12128 | + "visibleStroke", "visual", "w-resize", "wait", "wave", "wider", | |
| 12129 | + "window", "windowframe", "windowtext", "words", "wrap", "wrap-reverse", "x-large", "x-small", "xor", | |
| 12130 | + "xx-large", "xx-small" | |
| 12131 | + ], valueKeywords = keySet(valueKeywords_); | |
| 12132 | + | |
| 12133 | + var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(mediaValueKeywords_) | |
| 12134 | + .concat(propertyKeywords_).concat(nonStandardPropertyKeywords_).concat(colorKeywords_) | |
| 12135 | + .concat(valueKeywords_); | |
| 12136 | + CodeMirror.registerHelper("hintWords", "css", allWords); | |
| 12137 | + | |
| 12138 | + function tokenCComment(stream, state) { | |
| 12139 | + var maybeEnd = false, ch; | |
| 12140 | + while ((ch = stream.next()) != null) { | |
| 12141 | + if (maybeEnd && ch == "/") { | |
| 12142 | + state.tokenize = null; | |
| 12143 | + break; | |
| 12144 | + } | |
| 12145 | + maybeEnd = (ch == "*"); | |
| 12146 | + } | |
| 12147 | + return ["comment", "comment"]; | |
| 12148 | + } | |
| 12149 | + | |
| 12150 | + CodeMirror.defineMIME("text/css", { | |
| 12151 | + documentTypes: documentTypes, | |
| 12152 | + mediaTypes: mediaTypes, | |
| 12153 | + mediaFeatures: mediaFeatures, | |
| 12154 | + mediaValueKeywords: mediaValueKeywords, | |
| 12155 | + propertyKeywords: propertyKeywords, | |
| 12156 | + nonStandardPropertyKeywords: nonStandardPropertyKeywords, | |
| 12157 | + fontProperties: fontProperties, | |
| 12158 | + counterDescriptors: counterDescriptors, | |
| 12159 | + colorKeywords: colorKeywords, | |
| 12160 | + valueKeywords: valueKeywords, | |
| 12161 | + tokenHooks: { | |
| 12162 | + "/": function(stream, state) { | |
| 12163 | + if (!stream.eat("*")) return false; | |
| 12164 | + state.tokenize = tokenCComment; | |
| 12165 | + return tokenCComment(stream, state); | |
| 12166 | + } | |
| 12167 | + }, | |
| 12168 | + name: "css" | |
| 12169 | + }); | |
| 12170 | + | |
| 12171 | + CodeMirror.defineMIME("text/x-scss", { | |
| 12172 | + mediaTypes: mediaTypes, | |
| 12173 | + mediaFeatures: mediaFeatures, | |
| 12174 | + mediaValueKeywords: mediaValueKeywords, | |
| 12175 | + propertyKeywords: propertyKeywords, | |
| 12176 | + nonStandardPropertyKeywords: nonStandardPropertyKeywords, | |
| 12177 | + colorKeywords: colorKeywords, | |
| 12178 | + valueKeywords: valueKeywords, | |
| 12179 | + fontProperties: fontProperties, | |
| 12180 | + allowNested: true, | |
| 12181 | + lineComment: "//", | |
| 12182 | + tokenHooks: { | |
| 12183 | + "/": function(stream, state) { | |
| 12184 | + if (stream.eat("/")) { | |
| 12185 | + stream.skipToEnd(); | |
| 12186 | + return ["comment", "comment"]; | |
| 12187 | + } else if (stream.eat("*")) { | |
| 12188 | + state.tokenize = tokenCComment; | |
| 12189 | + return tokenCComment(stream, state); | |
| 12190 | + } else { | |
| 12191 | + return ["operator", "operator"]; | |
| 12192 | + } | |
| 12193 | + }, | |
| 12194 | + ":": function(stream) { | |
| 12195 | + if (stream.match(/^\s*\{/, false)) | |
| 12196 | + return [null, null] | |
| 12197 | + return false; | |
| 12198 | + }, | |
| 12199 | + "$": function(stream) { | |
| 12200 | + stream.match(/^[\w-]+/); | |
| 12201 | + if (stream.match(/^\s*:/, false)) | |
| 12202 | + return ["variable-2", "variable-definition"]; | |
| 12203 | + return ["variable-2", "variable"]; | |
| 12204 | + }, | |
| 12205 | + "#": function(stream) { | |
| 12206 | + if (!stream.eat("{")) return false; | |
| 12207 | + return [null, "interpolation"]; | |
| 12208 | + } | |
| 12209 | + }, | |
| 12210 | + name: "css", | |
| 12211 | + helperType: "scss" | |
| 12212 | + }); | |
| 12213 | + | |
| 12214 | + CodeMirror.defineMIME("text/x-less", { | |
| 12215 | + mediaTypes: mediaTypes, | |
| 12216 | + mediaFeatures: mediaFeatures, | |
| 12217 | + mediaValueKeywords: mediaValueKeywords, | |
| 12218 | + propertyKeywords: propertyKeywords, | |
| 12219 | + nonStandardPropertyKeywords: nonStandardPropertyKeywords, | |
| 12220 | + colorKeywords: colorKeywords, | |
| 12221 | + valueKeywords: valueKeywords, | |
| 12222 | + fontProperties: fontProperties, | |
| 12223 | + allowNested: true, | |
| 12224 | + lineComment: "//", | |
| 12225 | + tokenHooks: { | |
| 12226 | + "/": function(stream, state) { | |
| 12227 | + if (stream.eat("/")) { | |
| 12228 | + stream.skipToEnd(); | |
| 12229 | + return ["comment", "comment"]; | |
| 12230 | + } else if (stream.eat("*")) { | |
| 12231 | + state.tokenize = tokenCComment; | |
| 12232 | + return tokenCComment(stream, state); | |
| 12233 | + } else { | |
| 12234 | + return ["operator", "operator"]; | |
| 12235 | + } | |
| 12236 | + }, | |
| 12237 | + "@": function(stream) { | |
| 12238 | + if (stream.eat("{")) return [null, "interpolation"]; | |
| 12239 | + if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/i, false)) return false; | |
| 12240 | + stream.eatWhile(/[\w\\\-]/); | |
| 12241 | + if (stream.match(/^\s*:/, false)) | |
| 12242 | + return ["variable-2", "variable-definition"]; | |
| 12243 | + return ["variable-2", "variable"]; | |
| 12244 | + }, | |
| 12245 | + "&": function() { | |
| 12246 | + return ["atom", "atom"]; | |
| 12247 | + } | |
| 12248 | + }, | |
| 12249 | + name: "css", | |
| 12250 | + helperType: "less" | |
| 12251 | + }); | |
| 12252 | + | |
| 12253 | + CodeMirror.defineMIME("text/x-gss", { | |
| 12254 | + documentTypes: documentTypes, | |
| 12255 | + mediaTypes: mediaTypes, | |
| 12256 | + mediaFeatures: mediaFeatures, | |
| 12257 | + propertyKeywords: propertyKeywords, | |
| 12258 | + nonStandardPropertyKeywords: nonStandardPropertyKeywords, | |
| 12259 | + fontProperties: fontProperties, | |
| 12260 | + counterDescriptors: counterDescriptors, | |
| 12261 | + colorKeywords: colorKeywords, | |
| 12262 | + valueKeywords: valueKeywords, | |
| 12263 | + supportsAtComponent: true, | |
| 12264 | + tokenHooks: { | |
| 12265 | + "/": function(stream, state) { | |
| 12266 | + if (!stream.eat("*")) return false; | |
| 12267 | + state.tokenize = tokenCComment; | |
| 12268 | + return tokenCComment(stream, state); | |
| 12269 | + } | |
| 12270 | + }, | |
| 12271 | + name: "css", | |
| 12272 | + helperType: "gss" | |
| 12273 | + }); | |
| 12274 | + | |
| 12275 | +}); | |
| 12276 | + | |
| 12277 | +},{"../../lib/codemirror":14}],16:[function(require,module,exports){ | |
| 12278 | +// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
| 12279 | +// Distributed under an MIT license: https://codemirror.net/LICENSE | |
| 12280 | + | |
| 12281 | +(function(mod) { | |
| 12282 | + if (typeof exports == "object" && typeof module == "object") // CommonJS | |
| 12283 | + mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css")); | |
| 12284 | + else if (typeof define == "function" && define.amd) // AMD | |
| 12285 | + define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod); | |
| 12286 | + else // Plain browser env | |
| 12287 | + mod(CodeMirror); | |
| 12288 | +})(function(CodeMirror) { | |
| 12289 | + "use strict"; | |
| 12290 | + | |
| 12291 | + var defaultTags = { | |
| 12292 | + script: [ | |
| 12293 | + ["lang", /(javascript|babel)/i, "javascript"], | |
| 12294 | + ["type", /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i, "javascript"], | |
| 12295 | + ["type", /./, "text/plain"], | |
| 12296 | + [null, null, "javascript"] | |
| 12297 | + ], | |
| 12298 | + style: [ | |
| 12299 | + ["lang", /^css$/i, "css"], | |
| 12300 | + ["type", /^(text\/)?(x-)?(stylesheet|css)$/i, "css"], | |
| 12301 | + ["type", /./, "text/plain"], | |
| 12302 | + [null, null, "css"] | |
| 12303 | + ] | |
| 12304 | + }; | |
| 12305 | + | |
| 12306 | + function maybeBackup(stream, pat, style) { | |
| 12307 | + var cur = stream.current(), close = cur.search(pat); | |
| 12308 | + if (close > -1) { | |
| 12309 | + stream.backUp(cur.length - close); | |
| 12310 | + } else if (cur.match(/<\/?$/)) { | |
| 12311 | + stream.backUp(cur.length); | |
| 12312 | + if (!stream.match(pat, false)) stream.match(cur); | |
| 12313 | + } | |
| 12314 | + return style; | |
| 12315 | + } | |
| 12316 | + | |
| 12317 | + var attrRegexpCache = {}; | |
| 12318 | + function getAttrRegexp(attr) { | |
| 12319 | + var regexp = attrRegexpCache[attr]; | |
| 12320 | + if (regexp) return regexp; | |
| 12321 | + return attrRegexpCache[attr] = new RegExp("\\s+" + attr + "\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*"); | |
| 12322 | + } | |
| 12323 | + | |
| 12324 | + function getAttrValue(text, attr) { | |
| 12325 | + var match = text.match(getAttrRegexp(attr)) | |
| 12326 | + return match ? /^\s*(.*?)\s*$/.exec(match[2])[1] : "" | |
| 12327 | + } | |
| 12328 | + | |
| 12329 | + function getTagRegexp(tagName, anchored) { | |
| 12330 | + return new RegExp((anchored ? "^" : "") + "<\/\s*" + tagName + "\s*>", "i"); | |
| 12331 | + } | |
| 12332 | + | |
| 12333 | + function addTags(from, to) { | |
| 12334 | + for (var tag in from) { | |
| 12335 | + var dest = to[tag] || (to[tag] = []); | |
| 12336 | + var source = from[tag]; | |
| 12337 | + for (var i = source.length - 1; i >= 0; i--) | |
| 12338 | + dest.unshift(source[i]) | |
| 12339 | + } | |
| 12340 | + } | |
| 12341 | + | |
| 12342 | + function findMatchingMode(tagInfo, tagText) { | |
| 12343 | + for (var i = 0; i < tagInfo.length; i++) { | |
| 12344 | + var spec = tagInfo[i]; | |
| 12345 | + if (!spec[0] || spec[1].test(getAttrValue(tagText, spec[0]))) return spec[2]; | |
| 12346 | + } | |
| 12347 | + } | |
| 12348 | + | |
| 12349 | + CodeMirror.defineMode("htmlmixed", function (config, parserConfig) { | |
| 12350 | + var htmlMode = CodeMirror.getMode(config, { | |
| 12351 | + name: "xml", | |
| 12352 | + htmlMode: true, | |
| 12353 | + multilineTagIndentFactor: parserConfig.multilineTagIndentFactor, | |
| 12354 | + multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag, | |
| 12355 | + allowMissingTagName: parserConfig.allowMissingTagName, | |
| 12356 | + }); | |
| 12357 | + | |
| 12358 | + var tags = {}; | |
| 12359 | + var configTags = parserConfig && parserConfig.tags, configScript = parserConfig && parserConfig.scriptTypes; | |
| 12360 | + addTags(defaultTags, tags); | |
| 12361 | + if (configTags) addTags(configTags, tags); | |
| 12362 | + if (configScript) for (var i = configScript.length - 1; i >= 0; i--) | |
| 12363 | + tags.script.unshift(["type", configScript[i].matches, configScript[i].mode]) | |
| 12364 | + | |
| 12365 | + function html(stream, state) { | |
| 12366 | + var style = htmlMode.token(stream, state.htmlState), tag = /\btag\b/.test(style), tagName | |
| 12367 | + if (tag && !/[<>\s\/]/.test(stream.current()) && | |
| 12368 | + (tagName = state.htmlState.tagName && state.htmlState.tagName.toLowerCase()) && | |
| 12369 | + tags.hasOwnProperty(tagName)) { | |
| 12370 | + state.inTag = tagName + " " | |
| 12371 | + } else if (state.inTag && tag && />$/.test(stream.current())) { | |
| 12372 | + var inTag = /^([\S]+) (.*)/.exec(state.inTag) | |
| 12373 | + state.inTag = null | |
| 12374 | + var modeSpec = stream.current() == ">" && findMatchingMode(tags[inTag[1]], inTag[2]) | |
| 12375 | + var mode = CodeMirror.getMode(config, modeSpec) | |
| 12376 | + var endTagA = getTagRegexp(inTag[1], true), endTag = getTagRegexp(inTag[1], false); | |
| 12377 | + state.token = function (stream, state) { | |
| 12378 | + if (stream.match(endTagA, false)) { | |
| 12379 | + state.token = html; | |
| 12380 | + state.localState = state.localMode = null; | |
| 12381 | + return null; | |
| 12382 | + } | |
| 12383 | + return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState)); | |
| 12384 | + }; | |
| 12385 | + state.localMode = mode; | |
| 12386 | + state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, "", "")); | |
| 12387 | + } else if (state.inTag) { | |
| 12388 | + state.inTag += stream.current() | |
| 12389 | + if (stream.eol()) state.inTag += " " | |
| 12390 | + } | |
| 12391 | + return style; | |
| 12392 | + }; | |
| 12393 | + | |
| 12394 | + return { | |
| 12395 | + startState: function () { | |
| 12396 | + var state = CodeMirror.startState(htmlMode); | |
| 12397 | + return {token: html, inTag: null, localMode: null, localState: null, htmlState: state}; | |
| 12398 | + }, | |
| 12399 | + | |
| 12400 | + copyState: function (state) { | |
| 12401 | + var local; | |
| 12402 | + if (state.localState) { | |
| 12403 | + local = CodeMirror.copyState(state.localMode, state.localState); | |
| 12404 | + } | |
| 12405 | + return {token: state.token, inTag: state.inTag, | |
| 12406 | + localMode: state.localMode, localState: local, | |
| 12407 | + htmlState: CodeMirror.copyState(htmlMode, state.htmlState)}; | |
| 12408 | + }, | |
| 12409 | + | |
| 12410 | + token: function (stream, state) { | |
| 12411 | + return state.token(stream, state); | |
| 12412 | + }, | |
| 12413 | + | |
| 12414 | + indent: function (state, textAfter, line) { | |
| 12415 | + if (!state.localMode || /^\s*<\//.test(textAfter)) | |
| 12416 | + return htmlMode.indent(state.htmlState, textAfter, line); | |
| 12417 | + else if (state.localMode.indent) | |
| 12418 | + return state.localMode.indent(state.localState, textAfter, line); | |
| 12419 | + else | |
| 12420 | + return CodeMirror.Pass; | |
| 12421 | + }, | |
| 12422 | + | |
| 12423 | + innerMode: function (state) { | |
| 12424 | + return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode}; | |
| 12425 | + } | |
| 12426 | + }; | |
| 12427 | + }, "xml", "javascript", "css"); | |
| 12428 | + | |
| 12429 | + CodeMirror.defineMIME("text/html", "htmlmixed"); | |
| 12430 | +}); | |
| 12431 | + | |
| 12432 | +},{"../../lib/codemirror":14,"../css/css":15,"../javascript/javascript":17,"../xml/xml":18}],17:[function(require,module,exports){ | |
| 12433 | +// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
| 12434 | +// Distributed under an MIT license: https://codemirror.net/LICENSE | |
| 12435 | + | |
| 12436 | +(function(mod) { | |
| 12437 | + if (typeof exports == "object" && typeof module == "object") // CommonJS | |
| 12438 | + mod(require("../../lib/codemirror")); | |
| 12439 | + else if (typeof define == "function" && define.amd) // AMD | |
| 12440 | + define(["../../lib/codemirror"], mod); | |
| 12441 | + else // Plain browser env | |
| 12442 | + mod(CodeMirror); | |
| 12443 | +})(function(CodeMirror) { | |
| 12444 | +"use strict"; | |
| 12445 | + | |
| 12446 | +CodeMirror.defineMode("javascript", function(config, parserConfig) { | |
| 12447 | + var indentUnit = config.indentUnit; | |
| 12448 | + var statementIndent = parserConfig.statementIndent; | |
| 12449 | + var jsonldMode = parserConfig.jsonld; | |
| 12450 | + var jsonMode = parserConfig.json || jsonldMode; | |
| 12451 | + var trackScope = parserConfig.trackScope !== false | |
| 12452 | + var isTS = parserConfig.typescript; | |
| 12453 | + var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/; | |
| 12454 | + | |
| 12455 | + // Tokenizer | |
| 12456 | + | |
| 12457 | + var keywords = function(){ | |
| 12458 | + function kw(type) {return {type: type, style: "keyword"};} | |
| 12459 | + var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"), D = kw("keyword d"); | |
| 12460 | + var operator = kw("operator"), atom = {type: "atom", style: "atom"}; | |
| 12461 | + | |
| 12462 | + return { | |
| 12463 | + "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, | |
| 12464 | + "return": D, "break": D, "continue": D, "new": kw("new"), "delete": C, "void": C, "throw": C, | |
| 12465 | + "debugger": kw("debugger"), "var": kw("var"), "const": kw("var"), "let": kw("var"), | |
| 12466 | + "function": kw("function"), "catch": kw("catch"), | |
| 12467 | + "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), | |
| 12468 | + "in": operator, "typeof": operator, "instanceof": operator, | |
| 12469 | + "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom, | |
| 12470 | + "this": kw("this"), "class": kw("class"), "super": kw("atom"), | |
| 12471 | + "yield": C, "export": kw("export"), "import": kw("import"), "extends": C, | |
| 12472 | + "await": C | |
| 12473 | + }; | |
| 12474 | + }(); | |
| 12475 | + | |
| 12476 | + var isOperatorChar = /[+\-*&%=<>!?|~^@]/; | |
| 12477 | + var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/; | |
| 12478 | + | |
| 12479 | + function readRegexp(stream) { | |
| 12480 | + var escaped = false, next, inSet = false; | |
| 12481 | + while ((next = stream.next()) != null) { | |
| 12482 | + if (!escaped) { | |
| 12483 | + if (next == "/" && !inSet) return; | |
| 12484 | + if (next == "[") inSet = true; | |
| 12485 | + else if (inSet && next == "]") inSet = false; | |
| 12486 | + } | |
| 12487 | + escaped = !escaped && next == "\\"; | |
| 12488 | + } | |
| 12489 | + } | |
| 12490 | + | |
| 12491 | + // Used as scratch variables to communicate multiple values without | |
| 12492 | + // consing up tons of objects. | |
| 12493 | + var type, content; | |
| 12494 | + function ret(tp, style, cont) { | |
| 12495 | + type = tp; content = cont; | |
| 12496 | + return style; | |
| 12497 | + } | |
| 12498 | + function tokenBase(stream, state) { | |
| 12499 | + var ch = stream.next(); | |
| 12500 | + if (ch == '"' || ch == "'") { | |
| 12501 | + state.tokenize = tokenString(ch); | |
| 12502 | + return state.tokenize(stream, state); | |
| 12503 | + } else if (ch == "." && stream.match(/^\d[\d_]*(?:[eE][+\-]?[\d_]+)?/)) { | |
| 12504 | + return ret("number", "number"); | |
| 12505 | + } else if (ch == "." && stream.match("..")) { | |
| 12506 | + return ret("spread", "meta"); | |
| 12507 | + } else if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | |
| 12508 | + return ret(ch); | |
| 12509 | + } else if (ch == "=" && stream.eat(">")) { | |
| 12510 | + return ret("=>", "operator"); | |
| 12511 | + } else if (ch == "0" && stream.match(/^(?:x[\dA-Fa-f_]+|o[0-7_]+|b[01_]+)n?/)) { | |
| 12512 | + return ret("number", "number"); | |
| 12513 | + } else if (/\d/.test(ch)) { | |
| 12514 | + stream.match(/^[\d_]*(?:n|(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)?/); | |
| 12515 | + return ret("number", "number"); | |
| 12516 | + } else if (ch == "/") { | |
| 12517 | + if (stream.eat("*")) { | |
| 12518 | + state.tokenize = tokenComment; | |
| 12519 | + return tokenComment(stream, state); | |
| 12520 | + } else if (stream.eat("/")) { | |
| 12521 | + stream.skipToEnd(); | |
| 12522 | + return ret("comment", "comment"); | |
| 12523 | + } else if (expressionAllowed(stream, state, 1)) { | |
| 12524 | + readRegexp(stream); | |
| 12525 | + stream.match(/^\b(([gimyus])(?![gimyus]*\2))+\b/); | |
| 12526 | + return ret("regexp", "string-2"); | |
| 12527 | + } else { | |
| 12528 | + stream.eat("="); | |
| 12529 | + return ret("operator", "operator", stream.current()); | |
| 12530 | + } | |
| 12531 | + } else if (ch == "`") { | |
| 12532 | + state.tokenize = tokenQuasi; | |
| 12533 | + return tokenQuasi(stream, state); | |
| 12534 | + } else if (ch == "#" && stream.peek() == "!") { | |
| 12535 | + stream.skipToEnd(); | |
| 12536 | + return ret("meta", "meta"); | |
| 12537 | + } else if (ch == "#" && stream.eatWhile(wordRE)) { | |
| 12538 | + return ret("variable", "property") | |
| 12539 | + } else if (ch == "<" && stream.match("!--") || | |
| 12540 | + (ch == "-" && stream.match("->") && !/\S/.test(stream.string.slice(0, stream.start)))) { | |
| 12541 | + stream.skipToEnd() | |
| 12542 | + return ret("comment", "comment") | |
| 12543 | + } else if (isOperatorChar.test(ch)) { | |
| 12544 | + if (ch != ">" || !state.lexical || state.lexical.type != ">") { | |
| 12545 | + if (stream.eat("=")) { | |
| 12546 | + if (ch == "!" || ch == "=") stream.eat("=") | |
| 12547 | + } else if (/[<>*+\-|&?]/.test(ch)) { | |
| 12548 | + stream.eat(ch) | |
| 12549 | + if (ch == ">") stream.eat(ch) | |
| 12550 | + } | |
| 12551 | + } | |
| 12552 | + if (ch == "?" && stream.eat(".")) return ret(".") | |
| 12553 | + return ret("operator", "operator", stream.current()); | |
| 12554 | + } else if (wordRE.test(ch)) { | |
| 12555 | + stream.eatWhile(wordRE); | |
| 12556 | + var word = stream.current() | |
| 12557 | + if (state.lastType != ".") { | |
| 12558 | + if (keywords.propertyIsEnumerable(word)) { | |
| 12559 | + var kw = keywords[word] | |
| 12560 | + return ret(kw.type, kw.style, word) | |
| 12561 | + } | |
| 12562 | + if (word == "async" && stream.match(/^(\s|\/\*([^*]|\*(?!\/))*?\*\/)*[\[\(\w]/, false)) | |
| 12563 | + return ret("async", "keyword", word) | |
| 12564 | + } | |
| 12565 | + return ret("variable", "variable", word) | |
| 12566 | + } | |
| 12567 | + } | |
| 12568 | + | |
| 12569 | + function tokenString(quote) { | |
| 12570 | + return function(stream, state) { | |
| 12571 | + var escaped = false, next; | |
| 12572 | + if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){ | |
| 12573 | + state.tokenize = tokenBase; | |
| 12574 | + return ret("jsonld-keyword", "meta"); | |
| 12575 | + } | |
| 12576 | + while ((next = stream.next()) != null) { | |
| 12577 | + if (next == quote && !escaped) break; | |
| 12578 | + escaped = !escaped && next == "\\"; | |
| 12579 | + } | |
| 12580 | + if (!escaped) state.tokenize = tokenBase; | |
| 12581 | + return ret("string", "string"); | |
| 12582 | + }; | |
| 12583 | + } | |
| 12584 | + | |
| 12585 | + function tokenComment(stream, state) { | |
| 12586 | + var maybeEnd = false, ch; | |
| 12587 | + while (ch = stream.next()) { | |
| 12588 | + if (ch == "/" && maybeEnd) { | |
| 12589 | + state.tokenize = tokenBase; | |
| 12590 | + break; | |
| 12591 | + } | |
| 12592 | + maybeEnd = (ch == "*"); | |
| 12593 | + } | |
| 12594 | + return ret("comment", "comment"); | |
| 12595 | + } | |
| 12596 | + | |
| 12597 | + function tokenQuasi(stream, state) { | |
| 12598 | + var escaped = false, next; | |
| 12599 | + while ((next = stream.next()) != null) { | |
| 12600 | + if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) { | |
| 12601 | + state.tokenize = tokenBase; | |
| 12602 | + break; | |
| 12603 | + } | |
| 12604 | + escaped = !escaped && next == "\\"; | |
| 12605 | + } | |
| 12606 | + return ret("quasi", "string-2", stream.current()); | |
| 12607 | + } | |
| 12608 | + | |
| 12609 | + var brackets = "([{}])"; | |
| 12610 | + // This is a crude lookahead trick to try and notice that we're | |
| 12611 | + // parsing the argument patterns for a fat-arrow function before we | |
| 12612 | + // actually hit the arrow token. It only works if the arrow is on | |
| 12613 | + // the same line as the arguments and there's no strange noise | |
| 12614 | + // (comments) in between. Fallback is to only notice when we hit the | |
| 12615 | + // arrow, and not declare the arguments as locals for the arrow | |
| 12616 | + // body. | |
| 12617 | + function findFatArrow(stream, state) { | |
| 12618 | + if (state.fatArrowAt) state.fatArrowAt = null; | |
| 12619 | + var arrow = stream.string.indexOf("=>", stream.start); | |
| 12620 | + if (arrow < 0) return; | |
| 12621 | + | |
| 12622 | + if (isTS) { // Try to skip TypeScript return type declarations after the arguments | |
| 12623 | + var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow)) | |
| 12624 | + if (m) arrow = m.index | |
| 12625 | + } | |
| 12626 | + | |
| 12627 | + var depth = 0, sawSomething = false; | |
| 12628 | + for (var pos = arrow - 1; pos >= 0; --pos) { | |
| 12629 | + var ch = stream.string.charAt(pos); | |
| 12630 | + var bracket = brackets.indexOf(ch); | |
| 12631 | + if (bracket >= 0 && bracket < 3) { | |
| 12632 | + if (!depth) { ++pos; break; } | |
| 12633 | + if (--depth == 0) { if (ch == "(") sawSomething = true; break; } | |
| 12634 | + } else if (bracket >= 3 && bracket < 6) { | |
| 12635 | + ++depth; | |
| 12636 | + } else if (wordRE.test(ch)) { | |
| 12637 | + sawSomething = true; | |
| 12638 | + } else if (/["'\/`]/.test(ch)) { | |
| 12639 | + for (;; --pos) { | |
| 12640 | + if (pos == 0) return | |
| 12641 | + var next = stream.string.charAt(pos - 1) | |
| 12642 | + if (next == ch && stream.string.charAt(pos - 2) != "\\") { pos--; break } | |
| 12643 | + } | |
| 12644 | + } else if (sawSomething && !depth) { | |
| 12645 | + ++pos; | |
| 12646 | + break; | |
| 12647 | + } | |
| 12648 | + } | |
| 12649 | + if (sawSomething && !depth) state.fatArrowAt = pos; | |
| 12650 | + } | |
| 12651 | + | |
| 12652 | + // Parser | |
| 12653 | + | |
| 12654 | + var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, | |
| 12655 | + "regexp": true, "this": true, "import": true, "jsonld-keyword": true}; | |
| 12656 | + | |
| 12657 | + function JSLexical(indented, column, type, align, prev, info) { | |
| 12658 | + this.indented = indented; | |
| 12659 | + this.column = column; | |
| 12660 | + this.type = type; | |
| 12661 | + this.prev = prev; | |
| 12662 | + this.info = info; | |
| 12663 | + if (align != null) this.align = align; | |
| 12664 | + } | |
| 12665 | + | |
| 12666 | + function inScope(state, varname) { | |
| 12667 | + if (!trackScope) return false | |
| 12668 | + for (var v = state.localVars; v; v = v.next) | |
| 12669 | + if (v.name == varname) return true; | |
| 12670 | + for (var cx = state.context; cx; cx = cx.prev) { | |
| 12671 | + for (var v = cx.vars; v; v = v.next) | |
| 12672 | + if (v.name == varname) return true; | |
| 12673 | + } | |
| 12674 | + } | |
| 12675 | + | |
| 12676 | + function parseJS(state, style, type, content, stream) { | |
| 12677 | + var cc = state.cc; | |
| 12678 | + // Communicate our context to the combinators. | |
| 12679 | + // (Less wasteful than consing up a hundred closures on every call.) | |
| 12680 | + cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style; | |
| 12681 | + | |
| 12682 | + if (!state.lexical.hasOwnProperty("align")) | |
| 12683 | + state.lexical.align = true; | |
| 12684 | + | |
| 12685 | + while(true) { | |
| 12686 | + var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement; | |
| 12687 | + if (combinator(type, content)) { | |
| 12688 | + while(cc.length && cc[cc.length - 1].lex) | |
| 12689 | + cc.pop()(); | |
| 12690 | + if (cx.marked) return cx.marked; | |
| 12691 | + if (type == "variable" && inScope(state, content)) return "variable-2"; | |
| 12692 | + return style; | |
| 12693 | + } | |
| 12694 | + } | |
| 12695 | + } | |
| 12696 | + | |
| 12697 | + // Combinator utils | |
| 12698 | + | |
| 12699 | + var cx = {state: null, column: null, marked: null, cc: null}; | |
| 12700 | + function pass() { | |
| 12701 | + for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]); | |
| 12702 | + } | |
| 12703 | + function cont() { | |
| 12704 | + pass.apply(null, arguments); | |
| 12705 | + return true; | |
| 12706 | + } | |
| 12707 | + function inList(name, list) { | |
| 12708 | + for (var v = list; v; v = v.next) if (v.name == name) return true | |
| 12709 | + return false; | |
| 12710 | + } | |
| 12711 | + function register(varname) { | |
| 12712 | + var state = cx.state; | |
| 12713 | + cx.marked = "def"; | |
| 12714 | + if (!trackScope) return | |
| 12715 | + if (state.context) { | |
| 12716 | + if (state.lexical.info == "var" && state.context && state.context.block) { | |
| 12717 | + // FIXME function decls are also not block scoped | |
| 12718 | + var newContext = registerVarScoped(varname, state.context) | |
| 12719 | + if (newContext != null) { | |
| 12720 | + state.context = newContext | |
| 12721 | + return | |
| 12722 | + } | |
| 12723 | + } else if (!inList(varname, state.localVars)) { | |
| 12724 | + state.localVars = new Var(varname, state.localVars) | |
| 12725 | + return | |
| 12726 | + } | |
| 12727 | + } | |
| 12728 | + // Fall through means this is global | |
| 12729 | + if (parserConfig.globalVars && !inList(varname, state.globalVars)) | |
| 12730 | + state.globalVars = new Var(varname, state.globalVars) | |
| 12731 | + } | |
| 12732 | + function registerVarScoped(varname, context) { | |
| 12733 | + if (!context) { | |
| 12734 | + return null | |
| 12735 | + } else if (context.block) { | |
| 12736 | + var inner = registerVarScoped(varname, context.prev) | |
| 12737 | + if (!inner) return null | |
| 12738 | + if (inner == context.prev) return context | |
| 12739 | + return new Context(inner, context.vars, true) | |
| 12740 | + } else if (inList(varname, context.vars)) { | |
| 12741 | + return context | |
| 12742 | + } else { | |
| 12743 | + return new Context(context.prev, new Var(varname, context.vars), false) | |
| 12744 | + } | |
| 12745 | + } | |
| 12746 | + | |
| 12747 | + function isModifier(name) { | |
| 12748 | + return name == "public" || name == "private" || name == "protected" || name == "abstract" || name == "readonly" | |
| 12749 | + } | |
| 12750 | + | |
| 12751 | + // Combinators | |
| 12752 | + | |
| 12753 | + function Context(prev, vars, block) { this.prev = prev; this.vars = vars; this.block = block } | |
| 12754 | + function Var(name, next) { this.name = name; this.next = next } | |
| 12755 | + | |
| 12756 | + var defaultVars = new Var("this", new Var("arguments", null)) | |
| 12757 | + function pushcontext() { | |
| 12758 | + cx.state.context = new Context(cx.state.context, cx.state.localVars, false) | |
| 12759 | + cx.state.localVars = defaultVars | |
| 12760 | + } | |
| 12761 | + function pushblockcontext() { | |
| 12762 | + cx.state.context = new Context(cx.state.context, cx.state.localVars, true) | |
| 12763 | + cx.state.localVars = null | |
| 12764 | + } | |
| 12765 | + function popcontext() { | |
| 12766 | + cx.state.localVars = cx.state.context.vars | |
| 12767 | + cx.state.context = cx.state.context.prev | |
| 12768 | + } | |
| 12769 | + popcontext.lex = true | |
| 12770 | + function pushlex(type, info) { | |
| 12771 | + var result = function() { | |
| 12772 | + var state = cx.state, indent = state.indented; | |
| 12773 | + if (state.lexical.type == "stat") indent = state.lexical.indented; | |
| 12774 | + else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev) | |
| 12775 | + indent = outer.indented; | |
| 12776 | + state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info); | |
| 12777 | + }; | |
| 12778 | + result.lex = true; | |
| 12779 | + return result; | |
| 12780 | + } | |
| 12781 | + function poplex() { | |
| 12782 | + var state = cx.state; | |
| 12783 | + if (state.lexical.prev) { | |
| 12784 | + if (state.lexical.type == ")") | |
| 12785 | + state.indented = state.lexical.indented; | |
| 12786 | + state.lexical = state.lexical.prev; | |
| 12787 | + } | |
| 12788 | + } | |
| 12789 | + poplex.lex = true; | |
| 12790 | + | |
| 12791 | + function expect(wanted) { | |
| 12792 | + function exp(type) { | |
| 12793 | + if (type == wanted) return cont(); | |
| 12794 | + else if (wanted == ";" || type == "}" || type == ")" || type == "]") return pass(); | |
| 12795 | + else return cont(exp); | |
| 12796 | + }; | |
| 12797 | + return exp; | |
| 12798 | + } | |
| 12799 | + | |
| 12800 | + function statement(type, value) { | |
| 12801 | + if (type == "var") return cont(pushlex("vardef", value), vardef, expect(";"), poplex); | |
| 12802 | + if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex); | |
| 12803 | + if (type == "keyword b") return cont(pushlex("form"), statement, poplex); | |
| 12804 | + if (type == "keyword d") return cx.stream.match(/^\s*$/, false) ? cont() : cont(pushlex("stat"), maybeexpression, expect(";"), poplex); | |
| 12805 | + if (type == "debugger") return cont(expect(";")); | |
| 12806 | + if (type == "{") return cont(pushlex("}"), pushblockcontext, block, poplex, popcontext); | |
| 12807 | + if (type == ";") return cont(); | |
| 12808 | + if (type == "if") { | |
| 12809 | + if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex) | |
| 12810 | + cx.state.cc.pop()(); | |
| 12811 | + return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse); | |
| 12812 | + } | |
| 12813 | + if (type == "function") return cont(functiondef); | |
| 12814 | + if (type == "for") return cont(pushlex("form"), pushblockcontext, forspec, statement, popcontext, poplex); | |
| 12815 | + if (type == "class" || (isTS && value == "interface")) { | |
| 12816 | + cx.marked = "keyword" | |
| 12817 | + return cont(pushlex("form", type == "class" ? type : value), className, poplex) | |
| 12818 | + } | |
| 12819 | + if (type == "variable") { | |
| 12820 | + if (isTS && value == "declare") { | |
| 12821 | + cx.marked = "keyword" | |
| 12822 | + return cont(statement) | |
| 12823 | + } else if (isTS && (value == "module" || value == "enum" || value == "type") && cx.stream.match(/^\s*\w/, false)) { | |
| 12824 | + cx.marked = "keyword" | |
| 12825 | + if (value == "enum") return cont(enumdef); | |
| 12826 | + else if (value == "type") return cont(typename, expect("operator"), typeexpr, expect(";")); | |
| 12827 | + else return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex) | |
| 12828 | + } else if (isTS && value == "namespace") { | |
| 12829 | + cx.marked = "keyword" | |
| 12830 | + return cont(pushlex("form"), expression, statement, poplex) | |
| 12831 | + } else if (isTS && value == "abstract") { | |
| 12832 | + cx.marked = "keyword" | |
| 12833 | + return cont(statement) | |
| 12834 | + } else { | |
| 12835 | + return cont(pushlex("stat"), maybelabel); | |
| 12836 | + } | |
| 12837 | + } | |
| 12838 | + if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"), pushblockcontext, | |
| 12839 | + block, poplex, poplex, popcontext); | |
| 12840 | + if (type == "case") return cont(expression, expect(":")); | |
| 12841 | + if (type == "default") return cont(expect(":")); | |
| 12842 | + if (type == "catch") return cont(pushlex("form"), pushcontext, maybeCatchBinding, statement, poplex, popcontext); | |
| 12843 | + if (type == "export") return cont(pushlex("stat"), afterExport, poplex); | |
| 12844 | + if (type == "import") return cont(pushlex("stat"), afterImport, poplex); | |
| 12845 | + if (type == "async") return cont(statement) | |
| 12846 | + if (value == "@") return cont(expression, statement) | |
| 12847 | + return pass(pushlex("stat"), expression, expect(";"), poplex); | |
| 12848 | + } | |
| 12849 | + function maybeCatchBinding(type) { | |
| 12850 | + if (type == "(") return cont(funarg, expect(")")) | |
| 12851 | + } | |
| 12852 | + function expression(type, value) { | |
| 12853 | + return expressionInner(type, value, false); | |
| 12854 | + } | |
| 12855 | + function expressionNoComma(type, value) { | |
| 12856 | + return expressionInner(type, value, true); | |
| 12857 | + } | |
| 12858 | + function parenExpr(type) { | |
| 12859 | + if (type != "(") return pass() | |
| 12860 | + return cont(pushlex(")"), maybeexpression, expect(")"), poplex) | |
| 12861 | + } | |
| 12862 | + function expressionInner(type, value, noComma) { | |
| 12863 | + if (cx.state.fatArrowAt == cx.stream.start) { | |
| 12864 | + var body = noComma ? arrowBodyNoComma : arrowBody; | |
| 12865 | + if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext); | |
| 12866 | + else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext); | |
| 12867 | + } | |
| 12868 | + | |
| 12869 | + var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma; | |
| 12870 | + if (atomicTypes.hasOwnProperty(type)) return cont(maybeop); | |
| 12871 | + if (type == "function") return cont(functiondef, maybeop); | |
| 12872 | + if (type == "class" || (isTS && value == "interface")) { cx.marked = "keyword"; return cont(pushlex("form"), classExpression, poplex); } | |
| 12873 | + if (type == "keyword c" || type == "async") return cont(noComma ? expressionNoComma : expression); | |
| 12874 | + if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop); | |
| 12875 | + if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression); | |
| 12876 | + if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop); | |
| 12877 | + if (type == "{") return contCommasep(objprop, "}", null, maybeop); | |
| 12878 | + if (type == "quasi") return pass(quasi, maybeop); | |
| 12879 | + if (type == "new") return cont(maybeTarget(noComma)); | |
| 12880 | + return cont(); | |
| 12881 | + } | |
| 12882 | + function maybeexpression(type) { | |
| 12883 | + if (type.match(/[;\}\)\],]/)) return pass(); | |
| 12884 | + return pass(expression); | |
| 12885 | + } | |
| 12886 | + | |
| 12887 | + function maybeoperatorComma(type, value) { | |
| 12888 | + if (type == ",") return cont(maybeexpression); | |
| 12889 | + return maybeoperatorNoComma(type, value, false); | |
| 12890 | + } | |
| 12891 | + function maybeoperatorNoComma(type, value, noComma) { | |
| 12892 | + var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma; | |
| 12893 | + var expr = noComma == false ? expression : expressionNoComma; | |
| 12894 | + if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext); | |
| 12895 | + if (type == "operator") { | |
| 12896 | + if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me); | |
| 12897 | + if (isTS && value == "<" && cx.stream.match(/^([^<>]|<[^<>]*>)*>\s*\(/, false)) | |
| 12898 | + return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, me); | |
| 12899 | + if (value == "?") return cont(expression, expect(":"), expr); | |
| 12900 | + return cont(expr); | |
| 12901 | + } | |
| 12902 | + if (type == "quasi") { return pass(quasi, me); } | |
| 12903 | + if (type == ";") return; | |
| 12904 | + if (type == "(") return contCommasep(expressionNoComma, ")", "call", me); | |
| 12905 | + if (type == ".") return cont(property, me); | |
| 12906 | + if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me); | |
| 12907 | + if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) } | |
| 12908 | + if (type == "regexp") { | |
| 12909 | + cx.state.lastType = cx.marked = "operator" | |
| 12910 | + cx.stream.backUp(cx.stream.pos - cx.stream.start - 1) | |
| 12911 | + return cont(expr) | |
| 12912 | + } | |
| 12913 | + } | |
| 12914 | + function quasi(type, value) { | |
| 12915 | + if (type != "quasi") return pass(); | |
| 12916 | + if (value.slice(value.length - 2) != "${") return cont(quasi); | |
| 12917 | + return cont(expression, continueQuasi); | |
| 12918 | + } | |
| 12919 | + function continueQuasi(type) { | |
| 12920 | + if (type == "}") { | |
| 12921 | + cx.marked = "string-2"; | |
| 12922 | + cx.state.tokenize = tokenQuasi; | |
| 12923 | + return cont(quasi); | |
| 12924 | + } | |
| 12925 | + } | |
| 12926 | + function arrowBody(type) { | |
| 12927 | + findFatArrow(cx.stream, cx.state); | |
| 12928 | + return pass(type == "{" ? statement : expression); | |
| 12929 | + } | |
| 12930 | + function arrowBodyNoComma(type) { | |
| 12931 | + findFatArrow(cx.stream, cx.state); | |
| 12932 | + return pass(type == "{" ? statement : expressionNoComma); | |
| 12933 | + } | |
| 12934 | + function maybeTarget(noComma) { | |
| 12935 | + return function(type) { | |
| 12936 | + if (type == ".") return cont(noComma ? targetNoComma : target); | |
| 12937 | + else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma) | |
| 12938 | + else return pass(noComma ? expressionNoComma : expression); | |
| 12939 | + }; | |
| 12940 | + } | |
| 12941 | + function target(_, value) { | |
| 12942 | + if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); } | |
| 12943 | + } | |
| 12944 | + function targetNoComma(_, value) { | |
| 12945 | + if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); } | |
| 12946 | + } | |
| 12947 | + function maybelabel(type) { | |
| 12948 | + if (type == ":") return cont(poplex, statement); | |
| 12949 | + return pass(maybeoperatorComma, expect(";"), poplex); | |
| 12950 | + } | |
| 12951 | + function property(type) { | |
| 12952 | + if (type == "variable") {cx.marked = "property"; return cont();} | |
| 12953 | + } | |
| 12954 | + function objprop(type, value) { | |
| 12955 | + if (type == "async") { | |
| 12956 | + cx.marked = "property"; | |
| 12957 | + return cont(objprop); | |
| 12958 | + } else if (type == "variable" || cx.style == "keyword") { | |
| 12959 | + cx.marked = "property"; | |
| 12960 | + if (value == "get" || value == "set") return cont(getterSetter); | |
| 12961 | + var m // Work around fat-arrow-detection complication for detecting typescript typed arrow params | |
| 12962 | + if (isTS && cx.state.fatArrowAt == cx.stream.start && (m = cx.stream.match(/^\s*:\s*/, false))) | |
| 12963 | + cx.state.fatArrowAt = cx.stream.pos + m[0].length | |
| 12964 | + return cont(afterprop); | |
| 12965 | + } else if (type == "number" || type == "string") { | |
| 12966 | + cx.marked = jsonldMode ? "property" : (cx.style + " property"); | |
| 12967 | + return cont(afterprop); | |
| 12968 | + } else if (type == "jsonld-keyword") { | |
| 12969 | + return cont(afterprop); | |
| 12970 | + } else if (isTS && isModifier(value)) { | |
| 12971 | + cx.marked = "keyword" | |
| 12972 | + return cont(objprop) | |
| 12973 | + } else if (type == "[") { | |
| 12974 | + return cont(expression, maybetype, expect("]"), afterprop); | |
| 12975 | + } else if (type == "spread") { | |
| 12976 | + return cont(expressionNoComma, afterprop); | |
| 12977 | + } else if (value == "*") { | |
| 12978 | + cx.marked = "keyword"; | |
| 12979 | + return cont(objprop); | |
| 12980 | + } else if (type == ":") { | |
| 12981 | + return pass(afterprop) | |
| 12982 | + } | |
| 12983 | + } | |
| 12984 | + function getterSetter(type) { | |
| 12985 | + if (type != "variable") return pass(afterprop); | |
| 12986 | + cx.marked = "property"; | |
| 12987 | + return cont(functiondef); | |
| 12988 | + } | |
| 12989 | + function afterprop(type) { | |
| 12990 | + if (type == ":") return cont(expressionNoComma); | |
| 12991 | + if (type == "(") return pass(functiondef); | |
| 12992 | + } | |
| 12993 | + function commasep(what, end, sep) { | |
| 12994 | + function proceed(type, value) { | |
| 12995 | + if (sep ? sep.indexOf(type) > -1 : type == ",") { | |
| 12996 | + var lex = cx.state.lexical; | |
| 12997 | + if (lex.info == "call") lex.pos = (lex.pos || 0) + 1; | |
| 12998 | + return cont(function(type, value) { | |
| 12999 | + if (type == end || value == end) return pass() | |
| 13000 | + return pass(what) | |
| 13001 | + }, proceed); | |
| 13002 | + } | |
| 13003 | + if (type == end || value == end) return cont(); | |
| 13004 | + if (sep && sep.indexOf(";") > -1) return pass(what) | |
| 13005 | + return cont(expect(end)); | |
| 13006 | + } | |
| 13007 | + return function(type, value) { | |
| 13008 | + if (type == end || value == end) return cont(); | |
| 13009 | + return pass(what, proceed); | |
| 13010 | + }; | |
| 13011 | + } | |
| 13012 | + function contCommasep(what, end, info) { | |
| 13013 | + for (var i = 3; i < arguments.length; i++) | |
| 13014 | + cx.cc.push(arguments[i]); | |
| 13015 | + return cont(pushlex(end, info), commasep(what, end), poplex); | |
| 13016 | + } | |
| 13017 | + function block(type) { | |
| 13018 | + if (type == "}") return cont(); | |
| 13019 | + return pass(statement, block); | |
| 13020 | + } | |
| 13021 | + function maybetype(type, value) { | |
| 13022 | + if (isTS) { | |
| 13023 | + if (type == ":") return cont(typeexpr); | |
| 13024 | + if (value == "?") return cont(maybetype); | |
| 13025 | + } | |
| 13026 | + } | |
| 13027 | + function maybetypeOrIn(type, value) { | |
| 13028 | + if (isTS && (type == ":" || value == "in")) return cont(typeexpr) | |
| 13029 | + } | |
| 13030 | + function mayberettype(type) { | |
| 13031 | + if (isTS && type == ":") { | |
| 13032 | + if (cx.stream.match(/^\s*\w+\s+is\b/, false)) return cont(expression, isKW, typeexpr) | |
| 13033 | + else return cont(typeexpr) | |
| 13034 | + } | |
| 13035 | + } | |
| 13036 | + function isKW(_, value) { | |
| 13037 | + if (value == "is") { | |
| 13038 | + cx.marked = "keyword" | |
| 13039 | + return cont() | |
| 13040 | + } | |
| 13041 | + } | |
| 13042 | + function typeexpr(type, value) { | |
| 13043 | + if (value == "keyof" || value == "typeof" || value == "infer" || value == "readonly") { | |
| 13044 | + cx.marked = "keyword" | |
| 13045 | + return cont(value == "typeof" ? expressionNoComma : typeexpr) | |
| 13046 | + } | |
| 13047 | + if (type == "variable" || value == "void") { | |
| 13048 | + cx.marked = "type" | |
| 13049 | + return cont(afterType) | |
| 13050 | + } | |
| 13051 | + if (value == "|" || value == "&") return cont(typeexpr) | |
| 13052 | + if (type == "string" || type == "number" || type == "atom") return cont(afterType); | |
| 13053 | + if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType) | |
| 13054 | + if (type == "{") return cont(pushlex("}"), typeprops, poplex, afterType) | |
| 13055 | + if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType, afterType) | |
| 13056 | + if (type == "<") return cont(commasep(typeexpr, ">"), typeexpr) | |
| 13057 | + } | |
| 13058 | + function maybeReturnType(type) { | |
| 13059 | + if (type == "=>") return cont(typeexpr) | |
| 13060 | + } | |
| 13061 | + function typeprops(type) { | |
| 13062 | + if (type.match(/[\}\)\]]/)) return cont() | |
| 13063 | + if (type == "," || type == ";") return cont(typeprops) | |
| 13064 | + return pass(typeprop, typeprops) | |
| 13065 | + } | |
| 13066 | + function typeprop(type, value) { | |
| 13067 | + if (type == "variable" || cx.style == "keyword") { | |
| 13068 | + cx.marked = "property" | |
| 13069 | + return cont(typeprop) | |
| 13070 | + } else if (value == "?" || type == "number" || type == "string") { | |
| 13071 | + return cont(typeprop) | |
| 13072 | + } else if (type == ":") { | |
| 13073 | + return cont(typeexpr) | |
| 13074 | + } else if (type == "[") { | |
| 13075 | + return cont(expect("variable"), maybetypeOrIn, expect("]"), typeprop) | |
| 13076 | + } else if (type == "(") { | |
| 13077 | + return pass(functiondecl, typeprop) | |
| 13078 | + } else if (!type.match(/[;\}\)\],]/)) { | |
| 13079 | + return cont() | |
| 13080 | + } | |
| 13081 | + } | |
| 13082 | + function typearg(type, value) { | |
| 13083 | + if (type == "variable" && cx.stream.match(/^\s*[?:]/, false) || value == "?") return cont(typearg) | |
| 13084 | + if (type == ":") return cont(typeexpr) | |
| 13085 | + if (type == "spread") return cont(typearg) | |
| 13086 | + return pass(typeexpr) | |
| 13087 | + } | |
| 13088 | + function afterType(type, value) { | |
| 13089 | + if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType) | |
| 13090 | + if (value == "|" || type == "." || value == "&") return cont(typeexpr) | |
| 13091 | + if (type == "[") return cont(typeexpr, expect("]"), afterType) | |
| 13092 | + if (value == "extends" || value == "implements") { cx.marked = "keyword"; return cont(typeexpr) } | |
| 13093 | + if (value == "?") return cont(typeexpr, expect(":"), typeexpr) | |
| 13094 | + } | |
| 13095 | + function maybeTypeArgs(_, value) { | |
| 13096 | + if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType) | |
| 13097 | + } | |
| 13098 | + function typeparam() { | |
| 13099 | + return pass(typeexpr, maybeTypeDefault) | |
| 13100 | + } | |
| 13101 | + function maybeTypeDefault(_, value) { | |
| 13102 | + if (value == "=") return cont(typeexpr) | |
| 13103 | + } | |
| 13104 | + function vardef(_, value) { | |
| 13105 | + if (value == "enum") {cx.marked = "keyword"; return cont(enumdef)} | |
| 13106 | + return pass(pattern, maybetype, maybeAssign, vardefCont); | |
| 13107 | + } | |
| 13108 | + function pattern(type, value) { | |
| 13109 | + if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(pattern) } | |
| 13110 | + if (type == "variable") { register(value); return cont(); } | |
| 13111 | + if (type == "spread") return cont(pattern); | |
| 13112 | + if (type == "[") return contCommasep(eltpattern, "]"); | |
| 13113 | + if (type == "{") return contCommasep(proppattern, "}"); | |
| 13114 | + } | |
| 13115 | + function proppattern(type, value) { | |
| 13116 | + if (type == "variable" && !cx.stream.match(/^\s*:/, false)) { | |
| 13117 | + register(value); | |
| 13118 | + return cont(maybeAssign); | |
| 13119 | + } | |
| 13120 | + if (type == "variable") cx.marked = "property"; | |
| 13121 | + if (type == "spread") return cont(pattern); | |
| 13122 | + if (type == "}") return pass(); | |
| 13123 | + if (type == "[") return cont(expression, expect(']'), expect(':'), proppattern); | |
| 13124 | + return cont(expect(":"), pattern, maybeAssign); | |
| 13125 | + } | |
| 13126 | + function eltpattern() { | |
| 13127 | + return pass(pattern, maybeAssign) | |
| 13128 | + } | |
| 13129 | + function maybeAssign(_type, value) { | |
| 13130 | + if (value == "=") return cont(expressionNoComma); | |
| 13131 | + } | |
| 13132 | + function vardefCont(type) { | |
| 13133 | + if (type == ",") return cont(vardef); | |
| 13134 | + } | |
| 13135 | + function maybeelse(type, value) { | |
| 13136 | + if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex); | |
| 13137 | + } | |
| 13138 | + function forspec(type, value) { | |
| 13139 | + if (value == "await") return cont(forspec); | |
| 13140 | + if (type == "(") return cont(pushlex(")"), forspec1, poplex); | |
| 13141 | + } | |
| 13142 | + function forspec1(type) { | |
| 13143 | + if (type == "var") return cont(vardef, forspec2); | |
| 13144 | + if (type == "variable") return cont(forspec2); | |
| 13145 | + return pass(forspec2) | |
| 13146 | + } | |
| 13147 | + function forspec2(type, value) { | |
| 13148 | + if (type == ")") return cont() | |
| 13149 | + if (type == ";") return cont(forspec2) | |
| 13150 | + if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression, forspec2) } | |
| 13151 | + return pass(expression, forspec2) | |
| 13152 | + } | |
| 13153 | + function functiondef(type, value) { | |
| 13154 | + if (value == "*") {cx.marked = "keyword"; return cont(functiondef);} | |
| 13155 | + if (type == "variable") {register(value); return cont(functiondef);} | |
| 13156 | + if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, statement, popcontext); | |
| 13157 | + if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondef) | |
| 13158 | + } | |
| 13159 | + function functiondecl(type, value) { | |
| 13160 | + if (value == "*") {cx.marked = "keyword"; return cont(functiondecl);} | |
| 13161 | + if (type == "variable") {register(value); return cont(functiondecl);} | |
| 13162 | + if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, popcontext); | |
| 13163 | + if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondecl) | |
| 13164 | + } | |
| 13165 | + function typename(type, value) { | |
| 13166 | + if (type == "keyword" || type == "variable") { | |
| 13167 | + cx.marked = "type" | |
| 13168 | + return cont(typename) | |
| 13169 | + } else if (value == "<") { | |
| 13170 | + return cont(pushlex(">"), commasep(typeparam, ">"), poplex) | |
| 13171 | + } | |
| 13172 | + } | |
| 13173 | + function funarg(type, value) { | |
| 13174 | + if (value == "@") cont(expression, funarg) | |
| 13175 | + if (type == "spread") return cont(funarg); | |
| 13176 | + if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(funarg); } | |
| 13177 | + if (isTS && type == "this") return cont(maybetype, maybeAssign) | |
| 13178 | + return pass(pattern, maybetype, maybeAssign); | |
| 13179 | + } | |
| 13180 | + function classExpression(type, value) { | |
| 13181 | + // Class expressions may have an optional name. | |
| 13182 | + if (type == "variable") return className(type, value); | |
| 13183 | + return classNameAfter(type, value); | |
| 13184 | + } | |
| 13185 | + function className(type, value) { | |
| 13186 | + if (type == "variable") {register(value); return cont(classNameAfter);} | |
| 13187 | + } | |
| 13188 | + function classNameAfter(type, value) { | |
| 13189 | + if (value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, classNameAfter) | |
| 13190 | + if (value == "extends" || value == "implements" || (isTS && type == ",")) { | |
| 13191 | + if (value == "implements") cx.marked = "keyword"; | |
| 13192 | + return cont(isTS ? typeexpr : expression, classNameAfter); | |
| 13193 | + } | |
| 13194 | + if (type == "{") return cont(pushlex("}"), classBody, poplex); | |
| 13195 | + } | |
| 13196 | + function classBody(type, value) { | |
| 13197 | + if (type == "async" || | |
| 13198 | + (type == "variable" && | |
| 13199 | + (value == "static" || value == "get" || value == "set" || (isTS && isModifier(value))) && | |
| 13200 | + cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) { | |
| 13201 | + cx.marked = "keyword"; | |
| 13202 | + return cont(classBody); | |
| 13203 | + } | |
| 13204 | + if (type == "variable" || cx.style == "keyword") { | |
| 13205 | + cx.marked = "property"; | |
| 13206 | + return cont(classfield, classBody); | |
| 13207 | + } | |
| 13208 | + if (type == "number" || type == "string") return cont(classfield, classBody); | |
| 13209 | + if (type == "[") | |
| 13210 | + return cont(expression, maybetype, expect("]"), classfield, classBody) | |
| 13211 | + if (value == "*") { | |
| 13212 | + cx.marked = "keyword"; | |
| 13213 | + return cont(classBody); | |
| 13214 | + } | |
| 13215 | + if (isTS && type == "(") return pass(functiondecl, classBody) | |
| 13216 | + if (type == ";" || type == ",") return cont(classBody); | |
| 13217 | + if (type == "}") return cont(); | |
| 13218 | + if (value == "@") return cont(expression, classBody) | |
| 13219 | + } | |
| 13220 | + function classfield(type, value) { | |
| 13221 | + if (value == "?") return cont(classfield) | |
| 13222 | + if (type == ":") return cont(typeexpr, maybeAssign) | |
| 13223 | + if (value == "=") return cont(expressionNoComma) | |
| 13224 | + var context = cx.state.lexical.prev, isInterface = context && context.info == "interface" | |
| 13225 | + return pass(isInterface ? functiondecl : functiondef) | |
| 13226 | + } | |
| 13227 | + function afterExport(type, value) { | |
| 13228 | + if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); } | |
| 13229 | + if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); } | |
| 13230 | + if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";")); | |
| 13231 | + return pass(statement); | |
| 13232 | + } | |
| 13233 | + function exportField(type, value) { | |
| 13234 | + if (value == "as") { cx.marked = "keyword"; return cont(expect("variable")); } | |
| 13235 | + if (type == "variable") return pass(expressionNoComma, exportField); | |
| 13236 | + } | |
| 13237 | + function afterImport(type) { | |
| 13238 | + if (type == "string") return cont(); | |
| 13239 | + if (type == "(") return pass(expression); | |
| 13240 | + if (type == ".") return pass(maybeoperatorComma); | |
| 13241 | + return pass(importSpec, maybeMoreImports, maybeFrom); | |
| 13242 | + } | |
| 13243 | + function importSpec(type, value) { | |
| 13244 | + if (type == "{") return contCommasep(importSpec, "}"); | |
| 13245 | + if (type == "variable") register(value); | |
| 13246 | + if (value == "*") cx.marked = "keyword"; | |
| 13247 | + return cont(maybeAs); | |
| 13248 | + } | |
| 13249 | + function maybeMoreImports(type) { | |
| 13250 | + if (type == ",") return cont(importSpec, maybeMoreImports) | |
| 13251 | + } | |
| 13252 | + function maybeAs(_type, value) { | |
| 13253 | + if (value == "as") { cx.marked = "keyword"; return cont(importSpec); } | |
| 13254 | + } | |
| 13255 | + function maybeFrom(_type, value) { | |
| 13256 | + if (value == "from") { cx.marked = "keyword"; return cont(expression); } | |
| 13257 | + } | |
| 13258 | + function arrayLiteral(type) { | |
| 13259 | + if (type == "]") return cont(); | |
| 13260 | + return pass(commasep(expressionNoComma, "]")); | |
| 13261 | + } | |
| 13262 | + function enumdef() { | |
| 13263 | + return pass(pushlex("form"), pattern, expect("{"), pushlex("}"), commasep(enummember, "}"), poplex, poplex) | |
| 13264 | + } | |
| 13265 | + function enummember() { | |
| 13266 | + return pass(pattern, maybeAssign); | |
| 13267 | + } | |
| 13268 | + | |
| 13269 | + function isContinuedStatement(state, textAfter) { | |
| 13270 | + return state.lastType == "operator" || state.lastType == "," || | |
| 13271 | + isOperatorChar.test(textAfter.charAt(0)) || | |
| 13272 | + /[,.]/.test(textAfter.charAt(0)); | |
| 13273 | + } | |
| 13274 | + | |
| 13275 | + function expressionAllowed(stream, state, backUp) { | |
| 13276 | + return state.tokenize == tokenBase && | |
| 13277 | + /^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(state.lastType) || | |
| 13278 | + (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0)))) | |
| 13279 | + } | |
| 13280 | + | |
| 13281 | + // Interface | |
| 13282 | + | |
| 13283 | + return { | |
| 13284 | + startState: function(basecolumn) { | |
| 13285 | + var state = { | |
| 13286 | + tokenize: tokenBase, | |
| 13287 | + lastType: "sof", | |
| 13288 | + cc: [], | |
| 13289 | + lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), | |
| 13290 | + localVars: parserConfig.localVars, | |
| 13291 | + context: parserConfig.localVars && new Context(null, null, false), | |
| 13292 | + indented: basecolumn || 0 | |
| 13293 | + }; | |
| 13294 | + if (parserConfig.globalVars && typeof parserConfig.globalVars == "object") | |
| 13295 | + state.globalVars = parserConfig.globalVars; | |
| 13296 | + return state; | |
| 13297 | + }, | |
| 13298 | + | |
| 13299 | + token: function(stream, state) { | |
| 13300 | + if (stream.sol()) { | |
| 13301 | + if (!state.lexical.hasOwnProperty("align")) | |
| 13302 | + state.lexical.align = false; | |
| 13303 | + state.indented = stream.indentation(); | |
| 13304 | + findFatArrow(stream, state); | |
| 13305 | + } | |
| 13306 | + if (state.tokenize != tokenComment && stream.eatSpace()) return null; | |
| 13307 | + var style = state.tokenize(stream, state); | |
| 13308 | + if (type == "comment") return style; | |
| 13309 | + state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type; | |
| 13310 | + return parseJS(state, style, type, content, stream); | |
| 13311 | + }, | |
| 13312 | + | |
| 13313 | + indent: function(state, textAfter) { | |
| 13314 | + if (state.tokenize == tokenComment || state.tokenize == tokenQuasi) return CodeMirror.Pass; | |
| 13315 | + if (state.tokenize != tokenBase) return 0; | |
| 13316 | + var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical, top | |
| 13317 | + // Kludge to prevent 'maybelse' from blocking lexical scope pops | |
| 13318 | + if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) { | |
| 13319 | + var c = state.cc[i]; | |
| 13320 | + if (c == poplex) lexical = lexical.prev; | |
| 13321 | + else if (c != maybeelse && c != popcontext) break; | |
| 13322 | + } | |
| 13323 | + while ((lexical.type == "stat" || lexical.type == "form") && | |
| 13324 | + (firstChar == "}" || ((top = state.cc[state.cc.length - 1]) && | |
| 13325 | + (top == maybeoperatorComma || top == maybeoperatorNoComma) && | |
| 13326 | + !/^[,\.=+\-*:?[\(]/.test(textAfter)))) | |
| 13327 | + lexical = lexical.prev; | |
| 13328 | + if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat") | |
| 13329 | + lexical = lexical.prev; | |
| 13330 | + var type = lexical.type, closing = firstChar == type; | |
| 13331 | + | |
| 13332 | + if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info.length + 1 : 0); | |
| 13333 | + else if (type == "form" && firstChar == "{") return lexical.indented; | |
| 13334 | + else if (type == "form") return lexical.indented + indentUnit; | |
| 13335 | + else if (type == "stat") | |
| 13336 | + return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0); | |
| 13337 | + else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false) | |
| 13338 | + return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); | |
| 13339 | + else if (lexical.align) return lexical.column + (closing ? 0 : 1); | |
| 13340 | + else return lexical.indented + (closing ? 0 : indentUnit); | |
| 13341 | + }, | |
| 13342 | + | |
| 13343 | + electricInput: /^\s*(?:case .*?:|default:|\{|\})$/, | |
| 13344 | + blockCommentStart: jsonMode ? null : "/*", | |
| 13345 | + blockCommentEnd: jsonMode ? null : "*/", | |
| 13346 | + blockCommentContinue: jsonMode ? null : " * ", | |
| 13347 | + lineComment: jsonMode ? null : "//", | |
| 13348 | + fold: "brace", | |
| 13349 | + closeBrackets: "()[]{}''\"\"``", | |
| 13350 | + | |
| 13351 | + helperType: jsonMode ? "json" : "javascript", | |
| 13352 | + jsonldMode: jsonldMode, | |
| 13353 | + jsonMode: jsonMode, | |
| 13354 | + | |
| 13355 | + expressionAllowed: expressionAllowed, | |
| 13356 | + | |
| 13357 | + skipExpression: function(state) { | |
| 13358 | + var top = state.cc[state.cc.length - 1] | |
| 13359 | + if (top == expression || top == expressionNoComma) state.cc.pop() | |
| 13360 | + } | |
| 13361 | + }; | |
| 13362 | +}); | |
| 13363 | + | |
| 13364 | +CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/); | |
| 13365 | + | |
| 13366 | +CodeMirror.defineMIME("text/javascript", "javascript"); | |
| 13367 | +CodeMirror.defineMIME("text/ecmascript", "javascript"); | |
| 13368 | +CodeMirror.defineMIME("application/javascript", "javascript"); | |
| 13369 | +CodeMirror.defineMIME("application/x-javascript", "javascript"); | |
| 13370 | +CodeMirror.defineMIME("application/ecmascript", "javascript"); | |
| 13371 | +CodeMirror.defineMIME("application/json", { name: "javascript", json: true }); | |
| 13372 | +CodeMirror.defineMIME("application/x-json", { name: "javascript", json: true }); | |
| 13373 | +CodeMirror.defineMIME("application/manifest+json", { name: "javascript", json: true }) | |
| 13374 | +CodeMirror.defineMIME("application/ld+json", { name: "javascript", jsonld: true }); | |
| 13375 | +CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true }); | |
| 13376 | +CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true }); | |
| 13377 | + | |
| 13378 | +}); | |
| 13379 | + | |
| 13380 | +},{"../../lib/codemirror":14}],18:[function(require,module,exports){ | |
| 13381 | +// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
| 13382 | +// Distributed under an MIT license: https://codemirror.net/LICENSE | |
| 13383 | + | |
| 13384 | +(function(mod) { | |
| 13385 | + if (typeof exports == "object" && typeof module == "object") // CommonJS | |
| 13386 | + mod(require("../../lib/codemirror")); | |
| 13387 | + else if (typeof define == "function" && define.amd) // AMD | |
| 13388 | + define(["../../lib/codemirror"], mod); | |
| 13389 | + else // Plain browser env | |
| 13390 | + mod(CodeMirror); | |
| 13391 | +})(function(CodeMirror) { | |
| 13392 | +"use strict"; | |
| 13393 | + | |
| 13394 | +var htmlConfig = { | |
| 13395 | + autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true, | |
| 13396 | + 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true, | |
| 13397 | + 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true, | |
| 13398 | + 'track': true, 'wbr': true, 'menuitem': true}, | |
| 13399 | + implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true, | |
| 13400 | + 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true, | |
| 13401 | + 'th': true, 'tr': true}, | |
| 13402 | + contextGrabbers: { | |
| 13403 | + 'dd': {'dd': true, 'dt': true}, | |
| 13404 | + 'dt': {'dd': true, 'dt': true}, | |
| 13405 | + 'li': {'li': true}, | |
| 13406 | + 'option': {'option': true, 'optgroup': true}, | |
| 13407 | + 'optgroup': {'optgroup': true}, | |
| 13408 | + 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true, | |
| 13409 | + 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true, | |
| 13410 | + 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true, | |
| 13411 | + 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true, | |
| 13412 | + 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true}, | |
| 13413 | + 'rp': {'rp': true, 'rt': true}, | |
| 13414 | + 'rt': {'rp': true, 'rt': true}, | |
| 13415 | + 'tbody': {'tbody': true, 'tfoot': true}, | |
| 13416 | + 'td': {'td': true, 'th': true}, | |
| 13417 | + 'tfoot': {'tbody': true}, | |
| 13418 | + 'th': {'td': true, 'th': true}, | |
| 13419 | + 'thead': {'tbody': true, 'tfoot': true}, | |
| 13420 | + 'tr': {'tr': true} | |
| 13421 | + }, | |
| 13422 | + doNotIndent: {"pre": true}, | |
| 13423 | + allowUnquoted: true, | |
| 13424 | + allowMissing: true, | |
| 13425 | + caseFold: true | |
| 13426 | +} | |
| 13427 | + | |
| 13428 | +var xmlConfig = { | |
| 13429 | + autoSelfClosers: {}, | |
| 13430 | + implicitlyClosed: {}, | |
| 13431 | + contextGrabbers: {}, | |
| 13432 | + doNotIndent: {}, | |
| 13433 | + allowUnquoted: false, | |
| 13434 | + allowMissing: false, | |
| 13435 | + allowMissingTagName: false, | |
| 13436 | + caseFold: false | |
| 13437 | +} | |
| 13438 | + | |
| 13439 | +CodeMirror.defineMode("xml", function(editorConf, config_) { | |
| 13440 | + var indentUnit = editorConf.indentUnit | |
| 13441 | + var config = {} | |
| 13442 | + var defaults = config_.htmlMode ? htmlConfig : xmlConfig | |
| 13443 | + for (var prop in defaults) config[prop] = defaults[prop] | |
| 13444 | + for (var prop in config_) config[prop] = config_[prop] | |
| 13445 | + | |
| 13446 | + // Return variables for tokenizers | |
| 13447 | + var type, setStyle; | |
| 13448 | + | |
| 13449 | + function inText(stream, state) { | |
| 13450 | + function chain(parser) { | |
| 13451 | + state.tokenize = parser; | |
| 13452 | + return parser(stream, state); | |
| 13453 | + } | |
| 13454 | + | |
| 13455 | + var ch = stream.next(); | |
| 13456 | + if (ch == "<") { | |
| 13457 | + if (stream.eat("!")) { | |
| 13458 | + if (stream.eat("[")) { | |
| 13459 | + if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>")); | |
| 13460 | + else return null; | |
| 13461 | + } else if (stream.match("--")) { | |
| 13462 | + return chain(inBlock("comment", "-->")); | |
| 13463 | + } else if (stream.match("DOCTYPE", true, true)) { | |
| 13464 | + stream.eatWhile(/[\w\._\-]/); | |
| 13465 | + return chain(doctype(1)); | |
| 13466 | + } else { | |
| 13467 | + return null; | |
| 13468 | + } | |
| 13469 | + } else if (stream.eat("?")) { | |
| 13470 | + stream.eatWhile(/[\w\._\-]/); | |
| 13471 | + state.tokenize = inBlock("meta", "?>"); | |
| 13472 | + return "meta"; | |
| 13473 | + } else { | |
| 13474 | + type = stream.eat("/") ? "closeTag" : "openTag"; | |
| 13475 | + state.tokenize = inTag; | |
| 13476 | + return "tag bracket"; | |
| 13477 | + } | |
| 13478 | + } else if (ch == "&") { | |
| 13479 | + var ok; | |
| 13480 | + if (stream.eat("#")) { | |
| 13481 | + if (stream.eat("x")) { | |
| 13482 | + ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";"); | |
| 13483 | + } else { | |
| 13484 | + ok = stream.eatWhile(/[\d]/) && stream.eat(";"); | |
| 13485 | + } | |
| 13486 | + } else { | |
| 13487 | + ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";"); | |
| 13488 | + } | |
| 13489 | + return ok ? "atom" : "error"; | |
| 13490 | + } else { | |
| 13491 | + stream.eatWhile(/[^&<]/); | |
| 13492 | + return null; | |
| 13493 | + } | |
| 13494 | + } | |
| 13495 | + inText.isInText = true; | |
| 13496 | + | |
| 13497 | + function inTag(stream, state) { | |
| 13498 | + var ch = stream.next(); | |
| 13499 | + if (ch == ">" || (ch == "/" && stream.eat(">"))) { | |
| 13500 | + state.tokenize = inText; | |
| 13501 | + type = ch == ">" ? "endTag" : "selfcloseTag"; | |
| 13502 | + return "tag bracket"; | |
| 13503 | + } else if (ch == "=") { | |
| 13504 | + type = "equals"; | |
| 13505 | + return null; | |
| 13506 | + } else if (ch == "<") { | |
| 13507 | + state.tokenize = inText; | |
| 13508 | + state.state = baseState; | |
| 13509 | + state.tagName = state.tagStart = null; | |
| 13510 | + var next = state.tokenize(stream, state); | |
| 13511 | + return next ? next + " tag error" : "tag error"; | |
| 13512 | + } else if (/[\'\"]/.test(ch)) { | |
| 13513 | + state.tokenize = inAttribute(ch); | |
| 13514 | + state.stringStartCol = stream.column(); | |
| 13515 | + return state.tokenize(stream, state); | |
| 13516 | + } else { | |
| 13517 | + stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/); | |
| 13518 | + return "word"; | |
| 13519 | + } | |
| 13520 | + } | |
| 13521 | + | |
| 13522 | + function inAttribute(quote) { | |
| 13523 | + var closure = function(stream, state) { | |
| 13524 | + while (!stream.eol()) { | |
| 13525 | + if (stream.next() == quote) { | |
| 13526 | + state.tokenize = inTag; | |
| 13527 | + break; | |
| 13528 | + } | |
| 13529 | + } | |
| 13530 | + return "string"; | |
| 13531 | + }; | |
| 13532 | + closure.isInAttribute = true; | |
| 13533 | + return closure; | |
| 13534 | + } | |
| 13535 | + | |
| 13536 | + function inBlock(style, terminator) { | |
| 13537 | + return function(stream, state) { | |
| 13538 | + while (!stream.eol()) { | |
| 13539 | + if (stream.match(terminator)) { | |
| 13540 | + state.tokenize = inText; | |
| 13541 | + break; | |
| 13542 | + } | |
| 13543 | + stream.next(); | |
| 13544 | + } | |
| 13545 | + return style; | |
| 13546 | + } | |
| 13547 | + } | |
| 13548 | + | |
| 13549 | + function doctype(depth) { | |
| 13550 | + return function(stream, state) { | |
| 13551 | + var ch; | |
| 13552 | + while ((ch = stream.next()) != null) { | |
| 13553 | + if (ch == "<") { | |
| 13554 | + state.tokenize = doctype(depth + 1); | |
| 13555 | + return state.tokenize(stream, state); | |
| 13556 | + } else if (ch == ">") { | |
| 13557 | + if (depth == 1) { | |
| 13558 | + state.tokenize = inText; | |
| 13559 | + break; | |
| 13560 | + } else { | |
| 13561 | + state.tokenize = doctype(depth - 1); | |
| 13562 | + return state.tokenize(stream, state); | |
| 13563 | + } | |
| 13564 | + } | |
| 13565 | + } | |
| 13566 | + return "meta"; | |
| 13567 | + }; | |
| 13568 | + } | |
| 13569 | + | |
| 13570 | + function Context(state, tagName, startOfLine) { | |
| 13571 | + this.prev = state.context; | |
| 13572 | + this.tagName = tagName || ""; | |
| 13573 | + this.indent = state.indented; | |
| 13574 | + this.startOfLine = startOfLine; | |
| 13575 | + if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent)) | |
| 13576 | + this.noIndent = true; | |
| 13577 | + } | |
| 13578 | + function popContext(state) { | |
| 13579 | + if (state.context) state.context = state.context.prev; | |
| 13580 | + } | |
| 13581 | + function maybePopContext(state, nextTagName) { | |
| 13582 | + var parentTagName; | |
| 13583 | + while (true) { | |
| 13584 | + if (!state.context) { | |
| 13585 | + return; | |
| 13586 | + } | |
| 13587 | + parentTagName = state.context.tagName; | |
| 13588 | + if (!config.contextGrabbers.hasOwnProperty(parentTagName) || | |
| 13589 | + !config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) { | |
| 13590 | + return; | |
| 13591 | + } | |
| 13592 | + popContext(state); | |
| 13593 | + } | |
| 13594 | + } | |
| 13595 | + | |
| 13596 | + function baseState(type, stream, state) { | |
| 13597 | + if (type == "openTag") { | |
| 13598 | + state.tagStart = stream.column(); | |
| 13599 | + return tagNameState; | |
| 13600 | + } else if (type == "closeTag") { | |
| 13601 | + return closeTagNameState; | |
| 13602 | + } else { | |
| 13603 | + return baseState; | |
| 13604 | + } | |
| 13605 | + } | |
| 13606 | + function tagNameState(type, stream, state) { | |
| 13607 | + if (type == "word") { | |
| 13608 | + state.tagName = stream.current(); | |
| 13609 | + setStyle = "tag"; | |
| 13610 | + return attrState; | |
| 13611 | + } else if (config.allowMissingTagName && type == "endTag") { | |
| 13612 | + setStyle = "tag bracket"; | |
| 13613 | + return attrState(type, stream, state); | |
| 13614 | + } else { | |
| 13615 | + setStyle = "error"; | |
| 13616 | + return tagNameState; | |
| 13617 | + } | |
| 13618 | + } | |
| 13619 | + function closeTagNameState(type, stream, state) { | |
| 13620 | + if (type == "word") { | |
| 13621 | + var tagName = stream.current(); | |
| 13622 | + if (state.context && state.context.tagName != tagName && | |
| 13623 | + config.implicitlyClosed.hasOwnProperty(state.context.tagName)) | |
| 13624 | + popContext(state); | |
| 13625 | + if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) { | |
| 13626 | + setStyle = "tag"; | |
| 13627 | + return closeState; | |
| 13628 | + } else { | |
| 13629 | + setStyle = "tag error"; | |
| 13630 | + return closeStateErr; | |
| 13631 | + } | |
| 13632 | + } else if (config.allowMissingTagName && type == "endTag") { | |
| 13633 | + setStyle = "tag bracket"; | |
| 13634 | + return closeState(type, stream, state); | |
| 13635 | + } else { | |
| 13636 | + setStyle = "error"; | |
| 13637 | + return closeStateErr; | |
| 13638 | + } | |
| 13639 | + } | |
| 13640 | + | |
| 13641 | + function closeState(type, _stream, state) { | |
| 13642 | + if (type != "endTag") { | |
| 13643 | + setStyle = "error"; | |
| 13644 | + return closeState; | |
| 13645 | + } | |
| 13646 | + popContext(state); | |
| 13647 | + return baseState; | |
| 13648 | + } | |
| 13649 | + function closeStateErr(type, stream, state) { | |
| 13650 | + setStyle = "error"; | |
| 13651 | + return closeState(type, stream, state); | |
| 13652 | + } | |
| 13653 | + | |
| 13654 | + function attrState(type, _stream, state) { | |
| 13655 | + if (type == "word") { | |
| 13656 | + setStyle = "attribute"; | |
| 13657 | + return attrEqState; | |
| 13658 | + } else if (type == "endTag" || type == "selfcloseTag") { | |
| 13659 | + var tagName = state.tagName, tagStart = state.tagStart; | |
| 13660 | + state.tagName = state.tagStart = null; | |
| 13661 | + if (type == "selfcloseTag" || | |
| 13662 | + config.autoSelfClosers.hasOwnProperty(tagName)) { | |
| 13663 | + maybePopContext(state, tagName); | |
| 13664 | + } else { | |
| 13665 | + maybePopContext(state, tagName); | |
| 13666 | + state.context = new Context(state, tagName, tagStart == state.indented); | |
| 13667 | + } | |
| 13668 | + return baseState; | |
| 13669 | + } | |
| 13670 | + setStyle = "error"; | |
| 13671 | + return attrState; | |
| 13672 | + } | |
| 13673 | + function attrEqState(type, stream, state) { | |
| 13674 | + if (type == "equals") return attrValueState; | |
| 13675 | + if (!config.allowMissing) setStyle = "error"; | |
| 13676 | + return attrState(type, stream, state); | |
| 13677 | + } | |
| 13678 | + function attrValueState(type, stream, state) { | |
| 13679 | + if (type == "string") return attrContinuedState; | |
| 13680 | + if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;} | |
| 13681 | + setStyle = "error"; | |
| 13682 | + return attrState(type, stream, state); | |
| 13683 | + } | |
| 13684 | + function attrContinuedState(type, stream, state) { | |
| 13685 | + if (type == "string") return attrContinuedState; | |
| 13686 | + return attrState(type, stream, state); | |
| 13687 | + } | |
| 13688 | + | |
| 13689 | + return { | |
| 13690 | + startState: function(baseIndent) { | |
| 13691 | + var state = {tokenize: inText, | |
| 13692 | + state: baseState, | |
| 13693 | + indented: baseIndent || 0, | |
| 13694 | + tagName: null, tagStart: null, | |
| 13695 | + context: null} | |
| 13696 | + if (baseIndent != null) state.baseIndent = baseIndent | |
| 13697 | + return state | |
| 13698 | + }, | |
| 13699 | + | |
| 13700 | + token: function(stream, state) { | |
| 13701 | + if (!state.tagName && stream.sol()) | |
| 13702 | + state.indented = stream.indentation(); | |
| 13703 | + | |
| 13704 | + if (stream.eatSpace()) return null; | |
| 13705 | + type = null; | |
| 13706 | + var style = state.tokenize(stream, state); | |
| 13707 | + if ((style || type) && style != "comment") { | |
| 13708 | + setStyle = null; | |
| 13709 | + state.state = state.state(type || style, stream, state); | |
| 13710 | + if (setStyle) | |
| 13711 | + style = setStyle == "error" ? style + " error" : setStyle; | |
| 13712 | + } | |
| 13713 | + return style; | |
| 13714 | + }, | |
| 13715 | + | |
| 13716 | + indent: function(state, textAfter, fullLine) { | |
| 13717 | + var context = state.context; | |
| 13718 | + // Indent multi-line strings (e.g. css). | |
| 13719 | + if (state.tokenize.isInAttribute) { | |
| 13720 | + if (state.tagStart == state.indented) | |
| 13721 | + return state.stringStartCol + 1; | |
| 13722 | + else | |
| 13723 | + return state.indented + indentUnit; | |
| 13724 | + } | |
| 13725 | + if (context && context.noIndent) return CodeMirror.Pass; | |
| 13726 | + if (state.tokenize != inTag && state.tokenize != inText) | |
| 13727 | + return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0; | |
| 13728 | + // Indent the starts of attribute names. | |
| 13729 | + if (state.tagName) { | |
| 13730 | + if (config.multilineTagIndentPastTag !== false) | |
| 13731 | + return state.tagStart + state.tagName.length + 2; | |
| 13732 | + else | |
| 13733 | + return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1); | |
| 13734 | + } | |
| 13735 | + if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0; | |
| 13736 | + var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter); | |
| 13737 | + if (tagAfter && tagAfter[1]) { // Closing tag spotted | |
| 13738 | + while (context) { | |
| 13739 | + if (context.tagName == tagAfter[2]) { | |
| 13740 | + context = context.prev; | |
| 13741 | + break; | |
| 13742 | + } else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) { | |
| 13743 | + context = context.prev; | |
| 13744 | + } else { | |
| 13745 | + break; | |
| 13746 | + } | |
| 13747 | + } | |
| 13748 | + } else if (tagAfter) { // Opening tag spotted | |
| 13749 | + while (context) { | |
| 13750 | + var grabbers = config.contextGrabbers[context.tagName]; | |
| 13751 | + if (grabbers && grabbers.hasOwnProperty(tagAfter[2])) | |
| 13752 | + context = context.prev; | |
| 13753 | + else | |
| 13754 | + break; | |
| 13755 | + } | |
| 13756 | + } | |
| 13757 | + while (context && context.prev && !context.startOfLine) | |
| 13758 | + context = context.prev; | |
| 13759 | + if (context) return context.indent + indentUnit; | |
| 13760 | + else return state.baseIndent || 0; | |
| 13761 | + }, | |
| 13762 | + | |
| 13763 | + electricInput: /<\/[\s\w:]+>$/, | |
| 13764 | + blockCommentStart: "<!--", | |
| 13765 | + blockCommentEnd: "-->", | |
| 13766 | + | |
| 13767 | + configuration: config.htmlMode ? "html" : "xml", | |
| 13768 | + helperType: config.htmlMode ? "html" : "xml", | |
| 13769 | + | |
| 13770 | + skipAttribute: function(state) { | |
| 13771 | + if (state.state == attrValueState) | |
| 13772 | + state.state = attrState | |
| 13773 | + }, | |
| 13774 | + | |
| 13775 | + xmlCurrentTag: function(state) { | |
| 13776 | + return state.tagName ? {name: state.tagName, close: state.type == "closeTag"} : null | |
| 13777 | + }, | |
| 13778 | + | |
| 13779 | + xmlCurrentContext: function(state) { | |
| 13780 | + var context = [] | |
| 13781 | + for (var cx = state.context; cx; cx = cx.prev) | |
| 13782 | + context.push(cx.tagName) | |
| 13783 | + return context.reverse() | |
| 13784 | + } | |
| 13785 | + }; | |
| 13786 | +}); | |
| 13787 | + | |
| 13788 | +CodeMirror.defineMIME("text/xml", "xml"); | |
| 13789 | +CodeMirror.defineMIME("application/xml", "xml"); | |
| 13790 | +if (!CodeMirror.mimeModes.hasOwnProperty("text/html")) | |
| 13791 | + CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true}); | |
| 13792 | + | |
| 13793 | +}); | |
| 13794 | + | |
| 13795 | +},{"../../lib/codemirror":14}],19:[function(require,module,exports){ | |
| 13796 | +function dlv(t,e,n,l){for(l=0,e=e.split?e.split("."):e;t&&l<e.length;)t=t[e[l++]];return void 0===t?n:t}function linkState(t,e,n){var l=e.split("."),r=t.__lsc||(t.__lsc={});return r[e+n]||(r[e+n]=function(e){for(var r=e&&e.target||this,a={},i=a,o="string"==typeof n?dlv(e,n):r.nodeName?r.type.match(/^che|rad/)?r.checked:r.value:e,s=0;s<l.length-1;s++)i=i[l[s]]||(i[l[s]]=!s&&t.state[l[s]]||{});i[l[s]]=o,t.setState(a)})}module.exports=linkState; | |
| 13797 | + | |
| 13798 | + | |
| 13799 | +},{}],20:[function(require,module,exports){ | |
| 13800 | +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],t):t((e||self).preactRenderToString={},e.preact)}(this,function(e,t){var n=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i,r=/[&<>"]/;function o(e){var t=String(e);return r.test(t)?t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""):t}var i=function(e,t){return String(e).replace(/(\n+)/g,"$1"+(t||"\t"))},a=function(e,t,n){return String(e).length>(t||40)||!n&&-1!==String(e).indexOf("\n")||-1!==String(e).indexOf("<")},l={};function s(e){var t="";for(var r in e){var o=e[r];null!=o&&""!==o&&(t&&(t+=" "),t+="-"==r[0]?r:l[r]||(l[r]=r.replace(/([A-Z])/g,"-$1").toLowerCase()),t+=": ",t+=o,"number"==typeof o&&!1===n.test(r)&&(t+="px"),t+=";")}return t||void 0}function f(e,t){for(var n in t)e[n]=t[n];return e}function p(e,t){return Array.isArray(t)?t.reduce(p,e):null!=t&&!1!==t&&e.push(t),e}var u={shallow:!0},c=[],_=/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/,d=/[\s\n\\/='"\0<>]/,g=function(){};y.render=y;var v=function(e,t){return y(e,t,u)},h=[];function y(e,n,r){n=n||{},r=r||{};var o=t.options.__s;t.options.__s=!0;var i=m(e,n,r);return t.options.__c&&t.options.__c(e,h),h.length=0,t.options.__s=o,i}function m(e,n,r,l,u,v){if(null==e||"boolean"==typeof e)return"";if("object"!=typeof e)return o(e);var h=r.pretty,y=h&&"string"==typeof h?h:"\t";if(Array.isArray(e)){for(var x="",b=0;b<e.length;b++)h&&b>0&&(x+="\n"),x+=m(e[b],n,r,l,u,v);return x}var S,w=e.type,k=e.props,O=!1;if("function"==typeof w){if(O=!0,!r.shallow||!l&&!1!==r.renderRootComponent){if(w===t.Fragment){var T=[];return p(T,e.props.children),m(T,n,r,!1!==r.shallowHighOrder,u,v)}var C,A=e.__c={__v:e,context:n,props:e.props,setState:g,forceUpdate:g,__h:[]};if(t.options.__b&&t.options.__b(e),t.options.__r&&t.options.__r(e),w.prototype&&"function"==typeof w.prototype.render){var j=w.contextType,F=j&&n[j.__c],H=null!=j?F?F.props.value:j.__:n;(A=e.__c=new w(k,H)).__v=e,A._dirty=A.__d=!0,A.props=k,null==A.state&&(A.state={}),null==A._nextState&&null==A.__s&&(A._nextState=A.__s=A.state),A.context=H,w.getDerivedStateFromProps?A.state=f(f({},A.state),w.getDerivedStateFromProps(A.props,A.state)):A.componentWillMount&&(A.componentWillMount(),A.state=A._nextState!==A.state?A._nextState:A.__s!==A.state?A.__s:A.state),C=A.render(A.props,A.state,A.context)}else{var M=w.contextType,$=M&&n[M.__c];C=w.call(e.__c,k,null!=M?$?$.props.value:M.__:n)}return A.getChildContext&&(n=f(f({},n),A.getChildContext())),t.options.diffed&&t.options.diffed(e),m(C,n,r,!1!==r.shallowHighOrder,u,v)}w=(S=w).displayName||S!==Function&&S.name||function(e){var t=(Function.prototype.toString.call(e).match(/^\s*function\s+([^( ]+)/)||"")[1];if(!t){for(var n=-1,r=c.length;r--;)if(c[r]===e){n=r;break}n<0&&(n=c.push(e)-1),t="UnnamedComponent"+n}return t}(S)}var L,R,E="<"+w;if(k){var q=Object.keys(k);r&&!0===r.sortAttributes&&q.sort();for(var D=0;D<q.length;D++){var N=q[D],P=k[N];if("children"!==N){if(!d.test(N)&&(r&&r.allAttributes||"key"!==N&&"ref"!==N&&"__self"!==N&&"__source"!==N&&"defaultValue"!==N)){if("className"===N){if(k.class)continue;N="class"}else u&&N.match(/^xlink:?./)&&(N=N.toLowerCase().replace(/^xlink:?/,"xlink:"));if("htmlFor"===N){if(k.for)continue;N="for"}"style"===N&&P&&"object"==typeof P&&(P=s(P)),"a"===N[0]&&"r"===N[1]&&"boolean"==typeof P&&(P=String(P));var U=r.attributeHook&&r.attributeHook(N,P,n,r,O);if(U||""===U)E+=U;else if("dangerouslySetInnerHTML"===N)R=P&&P.__html;else if("textarea"===w&&"value"===N)L=P;else if((P||0===P||""===P)&&"function"!=typeof P){if(!(!0!==P&&""!==P||(P=N,r&&r.xml))){E+=" "+N;continue}if("value"===N){if("select"===w){v=P;continue}"option"===w&&v==P&&(E+=" selected")}E+=" "+N+'="'+o(P)+'"'}}}else L=P}}if(h){var W=E.replace(/\n\s*/," ");W===E||~W.indexOf("\n")?h&&~E.indexOf("\n")&&(E+="\n"):E=W}if(E+=">",d.test(w))throw new Error(w+" is not a valid HTML tag name in "+E);var z,I=_.test(w)||r.voidElements&&r.voidElements.test(w),V=[];if(R)h&&a(R)&&(R="\n"+y+i(R,y)),E+=R;else if(null!=L&&p(z=[],L).length){for(var Z=h&&~E.indexOf("\n"),B=!1,G=0;G<z.length;G++){var J=z[G];if(null!=J&&!1!==J){var K=m(J,n,r,!0,"svg"===w||"foreignObject"!==w&&u,v);if(h&&!Z&&a(K)&&(Z=!0),K)if(h){var Q=K.length>0&&"<"!=K[0];B&&Q?V[V.length-1]+=K:V.push(K),B=Q}else V.push(K)}}if(h&&Z)for(var X=V.length;X--;)V[X]="\n"+y+i(V[X],y)}if(V.length||R)E+=V.join("");else if(r&&r.xml)return E.substring(0,E.length-1)+" />";return!I||z||R?(h&&~E.indexOf("\n")&&(E+="\n"),E+="</"+w+">"):E=E.replace(/>$/," />"),E}y.shallowRender=v,e.default=y,e.render=y,e.renderToStaticMarkup=y,e.renderToString=y,e.shallowRender=v}); | |
| 13801 | + | |
| 13802 | + | |
| 13803 | +},{"preact":22}],21:[function(require,module,exports){ | |
| 13804 | +module.exports = require('./commonjs').default; | |
| 13805 | +},{"./commonjs":20}],22:[function(require,module,exports){ | |
| 13806 | +var n,l,u,t,i,o,r={},f=[],e=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function c(n,l){for(var u in l)n[u]=l[u];return n}function s(n){var l=n.parentNode;l&&l.removeChild(n)}function a(n,l,u){var t,i,o,r=arguments,f={};for(o in l)"key"==o?t=l[o]:"ref"==o?i=l[o]:f[o]=l[o];if(arguments.length>3)for(u=[u],o=3;o<arguments.length;o++)u.push(r[o]);if(null!=u&&(f.children=u),"function"==typeof n&&null!=n.defaultProps)for(o in n.defaultProps)void 0===f[o]&&(f[o]=n.defaultProps[o]);return v(n,f,t,i,null)}function v(l,u,t,i,o){var r={type:l,props:u,key:t,ref:i,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++n.__v:o};return null!=n.vnode&&n.vnode(r),r}function p(n){return n.children}function h(n,l){this.props=n,this.context=l}function y(n,l){if(null==l)return n.__?y(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return"function"==typeof n.type?y(n):null}function d(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return d(n)}}function _(l){(!l.__d&&(l.__d=!0)&&u.push(l)&&!k.__r++||i!==n.debounceRendering)&&((i=n.debounceRendering)||t)(k)}function k(){for(var n;k.__r=u.length;)n=u.sort(function(n,l){return n.__v.__b-l.__v.__b}),u=[],n.some(function(n){var l,u,t,i,o,r;n.__d&&(o=(i=(l=n).__v).__e,(r=l.__P)&&(u=[],(t=c({},i)).__v=i.__v+1,$(r,i,t,l.__n,void 0!==r.ownerSVGElement,null!=i.__h?[o]:null,u,null==o?y(i):o,i.__h),H(u,i),i.__e!=o&&d(i)))})}function x(n,l,u,t,i,o,e,c,s,a){var h,d,_,k,x,g,w,A=t&&t.__k||f,P=A.length;for(u.__k=[],h=0;h<l.length;h++)if(null!=(k=u.__k[h]=null==(k=l[h])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k||"bigint"==typeof k?v(null,k,null,null,k):Array.isArray(k)?v(p,{children:k},null,null,null):k.__b>0?v(k.type,k.props,k.key,null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(_=A[h])||_&&k.key==_.key&&k.type===_.type)A[h]=void 0;else for(d=0;d<P;d++){if((_=A[d])&&k.key==_.key&&k.type===_.type){A[d]=void 0;break}_=null}$(n,k,_=_||r,i,o,e,c,s,a),x=k.__e,(d=k.ref)&&_.ref!=d&&(w||(w=[]),_.ref&&w.push(_.ref,null,k),w.push(d,k.__c||x,k)),null!=x?(null==g&&(g=x),"function"==typeof k.type&&null!=k.__k&&k.__k===_.__k?k.__d=s=b(k,s,n):s=m(n,k,_,A,x,s),a||"option"!==u.type?"function"==typeof u.type&&(u.__d=s):n.value=""):s&&_.__e==s&&s.parentNode!=n&&(s=y(_))}for(u.__e=g,h=P;h--;)null!=A[h]&&("function"==typeof u.type&&null!=A[h].__e&&A[h].__e==u.__d&&(u.__d=y(t,h+1)),j(A[h],A[h]));if(w)for(h=0;h<w.length;h++)T(w[h],w[++h],w[++h])}function b(n,l,u){var t,i;for(t=0;t<n.__k.length;t++)(i=n.__k[t])&&(i.__=n,l="function"==typeof i.type?b(i,l,u):m(u,i,i,n.__k,i.__e,l));return l}function m(n,l,u,t,i,o){var r,f,e;if(void 0!==l.__d)r=l.__d,l.__d=void 0;else if(null==u||i!=o||null==i.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(i),r=null;else{for(f=o,e=0;(f=f.nextSibling)&&e<t.length;e+=2)if(f==i)break n;n.insertBefore(i,o),r=o}return void 0!==r?r:i.nextSibling}function g(n,l,u,t,i){var o;for(o in u)"children"===o||"key"===o||o in l||A(n,o,null,u[o],t);for(o in l)i&&"function"!=typeof l[o]||"children"===o||"key"===o||"value"===o||"checked"===o||u[o]===l[o]||A(n,o,l[o],u[o],t)}function w(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]=null==u?"":"number"!=typeof u||e.test(l)?u:u+"px"}function A(n,l,u,t,i){var o;n:if("style"===l)if("string"==typeof u)n.style.cssText=u;else{if("string"==typeof t&&(n.style.cssText=t=""),t)for(l in t)u&&l in u||w(n.style,l,"");if(u)for(l in u)t&&u[l]===t[l]||w(n.style,l,u[l])}else if("o"===l[0]&&"n"===l[1])o=l!==(l=l.replace(/Capture$/,"")),l=l.toLowerCase()in n?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+o]=u,u?t||n.addEventListener(l,o?C:P,o):n.removeEventListener(l,o?C:P,o);else if("dangerouslySetInnerHTML"!==l){if(i)l=l.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==l&&"list"!==l&&"form"!==l&&"tabIndex"!==l&&"download"!==l&&l in n)try{n[l]=null==u?"":u;break n}catch(n){}"function"==typeof u||(null!=u&&(!1!==u||"a"===l[0]&&"r"===l[1])?n.setAttribute(l,u):n.removeAttribute(l))}}function P(l){this.l[l.type+!1](n.event?n.event(l):l)}function C(l){this.l[l.type+!0](n.event?n.event(l):l)}function $(l,u,t,i,o,r,f,e,s){var a,v,y,d,_,k,b,m,g,w,A,P=u.type;if(void 0!==u.constructor)return null;null!=t.__h&&(s=t.__h,e=u.__e=t.__e,u.__h=null,r=[e]),(a=n.__b)&&a(u);try{n:if("function"==typeof P){if(m=u.props,g=(a=P.contextType)&&i[a.__c],w=a?g?g.props.value:a.__:i,t.__c?b=(v=u.__c=t.__c).__=v.__E:("prototype"in P&&P.prototype.render?u.__c=v=new P(m,w):(u.__c=v=new h(m,w),v.constructor=P,v.render=z),g&&g.sub(v),v.props=m,v.state||(v.state={}),v.context=w,v.__n=i,y=v.__d=!0,v.__h=[]),null==v.__s&&(v.__s=v.state),null!=P.getDerivedStateFromProps&&(v.__s==v.state&&(v.__s=c({},v.__s)),c(v.__s,P.getDerivedStateFromProps(m,v.__s))),d=v.props,_=v.state,y)null==P.getDerivedStateFromProps&&null!=v.componentWillMount&&v.componentWillMount(),null!=v.componentDidMount&&v.__h.push(v.componentDidMount);else{if(null==P.getDerivedStateFromProps&&m!==d&&null!=v.componentWillReceiveProps&&v.componentWillReceiveProps(m,w),!v.__e&&null!=v.shouldComponentUpdate&&!1===v.shouldComponentUpdate(m,v.__s,w)||u.__v===t.__v){v.props=m,v.state=v.__s,u.__v!==t.__v&&(v.__d=!1),v.__v=u,u.__e=t.__e,u.__k=t.__k,u.__k.forEach(function(n){n&&(n.__=u)}),v.__h.length&&f.push(v);break n}null!=v.componentWillUpdate&&v.componentWillUpdate(m,v.__s,w),null!=v.componentDidUpdate&&v.__h.push(function(){v.componentDidUpdate(d,_,k)})}v.context=w,v.props=m,v.state=v.__s,(a=n.__r)&&a(u),v.__d=!1,v.__v=u,v.__P=l,a=v.render(v.props,v.state,v.context),v.state=v.__s,null!=v.getChildContext&&(i=c(c({},i),v.getChildContext())),y||null==v.getSnapshotBeforeUpdate||(k=v.getSnapshotBeforeUpdate(d,_)),A=null!=a&&a.type===p&&null==a.key?a.props.children:a,x(l,Array.isArray(A)?A:[A],u,t,i,o,r,f,e,s),v.base=u.__e,u.__h=null,v.__h.length&&f.push(v),b&&(v.__E=v.__=null),v.__e=!1}else null==r&&u.__v===t.__v?(u.__k=t.__k,u.__e=t.__e):u.__e=I(t.__e,u,t,i,o,r,f,s);(a=n.diffed)&&a(u)}catch(l){u.__v=null,(s||null!=r)&&(u.__e=e,u.__h=!!s,r[r.indexOf(e)]=null),n.__e(l,u,t)}}function H(l,u){n.__c&&n.__c(u,l),l.some(function(u){try{l=u.__h,u.__h=[],l.some(function(n){n.call(u)})}catch(l){n.__e(l,u.__v)}})}function I(n,l,u,t,i,o,e,c){var a,v,p,h,y=u.props,d=l.props,_=l.type,k=0;if("svg"===_&&(i=!0),null!=o)for(;k<o.length;k++)if((a=o[k])&&(a===n||(_?a.localName==_:3==a.nodeType))){n=a,o[k]=null;break}if(null==n){if(null===_)return document.createTextNode(d);n=i?document.createElementNS("http://www.w3.org/2000/svg",_):document.createElement(_,d.is&&d),o=null,c=!1}if(null===_)y===d||c&&n.data===d||(n.data=d);else{if(o=o&&f.slice.call(n.childNodes),v=(y=u.props||r).dangerouslySetInnerHTML,p=d.dangerouslySetInnerHTML,!c){if(null!=o)for(y={},h=0;h<n.attributes.length;h++)y[n.attributes[h].name]=n.attributes[h].value;(p||v)&&(p&&(v&&p.__html==v.__html||p.__html===n.innerHTML)||(n.innerHTML=p&&p.__html||""))}if(g(n,d,y,i,c),p)l.__k=[];else if(k=l.props.children,x(n,Array.isArray(k)?k:[k],l,u,t,i&&"foreignObject"!==_,o,e,n.firstChild,c),null!=o)for(k=o.length;k--;)null!=o[k]&&s(o[k]);c||("value"in d&&void 0!==(k=d.value)&&(k!==n.value||"progress"===_&&!k)&&A(n,"value",k,y.value,!1),"checked"in d&&void 0!==(k=d.checked)&&k!==n.checked&&A(n,"checked",k,y.checked,!1))}return n}function T(l,u,t){try{"function"==typeof l?l(u):l.current=u}catch(l){n.__e(l,t)}}function j(l,u,t){var i,o,r;if(n.unmount&&n.unmount(l),(i=l.ref)&&(i.current&&i.current!==l.__e||T(i,null,u)),t||"function"==typeof l.type||(t=null!=(o=l.__e)),l.__e=l.__d=void 0,null!=(i=l.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(l){n.__e(l,u)}i.base=i.__P=null}if(i=l.__k)for(r=0;r<i.length;r++)i[r]&&j(i[r],u,t);null!=o&&s(o)}function z(n,l,u){return this.constructor(n,u)}function L(l,u,t){var i,o,e;n.__&&n.__(l,u),o=(i="function"==typeof t)?null:t&&t.__k||u.__k,e=[],$(u,l=(!i&&t||u).__k=a(p,null,[l]),o||r,r,void 0!==u.ownerSVGElement,!i&&t?[t]:o?null:u.firstChild?f.slice.call(u.childNodes):null,e,!i&&t?t:o?o.__e:u.firstChild,i),H(e,l)}n={__e:function(n,l){for(var u,t,i;l=l.__;)if((u=l.__c)&&!u.__)try{if((t=u.constructor)&&null!=t.getDerivedStateFromError&&(u.setState(t.getDerivedStateFromError(n)),i=u.__d),null!=u.componentDidCatch&&(u.componentDidCatch(n),i=u.__d),i)return u.__E=u}catch(l){n=l}throw n},__v:0},l=function(n){return null!=n&&void 0===n.constructor},h.prototype.setState=function(n,l){var u;u=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=c({},this.state),"function"==typeof n&&(n=n(c({},u),this.props)),n&&c(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),_(this))},h.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),_(this))},h.prototype.render=p,u=[],t="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,k.__r=0,o=0,exports.render=L,exports.hydrate=function n(l,u){L(l,u,n)},exports.createElement=a,exports.h=a,exports.Fragment=p,exports.createRef=function(){return{current:null}},exports.isValidElement=l,exports.Component=h,exports.cloneElement=function(n,l,u){var t,i,o,r=arguments,f=c({},n.props);for(o in l)"key"==o?t=l[o]:"ref"==o?i=l[o]:f[o]=l[o];if(arguments.length>3)for(u=[u],o=3;o<arguments.length;o++)u.push(r[o]);return null!=u&&(f.children=u),v(n.type,f,t||n.key,i||n.ref,null)},exports.createContext=function(n,l){var u={__c:l="__cC"+o++,__:n,Consumer:function(n,l){return n.children(l)},Provider:function(n){var u,t;return this.getChildContext||(u=[],(t={})[l]=this,this.getChildContext=function(){return t},this.shouldComponentUpdate=function(n){this.props.value!==n.value&&u.some(_)},this.sub=function(n){u.push(n);var l=n.componentWillUnmount;n.componentWillUnmount=function(){u.splice(u.indexOf(n),1),l&&l.call(n)}}),n.children}};return u.Provider.__=u.Consumer.contextType=u},exports.toChildArray=function n(l,u){return u=u||[],null==l||"boolean"==typeof l||(Array.isArray(l)?l.some(function(l){n(l,u)}):u.push(l)),u},exports.options=n; | |
| 13807 | + | |
| 13808 | + | |
| 13809 | +},{}],23:[function(require,module,exports){ | |
| 13810 | +function tlite(getTooltipOpts) { | |
| 13811 | + document.addEventListener('mouseover', function (e) { | |
| 13812 | + var el = e.target; | |
| 13813 | + var opts = getTooltipOpts(el); | |
| 13814 | + | |
| 13815 | + if (!opts) { | |
| 13816 | + el = el.parentElement; | |
| 13817 | + opts = el && getTooltipOpts(el); | |
| 13818 | + } | |
| 13819 | + | |
| 13820 | + opts && tlite.show(el, opts, true); | |
| 13821 | + }); | |
| 13822 | +} | |
| 13823 | + | |
| 13824 | +tlite.show = function (el, opts, isAuto) { | |
| 13825 | + var fallbackAttrib = 'data-tlite'; | |
| 13826 | + opts = opts || {}; | |
| 13827 | + | |
| 13828 | + (el.tooltip || Tooltip(el, opts)).show(); | |
| 13829 | + | |
| 13830 | + function Tooltip(el, opts) { | |
| 13831 | + var tooltipEl; | |
| 13832 | + var showTimer; | |
| 13833 | + var text; | |
| 13834 | + | |
| 13835 | + el.addEventListener('mousedown', autoHide); | |
| 13836 | + el.addEventListener('mouseleave', autoHide); | |
| 13837 | + | |
| 13838 | + function show() { | |
| 13839 | + text = el.title || el.getAttribute(fallbackAttrib) || text; | |
| 13840 | + el.title = ''; | |
| 13841 | + el.setAttribute(fallbackAttrib, ''); | |
| 13842 | + text && !showTimer && (showTimer = setTimeout(fadeIn, isAuto ? 150 : 1)) | |
| 13843 | + } | |
| 13844 | + | |
| 13845 | + function autoHide() { | |
| 13846 | + tlite.hide(el, true); | |
| 13847 | + } | |
| 13848 | + | |
| 13849 | + function hide(isAutoHiding) { | |
| 13850 | + if (isAuto === isAutoHiding) { | |
| 13851 | + showTimer = clearTimeout(showTimer); | |
| 13852 | + var parent = tooltipEl && tooltipEl.parentNode; | |
| 13853 | + parent && parent.removeChild(tooltipEl); | |
| 13854 | + tooltipEl = undefined; | |
| 13855 | + } | |
| 13856 | + } | |
| 13857 | + | |
| 13858 | + function fadeIn() { | |
| 13859 | + if (!tooltipEl) { | |
| 13860 | + tooltipEl = createTooltip(el, text, opts); | |
| 13861 | + } | |
| 13862 | + } | |
| 13863 | + | |
| 13864 | + return el.tooltip = { | |
| 13865 | + show: show, | |
| 13866 | + hide: hide | |
| 13867 | + }; | |
| 13868 | + } | |
| 13869 | + | |
| 13870 | + function createTooltip(el, text, opts) { | |
| 13871 | + var tooltipEl = document.createElement('span'); | |
| 13872 | + var grav = opts.grav || el.getAttribute('data-tlite') || 'n'; | |
| 13873 | + | |
| 13874 | + tooltipEl.innerHTML = text; | |
| 13875 | + | |
| 13876 | + el.appendChild(tooltipEl); | |
| 13877 | + | |
| 13878 | + var vertGrav = grav[0] || ''; | |
| 13879 | + var horzGrav = grav[1] || ''; | |
| 13880 | + | |
| 13881 | + function positionTooltip() { | |
| 13882 | + tooltipEl.className = 'tlite ' + 'tlite-' + vertGrav + horzGrav; | |
| 13883 | + | |
| 13884 | + var arrowSize = 10; | |
| 13885 | + var top = el.offsetTop; | |
| 13886 | + var left = el.offsetLeft; | |
| 13887 | + | |
| 13888 | + if (tooltipEl.offsetParent === el) { | |
| 13889 | + top = left = 0; | |
| 13890 | + } | |
| 13891 | + | |
| 13892 | + var width = el.offsetWidth; | |
| 13893 | + var height = el.offsetHeight; | |
| 13894 | + var tooltipHeight = tooltipEl.offsetHeight; | |
| 13895 | + var tooltipWidth = tooltipEl.offsetWidth; | |
| 13896 | + var centerEl = left + (width / 2); | |
| 13897 | + | |
| 13898 | + tooltipEl.style.top = ( | |
| 13899 | + vertGrav === 's' ? (top - tooltipHeight - arrowSize) : | |
| 13900 | + vertGrav === 'n' ? (top + height + arrowSize) : | |
| 13901 | + (top + (height / 2) - (tooltipHeight / 2)) | |
| 13902 | + ) + 'px'; | |
| 13903 | + | |
| 13904 | + tooltipEl.style.left = ( | |
| 13905 | + horzGrav === 'w' ? left : | |
| 13906 | + horzGrav === 'e' ? left + width - tooltipWidth : | |
| 13907 | + vertGrav === 'w' ? (left + width + arrowSize) : | |
| 13908 | + vertGrav === 'e' ? (left - tooltipWidth - arrowSize) : | |
| 13909 | + (centerEl - tooltipWidth / 2) | |
| 13910 | + ) + 'px'; | |
| 13911 | + } | |
| 13912 | + | |
| 13913 | + positionTooltip(); | |
| 13914 | + | |
| 13915 | + var rect = tooltipEl.getBoundingClientRect(); | |
| 13916 | + | |
| 13917 | + if (vertGrav === 's' && rect.top < 0) { | |
| 13918 | + vertGrav = 'n'; | |
| 13919 | + positionTooltip(); | |
| 13920 | + } else if (vertGrav === 'n' && rect.bottom > window.innerHeight) { | |
| 13921 | + vertGrav = 's'; | |
| 13922 | + positionTooltip(); | |
| 13923 | + } else if (vertGrav === 'e' && rect.left < 0) { | |
| 13924 | + vertGrav = 'w'; | |
| 13925 | + positionTooltip(); | |
| 13926 | + } else if (vertGrav === 'w' && rect.right > window.innerWidth) { | |
| 13927 | + vertGrav = 'e'; | |
| 13928 | + positionTooltip(); | |
| 13929 | + } | |
| 13930 | + | |
| 13931 | + tooltipEl.className += ' tlite-visible'; | |
| 13932 | + | |
| 13933 | + return tooltipEl; | |
| 13934 | + } | |
| 13935 | +}; | |
| 13936 | + | |
| 13937 | +tlite.hide = function (el, isAuto) { | |
| 13938 | + el.tooltip && el.tooltip.hide(isAuto); | |
| 13939 | +}; | |
| 13940 | + | |
| 13941 | +if (typeof module !== 'undefined' && module.exports) { | |
| 13942 | + module.exports = tlite; | |
| 13943 | +} | |
| 13944 | + | |
| 13945 | +},{}]},{},[2]); | |