17 lines
8.2 KiB
JavaScript
17 lines
8.2 KiB
JavaScript
(function(b){"object"==typeof exports&&"object"==typeof module?b(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],b):b(CodeMirror)})(function(b){function l(b,c,a){var e;return e=b.getWrapperElement().appendChild(document.createElement("div")),e.className=a?"CodeMirror-dialog CodeMirror-dialog-bottom":"CodeMirror-dialog CodeMirror-dialog-top","string"==typeof c?e.innerHTML=c:e.appendChild(c),e}function o(b,c){b.state.currentNotificationClose&&b.state.currentNotificationClose();
|
|
b.state.currentNotificationClose=c}b.defineExtension("openDialog",function(g,c,a){function e(){h||(h=!0,i.parentNode.removeChild(i))}var d;o(this,null);var i=l(this,g,a&&a.bottom),h=!1,k=this;if(d=i.getElementsByTagName("input")[0],d){a&&a.value&&(d.value=a.value);b.on(d,"keydown",function(g){a&&a.onKeyDown&&a.onKeyDown(g,d.value,e)||(13==g.keyCode||27==g.keyCode)&&(d.blur(),b.e_stop(g),e(),k.focus(),13==g.keyCode&&c(d.value))});if(a&&a.onKeyUp)b.on(d,"keyup",function(c){a.onKeyUp(c,d.value,e)});
|
|
a&&a.value&&(d.value=a.value);d.focus();b.on(d,"blur",e)}else if(g=i.getElementsByTagName("button")[0])b.on(g,"click",function(){e();k.focus()}),g.focus(),b.on(g,"blur",e);return e});b.defineExtension("openConfirm",function(g,c,a){function e(){h||(h=!0,i.parentNode.removeChild(i),k.focus())}var d;o(this,null);var i=l(this,g,a&&a.bottom),a=i.getElementsByTagName("button"),h=!1,k=this,m=1;a[0].focus();for(g=0;g<a.length;++g)d=a[g],function(a){b.on(d,"click",function(c){b.e_preventDefault(c);e();a&&
|
|
a(k)})}(c[g]),b.on(d,"blur",function(){--m;setTimeout(function(){0>=m&&e()},200)}),b.on(d,"focus",function(){++m})});b.defineExtension("openNotification",function(g,c){function a(){i||(i=!0,clearTimeout(h),e.parentNode.removeChild(e))}o(this,a);var e=l(this,g,c&&c.bottom),d=c&&(void 0===c.duration?5E3:c.duration),i=!1,h;b.on(e,"click",function(c){b.e_preventDefault(c);a()});d&&(h=setTimeout(a,c.duration))})});
|
|
(function(b){"object"==typeof exports&&"object"==typeof module?b(require("../../lib/codemirror"),require("./searchcursor"),require("../dialog/dialog")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","./searchcursor","../dialog/dialog"],b):b(CodeMirror)})(function(b){function l(f,a){return"string"==typeof f?f=RegExp(f.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),a?"gi":"g"):f.global||(f=RegExp(f.source,f.ignoreCase?"gi":"g")),{token:function(a){f.lastIndex=a.pos;var c=
|
|
f.exec(a.string);if(c&&c.index==a.pos)return a.pos+=c[0].length,"searching";c?a.pos=c.index:a.skipToEnd()}}}function o(){this.overlay=this.posFrom=this.posTo=this.query=null}function g(f){return f.state.search||(f.state.search=new o)}function c(f){return"string"==typeof f&&f==f.toLowerCase()}function a(f,a,b){return f.getSearchCursor(a,b,c(a))}function e(f,a,c,b,e){f.openDialog?f.openDialog(a,e,{value:b}):e(prompt(c,b))}function d(f,a,c,b){f.openConfirm?f.openConfirm(a,b):confirm(c)&&b[0]()}function i(f){var a=
|
|
f.match(/^\/(.*)\/([a-z]*)$/);return a?(f=RegExp(a[1],-1==a[2].indexOf("i")?"":"i"),f.test("")&&(f=/x^/)):""==f&&(f=/x^/),f}function h(a,b){var d=g(a);if(d.query)return k(a,b);e(a,n,"Search for:",a.getSelection(),function(e){a.operation(function(){e&&!d.query&&(d.query=i(e),a.removeOverlay(d.overlay,c(d.query)),d.overlay=l(d.query,c(d.query)),a.addOverlay(d.overlay),d.posFrom=d.posTo=a.getCursor(),k(a,b))})})}function k(f,c){f.operation(function(){var d=g(f),e=a(f,d.query,c?d.posFrom:d.posTo);(e.find(c)||
|
|
(e=a(f,d.query,c?b.Pos(f.lastLine()):b.Pos(f.firstLine(),0)),e.find(c)))&&(f.setSelection(e.from(),e.to()),f.scrollIntoView({from:e.from(),to:e.to()}),d.posFrom=e.from(),d.posTo=e.to())})}function m(a){a.operation(function(){var c=g(a);c.query&&(c.query=null,a.removeOverlay(c.overlay))})}function q(c,b){e(c,r,"Replace:",c.getSelection(),function(g){g&&(g=i(g),e(c,p,"Replace with:","",function(e){if(b)c.operation(function(){for(var d,b=a(c,g);b.findNext();)"string"!=typeof g?(d=c.getRange(b.from(),
|
|
b.to()).match(g),b.replace(e.replace(/\$(\d)/g,function(a,c){return d[c]}))):b.replace(e)});else{m(c);var n=a(c,g,c.getCursor()),h=function(){var b=n.from(),e;((e=n.findNext())||(n=a(c,g),(e=n.findNext())&&(!b||n.from().line!=b.line||n.from().ch!=b.ch)))&&(c.setSelection(n.from(),n.to()),c.scrollIntoView({from:n.from(),to:n.to()}),d(c,j,"Replace?",[function(){p(e)},h]))},p=function(a){n.replace("string"==typeof g?e:e.replace(/\$(\d)/g,function(c,b){return a[b]}));h()};h()}}))})}var n='Search: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>',
|
|
r='Replace: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>',p='With: <input type="text" style="width: 10em"/>',j="Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";b.commands.find=function(a){m(a);h(a)};b.commands.findNext=h;b.commands.findPrev=function(a){h(a,!0)};b.commands.clearSearch=m;b.commands.replace=q;b.commands.replaceAll=function(a){q(a,!0)}});
|
|
(function(b){"object"==typeof exports&&"object"==typeof module?b(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],b):b(CodeMirror)})(function(b){function l(c,a,b,d){var i,h,k,m;this.atOccurrence=!1;this.doc=c;null==d&&"string"==typeof a&&(d=!1);b=b?c.clipPos(b):g(0,0);this.pos={from:b,to:b};"string"!=typeof a?(a.global||(a=RegExp(a.source,a.ignoreCase?"ig":"g")),this.matches=function(b,d){var e,h,j,f,i;if(b){a.lastIndex=0;e=c.getLine(d.line).slice(0,
|
|
d.ch);for(h=0;!(a.lastIndex=h,i=a.exec(e),!i)&&!(j=i,f=j.index,h=j.index+(j[0].length||1),h==e.length););(h=j&&j[0].length||0)||(0==f&&0==e.length?j=void 0:f!=c.getLine(d.line).length&&h++)}else a.lastIndex=d.ch,e=c.getLine(d.line),h=(j=a.exec(e))&&j[0].length||0,f=j&&j.index,f+h==e.length||h||(h=1);if(j&&h)return{from:g(d.line,f),to:g(d.line,f+h),match:j}}):(i=a,d&&(a=a.toLowerCase()),h=d?function(a){return a.toLowerCase()}:function(a){return a},k=a.split("\n"),1==k.length?this.matches=a.length?
|
|
function(b,d){if(b){var e=c.getLine(d.line).slice(0,d.ch),k=h(e),j=k.lastIndexOf(a);if(-1<j)return j=o(e,k,j),{from:g(d.line,j),to:g(d.line,j+i.length)}}else if(e=c.getLine(d.line).slice(d.ch),k=h(e),j=k.indexOf(a),-1<j)return j=o(e,k,j)+d.ch,{from:g(d.line,j),to:g(d.line,j+i.length)}}:function(){}:(m=i.split("\n"),this.matches=function(a,b){var d=k.length-1,e,j,f,i,l;if(a){if(b.line-(k.length-1)<c.firstLine()||h(c.getLine(b.line).slice(0,m[d].length))!=k[k.length-1])return;e=g(b.line,m[d].length);
|
|
i=b.line-1;for(l=d-1;1<=l;--l,--i)if(k[l]!=h(c.getLine(i)))return;return(j=c.getLine(i),f=j.length-m[0].length,h(j.slice(f))!=k[0])?void 0:{from:g(i,f),to:e}}if(!(b.line+(k.length-1)>c.lastLine())&&(j=c.getLine(b.line),f=j.length-m[0].length,h(j.slice(f))==k[0])){e=g(b.line,f);i=b.line+1;for(l=1;l<d;++l,++i)if(k[l]!=h(c.getLine(i)))return;if(c.getLine(i).slice(0,m[d].length)==k[d])return{from:e,to:g(i,m[d].length)}}}))}function o(c,a,b){var d;if(c.length==a.length)return b;for(a=Math.min(b,c.length);;)if(d=
|
|
c.slice(0,a).toLowerCase().length,d<b)++a;else if(d>b)--a;else return a}var g=b.Pos;l.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(c){function a(a){a=g(a,0);return b.pos={from:a,to:a},b.atOccurrence=!1,!1}for(var b=this,d=this.doc.clipPos(c?this.pos.from:this.pos.to),i;;){if(this.pos=this.matches(c,d))return this.atOccurrence=!0,this.pos.match||!0;if(c){if(!d.line)return a(0);d=g(d.line-1,this.doc.getLine(d.line-1).length)}else{if(i=
|
|
this.doc.lineCount(),d.line==i-1)return a(i);d=g(d.line+1,0)}}},from:function(){if(this.atOccurrence)return this.pos.from},to:function(){if(this.atOccurrence)return this.pos.to},replace:function(c){this.atOccurrence&&(c=b.splitLines(c),this.doc.replaceRange(c,this.pos.from,this.pos.to),this.pos.to=g(this.pos.from.line+c.length-1,c[c.length-1].length+(1==c.length?this.pos.from.ch:0)))}};b.defineExtension("getSearchCursor",function(b,a,e){return new l(this.doc,b,a,e)});b.defineDocExtension("getSearchCursor",
|
|
function(b,a,e){return new l(this,b,a,e)});b.defineExtension("selectMatches",function(c,a){for(var e=[],d=this.getSearchCursor(c,this.getCursor("from"),a);d.findNext()&&!(0<b.cmpPos(d.to(),this.getCursor("to")));)e.push({anchor:d.from(),head:d.to()});e.length&&this.setSelections(e,0)})}); |