!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define("addon/search/searchcursor",["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function n(e){var n=e.flags;return null!=n?n:(e.ignoreCase?"i":"")+(e.global?"g":"")+(e.multiline?"m":"")}function t(e,t){for(var o=n(e),r=o,i=0;ic);u++){var f=e.getLine(l++);s=null==s?f:s+"\n"+f}a*=2,n.lastIndex=i.ch;var h=n.exec(s);if(h){var p=s.slice(0,h.index).split("\n"),d=h[0].split("\n"),m=i.line+p.length-1,v=p[p.length-1].length;return{from:g(m,v),to:g(m+d.length-1,1==d.length?v+d[0].length:d[d.length-1].length),match:h}}}}function s(e,n){for(var t,o=0;;){n.lastIndex=o;var r=n.exec(e);if(!r)return t;if(t=r,(o=t.index+(t[0].length||1))==e.length)return t}}function a(e,n,o){n=t(n,"g");for(var r=o.line,i=o.ch,a=e.firstLine();r>=a;r--,i=-1){var l=e.getLine(r);i>-1&&(l=l.slice(0,i));var c=s(l,n);if(c)return{from:g(r,c.index),to:g(r,c.index+c[0].length),match:c}}}function l(e,n,o){n=t(n,"gm");for(var r,i=1,a=o.line,l=e.firstLine();a>=l;){for(var c=0;c>1,a=o(e.slice(0,s)).length;if(a==t)return s;a>t?i=s:r=s+1}}function u(e,n,t,o){if(!n.length)return null;var r=o?p:d,i=r(n).split(/\r|\n\r?/);e:for(var s=t.line,a=t.ch,l=e.lastLine()+1-i.length;s<=l;s++,a=0){var u=e.getLine(s).slice(a),f=r(u);if(1==i.length){var h=f.indexOf(i[0]);if(-1==h)continue e;var t=c(u,f,h,r)+a;return{from:g(s,c(u,f,h,r)+a),to:g(s,c(u,f,h+i[0].length,r)+a)}}var m=f.length-i[0].length;if(f.slice(m)==i[0]){for(var v=1;v=l;s--,a=-1){var u=e.getLine(s);a>-1&&(u=u.slice(0,a));var f=r(u);if(1==i.length){var h=f.lastIndexOf(i[0]);if(-1==h)continue e;return{from:g(s,c(u,f,h,r)),to:g(s,c(u,f,h+i[0].length,r))}}var m=i[i.length-1];if(f.slice(0,m.length)==m){for(var v=1,t=s-i.length+1;v0);)o.push({anchor:r.from(),head:r.to()});o.length&&this.setSelections(o,0)})}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define("addon/dialog/dialog",["../../lib/codemirror"],e):e(CodeMirror)}(function(e){function n(n,t,o){var r,i=n.getWrapperElement();return r=i.appendChild(document.createElement("div")),r.className=o?"CodeMirror-dialog CodeMirror-dialog-bottom":"CodeMirror-dialog CodeMirror-dialog-top","string"==typeof t?r.innerHTML=t:r.appendChild(t),e.addClass(i,"dialog-opened"),r}function t(e,n){e.state.currentNotificationClose&&e.state.currentNotificationClose(),e.state.currentNotificationClose=n}e.defineExtension("openDialog",function(o,r,i){function s(n){if("string"==typeof n)f.value=n;else{if(c)return;c=!0,e.rmClass(l.parentNode,"dialog-opened"),l.parentNode.removeChild(l),u.focus(),i.onClose&&i.onClose(l)}}i||(i={}),t(this,null);var a,l=n(this,o,i.bottom),c=!1,u=this,f=l.getElementsByTagName("input")[0];return f?(f.focus(),i.value&&(f.value=i.value,!1!==i.selectValueOnOpen&&f.select()),i.onInput&&e.on(f,"input",function(e){i.onInput(e,f.value,s)}),i.onKeyUp&&e.on(f,"keyup",function(e){i.onKeyUp(e,f.value,s)}),e.on(f,"keydown",function(n){i&&i.onKeyDown&&i.onKeyDown(n,f.value,s)||((27==n.keyCode||!1!==i.closeOnEnter&&13==n.keyCode)&&(f.blur(),e.e_stop(n),s()),13==n.keyCode&&r(f.value,n))}),!1!==i.closeOnBlur&&e.on(f,"blur",s)):(a=l.getElementsByTagName("button")[0])&&(e.on(a,"click",function(){s(),u.focus()}),!1!==i.closeOnBlur&&e.on(a,"blur",s),a.focus()),s}),e.defineExtension("openConfirm",function(o,r,i){function s(){c||(c=!0,e.rmClass(a.parentNode,"dialog-opened"),a.parentNode.removeChild(a),u.focus())}t(this,null);var a=n(this,o,i&&i.bottom),l=a.getElementsByTagName("button"),c=!1,u=this,f=1;l[0].focus();for(var h=0;hn.cursorCoords(t,"window").top&&((u=o).style.opacity=.4)}))};s(n,g(n),c,h,function(t,r){var i=e.keyName(t),s=n.getOption("extraKeys"),a=s&&s[i]||e.keyMap[n.getOption("keyMap")][i];"findNext"==a||"findPrev"==a||"findPersistentNext"==a||"findPersistentPrev"==a?(e.e_stop(t),f(n,o(n),r),n.execCommand(a)):"find"!=a&&"findPersistent"!=a||(e.e_stop(t),h(r,t))}),i&&c&&(f(n,l,c),p(n,t))}else a(n,g(n),"Search for:",c,function(e){e&&!l.query&&n.operation(function(){f(n,l,e),l.posFrom=l.posTo=n.getCursor(),p(n,t)})})}function p(n,t,r){n.operation(function(){var s=o(n),a=i(n,s.query,t?s.posFrom:s.posTo);(a.find(t)||(a=i(n,s.query,t?e.Pos(n.lastLine()):e.Pos(n.firstLine(),0)),a.find(t)))&&(n.setSelection(a.from(),a.to()),n.scrollIntoView({from:a.from(),to:a.to()},20),s.posFrom=a.from(),s.posTo=a.to(),r&&r(a.from(),a.to()))})}function d(e){e.operation(function(){var n=o(e);n.lastQuery=n.query,n.query&&(n.query=n.queryText=null,e.removeOverlay(n.overlay),n.annotate&&(n.annotate.clear(),n.annotate=null))})}function g(e){return''+e.phrase("Search:")+' '+e.phrase("(Use /re/ syntax for regexp search)")+""}function m(e){return' '+e.phrase("(Use /re/ syntax for regexp search)")+""}function v(e){return''+e.phrase("With:")+' '}function y(e){return''+e.phrase("Replace?")+" "}function x(e,n,t){e.operation(function(){for(var o=i(e,n);o.findNext();)if("string"!=typeof n){var r=e.getRange(o.from(),o.to()).match(n);o.replace(t.replace(/\$(\d)/g,function(e,n){return r[n]}))}else o.replace(t)})}function C(e,n){if(!e.getOption("readOnly")){var t=e.getSelection()||o(e).lastQuery,r=''+(n?e.phrase("Replace all:"):e.phrase("Replace:"))+"";a(e,r+m(e),r,t,function(t){t&&(t=u(t),a(e,v(e),e.phrase("Replace with:"),"",function(o){if(o=c(o),n)x(e,t,o);else{d(e);var r=i(e,t,e.getCursor("from")),s=function(){var n,c=r.from();!(n=r.findNext())&&(r=i(e,t),!(n=r.findNext())||c&&r.from().line==c.line&&r.from().ch==c.ch)||(e.setSelection(r.from(),r.to()),e.scrollIntoView({from:r.from(),to:r.to()}),l(e,y(e),e.phrase("Replace?"),[function(){a(n)},s,function(){x(e,t,o)}]))},a=function(e){r.replace("string"==typeof t?o:o.replace(/\$(\d)/g,function(n,t){return e[t]})),s()};s()}}))})}}e.commands.find=function(e){d(e),h(e)},e.commands.findPersistent=function(e){d(e),h(e,!1,!0)},e.commands.findPersistentNext=function(e){h(e,!1,!0,!0)},e.commands.findPersistentPrev=function(e){h(e,!0,!0,!0)},e.commands.findNext=h,e.commands.findPrev=function(e){h(e,!0)},e.commands.clearSearch=d,e.commands.replace=C,e.commands.replaceAll=function(e){C(e,!0)}}),function(e){"function"==typeof e.define&&e.define("addonSearch",["addon/search/search.js"],function(){})}(this);