mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-27 10:30:28 +00:00
769ffa19b7
* Update codemirror.js to 5.58.2 * Update codemirror.css to 5.58.2 * Update activeline.js to 5.58.2 * Update dialog.js to 5.58.2 * Update jump-to-line.js to 5.58.2 * Update search.js to 5.58.2 * Update searchcursor.js to 5.58.2 * Update xml.js to 5.58.2 * Update show-hint.js to 5.58.2 * Update show-hint.css to 5.58.2 * Update javascript-hint.js to 5.58.2 * Update xml-hint.js to 5.58.2 * Update html-hint.js to 5.58.2 * Update css-hint.js to 5.58.2 * Update anyword-hint.js to 5.58.2 * Update closebrackets.js to 5.58.2 * Update matchbrackets.js to 5.58.2 * Update closetag.js to 5.58.2 * Update xml-fold.js to 5.58.2 * Update fullscreen.js to 5.58.2 * Update emacs.js to 5.58.2 * Update sublime.js to 5.58.2 * Update comment.js to 5.58.2 * Update vim.js to 5.58.2 * Update css.js to 5.58.2 * Update multiplex.js to 5.58.2 * Update htmlembedded.js to 5.58.2 * Update htmlmixed.js to 5.58.2 * Update javascript.js to 5.58.2 * Update markdown.js to 5.58.2 * Update markdown.js * Update readme.tid * Update markdown.js
4 lines
5.3 KiB
JavaScript
4 lines
5.3 KiB
JavaScript
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: https://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(d){"use strict";function n(){this.posFrom=this.posTo=this.lastQuery=this.query=null,this.overlay=null}function y(e){return e.state.search||(e.state.search=new n)}function a(e){return"string"==typeof e&&e==e.toLowerCase()}function m(e,n,o){return e.getSearchCursor(n,o,{caseFold:a(n),multiline:!0})}function h(e,n,o,r,t){e.openDialog?e.openDialog(n,t,{value:r,selectValueOnOpen:!0}):t(prompt(o,r))}function r(e){return e.replace(/\\([nrt\\])/g,function(e,n){return"n"==n?"\n":"r"==n?"\r":"t"==n?"\t":"\\"==n?"\\":e})}function s(e){var n=e.match(/^\/(.*)\/([a-z]*)$/);if(n)try{e=new RegExp(n[1],-1==n[2].indexOf("i")?"":"i")}catch(e){}else e=r(e);return("string"==typeof e?""==e:e.test(""))&&(e=/x^/),e}function g(e,n,o){var r,t;n.queryText=o,n.query=s(o),e.removeOverlay(n.overlay,a(n.query)),n.overlay=(r=n.query,t=a(n.query),"string"==typeof r?r=new RegExp(r.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),t?"gi":"g"):r.global||(r=new RegExp(r.source,r.ignoreCase?"gi":"g")),{token:function(e){r.lastIndex=e.pos;var n=r.exec(e.string);if(n&&n.index==e.pos)return e.pos+=n[0].length||1,"searching";n?e.pos=n.index:e.skipToEnd()}}),e.addOverlay(n.overlay),e.showMatchesOnScrollbar&&(n.annotate&&(n.annotate.clear(),n.annotate=null),n.annotate=e.showMatchesOnScrollbar(n.query,a(n.query)))}function o(a,n,e,o){var r=y(a);if(r.query)return x(a,n);var t,s,i,c,l,u,p,f=a.getSelection()||r.lastQuery;f instanceof RegExp&&"x^"==f.source&&(f=null),e&&a.openDialog?(t=null,s=function(e,n){d.e_stop(n),e&&(e!=r.queryText&&(g(a,r,e),r.posFrom=r.posTo=a.getCursor()),t&&(t.style.opacity=1),x(a,n.shiftKey,function(e,n){var o;n.line<3&&document.querySelector&&(o=a.display.wrapper.querySelector(".CodeMirror-dialog"))&&o.getBoundingClientRect().bottom-4>a.cursorCoords(n,"window").top&&((t=o).style.opacity=.4)}))},c=C(i=a),l=f,u=s,p=function(e,n){var o=d.keyName(e),r=a.getOption("extraKeys"),t=r&&r[o]||d.keyMap[a.getOption("keyMap")][o];"findNext"==t||"findPrev"==t||"findPersistentNext"==t||"findPersistentPrev"==t?(d.e_stop(e),g(a,y(a),n),a.execCommand(t)):"find"!=t&&"findPersistent"!=t||(d.e_stop(e),s(n,e))},i.openDialog(c,u,{value:l,selectValueOnOpen:!0,closeOnEnter:!1,onClose:function(){v(i)},onKeyDown:p}),o&&f&&(g(a,r,f),x(a,n))):h(a,C(a),"Search for:",f,function(e){e&&!r.query&&a.operation(function(){g(a,r,e),r.posFrom=r.posTo=a.getCursor(),x(a,n)})})}function x(o,r,t){o.operation(function(){var e=y(o),n=m(o,e.query,r?e.posFrom:e.posTo);(n.find(r)||(n=m(o,e.query,r?d.Pos(o.lastLine()):d.Pos(o.firstLine(),0))).find(r))&&(o.setSelection(n.from(),n.to()),o.scrollIntoView({from:n.from(),to:n.to()},20),e.posFrom=n.from(),e.posTo=n.to(),t&&t(n.from(),n.to()))})}function v(n){n.operation(function(){var e=y(n);e.lastQuery=e.query,e.query&&(e.query=e.queryText=null,n.removeOverlay(e.overlay),e.annotate&&(e.annotate.clear(),e.annotate=null))})}function C(e){return'<span class="CodeMirror-search-label">'+e.phrase("Search:")+'</span> <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">'+e.phrase("(Use /re/ syntax for regexp search)")+"</span>"}function q(n,r,t){n.operation(function(){for(var o,e=m(n,r);e.findNext();){"string"!=typeof r?(o=n.getRange(e.from(),e.to()).match(r),e.replace(t.replace(/\$(\d)/g,function(e,n){return o[n]}))):e.replace(t)}})}function t(f,e){var n,o;f.getOption("readOnly")||(n=f.getSelection()||y(f).lastQuery,o='<span class="CodeMirror-search-label">'+(e?f.phrase("Replace all:"):f.phrase("Replace:"))+"</span>",h(f,o+(' <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">'+f.phrase("(Use /re/ syntax for regexp search)")+"</span>"),o,n,function(p){p&&(p=s(p),h(f,'<span class="CodeMirror-search-label">'+f.phrase("With:")+'</span> <input type="text" style="width: 10em" class="CodeMirror-search-field"/>',f.phrase("Replace with:"),"",function(i){var c,l,u;i=r(i),e?q(f,p,i):(v(f),c=m(f,p,f.getCursor("from")),l=function(){var e,n,o,r,t,a,s=c.from();!(e=c.findNext())&&(c=m(f,p),!(e=c.findNext())||s&&c.from().line==s.line&&c.from().ch==s.ch)||(f.setSelection(c.from(),c.to()),f.scrollIntoView({from:c.from(),to:c.to()}),o='<span class="CodeMirror-search-label">'+(a=n=f).phrase("Replace?")+"</span> <button>"+a.phrase("Yes")+"</button> <button>"+a.phrase("No")+"</button> <button>"+a.phrase("All")+"</button> <button>"+a.phrase("Stop")+"</button> ",r=f.phrase("Replace?"),t=[function(){u(e)},l,function(){q(f,p,i)}],n.openConfirm?n.openConfirm(o,t):confirm(r)&&t[0]())},u=function(o){c.replace("string"==typeof p?i:i.replace(/\$(\d)/g,function(e,n){return o[n]})),l()},l())}))}))}d.commands.find=function(e){v(e),o(e)},d.commands.findPersistent=function(e){v(e),o(e,!1,!0)},d.commands.findPersistentNext=function(e){o(e,!1,!0,!0)},d.commands.findPersistentPrev=function(e){o(e,!0,!0,!0)},d.commands.findNext=o,d.commands.findPrev=function(e){o(e,!0)},d.commands.clearSearch=v,d.commands.replace=t,d.commands.replaceAll=function(e){t(e,!0)}});
|