mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-15 22:34:51 +00:00
3 lines
5.1 KiB
JavaScript
3 lines
5.1 KiB
JavaScript
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||
|
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror"),require("./searchcursor"),require("../dialog/dialog")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","./searchcursor","../dialog/dialog"],e):e(CodeMirror)}(function(e){"use strict";function o(e){return e.state.search||(e.state.search=new function(){this.posFrom=this.posTo=this.lastQuery=this.query=null,this.overlay=null})}function n(e){return"string"==typeof e&&e==e.toLowerCase()}function r(e,o,r){return e.getSearchCursor(o,r,{caseFold:n(o),multiline:!0})}function t(e,o,n,r,t){e.openDialog?e.openDialog(o,t,{value:r,selectValueOnOpen:!0}):t(prompt(n,r))}function i(e){return e.replace(/\\(.)/g,function(e,o){return"n"==o?"\n":"r"==o?"\r":o})}function a(e){var o=e.match(/^\/(.*)\/([a-z]*)$/);if(o)try{e=new RegExp(o[1],-1==o[2].indexOf("i")?"":"i")}catch(e){}else e=i(e);return("string"==typeof e?""==e:e.test(""))&&(e=/x^/),e}var s='<span class="CodeMirror-search-label">Search:</span> <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';function c(e,o,r){var t,i;o.queryText=r,o.query=a(r),e.removeOverlay(o.overlay,n(o.query)),o.overlay=(t=o.query,i=n(o.query),"string"==typeof t?t=new RegExp(t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),i?"gi":"g"):t.global||(t=new RegExp(t.source,t.ignoreCase?"gi":"g")),{token:function(e){t.lastIndex=e.pos;var o=t.exec(e.string);if(o&&o.index==e.pos)return e.pos+=o[0].length||1,"searching";o?e.pos=o.index:e.skipToEnd()}}),e.addOverlay(o.overlay),e.showMatchesOnScrollbar&&(o.annotate&&(o.annotate.clear(),o.annotate=null),o.annotate=e.showMatchesOnScrollbar(o.query,n(o.query)))}function l(n,r,i,a){var l=o(n);if(l.query)return u(n,r);var p,d,y,m,g,h=n.getSelection()||l.lastQuery;if(h instanceof RegExp&&"x^"==h.source&&(h=null),i&&n.openDialog){var v=null,x=function(o,r){e.e_stop(r),o&&(o!=l.queryText&&(c(n,l,o),l.posFrom=l.posTo=n.getCursor()),v&&(v.style.opacity=1),u(n,r.shiftKey,function(e,o){var r;o.line<3&&document.querySelector&&(r=n.display.wrapper.querySelector(".CodeMirror-dialog"))&&r.getBoundingClientRect().bottom-4>n.cursorCoords(o,"window").top&&((v=r).style.opacity=.4)}))};d=s,y=h,m=x,g=function(r,t){var i=e.keyName(r),a=n.getOption("extraKeys"),s=a&&a[i]||e.keyMap[n.getOption("keyMap")][i];"findNext"==s||"findPrev"==s||"findPersistentNext"==s||"findPersistentPrev"==s?(e.e_stop(r),c(n,o(n),t),n.execCommand(s)):"find"!=s&&"findPersistent"!=s||(e.e_stop(r),x(t,r))},(p=n).openDialog(d,m,{value:y,selectValueOnOpen:!0,closeOnEnter:!1,onClose:function(){f(p)},onKeyDown:g}),a&&h&&(c(n,l,h),u(n,r))}else t(n,s,"Search for:",h,function(e){e&&!l.query&&n.operation(function(){c(n,l,e),l.posFrom=l.posTo=n.getCursor(),u(n,r)})})}function u(n,t,i){n.operation(function(){var a=o(n),s=r(n,a.query,t?a.posFrom:a.posTo);(s.find(t)||(s=r(n,a.query,t?e.Pos(n.lastLine()):e.Pos(n.firstLine(),0))).find(t))&&(n.setSelection(s.from(),s.to()),n.scrollIntoView({from:s.from(),to:s.to()},20),a.posFrom=s.from(),a.posTo=s.to(),i&&i(s.from(),s.to()))})}function f(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))})}var p=' <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>',d='<span class="CodeMirror-search-label">With:</span> <input type="text" style="width: 10em" class="CodeMirror-search-field"/>',y='<span class="CodeMirror-search-label">Replace?</span> <button>Yes</button> <button>No</button> <button>All</button> <button>Stop</button>';function m(e,o,n){e.operation(function(){for(var t=r(e,o);t.findNext();)if("string"!=typeof o){var i=e.getRange(t.from(),t.to()).match(o);t.replace(n.replace(/\$(\d)/g,function(e,o){return i[o]}))}else t.replace(n)})}function g(e,n){if(!e.getOption("readOnly")){var s=e.getSelection()||o(e).lastQuery,
|