(function(n){typeof exports=="object"&&typeof module=="object"?n(require("../../lib/codemirror")):typeof define=="function"&&define.amd?define(["../../lib/codemirror"],n):n(CodeMirror)})(function(n){function t(n,t,i){var u=n.getWrapperElement(),r;return r=u.appendChild(document.createElement("div")),r.className=i?"CodeMirror-dialog CodeMirror-dialog-bottom":"CodeMirror-dialog CodeMirror-dialog-top",typeof t=="string"?r.innerHTML=t:r.appendChild(t),r}function i(n,t){n.state.currentNotificationClose&&n.state.currentNotificationClose();n.state.currentNotificationClose=t}n.defineExtension("openDialog",function(r,u,f){function o(n){if(typeof n=="string")e.value=n;else{if(c)return;if(c=!0,s.parentNode.removeChild(s),l.focus(),f.onClose)f.onClose(s)}}var e,h;f||(f={});i(this,null);var s=t(this,r,f.bottom),c=!1,l=this;if(e=s.getElementsByTagName("input")[0],e){if(e.focus(),f.value&&(e.value=f.value,f.selectValueOnOpen!==!1&&e.select()),f.onInput)n.on(e,"input",function(n){f.onInput(n,e.value,o)});if(f.onKeyUp)n.on(e,"keyup",function(n){f.onKeyUp(n,e.value,o)});n.on(e,"keydown",function(t){f&&f.onKeyDown&&f.onKeyDown(t,e.value,o)||((t.keyCode==27||f.closeOnEnter!==!1&&t.keyCode==13)&&(e.blur(),n.e_stop(t),o()),t.keyCode==13&&u(e.value,t))});if(f.closeOnBlur!==!1)n.on(e,"blur",o)}else if(h=s.getElementsByTagName("button")[0]){n.on(h,"click",function(){o();l.focus()});if(f.closeOnBlur!==!1)n.on(h,"blur",o);h.focus()}return o});n.defineExtension("openConfirm",function(r,u,f){function v(){l||(l=!0,s.parentNode.removeChild(s),a.focus())}var e,o;i(this,null);var s=t(this,r,f&&f.bottom),h=s.getElementsByTagName("button"),l=!1,a=this,c=1;for(h[0].focus(),e=0;et.cursorCoords(i,"window").top&&((a=r).style.opacity=.4)}))},w(t,l,c,v,function(r,u){var o=n.keyName(r),f=n.keyMap[t.getOption("keyMap")][o];f||(f=t.getOption("extraKeys")[o]);f=="findNext"||f=="findPrev"||f=="findPersistentNext"||f=="findPersistentPrev"?(n.e_stop(r),e(t,i(t),u),t.execCommand(f)):(f=="find"||f=="findPersistent")&&(n.e_stop(r),v(u,r))}),f&&c&&(e(t,h,c),o(t,r))):s(t,l,"Search for:",c,function(n){n&&!h.query&&t.operation(function(){e(t,h,n);h.posFrom=h.posTo=t.getCursor();o(t,r)})})}function o(t,u,f){t.operation(function(){var o=i(t),e=r(t,o.query,u?o.posFrom:o.posTo);(e.find(u)||(e=r(t,o.query,u?n.Pos(t.lastLine()):n.Pos(t.firstLine(),0)),e.find(u)))&&(t.setSelection(e.from(),e.to()),t.scrollIntoView({from:e.from(),to:e.to()},20),o.posFrom=e.from(),o.posTo=e.to(),f&&f(e.from(),e.to()))})}function u(n){n.operation(function(){var t=i(n);(t.lastQuery=t.query,t.query)&&(t.query=t.queryText=null,n.removeOverlay(t.overlay),t.annotate&&(t.annotate.clear(),t.annotate=null))})}function a(n,t,i){n.operation(function(){for(var f,u=r(n,t);u.findNext();)typeof t!="string"?(f=n.getRange(u.from(),u.to()).match(t),u.replace(i.replace(/\$(\d)/g,function(n,t){return f[t]}))):u.replace(i)})}function v(n,t){if(!n.getOption("readOnly")){var e=n.getSelection()||i(n).lastQuery,f=t?"Replace all:":"Replace:";s(n,f+k,f,e,function(i){i&&(i=c(i),s(n,d,"Replace with:","",function(f){if(f=h(f),t)a(n,i,f);else{u(n);var e=r(n,i,n.getCursor("from")),o=function(){var t=e.from(),u;((u=e.findNext())||(e=r(n,i),(u=e.findNext())&&(!t||e.from().line!=t.line||e.from().ch!=t.ch)))&&(n.setSelection(e.from(),e.to()),n.scrollIntoView({from:e.from(),to:e.to()}),b(n,g,"Replace?",[function(){s(u)},o,function(){a(n,i,f)}]))},s=function(n){e.replace(typeof i=="string"?f:f.replace(/\$(\d)/g,function(t,i){return n[i]}));o()};o()}}))})}}var l='Search: (Use /re/ syntax for regexp search)<\/span>',k=' (Use /re/ syntax for regexp search)<\/span>',d='With: ',g="Replace?