3 lines
20 KiB
JavaScript
3 lines
20 KiB
JavaScript
|
|
import{E as S,V as J,c as U,e as oe,D as f,d as he,r as ue}from"./cm-view-CiSFjroV.js";import{b as fe,S as Q,P as de,E as p,F as X,e as Y,c as me,d as ge,f as pe,C as g,l as xe,m as Se,i as Z}from"./cm-state-X9WpHEQO.js";import{c as m}from"./vendor-crelt-C8TCjufn.js";const K=typeof String.prototype.normalize=="function"?r=>r.normalize("NFKD"):r=>r;class C{constructor(e,t,n=0,i=e.length,s,l){this.test=l,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=s?c=>s(K(c)):K,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return me(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=pe(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=ge(e);let i=this.normalize(t);if(i.length)for(let s=0,l=n;;s++){let c=i.charCodeAt(s),a=this.match(c,l,this.bufferPos+this.bufferStart);if(s==i.length-1){if(a)return this.value=a,this;break}l==n&&s<t.length&&t.charCodeAt(s)==c&&l++}}}match(e,t,n){let i=null;for(let s=0;s<this.matches.length;s+=2){let l=this.matches[s],c=!1;this.query.charCodeAt(l)==e&&(l==this.query.length-1?i={from:this.matches[s+1],to:n}:(this.matches[s]++,c=!0)),c||(this.matches.splice(s,2),s-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?i={from:t,to:n}:this.matches.push(1,t)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(C.prototype[Symbol.iterator]=function(){return this});const ee={from:-1,to:-1,match:/.*/.exec("")},_="gm"+(/x/.unicode==null?"":"u");class te{constructor(e,t,n,i=0,s=e.length){if(this.text=e,this.to=s,this.curLine="",this.done=!1,this.value=ee,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new re(e,t,n,i,s);this.re=new RegExp(t,_+(n?.ignoreCase?"i":"")),this.test=n?.test,this.iter=e.iter();let l=e.lineAt(i);this.curLineStart=l.from,this.matchPos=D(e,i),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,i=n+t[0].length;if(this.matchPos=D(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<i||n>this.value.to)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const T=new WeakMap;class v{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,n){let i=T.get(e);if(!i||i.from>=n||i.to<=t){let c=new v(t,e.sliceString(t,n));return T.set(e,c),c}if(i.from==t&&i.to==n)return i;let{text:s,from:l}=i;return l>t&&(s=e.sliceString(t,l)+s,l=t),i.to<n&&(s+=e.sliceString(i.to,n)),T.set(e,new v(l,s)),new v(t,s.slice(t-l,n-l))}}class re{constructor(e,t,n,i,s){this.text=e,this.to=s,this.done=!1,this.value=ee,this.matchPos=D(e,i),this.re=new RegExp(t,_+(n?.ignoreCase?"i":"")),this.test=n?.test,this.flat=v.get(e,i,this.chunkEnd(i+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let n=this.flat.from+t.index,i=n+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},t
|
||
|
|
`:n=="r"?"\r":n=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Te(this):new we(this)}getCursor(e,t=0,n){let i=e.doc?e:xe.create({doc:e});return n==null&&(n=i.doc.length),this.regexp?y(this,i,t,n):M(this,i,t,n)}}class ie{constructor(e){this.spec=e}}function Re(r,e,t){return(n,i,s,l)=>{if(t&&!t(n,i,s,l))return!1;let c=n>=l&&i<=l+s.length?s.slice(n-l,i-l):e.doc.sliceString(n,i);return r(c,e,n,i)}}function M(r,e,t,n){let i;return r.wholeWord&&(i=qe(e.doc,e.charCategorizer(e.selection.main.head))),r.test&&(i=Re(r.test,e,i)),new C(e.doc,r.unquoted,t,n,r.caseSensitive?void 0:s=>s.toLowerCase(),i)}function qe(r,e){return(t,n,i,s)=>((s>t||s+i.length<n)&&(s=Math.max(0,t-2),i=r.sliceString(s,Math.min(r.length,n+2))),(e(R(i,t-s))!=g.Word||e(q(i,t-s))!=g.Word)&&(e(q(i,n-s))!=g.Word||e(R(i,n-s))!=g.Word))}class we extends ie{constructor(e){super(e)}nextMatch(e,t,n){let i=M(this.spec,e,n,e.doc.length).nextOverlapping();if(i.done){let s=Math.min(e.doc.length,t+this.spec.unquoted.length);i=M(this.spec,e,0,s).nextOverlapping()}return i.done||i.value.from==t&&i.value.to==n?null:i.value}prevMatchInRange(e,t,n){for(let i=n;;){let s=Math.max(t,i-1e4-this.spec.unquoted.length),l=M(this.spec,e,s,i),c=null;for(;!l.nextOverlapping().done;)c=l.value;if(c)return c;if(s==t)return null;i-=1e4}}prevMatch(e,t,n){let i=this.prevMatchInRange(e,0,t);return i||(i=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length)),i&&(i.from!=t||i.to!=n)?i:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=M(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let s=M(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}function Pe(r,e,t){return(n,i,s)=>(!t||t(n,i,s))&&r(s[0],e,n,i)}function y(r,e,t,n){let i;return r.wholeWord&&(i=Ie(e.charCategorizer(e.selection.main.head))),r.test&&(i=Pe(r.test,e,i)),new te(e.doc,r.search,{ignoreCase:!r.caseSensitive,test:i},t,n)}function R(r,e){return r.slice(Z(r,e,!1),e)}function q(r,e){return r.slice(e,Z(r,e))}function Ie(r){return(e,t,n)=>!n[0].length||(r(R(n.input,n.index))!=g.Word||r(q(n.input,n.index))!=g.Word)&&(r(q(n.input,n.index+n[0].length))!=g.Word||r(R(n.input,n.index+n[0].length))!=g.Word)}class Te extends ie{nextMatch(e,t,n){let i=y(this.spec,e,n,e.doc.length).next();return i.done&&(i=y(this.spec,e,0,t).next()),i.done?null:i.value}prevMatchInRange(e,t,n){for(let i=1;;i++){let s=Math.max(t,n-i*1e4),l=y(this.spec,e,s,n),c=null;for(;!l.next().done;)c=l.value;if(c&&(s==t||c.from>s+10))return c;if(s==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n=="&")return e.match[0];if(n=="$")return"$";for(let i=n.length;i>0;i--){let s=+n.slice(0,i);if(s>0&&s<e.match.length)return e.match[s]+n.slice(i)}return t})}matchAll(e,t){let n=y(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let s=y(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!s.next().done;)i(s.value.from,s.value.to)}}const L=Q.define(),z=Q.define(),x=fe.define({create(r){return new O($(r).create(),null)},update(r,e){for(let t of e.effects)t.is(L)?r=new O(t.value.create(),r.panel):t.is(z)&&(r=new O(r.query,t.value?B:null));return r},provide:r=>he.from(r,e=>e.panel)});class O{constructor(e,t){this.query=e,this.panel=t}}const Oe=f.mark({class:"cm-searchMatch"}),$e=f.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Qe=J.fromClass(class{constructor(r){this.view=r,this.decorations=this.highlight(r.state.field(x))}update(r){let e=r.state.field(x);(e!=r.startState.field(x)||r.docChanged||r.selectionSet||r.viewportChanged)&&(this.de
|