import{t as e}from"./chunk-D9Tnb9aB.js";import{t}from"./codemirror-DtW92bSi.js";var n=e(((e,n)=>{(function(r){typeof e==`object`&&typeof n==`object`?r(t()):typeof define==`function`&&define.amd?define([`../../lib/codemirror`],r):r(CodeMirror)})(function(e){var t=e.Pos;function n(e){return e.flags??(e.ignoreCase?`i`:``)+(e.global?`g`:``)+(e.multiline?`m`:``)}function r(e,t){for(var r=n(e),i=r,a=0;a<t.length;a++)i.indexOf(t.charAt(a))==-1&&(i+=t.charAt(a));return r==i?e:new RegExp(e.source,i)}function i(e){return/\\s|\\n|\n|\\W|\\D|\[\^/.test(e.source)}function a(e,n,i){n=r(n,`g`);for(var a=i.line,o=i.ch,s=e.lastLine();a<=s;a++,o=0){n.lastIndex=o;var c=e.getLine(a),l=n.exec(c);if(l)return{from:t(a,l.index),to:t(a,l.index+l[0].length),match:l}}}function o(e,n,o){if(!i(n))return a(e,n,o);n=r(n,`gm`);for(var s,c=1,l=o.line,u=e.lastLine();l<=u;){for(var d=0;d<c&&!(l>u);d++){var f=e.getLine(l++);s=s==null?f:s+`
`+f}c*=2,n.lastIndex=o.ch;var p=n.exec(s);if(p){var m=s.slice(0,p.index).split(`
`),h=p[0].split(`
`),g=o.line+m.length-1,_=m[m.length-1].length;return{from:t(g,_),to:t(g+h.length-1,h.length==1?_+h[0].length:h[h.length-1].length),match:p}}}}function s(e,t,n){for(var r,i=0;i<=e.length;){t.lastIndex=i;var a=t.exec(e);if(!a)break;var o=a.index+a[0].length;if(o>e.length-n)break;(!r||o>r.index+r[0].length)&&(r=a),i=a.index+1}return r}function c(e,n,i){n=r(n,`g`);for(var a=i.line,o=i.ch,c=e.firstLine();a>=c;a--,o=-1){var l=e.getLine(a),u=s(l,n,o<0?0:l.length-o);if(u)return{from:t(a,u.index),to:t(a,u.index+u[0].length),match:u}}}function l(e,n,a){if(!i(n))return c(e,n,a);n=r(n,`gm`);for(var o,l=1,u=e.getLine(a.line).length-a.ch,d=a.line,f=e.firstLine();d>=f;){for(var p=0;p<l&&d>=f;p++){var m=e.getLine(d--);o=o==null?m:m+`
`+o}l*=2;var h=s(o,n,u);if(h){var g=o.slice(0,h.index).split(`
`),_=h[0].split(`
`),v=d+g.length,y=g[g.length-1].length;return{from:t(v,y),to:t(v+_.length-1,_.length==1?y+_[0].length:_[_.length-1].length),match:h}}}}var u,d;String.prototype.normalize?(u=function(e){return e.normalize(`NFD`).toLowerCase()},d=function(e){return e.normalize(`NFD`)}):(u=function(e){return e.toLowerCase()},d=function(e){return e});function f(e,t,n,r){if(e.length==t.length)return n;for(var i=0,a=n+Math.max(0,e.length-t.length);;){if(i==a)return i;var o=i+a>>1,s=r(e.slice(0,o)).length;if(s==n)return o;s>n?a=o:i=o+1}}function p(e,n,r,i){if(!n.length)return null;var a=i?u:d,o=a(n).split(/\r|\n\r?/);search:for(var s=r.line,c=r.ch,l=e.lastLine()+1-o.length;s<=l;s++,c=0){var p=e.getLine(s).slice(c),m=a(p);if(o.length==1){var h=m.indexOf(o[0]);if(h==-1)continue search;var r=f(p,m,h,a)+c;return{from:t(s,f(p,m,h,a)+c),to:t(s,f(p,m,h+o[0].length,a)+c)}}else{var g=m.length-o[0].length;if(m.slice(g)!=o[0])continue search;for(var _=1;_<o.length-1;_++)if(a(e.getLine(s+_))!=o[_])continue search;var v=e.getLine(s+o.length-1),y=a(v),b=o[o.length-1];if(y.slice(0,b.length)!=b)continue search;return{from:t(s,f(p,m,g,a)+c),to:t(s+o.length-1,f(v,y,b.length,a))}}}}function m(e,n,r,i){if(!n.length)return null;var a=i?u:d,o=a(n).split(/\r|\n\r?/);search:for(var s=r.line,c=r.ch,l=e.firstLine()-1+o.length;s>=l;s--,c=-1){var p=e.getLine(s);c>-1&&(p=p.slice(0,c));var m=a(p);if(o.length==1){var h=m.lastIndexOf(o[0]);if(h==-1)continue search;return{from:t(s,f(p,m,h,a)),to:t(s,f(p,m,h+o[0].length,a))}}else{var g=o[o.length-1];if(m.slice(0,g.length)!=g)continue search;for(var _=1,r=s-o.length+1;_<o.length-1;_++)if(a(e.getLine(r+_))!=o[_])continue search;var v=e.getLine(s+1-o.length),y=a(v);if(y.slice(y.length-o[0].length)!=o[0])continue search;return{from:t(s+1-o.length,f(v,y,v.length-o[0].length,a)),to:t(s,f(p,m,g.length,a))}}}}function h(e,n,i,s){this.atOccurrence=!1,this.afterEmptyMatch=!1,this.doc=e,i=i?e.clipPos(i):t(0,0),this.pos={from:i,to:i};var u;typeof s==`object`?u=s.caseFold:(u=s,s=null),typeof n==`string`?(u??=!1,this.matches=function(t,r){return(t?m:p)(e,n,r,u)}):(n=r(n,`gm`),!s||s.multiline!==!1?this.matches=function(t,r){return(t?l:o)(e,n,r)}:this.matches=function(t,r){return(t?c:a)(e,n,r)})}h.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(n){var r=this.doc.clipPos(n?this.pos.from:this.pos.to);if(this.afterEmptyMatch&&this.atOccurrence&&(r=t(r.line,r.ch),n?(r.ch--,r.ch<0&&(r.line--,r.ch=(this.doc.getLine(r.line)||``).length)):(r.ch++,r.ch>(this.doc.getLine(r.line)||``).length&&(r.ch=0,r.line++)),e.cmpPos(r,this.doc.clipPos(r))!=0))return this.atOccurrence=!1;var i=this.matches(n,r);if(this.afterEmptyMatch=i&&e.cmpPos(i.from,i.to)==0,i)return this.pos=i,this.atOccurrence=!0,this.pos.match||!0;var a=t(n?this.doc.firstLine():this.doc.lastLine()+1,0);return this.pos={from:a,to:a},this.atOccurrence=!1},from:function(){if(this.atOccurrence)return this.pos.from},to:function(){if(this.atOccurrence)return this.pos.to},replace:function(n,r){if(this.atOccurrence){var i=e.splitLines(n);this.doc.replaceRange(i,this.pos.from,this.pos.to,r),this.pos.to=t(this.pos.from.line+i.length-1,i[i.length-1].length+(i.length==1?this.pos.from.ch:0))}}},e.defineExtension(`getSearchCursor`,function(e,t,n){return new h(this.doc,e,t,n)}),e.defineDocExtension(`getSearchCursor`,function(e,t,n){return new h(this,e,t,n)}),e.defineExtension(`selectMatches`,function(t,n){for(var r=[],i=this.getSearchCursor(t,this.getCursor(`from`),n);i.findNext()&&!(e.cmpPos(i.to(),this.getCursor(`to`))>0);)r.push({anchor:i.from(),head:i.to()});r.length&&this.setSelections(r,0)})})}));export default n();export{n as t};
//# sourceMappingURL=searchcursor-CuK1nHSn.js.map