-
Notifications
You must be signed in to change notification settings - Fork 1
/
anyword-hint.min.js
1 lines (1 loc) · 26.5 KB
/
anyword-hint.min.js
1
var isSame;!function(t){"object"==typeof exports&&"object"==typeof module?t(require("codemirror")):"function"==typeof define&&define.amd?define(["codemirror"],mod):t(CodeMirror)}(function(t){"use strict";var e=/[\w?.,%]+/,n=500;t.registerHelper("hint","anyword",function(i,o){for(var r=o&&o.word||e,s=o&&o.range||n,a=o&&o.extraWords||EXTRAWORDS,c=i.getCursor(),l=i.getLine(c.line),h=c.ch,u=h;u&&r.test(l.charAt(u-1));)--u;var f=u!=h&&l.slice(u,h);f&&(f=f.toLowerCase()),isSame=a.some(t=>t.toLowerCase()===f);for(var d=o&&o.list||[],p={},g=RegExp(r.source,"gi"),m=-1;m<=1;m+=2)for(var v=c.line,$=Math.min(Math.max(v+m*s,i.firstLine()),i.lastLine())+m;v!=$;v+=m){var y,C=i.getLine(v),_=(C=(C=C.replace(/\/{2}.*/g,"")).replace(/(=|-|\+|\*|<|>)\d+/g,"")).match(/\w+(?:,(\S+)){2}/);for(_&&(C=C.replace(_[1]," "+_[1])),C.includes("#")&&(g=RegExp(/[\w?#.,%]+/,"gi"));y=g.exec(C);)(v!=c.line||y[0].toLowerCase()!==f)&&(f&&0!=y[0].toLowerCase().lastIndexOf(f,0)||Object.prototype.hasOwnProperty.call(p,y[0])||(p[y[0]]=!0,d.push(y[0])))}d.sort(),d.reverse();(d=[...new Map(d.map(t=>[t.toLowerCase(),t])).values()]).sort();var b=a.filter(t=>t.toLowerCase().startsWith(f||""));return b.sort(),d=d.concat(b),(d=[...new Map(d.map(t=>[t.toLowerCase(),t])).values()]).sort(function(t,e){return t.toLowerCase().localeCompare(e.toLowerCase())}),{list:d,from:t.Pos(c.line,u),to:t.Pos(c.line,h)}})}),function(t){"object"==typeof exports&&"object"==typeof module?t(require("codemirror")):"function"==typeof define&&define.amd?define(["codemirror"],mod):t(CodeMirror)}(function(t){"use strict";var e="CodeMirror-hint-active";function n(e,n){if(this.cm=e,this.options=n,this.widget=null,this.debounce=0,this.tick=0,this.startPos=this.cm.getCursor("start"),this.startLen=this.cm.getLine(this.startPos.line).length-this.cm.getSelection().length,this.options.updateOnCursorActivity){var i=this;e.on("cursorActivity",this.activityFunc=function(){i.cursorActivity()})}t.signal(this,"startCompletion",this)}t.showHint=function(t,e,n){if(!e)return t.showHint(n);n&&n.async&&(e.async=!0);var i={hint:e};if(n)for(var o in n)i[o]=n[o];return t.showHint(i)},t.defineExtension("showHint",function(e){e=function t(e,n,i){var o=e.options.hintOptions,r={};for(var s in l)r[s]=l[s];if(o)for(var s in o)void 0!==o[s]&&(r[s]=o[s]);if(i)for(var s in i)void 0!==i[s]&&(r[s]=i[s]);return r.hint.resolve&&(r.hint=r.hint.resolve(e,n)),r}(this,this.getCursor("start"),e);var i=this.listSelections();if(!(i.length>1)){if(this.somethingSelected()){if(!e.hint.supportsSelection)return;for(var o=0;o<i.length;o++)if(i[o].head.line!=i[o].anchor.line)return}this.state.completionActive&&this.state.completionActive.close();var r=this.state.completionActive=new n(this,e);r.options.hint&&(t.signal(this,"startCompletion",this),r.update(!0))}}),t.defineExtension("closeHint",function(){this.state.completionActive&&this.state.completionActive.close()});var i=window.requestAnimationFrame||function(t){return setTimeout(t,1e3/60)},o=window.cancelAnimationFrame||clearTimeout;function r(t){return"string"==typeof t?t:t.text}function s(t,e){for(;e&&e!=t;){if("LI"===e.nodeName.toUpperCase()&&e.parentNode==t)return e;e=e.parentNode}}function a(n,i){this.id="cm-complete-"+Math.floor(Math.random(1e6)),this.completion=n,this.data=i,this.picked=!1;var o,a,c=this,l=n.cm,h=l.getInputField().ownerDocument,u=h.defaultView||h.parentWindow,f=this.hints=h.createElement("ul");f.setAttribute("role","listbox"),f.setAttribute("aria-expanded","true"),f.id=this.id;var d=n.cm.options.theme;f.className="CodeMirror-hints "+d,this.selectedHint=i.selectedHint||0;for(var p=i.list,g=0;g<p.length;++g){var m=f.appendChild(h.createElement("li")),v=p[g],$="CodeMirror-hint"+(g!=this.selectedHint?"":" "+e);null!=v.className&&($=v.className+" "+$),m.className=$,g==this.selectedHint&&m.setAttribute("aria-selected","true"),m.id=this.id+"-"+g,m.setAttribute("role","option"),v.render?v.render(m,i,v):m.appendChild(h.createTextNode(v.displayText||r(v))),m.hintId=g}var y=n.options.container||h.body,C=l.cursorCoords(n.options.alignWithWord?i.from:null),_=C.left,b=C.bottom,x=!0,w=0,S=0;if(y!==h.body){var N=-1!==["absolute","relative","fixed"].indexOf(u.getComputedStyle(y).position)?y:y.offsetParent,O=N.getBoundingClientRect(),L=h.body.getBoundingClientRect();w=O.left-L.left-N.scrollLeft,S=O.top-L.top-N.scrollTop}f.style.left=_-w+"px",f.style.top=b-S+"px";var k=u.innerWidth||Math.max(h.body.offsetWidth,h.documentElement.offsetWidth),A=u.innerHeight||Math.max(h.body.offsetHeight,h.documentElement.offsetHeight);y.appendChild(f),l.getInputField().setAttribute("aria-autocomplete","list"),l.getInputField().setAttribute("aria-owns",this.id),l.getInputField().setAttribute("aria-activedescendant",this.id+"-"+this.selectedHint);var H=n.options.moveOnOverlap?f.getBoundingClientRect():new DOMRect,M=!!n.options.paddingForScrollbar&&f.scrollHeight>f.clientHeight+1;if(setTimeout(function(){o=l.getScrollInfo()}),H.bottom-A>0){var P=H.bottom-H.top;if(C.top-(C.bottom-H.top)-P>0)f.style.top=(b=C.top-P-S)+"px",x=!1;else if(P>A){f.style.height=A-5+"px",f.style.top=(b=C.bottom-H.top-S)+"px";var E=l.getCursor();i.from.ch!=E.ch&&(C=l.cursorCoords(E),f.style.left=(_=C.left-w)+"px",H=f.getBoundingClientRect())}}var T=H.right-k;if(M&&(T+=l.display.nativeBarWidth),T>0&&(H.right-H.left>k&&(f.style.width=k-5+"px",T-=H.right-H.left-k),f.style.left=(_=C.left-T-w)+"px"),M)for(var F=f.firstChild;F;F=F.nextSibling)F.style.paddingRight=l.display.nativeBarWidth+"px";l.addKeyMap(this.keyMap=function t(e,n){var i={Up:function(){n.moveFocus(-1)},Down:function(){n.moveFocus(1)},PageUp:function(){n.moveFocus(-n.menuSize()+1,!0)},PageDown:function(){n.moveFocus(n.menuSize()-1,!0)},Home:function(){n.setFocus(0)},End:function(){n.setFocus(n.length-1)},Enter:n.pick,Tab:n.pick,Esc:n.close},o=/Mac/.test(navigator.platform);isSame&&(i.Space=n.pick,i[","]=n.pick),o&&(i["Ctrl-P"]=function(){n.moveFocus(-1)},i["Ctrl-N"]=function(){n.moveFocus(1)});var r=e.options.customKeys,s=r?{}:i;function a(t,e){var o;o="string"!=typeof e?function(t){return e(t,n)}:i.hasOwnProperty(e)?i[e]:e,s[t]=o}if(r)for(var c in r)r.hasOwnProperty(c)&&a(c,r[c]);var l=e.options.extraKeys;if(l)for(var c in l)l.hasOwnProperty(c)&&a(c,l[c]);return s}(n,{moveFocus:function(t,e){c.changeActive(c.selectedHint+t,e)},setFocus:function(t){c.changeActive(t)},menuSize:function(){return c.screenAmount()},length:p.length,close:function(){n.close()},pick:function(){c.pick()},data:i})),n.options.closeOnUnfocus&&(l.on("blur",this.onBlur=function(){a=setTimeout(function(){n.close()},100)}),l.on("focus",this.onFocus=function(){clearTimeout(a)})),l.on("scroll",this.onScroll=function(){var t=l.getScrollInfo(),e=l.getWrapperElement().getBoundingClientRect();o||(o=l.getScrollInfo());var i=b+o.top-t.top,r=i-(u.pageYOffset||(h.documentElement||h.body).scrollTop);if(x||(r+=f.offsetHeight),r<=e.top||r>=e.bottom)return n.close();f.style.top=i+"px",f.style.left=_+o.left-t.left+"px"}),t.on(f,"dblclick",function(t){var e=s(f,t.target||t.srcElement);e&&null!=e.hintId&&(c.changeActive(e.hintId),c.pick())}),t.on(f,"click",function(t){var e=s(f,t.target||t.srcElement);e&&null!=e.hintId&&(c.changeActive(e.hintId),n.options.completeOnSingleClick&&c.pick())}),t.on(f,"mousedown",function(){setTimeout(function(){l.focus()},20)});var I=this.getSelectedHintRange();return(0!==I.from||0!==I.to)&&this.scrollToActive(),t.signal(i,"select",p[this.selectedHint],f.childNodes[this.selectedHint]),!0}function c(t,e,n,i){if(t.async)t(e,i,n);else{var o=t(e,n);o&&o.then?o.then(i):i(o)}}n.prototype={close:function(){this.active()&&(this.cm.state.completionActive=null,this.tick=null,this.options.updateOnCursorActivity&&this.cm.off("cursorActivity",this.activityFunc),this.widget&&this.data&&t.signal(this.data,"close"),this.widget&&this.widget.close(),t.signal(this.cm,"endCompletion",this.cm))},active:function(){return this.cm.state.completionActive==this},pick:function(e,n){var i=e.list[n],o=this;this.cm.operation(function(){i.hint?i.hint(o.cm,e,i):o.cm.replaceRange(r(i),i.from||e.from,i.to||e.to,"complete"),t.signal(e,"pick",i),o.cm.scrollIntoView()}),this.options.closeOnPick&&this.close()},cursorActivity:function(){this.debounce&&(o(this.debounce),this.debounce=0);var t=this.startPos;this.data&&(t=this.data.from);var e=this.cm.getCursor(),n=this.cm.getLine(e.line);if(e.line!=this.startPos.line||n.length-e.ch!=this.startLen-this.startPos.ch||e.ch<t.ch||this.cm.somethingSelected()||!e.ch||this.options.closeCharacters.test(n.charAt(e.ch-1)))this.close();else{var r=this;this.debounce=i(function(){r.update()}),this.widget&&this.widget.disable()}},update:function(t){if(null!=this.tick){var e=this,n=++this.tick;c(this.options.hint,this.cm,this.options,function(i){e.tick==n&&e.finishUpdate(i,t)})}},finishUpdate:function(e,n){this.data&&t.signal(this.data,"update");var i=this.widget&&this.widget.picked||n&&this.options.completeSingle;this.widget&&this.widget.close(),this.data=e,e&&e.list.length&&(i&&1==e.list.length?this.pick(e,0):(this.widget=new a(this,e),t.signal(e,"shown")))}},a.prototype={close:function(){if(this.completion.widget==this){this.completion.widget=null,this.hints.parentNode&&this.hints.parentNode.removeChild(this.hints),this.completion.cm.removeKeyMap(this.keyMap);var t=this.completion.cm.getInputField();t.removeAttribute("aria-activedescendant"),t.removeAttribute("aria-owns");var e=this.completion.cm;this.completion.options.closeOnUnfocus&&(e.off("blur",this.onBlur),e.off("focus",this.onFocus)),e.off("scroll",this.onScroll)}},disable:function(){this.completion.cm.removeKeyMap(this.keyMap);var t=this;this.keyMap={Enter:function(){t.picked=!0}},this.completion.cm.addKeyMap(this.keyMap)},pick:function(){i=rEdit.getCursor().ch,o=rEdit.getCursor().ch-this.data.list[0].length,1===i||0===i?e="":(e=" ".repeat(i-2),n=o>0?" ".repeat(o):""),isSame&&"Space"===nameKey?"If"===this.data.list[0]?this.data.list[0]=this.data.list[0]+" ":"Do"!=this.data.list[0]&&(this.data.list[0]=this.data.list[0]+" ",isSame=!1,t=0):isSame&&"Enter"===nameKey?("If"===this.data.list[0]?(this.data.list[0]=this.data.list[0]+" \n"+e+"Endif",t=1):"On"===this.data.list[0]?(this.data.list[0]=this.data.list[0]+" Do\n\nEndon",t=2):"Do"===this.data.list[0]?(this.data.list[0]=this.data.list[0]+"\n\nEndon",t=2.2):(this.data.list[0]=this.data.list[0]+"\n"+n,t=0),isSame=!1):isSame&&","===nameKey&&(this.data.list[0]=this.data.list[0]+",",t=0,isSame=!1),"LogEntry"===this.data.list[this.selectedHint]&&(this.data.list[this.selectedHint]=this.data.list[this.selectedHint]+",''",t=3),this.completion.pick(this.data,this.selectedHint);var t,e,n,i,o,r=rEdit.getCursor().line,s=rEdit.getCursor().ch;if(1===t)rEdit.setCursor({line:r-1});else if(2===t)for(rEdit.setCursor({line:r-1}),rEdit.execCommand("insertSoftTab"),rEdit.setCursor({line:r-2,ch:i+1});rEdit.getCursor().ch>3;)rEdit.execCommand("indentLess");else 2.2===t?(rEdit.setCursor({line:r-1}),rEdit.execCommand("insertSoftTab")):3===t&&rEdit.setCursor({line:r,ch:s-1})},changeActive:function(n,i){if(n>=this.data.list.length?n=i?this.data.list.length-1:0:n<0&&(n=i?0:this.data.list.length-1),this.selectedHint!=n){var o=this.hints.childNodes[this.selectedHint];o&&(o.className=o.className.replace(" "+e,""),o.removeAttribute("aria-selected")),o=this.hints.childNodes[this.selectedHint=n],o.className+=" "+e,o.setAttribute("aria-selected","true"),this.completion.cm.getInputField().setAttribute("aria-activedescendant",o.id),this.scrollToActive(),t.signal(this.data,"select",this.data.list[this.selectedHint],o)}},scrollToActive:function(){var t=this.getSelectedHintRange(),e=this.hints.childNodes[t.from],n=this.hints.childNodes[t.to],i=this.hints.firstChild;e.offsetTop<this.hints.scrollTop?this.hints.scrollTop=e.offsetTop-i.offsetTop:n.offsetTop+n.offsetHeight>this.hints.scrollTop+this.hints.clientHeight&&(this.hints.scrollTop=n.offsetTop+n.offsetHeight-this.hints.clientHeight+i.offsetTop)},screenAmount:function(){return Math.floor(this.hints.clientHeight/this.hints.firstChild.offsetHeight)||1},getSelectedHintRange:function(){var t=this.completion.options.scrollMargin||0;return{from:Math.max(0,this.selectedHint-t),to:Math.min(this.data.list.length-1,this.selectedHint+t)}}},t.registerHelper("hint","auto",{resolve:function e(n,i){var o,r=n.getHelpers(i,"hint");if(r.length){var s=function(t,e,n){var i=function t(e,n){if(!e.somethingSelected())return n;for(var i=[],o=0;o<n.length;o++)n[o].supportsSelection&&i.push(n[o]);return i}(t,r);!function o(r){if(r==i.length)return e(null);c(i[r],t,n,function(t){t&&t.list.length>0?e(t):o(r+1)})}(0)};return s.async=!0,s.supportsSelection=!0,s}return(o=n.getHelper(n.getCursor(),"hintWords"))?function(e){return t.hint.fromList(e,{words:o})}:t.hint.anyword?function(e,n){return t.hint.anyword(e,n)}:function(){}}}),t.registerHelper("hint","fromList",function(e,n){var i,o=e.getCursor(),r=e.getTokenAt(o),s=t.Pos(o.line,r.start);r.start<o.ch&&/\w/.test(r.string.charAt(o.ch-r.start-1))?i=r.string.substr(0,o.ch-r.start):(i="",s=o);for(var a=[],c=0;c<n.words.length;c++){var l=n.words[c];l.slice(0,i.length)==i&&a.push(l)}if(a.length)return{list:a,from:s,to:o}}),t.commands.autocomplete=t.showHint;var l={hint:t.hint.auto,completeSingle:!0,alignWithWord:!0,closeCharacters:/[[\s=+*\-()\[\]{};:>]/,closeOnPick:!0,closeOnUnfocus:!0,updateOnCursorActivity:!0,completeOnSingleClick:!0,container:null,customKeys:null,extraKeys:null,paddingForScrollbar:!0,moveOnOverlap:!0};t.defineOption("hintOptions",null)}),function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("./searchcursor"),require("../dialog/dialog")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","./searchcursor","../dialog/dialog"],mod):t(CodeMirror)}(function(t){"use strict";function e(){this.posFrom=this.posTo=this.lastQuery=this.query=null,this.overlay=null}function n(t){return t.state.search||(t.state.search=new e)}function i(t){return"string"==typeof t&&t==t.toLowerCase()}function o(t,e,n){return t.getSearchCursor(e,n,{caseFold:i(e),multiline:!0})}function r(t,e,n,i,o){t.openDialog?t.openDialog(e,o,{value:i,selectValueOnOpen:!0,bottom:t.options.search.bottom}):o(prompt(n,i))}function s(t){return t.replace(/\\([nrt\\])/g,function(t,e){return"n"==e?"\n":"r"==e?"\r":"t"==e?" ":"\\"==e?"\\":t})}function a(t){var e=t.match(/^\/(.*)\/([a-z]*)$/);if(e)try{t=RegExp(e[1],-1==e[2].indexOf("i")?"":"i")}catch(n){}else t=s(t);return("string"==typeof t?""==t:t.test(""))&&(t=/x^/),t}function c(t,e,n){var o,r;e.queryText=n,e.query=a(n),t.removeOverlay(e.overlay,i(e.query)),e.overlay=(o=e.query,r=i(e.query),"string"==typeof o?o=RegExp(o.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),r?"gi":"g"):o.global||(o=RegExp(o.source,o.ignoreCase?"gi":"g")),{token:function(t){o.lastIndex=t.pos;var e=o.exec(t.string);if(e&&e.index==t.pos)return t.pos+=e[0].length||1,"searching";e?t.pos=e.index:t.skipToEnd()}}),t.addOverlay(e.overlay),t.showMatchesOnScrollbar&&(e.annotate&&(e.annotate.clear(),e.annotate=null),e.annotate=t.showMatchesOnScrollbar(e.query,i(e.query)))}function l(e,i,o,s){var a=n(e);if(a.query)return h(e,i);var l=e.getSelection()||a.lastQuery;if(l instanceof RegExp&&"x^"==l.source&&(l=null),o&&e.openDialog){var f=null,p=function(n,i){t.e_stop(i),n&&(n!=a.queryText&&(c(e,a,n),a.posFrom=a.posTo=e.getCursor()),f&&(f.style.opacity=1),h(e,i.shiftKey,function(t,n){var i;n.line<3&&document.querySelector&&(i=e.display.wrapper.querySelector(".CodeMirror-dialog"))&&i.getBoundingClientRect().bottom-4>e.cursorCoords(n,"window").top&&((f=i).style.opacity=.4)}))};(function t(e,n,i,o,r){e.openDialog(n,o,{value:i,selectValueOnOpen:!0,closeOnEnter:!1,onClose:function(){u(e)},onKeyDown:r,bottom:e.options.search.bottom})})(e,d(e),l,p,function(i,o){var r=t.keyName(i),s=e.getOption("extraKeys"),a=s&&s[r]||t.keyMap[e.getOption("keyMap")][r];"findNext"==a||"findPrev"==a||"findPersistentNext"==a||"findPersistentPrev"==a?(t.e_stop(i),c(e,n(e),o),e.execCommand(a)):("find"==a||"findPersistent"==a)&&(t.e_stop(i),p(o,i))}),s&&l&&(c(e,a,l),h(e,i))}else r(e,d(e),"Search for:",l,function(t){t&&!a.query&&e.operation(function(){c(e,a,t),a.posFrom=a.posTo=e.getCursor(),h(e,i)})})}function h(e,i,r){e.operation(function(){var s=n(e),a=o(e,s.query,i?s.posFrom:s.posTo);(a.find(i)||(a=o(e,s.query,i?t.Pos(e.lastLine()):t.Pos(e.firstLine(),0))).find(i))&&(e.setSelection(a.from(),a.to()),e.scrollIntoView({from:a.from(),to:a.to()},20),s.posFrom=a.from(),s.posTo=a.to(),r&&r(a.from(),a.to()))})}function u(t){t.operation(function(){var e=n(t);e.lastQuery=e.query,e.query&&(e.query=e.queryText=null,t.removeOverlay(e.overlay),e.annotate&&(e.annotate.clear(),e.annotate=null))})}function f(t,e){var n=t?document.createElement(t):document.createDocumentFragment();for(var i in e)n[i]=e[i];for(var o=2;o<arguments.length;o++){var r=arguments[o];n.appendChild("string"==typeof r?document.createTextNode(r):r)}return n}function d(t){var e=f("label",{className:"CodeMirror-search-label"},t.phrase("Search:"),f("input",{type:"text",style:"width: 10em",className:"CodeMirror-search-field",id:"CodeMirror-search-field"}));return e.setAttribute("for","CodeMirror-search-field"),f("",null,e," ",f("span",{style:"color: #666",className:"CodeMirror-search-hint"},t.phrase("(Use /re/ syntax for regexp search)")))}function p(t,e,n){t.operation(function(){for(var i=o(t,e);i.findNext();)if("string"!=typeof e){var r=t.getRange(i.from(),i.to()).match(e);i.replace(n.replace(/\$(\d)/g,function(t,e){return r[e]}))}else i.replace(n)})}function g(t,e){if(!t.getOption("readOnly")){var i,c=t.getSelection()||n(t).lastQuery,l=e?t.phrase("Replace all:"):t.phrase("Replace:"),h=f("",null,f("span",{className:"CodeMirror-search-label"},l),(i=t,f("",null," ",f("input",{type:"text",style:"width: 10em",className:"CodeMirror-search-field"})," ",f("span",{style:"color: #666",className:"CodeMirror-search-hint"},i.phrase("(Use /re/ syntax for regexp search)")))));r(t,h,l,c,function(n){if(n){var i;n=a(n),r(t,(i=t,f("",null,f("span",{className:"CodeMirror-search-label"},i.phrase("With:"))," ",f("input",{type:"text",style:"width: 10em",className:"CodeMirror-search-field"}))),t.phrase("Replace with:"),"",function(i){if(i=s(i),e)p(t,n,i);else{u(t);var r=o(t,n,t.getCursor("from")),a=function(){var e,s,l,h,u,d,g=r.from();((d=r.findNext())||(d=(r=o(t,n)).findNext())&&(!g||r.from().line!=g.line||r.from().ch!=g.ch))&&(t.setSelection(r.from(),r.to()),t.scrollIntoView({from:r.from(),to:r.to()}),s=t,l=(e=t,f("",null,f("span",{className:"CodeMirror-search-label"},e.phrase("Replace?"))," ",f("button",{},e.phrase("Yes"))," ",f("button",{},e.phrase("No"))," ",f("button",{},e.phrase("All"))," ",f("button",{},e.phrase("Stop")))),h=t.phrase("Replace?"),u=[function(){c(d)},a,function(){p(t,n,i)}],s.openConfirm?s.openConfirm(l,u):confirm(h)&&u[0]())},c=function(t){r.replace("string"==typeof n?i:i.replace(/\$(\d)/g,function(e,n){return t[n]})),a()};a()}})}})}}t.defineOption("search",{bottom:!1}),t.commands.find=function(t){u(t),l(t)},t.commands.findPersistent=function(t){u(t),l(t,!1,!0)},t.commands.findPersistentNext=function(t){l(t,!1,!0,!0)},t.commands.findPersistentPrev=function(t){l(t,!0,!0,!0)},t.commands.findNext=l,t.commands.findPrev=function(t){l(t,!0)},t.commands.clearSearch=u,t.commands.replace=g,t.commands.replaceAll=function(t){g(t,!0)}}),function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):t(CodeMirror)}(function(t){"use strict";var e,n,i=t.Pos;function o(t){var e=t.flags;return null!=e?e:(t.ignoreCase?"i":"")+(t.global?"g":"")+(t.multiline?"m":"")}function r(t,e){for(var n=o(t),i=n,r=0;r<e.length;r++)-1==i.indexOf(e.charAt(r))&&(i+=e.charAt(r));return n==i?t:RegExp(t.source,i)}function s(t){return/\\s|\\n|\n|\\W|\\D|\[\^/.test(t.source)}function a(t,e,n){e=r(e,"g");for(var o=n.line,s=n.ch,a=t.lastLine();o<=a;o++,s=0){e.lastIndex=s;var c=t.getLine(o),l=e.exec(c);if(l)return{from:i(o,l.index),to:i(o,l.index+l[0].length),match:l}}}function c(t,e,n){if(!s(e))return a(t,e,n);e=r(e,"gm");for(var o,c=1,l=n.line,h=t.lastLine();l<=h;){for(var u=0;u<c&&!(l>h);u++){var f=t.getLine(l++);o=null==o?f:o+"\n"+f}c*=2,e.lastIndex=n.ch;var d=e.exec(o);if(d){var p=o.slice(0,d.index).split("\n"),g=d[0].split("\n"),m=n.line+p.length-1,v=p[p.length-1].length;return{from:i(m,v),to:i(m+g.length-1,1==g.length?v+g[0].length:g[g.length-1].length),match:d}}}}function l(t,e,n){for(var i,o=0;o<=t.length;){e.lastIndex=o;var r=e.exec(t);if(!r)break;var s=r.index+r[0].length;if(s>t.length-n)break;(!i||s>i.index+i[0].length)&&(i=r),o=r.index+1}return i}function h(t,e,n){e=r(e,"g");for(var o=n.line,s=n.ch,a=t.firstLine();o>=a;o--,s=-1){var c=t.getLine(o),h=l(c,e,s<0?0:c.length-s);if(h)return{from:i(o,h.index),to:i(o,h.index+h[0].length),match:h}}}function u(t,e,n){if(!s(e))return h(t,e,n);e=r(e,"gm");for(var o,a=1,c=t.getLine(n.line).length-n.ch,u=n.line,f=t.firstLine();u>=f;){for(var d=0;d<a&&u>=f;d++){var p=t.getLine(u--);o=null==o?p:p+"\n"+o}a*=2;var g=l(o,e,c);if(g){var m=o.slice(0,g.index).split("\n"),v=g[0].split("\n"),$=u+m.length,y=m[m.length-1].length;return{from:i($,y),to:i($+v.length-1,1==v.length?y+v[0].length:v[v.length-1].length),match:g}}}}function f(t,e,n,i){if(t.length==e.length)return n;for(var o=0,r=n+Math.max(0,t.length-e.length);;){if(o==r)return o;var s=o+r>>1,a=i(t.slice(0,s)).length;if(a==n)return s;a>n?r=s:o=s+1}}function d(t,o,r,s){if(!o.length)return null;var a=s?e:n,c=a(o).split(/\r|\n\r?/);search:for(var l=r.line,h=r.ch,u=t.lastLine()+1-c.length;l<=u;l++,h=0){var d=t.getLine(l).slice(h),p=a(d);if(1==c.length){var g=p.indexOf(c[0]);if(-1==g)continue search;var r=f(d,p,g,a)+h;return{from:i(l,f(d,p,g,a)+h),to:i(l,f(d,p,g+c[0].length,a)+h)}}var m=p.length-c[0].length;if(p.slice(m)!=c[0])continue search;for(var v=1;v<c.length-1;v++)if(a(t.getLine(l+v))!=c[v])continue search;var $=t.getLine(l+c.length-1),y=a($),C=c[c.length-1];if(y.slice(0,C.length)!=C)continue search;return{from:i(l,f(d,p,m,a)+h),to:i(l+c.length-1,f($,y,C.length,a))}}}function p(t,o,r,s){if(!o.length)return null;var a=s?e:n,c=a(o).split(/\r|\n\r?/);search:for(var l=r.line,h=r.ch,u=t.firstLine()-1+c.length;l>=u;l--,h=-1){var d=t.getLine(l);h>-1&&(d=d.slice(0,h));var p=a(d);if(1==c.length){var g=p.lastIndexOf(c[0]);if(-1==g)continue search;return{from:i(l,f(d,p,g,a)),to:i(l,f(d,p,g+c[0].length,a))}}var m=c[c.length-1];if(p.slice(0,m.length)!=m)continue search;for(var v=1,r=l-c.length+1;v<c.length-1;v++)if(a(t.getLine(r+v))!=c[v])continue search;var $=t.getLine(l+1-c.length),y=a($);if(y.slice(y.length-c[0].length)!=c[0])continue search;return{from:i(l+1-c.length,f($,y,$.length-c[0].length,a)),to:i(l,f(d,p,m.length,a))}}}function g(t,e,n,o){var s;this.atOccurrence=!1,this.afterEmptyMatch=!1,this.doc=t,n=n?t.clipPos(n):i(0,0),this.pos={from:n,to:n},"object"==typeof o?s=o.caseFold:(s=o,o=null),"string"==typeof e?(null==s&&(s=!1),this.matches=function(n,i){return(n?p:d)(t,e,i,s)}):(e=r(e,"gm"),o&&!1===o.multiline?this.matches=function(n,i){return(n?h:a)(t,e,i)}:this.matches=function(n,i){return(n?u:c)(t,e,i)})}String.prototype.normalize?(e=function(t){return t.normalize("NFD").toLowerCase()},n=function(t){return t.normalize("NFD")}):(e=function(t){return t.toLowerCase()},n=function(t){return t}),g.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(e){var n=this.doc.clipPos(e?this.pos.from:this.pos.to);if(this.afterEmptyMatch&&this.atOccurrence&&(n=i(n.line,n.ch),e?(n.ch--,n.ch<0&&(n.line--,n.ch=(this.doc.getLine(n.line)||"").length)):(n.ch++,n.ch>(this.doc.getLine(n.line)||"").length&&(n.ch=0,n.line++)),0!=t.cmpPos(n,this.doc.clipPos(n))))return this.atOccurrence=!1;var o=this.matches(e,n);if(this.afterEmptyMatch=o&&0==t.cmpPos(o.from,o.to),o)return this.pos=o,this.atOccurrence=!0,this.pos.match||!0;var r=i(e?this.doc.firstLine():this.doc.lastLine()+1,0);return this.pos={from:r,to:r},this.atOccurrence=!1},from:function(){if(this.atOccurrence)return this.pos.from},to:function(){if(this.atOccurrence)return this.pos.to},replace:function(e,n){if(this.atOccurrence){var o=t.splitLines(e);this.doc.replaceRange(o,this.pos.from,this.pos.to,n),this.pos.to=i(this.pos.from.line+o.length-1,o[o.length-1].length+(1==o.length?this.pos.from.ch:0))}}},t.defineExtension("getSearchCursor",function(t,e,n){return new g(this.doc,t,e,n)}),t.defineDocExtension("getSearchCursor",function(t,e,n){return new g(this,t,e,n)}),t.defineExtension("selectMatches",function(e,n){for(var i=[],o=this.getSearchCursor(e,this.getCursor("from"),n);o.findNext()&&!(t.cmpPos(o.to(),this.getCursor("to"))>0);)i.push({anchor:o.from(),head:o.to()});i.length&&this.setSelections(i,0)})}),function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):t(CodeMirror)}(function(t){function e(e,n,i){var o,r=e.getWrapperElement();return o=r.appendChild(document.createElement("div")),i?o.className="CodeMirror-dialog CodeMirror-dialog-bottom":o.className="CodeMirror-dialog CodeMirror-dialog-top","string"==typeof n?o.innerHTML=n:o.appendChild(n),t.addClass(r,"dialog-opened"),o}function n(t,e){t.state.currentNotificationClose&&t.state.currentNotificationClose(),t.state.currentNotificationClose=e}t.defineExtension("openDialog",function(i,o,r){r||(r={}),n(this,null);var s=e(this,i,r.bottom),a=!1,c=this;function l(e){if("string"==typeof e)u.value=e;else{if(a)return;a=!0,t.rmClass(s.parentNode,"dialog-opened"),s.parentNode.removeChild(s),c.focus(),r.onClose&&r.onClose(s)}}var h,u=s.getElementsByTagName("input")[0];return u?(u.focus(),r.value&&(u.value=r.value,!1!==r.selectValueOnOpen&&u.select()),r.onInput&&t.on(u,"input",function(t){r.onInput(t,u.value,l)}),r.onKeyUp&&t.on(u,"keyup",function(t){r.onKeyUp(t,u.value,l)}),t.on(u,"keydown",function(e){!(r&&r.onKeyDown&&r.onKeyDown(e,u.value,l))&&((27==e.keyCode||!1!==r.closeOnEnter&&13==e.keyCode)&&(u.blur(),t.e_stop(e),l()),13==e.keyCode&&o(u.value,e))}),!1!==r.closeOnBlur&&t.on(s,"focusout",function(t){null!==t.relatedTarget&&l()})):(h=s.getElementsByTagName("button")[0])&&(t.on(h,"click",function(){l(),c.focus()}),!1!==r.closeOnBlur&&t.on(h,"blur",l),h.focus()),l}),t.defineExtension("openConfirm",function(i,o,r){n(this,null);var s=e(this,i,r&&r.bottom),a=s.getElementsByTagName("button"),c=!1,l=this,h=1;function u(){c||(c=!0,t.rmClass(s.parentNode,"dialog-opened"),s.parentNode.removeChild(s),l.focus())}a[0].focus();for(var f=0;f<a.length;++f){var d=a[f];(function(e){t.on(d,"click",function(n){t.e_preventDefault(n),u(),e&&e(l)})})(o[f]),t.on(d,"blur",function(){--h,setTimeout(function(){h<=0&&u()},200)}),t.on(d,"focus",function(){++h})}}),t.defineExtension("openNotification",function(i,o){n(this,l);var r,s=e(this,i,o&&o.bottom),a=!1,c=o&&void 0!==o.duration?o.duration:5e3;function l(){a||(a=!0,clearTimeout(r),t.rmClass(s.parentNode,"dialog-opened"),s.parentNode.removeChild(s))}return t.on(s,"click",function(e){t.e_preventDefault(e),l()}),c&&(r=setTimeout(l,c)),l})});