(function(){function l(){this.overlay=this.posFrom=this.posTo=this.query=null}function d(a){return a.state.search||(a.state.search=new l)}function j(a,b,j){return a.getSearchCursor(b,j,"string"==typeof b&&b==b.toLowerCase())}function b(a){var b=a.match(/^\/(.*)\/([a-z]*)$/);return b?RegExp(b[1],-1==b[2].indexOf("i")?"":"i"):a}function e(a,j){var c=d(a);if(c.query)return f(a,j);var g=function(g){a.operation(function(){if(g&&!c.query){c.query=b(g);a.removeOverlay(c.overlay);var h;var d=c.query;h="string"==
typeof d?{token:function(a){if(a.match(d))return"searching";a.next();a.skipTo(d.charAt(0))||a.skipToEnd()}}:{token:function(a){if(a.match(d))return"searching";for(;!a.eol()&&!(a.next(),a.match(d,!1)););}};c.overlay=h;a.addOverlay(c.overlay);c.posFrom=c.posTo=a.getCursor();f(a,j)}})};a.openDialog?a.openDialog(h,g):g(prompt("Search for:",""))}function f(a,b){a.operation(function(){var c=d(a),g=j(a,c.query,b?c.posFrom:c.posTo);if(!g.find(b)&&(g=j(a,c.query,b?CodeMirror.Pos(a.lastLine()):CodeMirror.Pos(a.firstLine(),
0)),!g.find(b)))return;a.setSelection(g.from(),g.to());c.posFrom=g.from();c.posTo=g.to()})}function k(a){a.operation(function(){var b=d(a);b.query&&(b.query=null,a.removeOverlay(b.overlay))})}function m(a,d){var h=function(c){if(c){c=b(c);var h=function(b){if(d)a.operation(function(){for(var h=j(a,c);h.findNext();)if("string"!=typeof c){var g=a.getRange(h.from(),h.to()).match(c);h.replace(b.replace(/\$(\d)/,function(a,b){return g[b]}))}else h.replace(b)});else{k(a);var h=j(a,c,a.getCursor()),e=function(){var d=
h.from(),f;if(!(f=h.findNext()))if(h=j(a,c),!(f=h.findNext())||d&&h.from().line==d.line&&h.from().ch==d.ch)return;a.setSelection(h.from(),h.to());d=[function(){var a=f;h.replace("string"==typeof c?b:b.replace(/\$(\d)/,function(b,c){return a[c]}));e()},e];if(a.openConfirm)a.openConfirm(g,d);else if(confirm("Replace?"))d[0]()};e()}};a.openDialog?a.openDialog(n,h):h(prompt("Replace with:",""))}};a.openDialog?a.openDialog(c,h):h(prompt("Replace:",""))}var h='Search: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>',
c='Replace: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>',n='With: <input type="text" style="width: 10em"/>',g="Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";CodeMirror.commands.find=function(a){k(a);e(a)};CodeMirror.commands.findNext=e;CodeMirror.commands.findPrev=function(a){e(a,!0)};CodeMirror.commands.clearSearch=k;CodeMirror.commands.replace=m;CodeMirror.commands.replaceAll=function(a){m(a,!0)}})();(function(){function l(j,b,e,f){this.atOccurrence=!1;this.doc=j;null==f&&"string"==typeof b&&(f=!1);e=e?j.clipPos(e):d(0,0);this.pos={from:e,to:e};if("string"!=typeof b)b.global||(b=RegExp(b.source,b.ignoreCase?"ig":"g")),this.matches=function(h,c){if(h){b.lastIndex=0;for(var e=j.getLine(c.line).slice(0,c.ch),g=0,a,f;;){b.lastIndex=g;g=b.exec(e);if(!g)break;a=g;f=a.index;g=a.index+(a[0].length||1);if(g==e.length)break}(g=a&&a[0].length||0)||(0==f&&0==e.length?a=void 0:f!=j.getLine(c.line).length&&
g++)}else b.lastIndex=c.ch,e=j.getLine(c.line),g=(a=b.exec(e))&&a[0].length||0,f=a&&a.index,f+g!=e.length&&!g&&(g=1);if(a&&g)return{from:d(c.line,f),to:d(c.line,f+g),match:a}};else{f&&(b=b.toLowerCase());var k=f?function(b){return b.toLowerCase()}:function(b){return b},m=b.split("\n");this.matches=1==m.length?b.length?function(h,c){var e=k(j.getLine(c.line)),g=b.length,a;if(h?c.ch>=g&&-1!=(a=e.lastIndexOf(b,c.ch-g)):-1!=(a=e.indexOf(b,c.ch)))return{from:d(c.line,a),to:d(c.line,a+g)}}:function(){}:
function(b,c){var e=c.line,g=b?m.length-1:0,a=m[g],f=k(j.getLine(e)),l=b?f.indexOf(a)+a.length:f.lastIndexOf(a);if(!(b?l>=c.ch||l!=a.length:l<=c.ch||l!=f.length-a.length))for(;!(b?!e:e==j.lineCount()-1);){f=k(j.getLine(e+=b?-1:1));a=m[b?--g:++g];if(0<g&&g<m.length-1)if(f!=a)break;else continue;g=b?f.lastIndexOf(a):f.indexOf(a)+a.length;if(b?g!=f.length-a.length:g!=a.length)break;a=d(c.line,l);e=d(e,g);return{from:b?e:a,to:b?a:e}}}}}var d=CodeMirror.Pos;l.prototype={findNext:function(){return this.find(!1)},
findPrevious:function(){return this.find(!0)},find:function(j){function b(b){b=d(b,0);e.pos={from:b,to:b};return e.atOccurrence=!1}for(var e=this,f=this.doc.clipPos(j?this.pos.from:this.pos.to);;){if(this.pos=this.matches(j,f))return(!this.pos.from||!this.pos.to)&&console.log(this.matches,this.pos),this.atOccurrence=!0,this.pos.match||!0;if(j){if(!f.line)return b(0);f=d(f.line-1,this.doc.getLine(f.line-1).length)}else{var k=this.doc.lineCount();if(f.line==k-1)return b(k);f=d(f.line+1,0)}}},from:function(){if(this.atOccurrence)return this.pos.from},
to:function(){if(this.atOccurrence)return this.pos.to},replace:function(j){this.atOccurrence&&(j=CodeMirror.splitLines(j),this.doc.replaceRange(j,this.pos.from,this.pos.to),this.pos.to=d(this.pos.from.line+j.length-1,j[j.length-1].length+(1==j.length?this.pos.from.ch:0)))}};CodeMirror.defineExtension("getSearchCursor",function(d,b,e){return new l(this.doc,d,b,e)});CodeMirror.defineDocExtension("getSearchCursor",function(d,b,e){return new l(this,d,b,e)})})();(function(){function l(d,j,b){d=d.getWrapperElement().appendChild(document.createElement("div"));d.className=b?"CodeMirror-dialog CodeMirror-dialog-bottom":"CodeMirror-dialog CodeMirror-dialog-top";d.innerHTML=j;return d}CodeMirror.defineExtension("openDialog",function(d,j,b){function e(){k||(k=!0,f.parentNode.removeChild(f))}var f=l(this,d,b&&b.bottom),k=!1,m=this,h=f.getElementsByTagName("input")[0];if(h){CodeMirror.on(h,"keydown",function(c){if(!b||!b.onKeyDown||!b.onKeyDown(c,h.value,e))if(13==
c.keyCode||27==c.keyCode)CodeMirror.e_stop(c),e(),m.focus(),13==c.keyCode&&j(h.value)});if(b&&b.onKeyUp)CodeMirror.on(h,"keyup",function(c){b.onKeyUp(c,h.value,e)});b&&b.value&&(h.value=b.value);h.focus();CodeMirror.on(h,"blur",e)}else if(d=f.getElementsByTagName("button")[0])CodeMirror.on(d,"click",function(){e();m.focus()}),d.focus(),CodeMirror.on(d,"blur",e);return e});CodeMirror.defineExtension("openConfirm",function(d,j,b){function e(){k||(k=!0,f.parentNode.removeChild(f),m.focus())}var f=l(this,
d,b&&b.bottom);d=f.getElementsByTagName("button");var k=!1,m=this,h=1;d[0].focus();for(b=0;b<d.length;++b){var c=d[b];(function(b){CodeMirror.on(c,"click",function(c){CodeMirror.e_preventDefault(c);e();b&&b(m)})})(j[b]);CodeMirror.on(c,"blur",function(){--h;setTimeout(function(){0>=h&&e()},200)});CodeMirror.on(c,"focus",function(){++h})}})})();