@xterm/addon-search 0.17.0-beta.21 → 0.17.0-beta.211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,31 +14,5 @@
14
14
  * Copyright (c) Microsoft Corporation. All rights reserved.
15
15
  * Licensed under the MIT License. See License.txt in the project root for license information.
16
16
  *--------------------------------------------------------------------------------------------*/
17
- var Re=class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?ae.isErrorNoTelemetry(e)?new ae(e.message+`
18
-
19
- `+e.stack):new Error(e.message+`
20
-
21
- `+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}},pt=new Re;function le(r){ft(r)||pt.onUnexpectedError(r)}var Ce="Canceled";function ft(r){return r instanceof ee?!0:r instanceof Error&&r.name===Ce&&r.message===Ce}var ee=class extends Error{constructor(){super(Ce),this.name=this.message}};var ae=class r extends Error{constructor(e){super(e),this.name="CodeExpectedError"}static fromError(e){if(e instanceof r)return e;let t=new r;return t.message=e.message,t.stack=e.stack,t}static isErrorNoTelemetry(e){return e.name==="CodeExpectedError"}};function mt(r,e,t=0,n=r.length){let i=t,s=n;for(;i<s;){let a=Math.floor((i+s)/2);e(r[a])?i=a+1:s=a}return i-1}var ue=class ue{constructor(e){this._array=e;this._findLastMonotonousLastIdx=0}findLastMonotonous(e){if(ue.assertInvariants){if(this._prevFindLastPredicate){for(let n of this._array)if(this._prevFindLastPredicate(n)&&!e(n))throw new Error("MonotonousArray: current predicate must be weaker than (or equal to) the previous predicate.")}this._prevFindLastPredicate=e}let t=mt(this._array,e,this._findLastMonotonousLastIdx);return this._findLastMonotonousLastIdx=t+1,t===-1?void 0:this._array[t]}};ue.assertInvariants=!1;var Ke=ue;var Qe;(h=>{function r(u){return u<0}h.isLessThan=r;function e(u){return u<=0}h.isLessThanOrEqual=e;function t(u){return u>0}h.isGreaterThan=t;function n(u){return u===0}h.isNeitherLessOrGreaterThan=n,h.greaterThan=1,h.lessThan=-1,h.neitherLessOrGreaterThan=0})(Qe||={});function $e(r,e){return(t,n)=>e(r(t),r(n))}var Be=(r,e)=>r-e;var V=class V{constructor(e){this.iterate=e}forEach(e){this.iterate(t=>(e(t),!0))}toArray(){let e=[];return this.iterate(t=>(e.push(t),!0)),e}filter(e){return new V(t=>this.iterate(n=>e(n)?t(n):!0))}map(e){return new V(t=>this.iterate(n=>t(e(n))))}some(e){let t=!1;return this.iterate(n=>(t=e(n),!t)),t}findFirst(e){let t;return this.iterate(n=>e(n)?(t=n,!1):!0),t}findLast(e){let t;return this.iterate(n=>(e(n)&&(t=n),!0)),t}findLastMaxBy(e){let t,n=!0;return this.iterate(i=>((n||Qe.isGreaterThan(e(i,t)))&&(n=!1,t=i),!0)),t}};V.empty=new V(e=>{});var He=V;function Xe(r,e){let t=Object.create(null);for(let n of r){let i=e(n),s=t[i];s||(s=t[i]=[]),s.push(n)}return t}var Ye,Je,Ge=class{constructor(e,t){this.toKey=t;this._map=new Map;this[Ye]="SetWithKey";for(let n of e)this.add(n)}get size(){return this._map.size}add(e){let t=this.toKey(e);return this._map.set(t,e),this}delete(e){return this._map.delete(this.toKey(e))}has(e){return this._map.has(this.toKey(e))}*entries(){for(let e of this._map.values())yield[e,e]}keys(){return this.values()}*values(){for(let e of this._map.values())yield e}clear(){this._map.clear()}forEach(e,t){this._map.forEach(n=>e.call(t,n,n,this))}[(Je=Symbol.iterator,Ye=Symbol.toStringTag,Je)](){return this.values()}};var ce=class{constructor(){this.map=new Map}add(e,t){let n=this.map.get(e);n||(n=new Set,this.map.set(e,n)),n.add(t)}delete(e,t){let n=this.map.get(e);n&&(n.delete(t),n.size===0&&this.map.delete(e))}forEach(e,t){let n=this.map.get(e);n&&n.forEach(t)}get(e){let t=this.map.get(e);return t||new Set}};function Pe(r,e){let t=this,n=!1,i;return function(){if(n)return i;if(n=!0,e)try{i=r.apply(t,arguments)}finally{e()}else i=r.apply(t,arguments);return i}}var Le;(z=>{function r(m){return m&&typeof m=="object"&&typeof m[Symbol.iterator]=="function"}z.is=r;let e=Object.freeze([]);function t(){return e}z.empty=t;function*n(m){yield m}z.single=n;function i(m){return r(m)?m:n(m)}z.wrap=i;function s(m){return m||e}z.from=s;function*a(m){for(let _=m.length-1;_>=0;_--)yield m[_]}z.reverse=a;function h(m){return!m||m[Symbol.iterator]().next().done===!0}z.isEmpty=h;function u(m){return m[Symbol.iterator]().next().value}z.first=u;function p(m,_){let y=0;for(let L of m)if(_(L,y++))return!0;return!1}z.some=p;function T(m,_){for(let y of m)if(_(y))return y}z.find=T;function*v(m,_){for(let y of m)_(y)&&(yield y)}z.filter=v;function*I(m,_){let y=0;for(let L of m)yield _(L,y++)}z.map=I;function*E(m,_){let y=0;for(let L of m)yield*_(L,y++)}z.flatMap=E;function*S(...m){for(let _ of m)yield*_}z.concat=S;function D(m,_,y){let L=y;for(let X of m)L=_(L,X);return L}z.reduce=D;function*x(m,_,y=m.length){for(_<0&&(_+=m.length),y<0?y+=m.length:y>m.length&&(y=m.length);_<y;_++)yield m[_]}z.slice=x;function J(m,_=Number.POSITIVE_INFINITY){let y=[];if(_===0)return[y,m];let L=m[Symbol.iterator]();for(let X=0;X<_;X++){let Se=L.next();if(Se.done)return[y,z.empty()];y.push(Se.value)}return[y,{[Symbol.iterator](){return L}}]}z.consume=J;async function q(m){let _=[];for await(let y of m)_.push(y);return Promise.resolve(_)}z.asyncToArray=q})(Le||={});var Tt=!1,K=null,de=class de{constructor(){this.livingDisposables=new Map}getDisposableData(e){let t=this.livingDisposables.get(e);return t||(t={parent:null,source:null,isSingleton:!1,value:e,idx:de.idx++},this.livingDisposables.set(e,t)),t}trackDisposable(e){let t=this.getDisposableData(e);t.source||(t.source=new Error().stack)}setParent(e,t){let n=this.getDisposableData(e);n.parent=t}markAsDisposed(e){this.livingDisposables.delete(e)}markAsSingleton(e){this.getDisposableData(e).isSingleton=!0}getRootParent(e,t){let n=t.get(e);if(n)return n;let i=e.parent?this.getRootParent(this.getDisposableData(e.parent),t):e;return t.set(e,i),i}getTrackedDisposables(){let e=new Map;return[...this.livingDisposables.entries()].filter(([,n])=>n.source!==null&&!this.getRootParent(n,e).isSingleton).flatMap(([n])=>n)}computeLeakingDisposables(e=10,t){let n;if(t)n=t;else{let u=new Map,p=[...this.livingDisposables.values()].filter(v=>v.source!==null&&!this.getRootParent(v,u).isSingleton);if(p.length===0)return;let T=new Set(p.map(v=>v.value));if(n=p.filter(v=>!(v.parent&&T.has(v.parent))),n.length===0)throw new Error("There are cyclic diposable chains!")}if(!n)return;function i(u){function p(v,I){for(;v.length>0&&I.some(E=>typeof E=="string"?E===v[0]:v[0].match(E));)v.shift()}let T=u.source.split(`
22
- `).map(v=>v.trim().replace("at ","")).filter(v=>v!=="");return p(T,["Error",/^trackDisposable \(.*\)$/,/^DisposableTracker.trackDisposable \(.*\)$/]),T.reverse()}let s=new ce;for(let u of n){let p=i(u);for(let T=0;T<=p.length;T++)s.add(p.slice(0,T).join(`
23
- `),u)}n.sort($e(u=>u.idx,Be));let a="",h=0;for(let u of n.slice(0,e)){h++;let p=i(u),T=[];for(let v=0;v<p.length;v++){let I=p[v];I=`(shared with ${s.get(p.slice(0,v+1).join(`
24
- `)).size}/${n.length} leaks) at ${I}`;let S=s.get(p.slice(0,v).join(`
25
- `)),D=Xe([...S].map(x=>i(x)[v]),x=>x);delete D[p[v]];for(let[x,J]of Object.entries(D))T.unshift(` - stacktraces of ${J.length} other leaks continue with ${x}`);T.unshift(I)}a+=`
26
-
27
-
28
- ==================== Leaking disposable ${h}/${n.length}: ${u.value.constructor.name} ====================
29
- ${T.join(`
30
- `)}
31
- ============================================================
32
-
33
- `}return n.length>e&&(a+=`
34
-
35
-
36
- ... and ${n.length-e} more leaking disposables
37
-
38
- `),{leaks:n,details:a}}};de.idx=0;var Ze=de;function vt(r){K=r}if(Tt){let r="__is_disposable_tracked__";vt(new class{trackDisposable(e){let t=new Error("Potentially leaked disposable").stack;setTimeout(()=>{e[r]||console.log(t)},3e3)}setParent(e,t){if(e&&e!==k.None)try{e[r]=!0}catch{}}markAsDisposed(e){if(e&&e!==k.None)try{e[r]=!0}catch{}}markAsSingleton(e){}})}function pe(r){return K?.trackDisposable(r),r}function fe(r){K?.markAsDisposed(r)}function te(r,e){K?.setParent(r,e)}function bt(r,e){if(K)for(let t of r)K.setParent(t,e)}function Q(r){if(Le.is(r)){let e=[];for(let t of r)if(t)try{t.dispose()}catch(n){e.push(n)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"Encountered errors while disposing of store");return Array.isArray(r)?[]:r}else if(r)return r.dispose(),r}function me(...r){let e=A(()=>Q(r));return bt(r,e),e}function A(r){let e=pe({dispose:Pe(()=>{fe(e),r()})});return e}var he=class he{constructor(){this._toDispose=new Set;this._isDisposed=!1;pe(this)}dispose(){this._isDisposed||(fe(this),this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{Q(this._toDispose)}finally{this._toDispose.clear()}}add(e){if(!e)return e;if(e===this)throw new Error("Cannot register a disposable on itself!");return te(e,this),this._isDisposed?he.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(e),e}delete(e){if(e){if(e===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(e),e.dispose()}}deleteAndLeak(e){e&&this._toDispose.has(e)&&(this._toDispose.delete(e),te(e,null))}};he.DISABLE_DISPOSED_WARNING=!1;var H=he,k=class{constructor(){this._store=new H;pe(this),te(this._store,this)}dispose(){fe(this),this._store.dispose()}_register(e){if(e===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(e)}};k.None=Object.freeze({dispose(){}});var F=class{constructor(){this._isDisposed=!1;pe(this)}get value(){return this._isDisposed?void 0:this._value}set value(e){this._isDisposed||e===this._value||(this._value?.dispose(),e&&te(e,this),this._value=e)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,fe(this),this._value?.dispose(),this._value=void 0}clearAndLeak(){let e=this._value;return this._value=void 0,e&&te(e,null),e}};var $=class ${constructor(e){this.element=e,this.next=$.Undefined,this.prev=$.Undefined}};$.Undefined=new $(void 0);var et=$;var _t=globalThis.performance&&typeof globalThis.performance.now=="function",Te=class r{static create(e){return new r(e)}constructor(e){this._now=_t&&e===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}};var gt=!1,tt=!1,yt=!1,ie;(re=>{re.None=()=>k.None;function e(d){if(yt){let{onDidAddListener:o}=d,c=ne.create(),l=0;d.onDidAddListener=()=>{++l===2&&(console.warn("snapshotted emitter LIKELY used public and SHOULD HAVE BEEN created with DisposableStore. snapshotted here"),c.print()),o?.()}}}function t(d,o){return I(d,()=>{},0,void 0,!0,void 0,o)}re.defer=t;function n(d){return(o,c=null,l)=>{let f=!1,b;return b=d(g=>{if(!f)return b?b.dispose():f=!0,o.call(c,g)},null,l),f&&b.dispose(),b}}re.once=n;function i(d,o,c){return T((l,f=null,b)=>d(g=>l.call(f,o(g)),null,b),c)}re.map=i;function s(d,o,c){return T((l,f=null,b)=>d(g=>{o(g),l.call(f,g)},null,b),c)}re.forEach=s;function a(d,o,c){return T((l,f=null,b)=>d(g=>o(g)&&l.call(f,g),null,b),c)}re.filter=a;function h(d){return d}re.signal=h;function u(...d){return(o,c=null,l)=>{let f=me(...d.map(b=>b(g=>o.call(c,g))));return v(f,l)}}re.any=u;function p(d,o,c,l){let f=c;return i(d,b=>(f=o(f,b),f),l)}re.reduce=p;function T(d,o){let c,l={onWillAddFirstListener(){c=d(f.fire,f)},onDidRemoveLastListener(){c?.dispose()}};o||e(l);let f=new C(l);return o?.add(f),f.event}function v(d,o){return o instanceof Array?o.push(d):o&&o.add(d),d}function I(d,o,c=100,l=!1,f=!1,b,g){let w,R,U,se=0,Z,Ve={leakWarningThreshold:b,onWillAddFirstListener(){w=d(dt=>{se++,R=o(R,dt),l&&!U&&(oe.fire(R),R=void 0),Z=()=>{let ht=R;R=void 0,U=void 0,(!l||se>1)&&oe.fire(ht),se=0},typeof c=="number"?(clearTimeout(U),U=setTimeout(Z,c)):U===void 0&&(U=0,queueMicrotask(Z))})},onWillRemoveListener(){f&&se>0&&Z?.()},onDidRemoveLastListener(){Z=void 0,w.dispose()}};g||e(Ve);let oe=new C(Ve);return g?.add(oe),oe.event}re.debounce=I;function E(d,o=0,c){return re.debounce(d,(l,f)=>l?(l.push(f),l):[f],o,void 0,!0,void 0,c)}re.accumulate=E;function S(d,o=(l,f)=>l===f,c){let l=!0,f;return a(d,b=>{let g=l||!o(b,f);return l=!1,f=b,g},c)}re.latch=S;function D(d,o,c){return[re.filter(d,o,c),re.filter(d,l=>!o(l),c)]}re.split=D;function x(d,o=!1,c=[],l){let f=c.slice(),b=d(R=>{f?f.push(R):w.fire(R)});l&&l.add(b);let g=()=>{f?.forEach(R=>w.fire(R)),f=null},w=new C({onWillAddFirstListener(){b||(b=d(R=>w.fire(R)),l&&l.add(b))},onDidAddFirstListener(){f&&(o?setTimeout(g):g())},onDidRemoveLastListener(){b&&b.dispose(),b=null}});return l&&l.add(w),w.event}re.buffer=x;function J(d,o){return(l,f,b)=>{let g=o(new z);return d(function(w){let R=g.evaluate(w);R!==q&&l.call(f,R)},void 0,b)}}re.chain=J;let q=Symbol("HaltChainable");class z{constructor(){this.steps=[]}map(o){return this.steps.push(o),this}forEach(o){return this.steps.push(c=>(o(c),c)),this}filter(o){return this.steps.push(c=>o(c)?c:q),this}reduce(o,c){let l=c;return this.steps.push(f=>(l=o(l,f),l)),this}latch(o=(c,l)=>c===l){let c=!0,l;return this.steps.push(f=>{let b=c||!o(f,l);return c=!1,l=f,b?f:q}),this}evaluate(o){for(let c of this.steps)if(o=c(o),o===q)break;return o}}function m(d,o,c=l=>l){let l=(...w)=>g.fire(c(...w)),f=()=>d.on(o,l),b=()=>d.removeListener(o,l),g=new C({onWillAddFirstListener:f,onDidRemoveLastListener:b});return g.event}re.fromNodeEventEmitter=m;function _(d,o,c=l=>l){let l=(...w)=>g.fire(c(...w)),f=()=>d.addEventListener(o,l),b=()=>d.removeEventListener(o,l),g=new C({onWillAddFirstListener:f,onDidRemoveLastListener:b});return g.event}re.fromDOMEventEmitter=_;function y(d){return new Promise(o=>n(d)(o))}re.toPromise=y;function L(d){let o=new C;return d.then(c=>{o.fire(c)},()=>{o.fire(void 0)}).finally(()=>{o.dispose()}),o.event}re.fromPromise=L;function X(d,o){return d(c=>o.fire(c))}re.forward=X;function Se(d,o,c){return o(c),d(l=>o(l))}re.runAndSubscribe=Se;class ct{constructor(o,c){this._observable=o;this._counter=0;this._hasChanged=!1;let l={onWillAddFirstListener:()=>{o.addObserver(this)},onDidRemoveLastListener:()=>{o.removeObserver(this)}};c||e(l),this.emitter=new C(l),c&&c.add(this.emitter)}beginUpdate(o){this._counter++}handlePossibleChange(o){}handleChange(o,c){this._hasChanged=!0}endUpdate(o){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function zt(d,o){return new ct(d,o).emitter.event}re.fromObservable=zt;function Ut(d){return(o,c,l)=>{let f=0,b=!1,g={beginUpdate(){f++},endUpdate(){f--,f===0&&(d.reportChanges(),b&&(b=!1,o.call(c)))},handlePossibleChange(){},handleChange(){b=!0}};d.addObserver(g),d.reportChanges();let w={dispose(){d.removeObserver(g)}};return l instanceof H?l.add(w):Array.isArray(l)&&l.push(w),w}}re.fromObservableLight=Ut})(ie||={});var B=class B{constructor(e){this.listenerCount=0;this.invocationCount=0;this.elapsedOverall=0;this.durations=[];this.name=`${e}_${B._idPool++}`,B.all.add(this)}start(e){this._stopWatch=new Te,this.listenerCount=e}stop(){if(this._stopWatch){let e=this._stopWatch.elapsed();this.durations.push(e),this.elapsedOverall+=e,this.invocationCount+=1,this._stopWatch=void 0}}};B.all=new Set,B._idPool=0;var Oe=B,nt=-1;var be=class be{constructor(e,t,n=(be._idPool++).toString(16).padStart(3,"0")){this._errorHandler=e;this.threshold=t;this.name=n;this._warnCountdown=0}dispose(){this._stacks?.clear()}check(e,t){let n=this.threshold;if(n<=0||t<n)return;this._stacks||(this._stacks=new Map);let i=this._stacks.get(e.value)||0;if(this._stacks.set(e.value,i+1),this._warnCountdown-=1,this._warnCountdown<=0){this._warnCountdown=n*.5;let[s,a]=this.getMostFrequentStack(),h=`[${this.name}] potential listener LEAK detected, having ${t} listeners already. MOST frequent listener (${a}):`;console.warn(h),console.warn(s);let u=new Me(h,s);this._errorHandler(u)}return()=>{let s=this._stacks.get(e.value)||0;this._stacks.set(e.value,s-1)}}getMostFrequentStack(){if(!this._stacks)return;let e,t=0;for(let[n,i]of this._stacks)(!e||t<i)&&(e=[n,i],t=i);return e}};be._idPool=1;var Ae=be,ne=class r{constructor(e){this.value=e}static create(){let e=new Error;return new r(e.stack??"")}print(){console.warn(this.value.split(`
39
- `).slice(2).join(`
40
- `))}},Me=class extends Error{constructor(e,t){super(e),this.name="ListenerLeakError",this.stack=t}},Fe=class extends Error{constructor(e,t){super(e),this.name="ListenerRefusalError",this.stack=t}},xt=0,G=class{constructor(e){this.value=e;this.id=xt++}},It=2,Dt=(r,e)=>{if(r instanceof G)e(r);else for(let t=0;t<r.length;t++){let n=r[t];n&&e(n)}},ve;if(gt){let r=[];setInterval(()=>{r.length!==0&&(console.warn("[LEAKING LISTENERS] GC'ed these listeners that were NOT yet disposed:"),console.warn(r.join(`
41
- `)),r.length=0)},3e3),ve=new FinalizationRegistry(e=>{typeof e=="string"&&r.push(e)})}var C=class{constructor(e){this._size=0;this._options=e,this._leakageMon=nt>0||this._options?.leakWarningThreshold?new Ae(e?.onListenerError??le,this._options?.leakWarningThreshold??nt):void 0,this._perfMon=this._options?._profName?new Oe(this._options._profName):void 0,this._deliveryQueue=this._options?.deliveryQueue}dispose(){if(!this._disposed){if(this._disposed=!0,this._deliveryQueue?.current===this&&this._deliveryQueue.reset(),this._listeners){if(tt){let e=this._listeners;queueMicrotask(()=>{Dt(e,t=>t.stack?.print())})}this._listeners=void 0,this._size=0}this._options?.onDidRemoveLastListener?.(),this._leakageMon?.dispose()}}get event(){return this._event??=(e,t,n)=>{if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let u=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(u);let p=this._leakageMon.getMostFrequentStack()??["UNKNOWN stack",-1],T=new Fe(`${u}. HINT: Stack shows most frequent listener (${p[1]}-times)`,p[0]);return(this._options?.onListenerError||le)(T),k.None}if(this._disposed)return k.None;t&&(e=e.bind(t));let i=new G(e),s,a;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(i.stack=ne.create(),s=this._leakageMon.check(i.stack,this._size+1)),tt&&(i.stack=a??ne.create()),this._listeners?this._listeners instanceof G?(this._deliveryQueue??=new Ne,this._listeners=[this._listeners,i]):this._listeners.push(i):(this._options?.onWillAddFirstListener?.(this),this._listeners=i,this._options?.onDidAddFirstListener?.(this)),this._size++;let h=A(()=>{ve?.unregister(h),s?.(),this._removeListener(i)});if(n instanceof H?n.add(h):Array.isArray(n)&&n.push(h),ve){let u=new Error().stack.split(`
42
- `).slice(2,3).join(`
43
- `).trim(),p=/(file:|vscode-file:\/\/vscode-app)?(\/[^:]*:\d+:\d+)/.exec(u);ve.register(h,p?.[2]??u,h)}return h},this._event}_removeListener(e){if(this._options?.onWillRemoveListener?.(this),!this._listeners)return;if(this._size===1){this._listeners=void 0,this._options?.onDidRemoveLastListener?.(this),this._size=0;return}let t=this._listeners,n=t.indexOf(e);if(n===-1)throw console.log("disposed?",this._disposed),console.log("size?",this._size),console.log("arr?",JSON.stringify(this._listeners)),new Error("Attempted to dispose unknown listener");this._size--,t[n]=void 0;let i=this._deliveryQueue.current===this;if(this._size*It<=t.length){let s=0;for(let a=0;a<t.length;a++)t[a]?t[s++]=t[a]:i&&(this._deliveryQueue.end--,s<this._deliveryQueue.i&&this._deliveryQueue.i--);t.length=s}}_deliver(e,t){if(!e)return;let n=this._options?.onListenerError||le;if(!n){e.value(t);return}try{e.value(t)}catch(i){n(i)}}_deliverQueue(e){let t=e.current._listeners;for(;e.i<e.end;)this._deliver(t[e.i++],e.value);e.reset()}fire(e){if(this._deliveryQueue?.current&&(this._deliverQueue(this._deliveryQueue),this._perfMon?.stop()),this._perfMon?.start(this._size),this._listeners)if(this._listeners instanceof G)this._deliver(this._listeners,e);else{let t=this._deliveryQueue;t.enqueue(this,e,this._listeners.length),this._deliverQueue(t)}this._perfMon?.stop()}hasListeners(){return this._size>0}};var Ne=class{constructor(){this.i=-1;this.end=0}enqueue(e,t,n){this.i=0,this.end=n,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}};var it=Object.freeze(function(r,e){let t=setTimeout(r.bind(e),0);return{dispose(){clearTimeout(t)}}}),Et;(n=>{function r(i){return i===n.None||i===n.Cancelled||i instanceof We?!0:!i||typeof i!="object"?!1:typeof i.isCancellationRequested=="boolean"&&typeof i.onCancellationRequested=="function"}n.isCancellationToken=r,n.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:ie.None}),n.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:it})})(Et||={});var We=class{constructor(){this._isCancelled=!1;this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?it:(this._emitter||(this._emitter=new C),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=null)}};var Y="en",qe=!1,ze=!1,ge=!1,wt=!1,kt=!1,st=!1,St=!1,Rt=!1,Ct=!1,Pt=!1,_e,ye=Y,rt=Y,Lt,N,W=globalThis,O;typeof W.vscode<"u"&&typeof W.vscode.process<"u"?O=W.vscode.process:typeof process<"u"&&typeof process?.versions?.node=="string"&&(O=process);var ot=typeof O?.versions?.electron=="string",Ot=ot&&O?.type==="renderer";if(typeof O=="object"){qe=O.platform==="win32",ze=O.platform==="darwin",ge=O.platform==="linux",wt=ge&&!!O.env.SNAP&&!!O.env.SNAP_REVISION,St=ot,Ct=!!O.env.CI||!!O.env.BUILD_ARTIFACTSTAGINGDIRECTORY,_e=Y,ye=Y;let r=O.env.VSCODE_NLS_CONFIG;if(r)try{let e=JSON.parse(r);_e=e.userLocale,rt=e.osLocale,ye=e.resolvedLanguage||Y,Lt=e.languagePack?.translationsConfigFile}catch{}kt=!0}else typeof navigator=="object"&&!Ot?(N=navigator.userAgent,qe=N.indexOf("Windows")>=0,ze=N.indexOf("Macintosh")>=0,Rt=(N.indexOf("Macintosh")>=0||N.indexOf("iPad")>=0||N.indexOf("iPhone")>=0)&&!!navigator.maxTouchPoints&&navigator.maxTouchPoints>0,ge=N.indexOf("Linux")>=0,Pt=N?.indexOf("Mobi")>=0,st=!0,ye=globalThis._VSCODE_NLS_LANGUAGE||Y,_e=navigator.language.toLowerCase(),rt=_e):console.error("Unable to resolve platform.");var je=0;ze?je=1:qe?je=3:ge&&(je=2);var At=st&&typeof W.importScripts=="function",gn=At?W.origin:void 0;var M=N,j=ye,Mt;(n=>{function r(){return j}n.value=r;function e(){return j.length===2?j==="en":j.length>=3?j[0]==="e"&&j[1]==="n"&&j[2]==="-":!1}n.isDefaultVariant=e;function t(){return j==="en"}n.isDefault=t})(Mt||={});var Ft=typeof W.postMessage=="function"&&!W.importScripts,at=(()=>{if(Ft){let r=[];W.addEventListener("message",t=>{if(t.data&&t.data.vscodeScheduleAsyncWork)for(let n=0,i=r.length;n<i;n++){let s=r[n];if(s.id===t.data.vscodeScheduleAsyncWork){r.splice(n,1),s.callback();return}}});let e=0;return t=>{let n=++e;r.push({id:n,callback:t}),W.postMessage({vscodeScheduleAsyncWork:n},"*")}}return r=>setTimeout(r)})();var Nt=!!(M&&M.indexOf("Chrome")>=0),yn=!!(M&&M.indexOf("Firefox")>=0),xn=!!(!Nt&&M&&M.indexOf("Safari")>=0),In=!!(M&&M.indexOf("Edg/")>=0),Dn=!!(M&&M.indexOf("Android")>=0);var Wt=Symbol("MicrotaskDelay");function xe(r,e=0,t){let n=setTimeout(()=>{r(),t&&i.dispose()},e),i=A(()=>{clearTimeout(n),t?.deleteAndLeak(i)});return t?.add(i),i}var jt,Ue;(function(){typeof globalThis.requestIdleCallback!="function"||typeof globalThis.cancelIdleCallback!="function"?Ue=(r,e)=>{at(()=>{if(t)return;let n=Date.now()+15;e(Object.freeze({didTimeout:!0,timeRemaining(){return Math.max(0,n-Date.now())}}))});let t=!1;return{dispose(){t||(t=!0)}}}:Ue=(r,e,t)=>{let n=r.requestIdleCallback(e,typeof t=="number"?{timeout:t}:void 0),i=!1;return{dispose(){i||(i=!0,r.cancelIdleCallback(n))}}},jt=r=>Ue(globalThis,r)})();var qt;(t=>{async function r(n){let i,s=await Promise.all(n.map(a=>a.then(h=>h,h=>{i||(i=h)})));if(typeof i<"u")throw i;return s}t.settled=r;function e(n){return new Promise(async(i,s)=>{try{await n(i,s)}catch(a){s(a)}})}t.withAsyncBody=e})(qt||={});var P=class P{static fromArray(e){return new P(t=>{t.emitMany(e)})}static fromPromise(e){return new P(async t=>{t.emitMany(await e)})}static fromPromises(e){return new P(async t=>{await Promise.all(e.map(async n=>t.emitOne(await n)))})}static merge(e){return new P(async t=>{await Promise.all(e.map(async n=>{for await(let i of n)t.emitOne(i)}))})}constructor(e,t){this._state=0,this._results=[],this._error=null,this._onReturn=t,this._onStateChanged=new C,queueMicrotask(async()=>{let n={emitOne:i=>this.emitOne(i),emitMany:i=>this.emitMany(i),reject:i=>this.reject(i)};try{await Promise.resolve(e(n)),this.resolve()}catch(i){this.reject(i)}finally{n.emitOne=void 0,n.emitMany=void 0,n.reject=void 0}})}[Symbol.asyncIterator](){let e=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(e<this._results.length)return{done:!1,value:this._results[e++]};if(this._state===1)return{done:!0,value:void 0};await ie.toPromise(this._onStateChanged.event)}while(!0)},return:async()=>(this._onReturn?.(),{done:!0,value:void 0})}}static map(e,t){return new P(async n=>{for await(let i of e)n.emitOne(t(i))})}map(e){return P.map(this,e)}static filter(e,t){return new P(async n=>{for await(let i of e)t(i)&&n.emitOne(i)})}filter(e){return P.filter(this,e)}static coalesce(e){return P.filter(e,t=>!!t)}coalesce(){return P.coalesce(this)}static async toPromise(e){let t=[];for await(let n of e)t.push(n);return t}toPromise(){return P.toPromise(this)}emitOne(e){this._state===0&&(this._results.push(e),this._onStateChanged.fire())}emitMany(e){this._state===0&&(this._results=this._results.concat(e),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(e){this._state===0&&(this._state=2,this._error=e,this._onStateChanged.fire())}};P.EMPTY=P.fromArray([]);var lt=P;var Ie=class extends k{constructor(t){super();this._terminal=t;this._linesCacheTimeout=this._register(new F);this._linesCacheDisposables=this._register(new F);this._register(A(()=>this._destroyLinesCache()))}initLinesCache(){this._linesCache||(this._linesCache=new Array(this._terminal.buffer.active.length),this._linesCacheDisposables.value=me(this._terminal.onLineFeed(()=>this._destroyLinesCache()),this._terminal.onCursorMove(()=>this._destroyLinesCache()),this._terminal.onResize(()=>this._destroyLinesCache()))),this._linesCacheTimeout.value=xe(()=>this._destroyLinesCache(),15e3)}_destroyLinesCache(){this._linesCache=void 0,this._linesCacheDisposables.clear(),this._linesCacheTimeout.clear()}getLineFromCache(t){return this._linesCache?.[t]}setLineInCache(t,n){this._linesCache&&(this._linesCache[t]=n)}translateBufferLineToStringWithWrap(t,n){let i=[],s=[0],a=this._terminal.buffer.active.getLine(t);for(;a;){let h=this._terminal.buffer.active.getLine(t+1),u=h?h.isWrapped:!1,p=a.translateToString(!u&&n);if(u&&h){let T=a.getCell(a.length-1);T&&T.getCode()===0&&T.getWidth()===1&&h.getCell(0)?.getWidth()===2&&(p=p.slice(0,-1))}if(i.push(p),u)s.push(s[s.length-1]+p.length);else break;t++,a=h}return[i.join(""),s]}};var De=class{get cachedSearchTerm(){return this._cachedSearchTerm}set cachedSearchTerm(e){this._cachedSearchTerm=e}get lastSearchOptions(){return this._lastSearchOptions}set lastSearchOptions(e){this._lastSearchOptions=e}isValidSearchTerm(e){return!!(e&&e.length>0)}didOptionsChange(e){return this._lastSearchOptions?e?this._lastSearchOptions.caseSensitive!==e.caseSensitive||this._lastSearchOptions.regex!==e.regex||this._lastSearchOptions.wholeWord!==e.wholeWord:!1:!0}shouldUpdateHighlighting(e,t){return t?.decorations?this._cachedSearchTerm===void 0||e!==this._cachedSearchTerm||this.didOptionsChange(t):!1}clearCachedTerm(){this._cachedSearchTerm=void 0}reset(){this._cachedSearchTerm=void 0,this._lastSearchOptions=void 0}};var Ee=class{constructor(e,t){this._terminal=e;this._lineCache=t}find(e,t,n,i){if(!e||e.length===0){this._terminal.clearSelection();return}if(n>this._terminal.cols)throw new Error(`Invalid col: ${n} to search in terminal of ${this._terminal.cols} cols`);this._lineCache.initLinesCache();let s={startRow:t,startCol:n},a=this._findInLine(e,s,i);if(!a)for(let h=t+1;h<this._terminal.buffer.active.baseY+this._terminal.rows&&(s.startRow=h,s.startCol=0,a=this._findInLine(e,s,i),!a);h++);return a}findNextWithSelection(e,t,n){if(!e||e.length===0){this._terminal.clearSelection();return}let i=this._terminal.getSelectionPosition();this._terminal.clearSelection();let s=0,a=0;i&&(n===e?(s=i.end.x,a=i.end.y):(s=i.start.x,a=i.start.y)),this._lineCache.initLinesCache();let h={startRow:a,startCol:s},u=this._findInLine(e,h,t);if(!u)for(let p=a+1;p<this._terminal.buffer.active.baseY+this._terminal.rows&&(h.startRow=p,h.startCol=0,u=this._findInLine(e,h,t),!u);p++);if(!u&&a!==0)for(let p=0;p<a&&(h.startRow=p,h.startCol=0,u=this._findInLine(e,h,t),!u);p++);return!u&&i&&(h.startRow=i.start.y,h.startCol=0,u=this._findInLine(e,h,t)),u}findPreviousWithSelection(e,t,n){if(!e||e.length===0){this._terminal.clearSelection();return}let i=this._terminal.getSelectionPosition();this._terminal.clearSelection();let s=this._terminal.buffer.active.baseY+this._terminal.rows-1,a=this._terminal.cols,h=!0;this._lineCache.initLinesCache();let u={startRow:s,startCol:a},p;if(i&&(u.startRow=s=i.start.y,u.startCol=a=i.start.x,n!==e&&(p=this._findInLine(e,u,t,!1),p||(u.startRow=s=i.end.y,u.startCol=a=i.end.x))),p||(p=this._findInLine(e,u,t,h)),!p){u.startCol=Math.max(u.startCol,this._terminal.cols);for(let T=s-1;T>=0&&(u.startRow=T,p=this._findInLine(e,u,t,h),!p);T--);}if(!p&&s!==this._terminal.buffer.active.baseY+this._terminal.rows-1)for(let T=this._terminal.buffer.active.baseY+this._terminal.rows-1;T>=s&&(u.startRow=T,p=this._findInLine(e,u,t,h),!p);T--);return p}_isWholeWord(e,t,n){return(e===0||" ~!@#$%^&*()+`-=[]{}|\\;:\"',./<>?".includes(t[e-1]))&&(e+n.length===t.length||" ~!@#$%^&*()+`-=[]{}|\\;:\"',./<>?".includes(t[e+n.length]))}_findInLine(e,t,n={},i=!1){let s=t.startRow,a=t.startCol;if(this._terminal.buffer.active.getLine(s)?.isWrapped){if(i){t.startCol+=this._terminal.cols;return}return t.startRow--,t.startCol+=this._terminal.cols,this._findInLine(e,t,n)}let u=this._lineCache.getLineFromCache(s);u||(u=this._lineCache.translateBufferLineToStringWithWrap(s,!0),this._lineCache.setLineInCache(s,u));let[p,T]=u,v=this._bufferColsToStringOffset(s,a),I=e,E=p;n.regex||(I=n.caseSensitive?e:e.toLowerCase(),E=n.caseSensitive?p:p.toLowerCase());let S=-1;if(n.regex){let D=RegExp(I,n.caseSensitive?"g":"gi"),x;if(i)for(;x=D.exec(E.slice(0,v));)S=D.lastIndex-x[0].length,e=x[0],D.lastIndex-=e.length-1;else x=D.exec(E.slice(v)),x&&x[0].length>0&&(S=v+(D.lastIndex-x[0].length),e=x[0])}else i?v-I.length>=0&&(S=E.lastIndexOf(I,v-I.length)):S=E.indexOf(I,v);if(S>=0){if(n.wholeWord&&!this._isWholeWord(S,E,e))return;let D=0;for(;D<T.length-1&&S>=T[D+1];)D++;let x=D;for(;x<T.length-1&&S+e.length>=T[x+1];)x++;let J=S-T[D],q=S+e.length-T[x],z=this._stringLengthToBufferSize(s+D,J),_=this._stringLengthToBufferSize(s+x,q)-z+this._terminal.cols*(x-D);return{term:e,col:z,row:s+D,size:_}}}_stringLengthToBufferSize(e,t){let n=this._terminal.buffer.active.getLine(e);if(!n)return 0;for(let i=0;i<t;i++){let s=n.getCell(i);if(!s)break;let a=s.getChars();a.length>1&&(t-=a.length-1);let h=n.getCell(i+1);h&&h.getWidth()===0&&t++}return t}_bufferColsToStringOffset(e,t){let n=e,i=0,s=this._terminal.buffer.active.getLine(n);for(;t>0&&s;){for(let a=0;a<t&&a<this._terminal.cols;a++){let h=s.getCell(a);if(!h)break;h.getWidth()&&(i+=h.getCode()===0?1:h.getChars().length)}if(n++,s=this._terminal.buffer.active.getLine(n),s&&!s.isWrapped)break;t-=this._terminal.cols}return i}};var we=class extends k{constructor(t){super();this._terminal=t;this._highlightDecorations=[];this._highlightedLines=new Set;this._register(A(()=>this.clearHighlightDecorations()))}createHighlightDecorations(t,n){this.clearHighlightDecorations();for(let i of t){let s=this._createResultDecorations(i,n,!1);if(s)for(let a of s)this._storeDecoration(a,i)}}createActiveDecoration(t,n){let i=this._createResultDecorations(t,n,!0);if(i)return{decorations:i,match:t,dispose(){Q(i)}}}clearHighlightDecorations(){Q(this._highlightDecorations),this._highlightDecorations=[],this._highlightedLines.clear()}_storeDecoration(t,n){this._highlightedLines.add(t.marker.line),this._highlightDecorations.push({decoration:t,match:n,dispose(){t.dispose()}})}_applyStyles(t,n,i){t.classList.contains("xterm-find-result-decoration")||(t.classList.add("xterm-find-result-decoration"),n&&(t.style.outline=`1px solid ${n}`)),i&&t.classList.add("xterm-find-active-result-decoration")}_createResultDecorations(t,n,i){let s=[],a=t.col,h=t.size,u=-this._terminal.buffer.active.baseY-this._terminal.buffer.active.cursorY+t.row;for(;h>0;){let T=Math.min(this._terminal.cols-a,h);s.push([u,a,T]),a=0,h-=T,u++}let p=[];for(let T of s){let v=this._terminal.registerMarker(T[0]),I=this._terminal.registerDecoration({marker:v,x:T[1],width:T[2],backgroundColor:i?n.activeMatchBackground:n.matchBackground,overviewRulerOptions:this._highlightedLines.has(v.line)?void 0:{color:i?n.activeMatchColorOverviewRuler:n.matchOverviewRuler,position:"center"}});if(I){let E=[];E.push(v),E.push(I.onRender(S=>this._applyStyles(S,i?n.activeMatchBorder:n.matchBorder,!1))),E.push(I.onDispose(()=>Q(E))),p.push(I)}}return p.length===0?void 0:p}};var ke=class extends k{constructor(){super(...arguments);this._searchResults=[];this._onDidChangeResults=this._register(new C)}get onDidChangeResults(){return this._onDidChangeResults.event}get searchResults(){return this._searchResults}get selectedDecoration(){return this._selectedDecoration}set selectedDecoration(t){this._selectedDecoration=t}updateResults(t,n){this._searchResults=t.slice(0,n)}clearResults(){this._searchResults=[]}clearSelectedDecoration(){this._selectedDecoration&&(this._selectedDecoration.dispose(),this._selectedDecoration=void 0)}findResultIndex(t){for(let n=0;n<this._searchResults.length;n++){let i=this._searchResults[n];if(i.row===t.row&&i.col===t.col&&i.size===t.size)return n}return-1}fireResultsChanged(t){if(!t)return;let n=-1;this._selectedDecoration&&(n=this.findResultIndex(this._selectedDecoration.match)),this._onDidChangeResults.fire({resultIndex:n,resultCount:this._searchResults.length})}reset(){this.clearSelectedDecoration(),this.clearResults()}};var ut=class extends k{constructor(t){super();this._highlightTimeout=this._register(new F);this._lineCache=this._register(new F);this._state=new De;this._resultTracker=this._register(new ke);this._highlightLimit=t?.highlightLimit??1e3}get onDidChangeResults(){return this._resultTracker.onDidChangeResults}activate(t){this._terminal=t,this._lineCache.value=new Ie(t),this._engine=new Ee(t,this._lineCache.value),this._decorationManager=new we(t),this._register(this._terminal.onWriteParsed(()=>this._updateMatches())),this._register(this._terminal.onResize(()=>this._updateMatches())),this._register(A(()=>this.clearDecorations()))}_updateMatches(){this._highlightTimeout.clear(),this._state.cachedSearchTerm&&this._state.lastSearchOptions?.decorations&&(this._highlightTimeout.value=xe(()=>{let t=this._state.cachedSearchTerm;this._state.clearCachedTerm(),this.findPrevious(t,{...this._state.lastSearchOptions,incremental:!0},{noScroll:!0})},200))}clearDecorations(t){this._resultTracker.clearSelectedDecoration(),this._decorationManager?.clearHighlightDecorations(),this._resultTracker.clearResults(),t||this._state.clearCachedTerm()}clearActiveDecoration(){this._resultTracker.clearSelectedDecoration()}findNext(t,n,i){if(!this._terminal||!this._engine)throw new Error("Cannot use addon until it has been loaded");this._state.lastSearchOptions=n,this._state.shouldUpdateHighlighting(t,n)&&this._highlightAllMatches(t,n);let s=this._findNextAndSelect(t,n,i);return this._fireResults(n),this._state.cachedSearchTerm=t,s}_highlightAllMatches(t,n){if(!this._terminal||!this._engine||!this._decorationManager)throw new Error("Cannot use addon until it has been loaded");if(!this._state.isValidSearchTerm(t)){this.clearDecorations();return}this.clearDecorations(!0);let i=[],s,a=this._engine.find(t,0,0,n);for(;a&&(s?.row!==a.row||s?.col!==a.col)&&!(i.length>=this._highlightLimit);)s=a,i.push(s),a=this._engine.find(t,s.col+s.term.length>=this._terminal.cols?s.row+1:s.row,s.col+s.term.length>=this._terminal.cols?0:s.col+1,n);this._resultTracker.updateResults(i,this._highlightLimit),n.decorations&&this._decorationManager.createHighlightDecorations(i,n.decorations)}_findNextAndSelect(t,n,i){if(!this._terminal||!this._engine)return!1;if(!this._state.isValidSearchTerm(t))return this._terminal.clearSelection(),this.clearDecorations(),!1;let s=this._engine.findNextWithSelection(t,n,this._state.cachedSearchTerm);return this._selectResult(s,n?.decorations,i?.noScroll)}findPrevious(t,n,i){if(!this._terminal||!this._engine)throw new Error("Cannot use addon until it has been loaded");this._state.lastSearchOptions=n,this._state.shouldUpdateHighlighting(t,n)&&this._highlightAllMatches(t,n);let s=this._findPreviousAndSelect(t,n,i);return this._fireResults(n),this._state.cachedSearchTerm=t,s}_fireResults(t){this._resultTracker.fireResultsChanged(!!t?.decorations)}_findPreviousAndSelect(t,n,i){if(!this._terminal||!this._engine)return!1;if(!this._state.isValidSearchTerm(t))return this._terminal.clearSelection(),this.clearDecorations(),!1;let s=this._engine.findPreviousWithSelection(t,n,this._state.cachedSearchTerm);return this._selectResult(s,n?.decorations,i?.noScroll)}_selectResult(t,n,i){if(!this._terminal||!this._decorationManager)return!1;if(this._resultTracker.clearSelectedDecoration(),!t)return this._terminal.clearSelection(),!1;if(this._terminal.select(t.col,t.row,t.size),n){let s=this._decorationManager.createActiveDecoration(t,n);s&&(this._resultTracker.selectedDecoration=s)}if(!i&&(t.row>=this._terminal.buffer.active.viewportY+this._terminal.rows||t.row<this._terminal.buffer.active.viewportY)){let s=t.row-this._terminal.buffer.active.viewportY;s-=Math.floor(this._terminal.rows/2),this._terminal.scrollLines(s)}return!0}};export{ut as SearchAddon};
17
+ function _(h){return{dispose:h}}function T(h){if(!h)return h;if(Array.isArray(h)){for(let i of h)i.dispose();return[]}return h.dispose(),h}function E(...h){return _(()=>T(h))}var S=class{constructor(){this._disposables=new Set;this._isDisposed=!1}get isDisposed(){return this._isDisposed}add(i){return this._isDisposed?i.dispose():this._disposables.add(i),i}dispose(){if(!this._isDisposed){this._isDisposed=!0;for(let i of this._disposables)i.dispose();this._disposables.clear()}}clear(){for(let i of this._disposables)i.dispose();this._disposables.clear()}},b=class{constructor(){this._store=new S}dispose(){this._store.dispose()}_register(i){return this._store.add(i)}};b.None=Object.freeze({dispose(){}});var v=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(i){this._isDisposed||i===this._value||(this._value?.dispose(),this._value=i)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,this._value?.dispose(),this._value=void 0}};var I=class{constructor(){this._listeners=[];this._disposed=!1}get event(){return this._event?this._event:(this._event=(i,e,t)=>{if(this._disposed)return _(()=>{});let r={fn:i,thisArgs:e};this._listeners.push(r);let s=_(()=>{let n=this._listeners.indexOf(r);n!==-1&&this._listeners.splice(n,1)});return t&&(Array.isArray(t)?t.push(s):t.add(s)),s},this._event)}fire(i){if(!this._disposed)switch(this._listeners.length){case 0:return;case 1:{let{fn:e,thisArgs:t}=this._listeners[0];e.call(t,i);return}default:{let e=this._listeners.slice();for(let{fn:t,thisArgs:r}of e)t.call(r,i)}}}dispose(){this._disposed||(this._disposed=!0,this._listeners.length=0)}},W;(r=>{function h(s,n){return s(a=>n.fire(a))}r.forward=h;function i(s,n){return(a,o,l)=>s(c=>a.call(o,n(c)),void 0,l)}r.map=i;function e(...s){return(n,a,o)=>{let l=new S;for(let c of s)l.add(c(p=>n.call(a,p)));return o&&(Array.isArray(o)?o.push(l):o.add(l)),l}}r.any=e;function t(s,n,a){return n(a),s(o=>n(o))}r.runAndSubscribe=t})(W||={});function D(h,i=0,e){let t=setTimeout(()=>{h(),e&&r.dispose()},i),r=_(()=>{clearTimeout(t)});return e?.add(r),r}var C=class extends b{constructor(e){super();this._terminal=e;this._linesCacheTimeout=this._register(new v);this._linesCacheDisposables=this._register(new v);this._lastAccessTimestamp=0;this._register(_(()=>this._destroyLinesCache()))}initLinesCache(){this._linesCache||(this._linesCache=new Array(this._terminal.buffer.active.length),this._linesCacheDisposables.value=E(this._terminal.onLineFeed(()=>this._destroyLinesCache()),this._terminal.onCursorMove(()=>this._destroyLinesCache()),this._terminal.onResize(()=>this._destroyLinesCache()))),this._lastAccessTimestamp=Date.now(),this._linesCacheTimeout.value||this._scheduleLinesCacheTimeout(15e3)}_destroyLinesCache(){this._linesCache=void 0,this._lastAccessTimestamp=0,this._linesCacheDisposables.clear(),this._linesCacheTimeout.clear()}_scheduleLinesCacheTimeout(e){this._linesCacheTimeout.value=D(()=>{if(!this._linesCache)return;let r=Date.now()-this._lastAccessTimestamp;if(r>=15e3){this._destroyLinesCache();return}this._scheduleLinesCacheTimeout(15e3-r)},e)}getLineFromCache(e){return this._linesCache?.[e]}setLineInCache(e,t){this._linesCache&&(this._linesCache[e]=t)}translateBufferLineToStringWithWrap(e,t){let r=[],s=[0],n=this._terminal.buffer.active.getLine(e);for(;n;){let a=this._terminal.buffer.active.getLine(e+1),o=a?a.isWrapped:!1,l=n.translateToString(!o&&t);if(o&&a){let c=n.getCell(n.length-1);c&&c.getCode()===0&&c.getWidth()===1&&a.getCell(0)?.getWidth()===2&&(l=l.slice(0,-1))}if(r.push(l),o)s.push(s[s.length-1]+l.length);else break;e++,n=a}return[r.join(""),s]}};var x=class{get cachedSearchTerm(){return this._cachedSearchTerm}set cachedSearchTerm(i){this._cachedSearchTerm=i}get lastSearchOptions(){return this._lastSearchOptions}set lastSearchOptions(i){this._lastSearchOptions=i}isValidSearchTerm(i){return!!(i&&i.length>0)}didOptionsChange(i){return this._lastSearchOptions?i?this._lastSearchOptions.caseSensitive!==i.caseSensitive||this._lastSearchOptions.regex!==i.regex||this._lastSearchOptions.wholeWord!==i.wholeWord:!1:!0}shouldUpdateHighlighting(i,e){return e?.decorations?this._cachedSearchTerm===void 0||i!==this._cachedSearchTerm||this.didOptionsChange(e):!1}clearCachedTerm(){this._cachedSearchTerm=void 0}reset(){this._cachedSearchTerm=void 0,this._lastSearchOptions=void 0}};var R=class{constructor(i,e){this._terminal=i;this._lineCache=e}find(i,e,t,r){if(!i||i.length===0){this._terminal.clearSelection();return}if(t>this._terminal.cols)throw new Error(`Invalid col: ${t} to search in terminal of ${this._terminal.cols} cols`);this._lineCache.initLinesCache();let s={startRow:e,startCol:t},n=this._findInLine(i,s,r);if(!n)for(let a=e+1;a<this._terminal.buffer.active.baseY+this._terminal.rows&&(s.startRow=a,s.startCol=0,n=this._findInLine(i,s,r),!n);a++);return n}findNextWithSelection(i,e,t){if(!i||i.length===0){this._terminal.clearSelection();return}let r=this._terminal.getSelectionPosition();this._terminal.clearSelection();let s=0,n=0;r&&(t===i?(s=r.end.x,n=r.end.y):(s=r.start.x,n=r.start.y)),this._lineCache.initLinesCache();let a={startRow:n,startCol:s},o=this._findInLine(i,a,e);if(!o)for(let l=n+1;l<this._terminal.buffer.active.baseY+this._terminal.rows&&(a.startRow=l,a.startCol=0,o=this._findInLine(i,a,e),!o);l++);if(!o&&n!==0)for(let l=0;l<n&&(a.startRow=l,a.startCol=0,o=this._findInLine(i,a,e),!o);l++);return!o&&r&&(a.startRow=r.start.y,a.startCol=0,o=this._findInLine(i,a,e)),o}findPreviousWithSelection(i,e,t){if(!i||i.length===0){this._terminal.clearSelection();return}let r=this._terminal.getSelectionPosition();this._terminal.clearSelection();let s=this._terminal.buffer.active.baseY+this._terminal.rows-1,n=this._terminal.cols,a=!0;this._lineCache.initLinesCache();let o={startRow:s,startCol:n},l;if(r&&(o.startRow=s=r.start.y,o.startCol=n=r.start.x,t!==i&&(l=this._findInLine(i,o,e,!1),l||(o.startRow=s=r.end.y,o.startCol=n=r.end.x))),l??=this._findInLine(i,o,e,a),!l){o.startCol=Math.max(o.startCol,this._terminal.cols);for(let c=s-1;c>=0&&(o.startRow=c,l=this._findInLine(i,o,e,a),!l);c--);}if(!l&&s!==this._terminal.buffer.active.baseY+this._terminal.rows-1)for(let c=this._terminal.buffer.active.baseY+this._terminal.rows-1;c>=s&&(o.startRow=c,l=this._findInLine(i,o,e,a),!l);c--);return l}_isWholeWord(i,e,t){return(i===0||" ~!@#$%^&*()+`-=[]{}|\\;:\"',./<>?".includes(e[i-1]))&&(i+t.length===e.length||" ~!@#$%^&*()+`-=[]{}|\\;:\"',./<>?".includes(e[i+t.length]))}_findInLine(i,e,t={},r=!1){let s=e.startRow,n=e.startCol;if(this._terminal.buffer.active.getLine(s)?.isWrapped){if(r){e.startCol+=this._terminal.cols;return}return e.startRow--,e.startCol+=this._terminal.cols,this._findInLine(i,e,t)}let o=this._lineCache.getLineFromCache(s);o||(o=this._lineCache.translateBufferLineToStringWithWrap(s,!0),this._lineCache.setLineInCache(s,o));let[l,c]=o,p=this._bufferColsToStringOffset(s,n),m=i,g=l;t.regex||(m=t.caseSensitive?i:i.toLowerCase(),g=t.caseSensitive?l:l.toLowerCase());let f=-1;if(t.regex){let u=RegExp(m,t.caseSensitive?"g":"gi"),d;if(r)for(;d=u.exec(g.slice(0,p));)f=u.lastIndex-d[0].length,i=d[0],u.lastIndex-=i.length-1;else d=u.exec(g.slice(p)),d&&d[0].length>0&&(f=p+(u.lastIndex-d[0].length),i=d[0])}else r?p-m.length>=0&&(f=g.lastIndexOf(m,p-m.length)):f=g.indexOf(m,p);if(f>=0){if(t.wholeWord&&!this._isWholeWord(f,g,i))return;let u=0;for(;u<c.length-1&&f>=c[u+1];)u++;let d=u;for(;d<c.length-1&&f+i.length>=c[d+1];)d++;let O=f-c[u],k=f+i.length-c[d],y=this._stringLengthToBufferSize(s+u,O),M=this._stringLengthToBufferSize(s+d,k)-y+this._terminal.cols*(d-u);return{term:i,col:y,row:s+u,size:M}}}_stringLengthToBufferSize(i,e){let t=this._terminal.buffer.active.getLine(i);if(!t)return 0;for(let r=0;r<e;r++){let s=t.getCell(r);if(!s)break;let n=s.getChars();n.length>1&&(e-=n.length-1);let a=t.getCell(r+1);a&&a.getWidth()===0&&e++}return e}_bufferColsToStringOffset(i,e){let t=i,r=0,s=this._terminal.buffer.active.getLine(t);for(;e>0&&s;){for(let n=0;n<e&&n<this._terminal.cols;n++){let a=s.getCell(n);if(!a)break;a.getWidth()&&(r+=a.getCode()===0?1:a.getChars().length)}if(t++,s=this._terminal.buffer.active.getLine(t),s&&!s.isWrapped)break;e-=this._terminal.cols}return r}};var w=class extends b{constructor(e){super();this._terminal=e;this._highlightDecorations=[];this._highlightedLines=new Set;this._register(_(()=>this.clearHighlightDecorations()))}createHighlightDecorations(e,t){this.clearHighlightDecorations();for(let r of e){let s=this._createResultDecorations(r,t,!1);if(s)for(let n of s)this._storeDecoration(n,r)}}createActiveDecoration(e,t){let r=this._createResultDecorations(e,t,!0);if(r)return{decorations:r,match:e,dispose(){T(r)}}}clearHighlightDecorations(){T(this._highlightDecorations),this._highlightDecorations=[],this._highlightedLines.clear()}_storeDecoration(e,t){this._highlightedLines.add(e.marker.line),this._highlightDecorations.push({decoration:e,match:t,dispose(){e.dispose()}})}_applyStyles(e,t,r){e.classList.contains("xterm-find-result-decoration")||(e.classList.add("xterm-find-result-decoration"),t&&(e.style.outline=`1px solid ${t}`)),r&&e.classList.add("xterm-find-active-result-decoration")}_createResultDecorations(e,t,r){let s=[],n=e.col,a=e.size,o=-this._terminal.buffer.active.baseY-this._terminal.buffer.active.cursorY+e.row;for(;a>0;){let c=Math.min(this._terminal.cols-n,a);s.push([o,n,c]),n=0,a-=c,o++}let l=[];for(let c of s){let p=this._terminal.registerMarker(c[0]),m=this._terminal.registerDecoration({marker:p,x:c[1],width:c[2],layer:r?"top":"bottom",backgroundColor:r?t.activeMatchBackground:t.matchBackground,overviewRulerOptions:this._highlightedLines.has(p.line)?void 0:{color:r?t.activeMatchColorOverviewRuler:t.matchOverviewRuler,position:"center"}});if(m){let g=[];g.push(p),g.push(m.onRender(f=>this._applyStyles(f,r?t.activeMatchBorder:t.matchBorder,!1))),g.push(m.onDispose(()=>T(g))),l.push(m)}}return l.length===0?void 0:l}};var L=class extends b{constructor(){super(...arguments);this._searchResults=[];this._onDidChangeResults=this._register(new I)}get onDidChangeResults(){return this._onDidChangeResults.event}get searchResults(){return this._searchResults}get selectedDecoration(){return this._selectedDecoration}set selectedDecoration(e){this._selectedDecoration=e}updateResults(e,t){this._searchResults=e.slice(0,t)}clearResults(){this._searchResults=[]}clearSelectedDecoration(){this._selectedDecoration&&(this._selectedDecoration.dispose(),this._selectedDecoration=void 0)}findResultIndex(e){for(let t=0;t<this._searchResults.length;t++){let r=this._searchResults[t];if(r.row===e.row&&r.col===e.col&&r.size===e.size)return t}return-1}fireResultsChanged(e){if(!e)return;let t=-1;this._selectedDecoration&&(t=this.findResultIndex(this._selectedDecoration.match)),this._onDidChangeResults.fire({resultIndex:t,resultCount:this._searchResults.length})}reset(){this.clearSelectedDecoration(),this.clearResults()}};var A=class extends b{constructor(e){super();this._highlightTimeout=this._register(new v);this._lineCache=this._register(new v);this._state=new x;this._resultTracker=this._register(new L);this._onAfterSearch=this._register(new I);this.onAfterSearch=this._onAfterSearch.event;this._onBeforeSearch=this._register(new I);this.onBeforeSearch=this._onBeforeSearch.event;this._highlightLimit=e?.highlightLimit??1e3}get onDidChangeResults(){return this._resultTracker.onDidChangeResults}activate(e){this._terminal=e,this._lineCache.value=new C(e),this._engine=new R(e,this._lineCache.value),this._decorationManager=new w(e),this._register(this._terminal.onWriteParsed(()=>this._updateMatches())),this._register(this._terminal.onResize(()=>this._updateMatches())),this._register(_(()=>this.clearDecorations()))}_updateMatches(){this._highlightTimeout.clear(),this._state.cachedSearchTerm&&this._state.lastSearchOptions?.decorations&&(this._highlightTimeout.value=D(()=>{let e=this._state.cachedSearchTerm;this._state.clearCachedTerm(),this.findPrevious(e,{...this._state.lastSearchOptions,incremental:!0},{noScroll:!0})},200))}clearDecorations(e){this._resultTracker.clearSelectedDecoration(),this._decorationManager?.clearHighlightDecorations(),this._resultTracker.clearResults(),e||this._state.clearCachedTerm()}clearActiveDecoration(){this._resultTracker.clearSelectedDecoration()}findNext(e,t,r){if(!this._terminal||!this._engine)throw new Error("Cannot use addon until it has been loaded");this._onBeforeSearch.fire(),this._state.lastSearchOptions=t,this._state.shouldUpdateHighlighting(e,t)&&this._highlightAllMatches(e,t);let s=this._findNextAndSelect(e,t,r);return this._fireResults(t),this._state.cachedSearchTerm=e,this._onAfterSearch.fire(),s}_highlightAllMatches(e,t){if(!this._terminal||!this._engine||!this._decorationManager)throw new Error("Cannot use addon until it has been loaded");if(!this._state.isValidSearchTerm(e)){this.clearDecorations();return}this.clearDecorations(!0);let r=[],s,n=this._engine.find(e,0,0,t);for(;n&&(s?.row!==n.row||s?.col!==n.col)&&!(r.length>=this._highlightLimit);)s=n,r.push(s),n=this._engine.find(e,s.col+s.term.length>=this._terminal.cols?s.row+1:s.row,s.col+s.term.length>=this._terminal.cols?0:s.col+1,t);this._resultTracker.updateResults(r,this._highlightLimit),t.decorations&&this._decorationManager.createHighlightDecorations(r,t.decorations)}_findNextAndSelect(e,t,r){if(!this._terminal||!this._engine)return!1;if(!this._state.isValidSearchTerm(e))return this._terminal.clearSelection(),this.clearDecorations(),!1;let s=this._engine.findNextWithSelection(e,t,this._state.cachedSearchTerm);return this._selectResult(s,t?.decorations,r?.noScroll)}findPrevious(e,t,r){if(!this._terminal||!this._engine)throw new Error("Cannot use addon until it has been loaded");this._onBeforeSearch.fire(),this._state.lastSearchOptions=t,this._state.shouldUpdateHighlighting(e,t)&&this._highlightAllMatches(e,t);let s=this._findPreviousAndSelect(e,t,r);return this._fireResults(t),this._state.cachedSearchTerm=e,this._onAfterSearch.fire(),s}_fireResults(e){this._resultTracker.fireResultsChanged(!!e?.decorations)}_findPreviousAndSelect(e,t,r){if(!this._terminal||!this._engine)return!1;if(!this._state.isValidSearchTerm(e))return this._terminal.clearSelection(),this.clearDecorations(),!1;let s=this._engine.findPreviousWithSelection(e,t,this._state.cachedSearchTerm);return this._selectResult(s,t?.decorations,r?.noScroll)}_selectResult(e,t,r){if(!this._terminal||!this._decorationManager)return!1;if(this._resultTracker.clearSelectedDecoration(),!e)return this._terminal.clearSelection(),!1;if(this._terminal.select(e.col,e.row,e.size),t){let s=this._decorationManager.createActiveDecoration(e,t);s&&(this._resultTracker.selectedDecoration=s)}if(!r&&(e.row>=this._terminal.buffer.active.viewportY+this._terminal.rows||e.row<this._terminal.buffer.active.viewportY)){let s=e.row-this._terminal.buffer.active.viewportY;s-=Math.floor(this._terminal.rows/2),this._terminal.scrollLines(s)}return!0}};export{A as SearchAddon};
44
18
  //# sourceMappingURL=addon-search.mjs.map