1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-08-28 03:52:43 +00:00
TiddlyWiki5/plugins/tiddlywiki/codemirror-search-replace/files/addon/search/search.js

4 lines
5.3 KiB
JavaScript
Raw Normal View History

CodeMirror 5.36.0 modularized (#3184) * v5.35.1 * codemirror 5.35.1 * v5.35.1 * v5.35.1 * v5.35.1 * v5.35.1 * v5.35.1 * adding search&replace and autocomplete * update version number * add jump-to-line.js required for search&replace * adding show-hint.js required by autocomplete * adding basic autocomplete for any word * adding autocomplete css * adding new files to tiddlywiki.files * forgot adding search.js * minify 'em all * Delete vim.js * Delete sublime.js * Delete emacs.js * Delete anyword-hint.js * Delete show-hint.css * Delete show-hint.js * Update config.tid * Update tiddlywiki.files * Update tiddlywiki.files * Update config.tid * Update config.tid * Update config.tid * Delete dialog.js * Delete dialog.css * Delete jump-to-line.js * Delete search.js * Delete searchcursor.js * Update tiddlywiki.files * Update tiddlywiki.files * Update tiddlywiki.files * add search-and-replace cm-addon as plugin * add autocomplete cm-addon as plugin * add fullscreen-editing cm-addon as plugin * add keymaps as plugins + cleanup * add highlighting modes as plugins * small update on usage.tid * moved multiplex.js to htmlembedded mode - the only one using it * config/CodeMirror update * how to disable line numbers * how to change CM theme * add closebrackets and closetags addons * packaging a base-addon * move meta.js from codemirror to base addon * inputStyle: textarea -> prevents contenteditable on mobile browsers, keeps focus when clicking toolbar buttons, prevents import on paste * default config no line numbers * temporary add panel plugin for demo * put base-plugin back to codemirror editor * searchcursor to searchnreplace plugin * bad copypasta mistake * another typo * stripped down meta.js + moved matchbrackets to closebrackets plugin * remove panel * change module-type to codemirro and make init "require" dynamic. * make config handling dynamic with sensible defaults * make cm settings translateable * delete multids. they will be replaced * add auto-config tiddlers * dynamically create config structure for CM * fix filename * change typo * kitchensink config, plus change plugin description for better sorting. * add matchBrackets config tiddler * RIP codeblock * removed install instructions from readme - codemirror usage tiddler still todo * control panel settings for cm base * add setting for auto-close tags * adding fontfamily settings and theme settings * change tags for settings from $:/tags/ControlPanel/Settings to $:/tags/ControlPanel/Settings/CodeMirror * more usage info * more usage info * update to v5.36.0 * ugly hack enables highlighting and tag-closing for vnd.tiddlywiki and x-tiddlywiki * disable auto-indent for vnd.tiddlywiki & x-tiddlywiki and add some hidden settings * remove engine.js hack * meta.js -> tw-meta.js * codemirror settings tab * rename tiddler to tw-meta.js * make editor font monospace or sans-serif - dropdown select * make editor font monospace or sans-serif - dropdown select * now using correct tiddler for editor font setting * better usage doc * make markdown-mode require tw-meta * add more themes info * add active-line highlighting option * mini usage change * add integer type to engine.js config-getter * blink rate config type string * correct engine.js * license for base-plugin, usage link in settings tab * codemirrordemo hellothere update * codemirrordemo hellothere update * Update license.tid * codemirror demo sidebarlayout, license * license headers to addon files * license formatting & forgot what year we have * license formatting & forgot what year we have & codemirror demo sitetitle sitesubtitle * more informations 'try-this-style' for codemirrordemo hellothere * codemirror demo sitetitle & cm fontfamily * hellothere * font-family setting must be editor-font-family, not code-font-family * add basic keyboard shortcuts table * shortcuts change to not interfere with toolbar shortcuts - needs testing - vim and emacs todo * formatting * controlpanel change keymap - default keymap is default * ctrl-T becomes Alt-T in default keymap * adjustments for codemirror demo * demo: hellothere - hint for sidebar keymap cheatsheet * toolbar focus fix + remove console log * engine.js cleanup * formatting * reverting focus fix * indenting engine.js * hoping that indenting gets better
2018-04-06 16:34:50 +00:00
// 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.phra