1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-17 09:24:30 +00:00
TiddlyWiki5/plugins/tiddlywiki/codemirror-search-replace/files/addon/search/searchcursor.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(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(i){"use strict";var p,x,L=i.Pos;function d(t,e){for(var n,r,i=null!=(r=(n=t).flags)?r:(n.ignoreCase?"i":"")+(n.global?"g":"")+(n.multiline?"m":""),o=i,l=0;l<e.length;l++)-1==o.indexOf(e.charAt(l))&&(o+=e.charAt(l));return i==o?t:new RegExp(t.source,o)}function v(t){return/\\s|\\n|\n|\\W|\\D|\[\^/.test(t.source)}function m(t,e,n){e=d(e,"g");for(var r=n.line,i=n.ch,o=t.lastLine();r<=o;r++,i=0){e.lastIndex=i;var l=t.getLine(r),h=e.exec(l);if(h)return{from:L(r,h.index),to:L(r,h.index+h[0].length),match:h}}}function C(t,e,n){for(var r,i=0;i<=t.length;){e.lastIndex=i;var o=e.exec(t);if(!o)break;var l=o.index+o[0].length;if(l>t.length-n)break;(!r||l>r.index+r[0].length)&&(r=o),i=o.index+1}return r}function O(t,e,n){e=d(e,"g");for(var r=n.line,i=n.ch,o=t.firstLine();o<=r;r--,i=-1){var l=t.getLine(r),h=C(l,e,i<0?0:l.length-i);if(h)return{from:L(r,h.index),to:L(r,h.index+h[0].length),match:h}}}function b(t,e,n,r){if(t.length==e.length)return n;for(var i=0,o=n+Math.max(0,t.length-e.length);;){if(i==o)return i;var l=i+o>>1,h=r(t.slice(0,l)).length;if(h==n)return l;n<h?o=l:i=1+l}}function r(n,r,t,e){var i;this.atOccurrence=!1,this.doc=n,t=t?n.clipPos(t):L(0,0),this.pos={from:t,to:t},"object"==typeof e?i=e.caseFold:(i=e,e=null),"string"==typeof r?(null==i&&(i=!1),this.matches=function(t,e){return(t?function(t,e,n,r){if(!e.length)return null;var i=r?p:x,o=i(e).split(/\r|\n\r?/);t:for(var l=n.line,h=n.ch,s=t.firstLine()-1+o.length;s<=l;l--,h=-1){var c=t.getLine(l);-1<h&&(c=c.slice(0,h));var f=i(c);if(1==o.length){var u=f.lastIndexOf(o[0]);if(-1==u)continue t;return{from:L(l,b(c,f,u,i)),to:L(l,b(c,f,u+o[0].length,i))}}var g=o[o.length-1];if(f.slice(0,g.length)==g){for(var a=1,n=l-o.length+1;a<o.length-1;a++)if(i(t.getLine(n+a))!=o[a])continue t;var m=t.getLine(l+1-o.length),d=i(m);if(d.slice(d.length-o[0].length)==o[0])return{from:L(l+1-o.length,b(m,d,m.length-o[0].length,i)),to:L(l,b(c,f,g.length,i))}}}}:function(t,e,n,r){if(!e.length)return null;var i=r?p:x,o=i(e).split(/\r|\n\r?/);t:for(var l=n.line,h=n.ch,s=t.lastLine()+1-o.length;l<=s;l++,h=0){var c=t.getLine(l).slice(h),f=i(c);if(1==o.length){var u=f.indexOf(o[0]);if(-1==u)continue t;n=b(c,f,u,i)+h;return{from:L(l,b(c,f,u,i)+h),to:L(l,b(c,f,u+o[0].length,i)+h)}}var g=f.length-o[0].length;if(f.slice(g)==o[0]){for(var a=1;a<o.length-1;a++)if(i(t.getLine(l+a))!=o[a])continue t;var m=t.getLine(l+o.length-1),d=i(m),v=o[o.length-1];if(d.slice(0,v.length)==v)return{from:L(l,b(c,f,g,i)+h),to:L(l+o.length-1,b(m,d,v.length,i))}}}})(n,r,e,i)}):(r=d(r,"gm"),e&&!1===e.multiline?this.matches=function(t,e){return(t?O:m)(n,r,e)}:this.matches=function(t,e){return(t?function(t,e,n){if(!v(e))return O(t,e,n);e=d(e,"gm");for(var r=1,i=t.getLine(n.line).length-n.ch,o=n.line,l=t.firstLine();l<=o;){for(var h=0;h<r&&l<=o;h++)var s=t.getLine(o--),c=null==c?s:s+"\n"+c;r*=2;var f=C(c,e,i);if(f){var u=c.slice(0,f.index).split("\n"),g=f[0].split("\n"),a=o+u.length,m=u[u.length-1].length;return{from:L(a,m),to:L(a+g.length-1,1==g.length?m+g[0].length:g[g.length-1].length),match:f}}}}:function(t,e,n){if(!v(e))return m(t,e,n);e=d(e,"gm");for(var r=1,i=n.line,o=t.lastLine();i<=o;){for(var l=0;l<r&&!(o<i);l++)var h=t.getLine(i++),s=null==s?h:s+"\n"+h;r*=2,e.lastIndex=n.ch;var c=e.exec(s);if(c){var f=s.slice(0,c.index).split("\n"),u=c[0].split("\n"),g=n.line+f.length-1,a=f[f.length-1].length;return{from:L(g,a),to:L(g+u.length-1,1==u.length?a+u[0].length:u[u.length-1].length),match:c}}}})(n,r,e)})}x=String.prototype.normalize?(p=function(t){return t.normalize("NFD").toLowerCase()},function(t){return t.normalize("NFD")}):(p=function(t){return t.toLowerCase()},function(t){return t}),r.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(t){for(var e=this.matches(t,this.doc.clipPos(t?this.pos.from:this.pos.to));e&&0==i.cmpPos(e.from,e.to);)t?e.from.ch?e.from=L(e.from.lin