@xterm/addon-search 0.16.0-beta.124 → 0.16.0-beta.126
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.
- package/lib/addon-search.js +1 -1
- package/lib/addon-search.js.map +1 -1
- package/lib/addon-search.mjs +12 -12
- package/lib/addon-search.mjs.map +4 -4
- package/package.json +3 -3
- package/src/SearchAddon.ts +16 -101
- package/src/SearchLineCache.ts +114 -0
package/lib/addon-search.mjs
CHANGED
|
@@ -14,19 +14,19 @@
|
|
|
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
|
|
17
|
+
var Ee=class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?ae.isErrorNoTelemetry(e)?new ae(e.message+`
|
|
18
18
|
|
|
19
19
|
`+e.stack):new Error(e.message+`
|
|
20
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)}},
|
|
22
|
-
`).map(
|
|
23
|
-
`),
|
|
24
|
-
`)).size}/${n.length} leaks) at ${I}`;let
|
|
25
|
-
`)),
|
|
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)}},ut=new Ee;function le(r){dt(r)||ut.onUnexpectedError(r)}var De="Canceled";function dt(r){return r instanceof ee?!0:r instanceof Error&&r.name===De&&r.message===De}var ee=class extends Error{constructor(){super(De),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 ke(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}}function ct(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=ct(this._array,e,this._findLastMonotonousLastIdx);return this._findLastMonotonousLastIdx=t+1,t===-1?void 0:this._array[t]}};ue.assertInvariants=!1;var qe=ue;var Ue;(l=>{function r(u){return u<0}l.isLessThan=r;function e(u){return u<=0}l.isLessThanOrEqual=e;function t(u){return u>0}l.isGreaterThan=t;function n(u){return u===0}l.isNeitherLessOrGreaterThan=n,l.greaterThan=1,l.lessThan=-1,l.neitherLessOrGreaterThan=0})(Ue||={});function Ve(r,e){return(t,n)=>e(r(t),r(n))}var Ke=(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||Ue.isGreaterThan(e(i,t)))&&(n=!1,t=i),!0)),t}};V.empty=new V(e=>{});var ze=V;function Be(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 Qe,$e,He=class{constructor(e,t){this.toKey=t;this._map=new Map;this[Qe]="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))}[($e=Symbol.iterator,Qe=Symbol.toStringTag,$e)](){return this.values()}};var de=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}};var Ce;(J=>{function r(v){return v&&typeof v=="object"&&typeof v[Symbol.iterator]=="function"}J.is=r;let e=Object.freeze([]);function t(){return e}J.empty=t;function*n(v){yield v}J.single=n;function i(v){return r(v)?v:n(v)}J.wrap=i;function s(v){return v||e}J.from=s;function*a(v){for(let g=v.length-1;g>=0;g--)yield v[g]}J.reverse=a;function l(v){return!v||v[Symbol.iterator]().next().done===!0}J.isEmpty=l;function u(v){return v[Symbol.iterator]().next().value}J.first=u;function p(v,g){let y=0;for(let R of v)if(g(R,y++))return!0;return!1}J.some=p;function f(v,g){for(let y of v)if(g(y))return y}J.find=f;function*T(v,g){for(let y of v)g(y)&&(yield y)}J.filter=T;function*I(v,g){let y=0;for(let R of v)yield g(R,y++)}J.map=I;function*w(v,g){let y=0;for(let R of v)yield*g(R,y++)}J.flatMap=w;function*S(...v){for(let g of v)yield*g}J.concat=S;function A(v,g,y){let R=y;for(let X of v)R=g(R,X);return R}J.reduce=A;function*E(v,g,y=v.length){for(g<0&&(g+=v.length),y<0?y+=v.length:y>v.length&&(y=v.length);g<y;g++)yield v[g]}J.slice=E;function D(v,g=Number.POSITIVE_INFINITY){let y=[];if(g===0)return[y,v];let R=v[Symbol.iterator]();for(let X=0;X<g;X++){let we=R.next();if(we.done)return[y,J.empty()];y.push(we.value)}return[y,{[Symbol.iterator](){return R}}]}J.consume=D;async function x(v){let g=[];for await(let y of v)g.push(y);return Promise.resolve(g)}J.asyncToArray=x})(Ce||={});var ht=!1,K=null,ce=class ce{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:ce.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(T=>T.source!==null&&!this.getRootParent(T,u).isSingleton);if(p.length===0)return;let f=new Set(p.map(T=>T.value));if(n=p.filter(T=>!(T.parent&&f.has(T.parent))),n.length===0)throw new Error("There are cyclic diposable chains!")}if(!n)return;function i(u){function p(T,I){for(;T.length>0&&I.some(w=>typeof w=="string"?w===T[0]:T[0].match(w));)T.shift()}let f=u.source.split(`
|
|
22
|
+
`).map(T=>T.trim().replace("at ","")).filter(T=>T!=="");return p(f,["Error",/^trackDisposable \(.*\)$/,/^DisposableTracker.trackDisposable \(.*\)$/]),f.reverse()}let s=new de;for(let u of n){let p=i(u);for(let f=0;f<=p.length;f++)s.add(p.slice(0,f).join(`
|
|
23
|
+
`),u)}n.sort(Ve(u=>u.idx,Ke));let a="",l=0;for(let u of n.slice(0,e)){l++;let p=i(u),f=[];for(let T=0;T<p.length;T++){let I=p[T];I=`(shared with ${s.get(p.slice(0,T+1).join(`
|
|
24
|
+
`)).size}/${n.length} leaks) at ${I}`;let S=s.get(p.slice(0,T).join(`
|
|
25
|
+
`)),A=Be([...S].map(E=>i(E)[T]),E=>E);delete A[p[T]];for(let[E,D]of Object.entries(A))f.unshift(` - stacktraces of ${D.length} other leaks continue with ${E}`);f.unshift(I)}a+=`
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
==================== Leaking disposable ${
|
|
29
|
-
${
|
|
28
|
+
==================== Leaking disposable ${l}/${n.length}: ${u.value.constructor.name} ====================
|
|
29
|
+
${f.join(`
|
|
30
30
|
`)}
|
|
31
31
|
============================================================
|
|
32
32
|
|
|
@@ -35,10 +35,10 @@ ${p.join(`
|
|
|
35
35
|
|
|
36
36
|
... and ${n.length-e} more leaking disposables
|
|
37
37
|
|
|
38
|
-
`),{leaks:n,details:a}}};
|
|
38
|
+
`),{leaks:n,details:a}}};ce.idx=0;var Ge=ce;function pt(r){K=r}if(ht){let r="__is_disposable_tracked__";pt(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!==O.None)try{e[r]=!0}catch{}}markAsDisposed(e){if(e&&e!==O.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 ft(r,e){if(K)for(let t of r)K.setParent(t,e)}function Q(r){if(Ce.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=N(()=>Q(r));return ft(r,e),e}function N(r){let e=pe({dispose:ke(()=>{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,O=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)}};O.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 Ye=$;var mt=globalThis.performance&&typeof globalThis.performance.now=="function",Te=class r{static create(e){return new r(e)}constructor(e){this._now=mt&&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 Tt=!1,Je=!1,vt=!1,ie;(re=>{re.None=()=>O.None;function e(h){if(vt){let{onDidAddListener:o}=h,c=ne.create(),d=0;h.onDidAddListener=()=>{++d===2&&(console.warn("snapshotted emitter LIKELY used public and SHOULD HAVE BEEN created with DisposableStore. snapshotted here"),c.print()),o?.()}}}function t(h,o){return I(h,()=>{},0,void 0,!0,void 0,o)}re.defer=t;function n(h){return(o,c=null,d)=>{let m=!1,b;return b=h(_=>{if(!m)return b?b.dispose():m=!0,o.call(c,_)},null,d),m&&b.dispose(),b}}re.once=n;function i(h,o,c){return f((d,m=null,b)=>h(_=>d.call(m,o(_)),null,b),c)}re.map=i;function s(h,o,c){return f((d,m=null,b)=>h(_=>{o(_),d.call(m,_)},null,b),c)}re.forEach=s;function a(h,o,c){return f((d,m=null,b)=>h(_=>o(_)&&d.call(m,_),null,b),c)}re.filter=a;function l(h){return h}re.signal=l;function u(...h){return(o,c=null,d)=>{let m=me(...h.map(b=>b(_=>o.call(c,_))));return T(m,d)}}re.any=u;function p(h,o,c,d){let m=c;return i(h,b=>(m=o(m,b),m),d)}re.reduce=p;function f(h,o){let c,d={onWillAddFirstListener(){c=h(m.fire,m)},onDidRemoveLastListener(){c?.dispose()}};o||e(d);let m=new P(d);return o?.add(m),m.event}function T(h,o){return o instanceof Array?o.push(h):o&&o.add(h),h}function I(h,o,c=100,d=!1,m=!1,b,_){let k,C,U,se=0,Z,je={leakWarningThreshold:b,onWillAddFirstListener(){k=h(at=>{se++,C=o(C,at),d&&!U&&(oe.fire(C),C=void 0),Z=()=>{let lt=C;C=void 0,U=void 0,(!d||se>1)&&oe.fire(lt),se=0},typeof c=="number"?(clearTimeout(U),U=setTimeout(Z,c)):U===void 0&&(U=0,queueMicrotask(Z))})},onWillRemoveListener(){m&&se>0&&Z?.()},onDidRemoveLastListener(){Z=void 0,k.dispose()}};_||e(je);let oe=new P(je);return _?.add(oe),oe.event}re.debounce=I;function w(h,o=0,c){return re.debounce(h,(d,m)=>d?(d.push(m),d):[m],o,void 0,!0,void 0,c)}re.accumulate=w;function S(h,o=(d,m)=>d===m,c){let d=!0,m;return a(h,b=>{let _=d||!o(b,m);return d=!1,m=b,_},c)}re.latch=S;function A(h,o,c){return[re.filter(h,o,c),re.filter(h,d=>!o(d),c)]}re.split=A;function E(h,o=!1,c=[],d){let m=c.slice(),b=h(C=>{m?m.push(C):k.fire(C)});d&&d.add(b);let _=()=>{m?.forEach(C=>k.fire(C)),m=null},k=new P({onWillAddFirstListener(){b||(b=h(C=>k.fire(C)),d&&d.add(b))},onDidAddFirstListener(){m&&(o?setTimeout(_):_())},onDidRemoveLastListener(){b&&b.dispose(),b=null}});return d&&d.add(k),k.event}re.buffer=E;function D(h,o){return(d,m,b)=>{let _=o(new J);return h(function(k){let C=_.evaluate(k);C!==x&&d.call(m,C)},void 0,b)}}re.chain=D;let x=Symbol("HaltChainable");class J{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:x),this}reduce(o,c){let d=c;return this.steps.push(m=>(d=o(d,m),d)),this}latch(o=(c,d)=>c===d){let c=!0,d;return this.steps.push(m=>{let b=c||!o(m,d);return c=!1,d=m,b?m:x}),this}evaluate(o){for(let c of this.steps)if(o=c(o),o===x)break;return o}}function v(h,o,c=d=>d){let d=(...k)=>_.fire(c(...k)),m=()=>h.on(o,d),b=()=>h.removeListener(o,d),_=new P({onWillAddFirstListener:m,onDidRemoveLastListener:b});return _.event}re.fromNodeEventEmitter=v;function g(h,o,c=d=>d){let d=(...k)=>_.fire(c(...k)),m=()=>h.addEventListener(o,d),b=()=>h.removeEventListener(o,d),_=new P({onWillAddFirstListener:m,onDidRemoveLastListener:b});return _.event}re.fromDOMEventEmitter=g;function y(h){return new Promise(o=>n(h)(o))}re.toPromise=y;function R(h){let o=new P;return h.then(c=>{o.fire(c)},()=>{o.fire(void 0)}).finally(()=>{o.dispose()}),o.event}re.fromPromise=R;function X(h,o){return h(c=>o.fire(c))}re.forward=X;function we(h,o,c){return o(c),h(d=>o(d))}re.runAndSubscribe=we;class ot{constructor(o,c){this._observable=o;this._counter=0;this._hasChanged=!1;let d={onWillAddFirstListener:()=>{o.addObserver(this)},onDidRemoveLastListener:()=>{o.removeObserver(this)}};c||e(d),this.emitter=new P(d),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 Wt(h,o){return new ot(h,o).emitter.event}re.fromObservable=Wt;function Nt(h){return(o,c,d)=>{let m=0,b=!1,_={beginUpdate(){m++},endUpdate(){m--,m===0&&(h.reportChanges(),b&&(b=!1,o.call(c)))},handlePossibleChange(){},handleChange(){b=!0}};h.addObserver(_),h.reportChanges();let k={dispose(){h.removeObserver(_)}};return d instanceof H?d.add(k):Array.isArray(d)&&d.push(k),k}}re.fromObservableLight=Nt})(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 Se=B,Xe=-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(),l=`[${this.name}] potential listener LEAK detected, having ${t} listeners already. MOST frequent listener (${a}):`;console.warn(l),console.warn(s);let u=new Pe(l,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 Re=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
39
|
`).slice(2).join(`
|
|
40
|
-
`))}},
|
|
41
|
-
`)),r.length=0)},3e3),
|
|
40
|
+
`))}},Pe=class extends Error{constructor(e,t){super(e),this.name="ListenerLeakError",this.stack=t}},Le=class extends Error{constructor(e,t){super(e),this.name="ListenerRefusalError",this.stack=t}},bt=0,G=class{constructor(e){this.value=e;this.id=bt++}},gt=2,_t=(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(Tt){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 P=class{constructor(e){this._size=0;this._options=e,this._leakageMon=Xe>0||this._options?.leakWarningThreshold?new Re(e?.onListenerError??le,this._options?.leakWarningThreshold??Xe):void 0,this._perfMon=this._options?._profName?new Se(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(Je){let e=this._listeners;queueMicrotask(()=>{_t(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],f=new Le(`${u}. HINT: Stack shows most frequent listener (${p[1]}-times)`,p[0]);return(this._options?.onListenerError||le)(f),O.None}if(this._disposed)return O.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)),Je&&(i.stack=a??ne.create()),this._listeners?this._listeners instanceof G?(this._deliveryQueue??=new Oe,this._listeners=[this._listeners,i]):this._listeners.push(i):(this._options?.onWillAddFirstListener?.(this),this._listeners=i,this._options?.onDidAddFirstListener?.(this)),this._size++;let l=N(()=>{ve?.unregister(l),s?.(),this._removeListener(i)});if(n instanceof H?n.add(l):Array.isArray(n)&&n.push(l),ve){let u=new Error().stack.split(`
|
|
42
42
|
`).slice(2,3).join(`
|
|
43
|
-
`).trim(),f=/(file:|vscode-file:\/\/vscode-app)?(\/[^:]*:\d+:\d+)/.exec(l);ue.register(d,f?.[2]??l,d)}return d},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*Ye<=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||ee;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 V)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 _e=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 Fe=class extends O{constructor(t){super();this._highlightedLines=new Set;this._highlightDecorations=[];this._searchResultsWithHighlight=[];this._selectedDecoration=this._register(new $);this._linesCacheTimeoutId=0;this._linesCacheDisposables=new $;this._onDidChangeResults=this._register(new A);this._highlightLimit=t?.highlightLimit??1e3}get onDidChangeResults(){return this._onDidChangeResults.event}activate(t){this._terminal=t,this._register(this._terminal.onWriteParsed(()=>this._updateMatches())),this._register(this._terminal.onResize(()=>this._updateMatches())),this._register(q(()=>this.clearDecorations()))}_updateMatches(){this._highlightTimeout&&window.clearTimeout(this._highlightTimeout),this._cachedSearchTerm&&this._lastSearchOptions?.decorations&&(this._highlightTimeout=setTimeout(()=>{let t=this._cachedSearchTerm;this._cachedSearchTerm=void 0,this.findPrevious(t,{...this._lastSearchOptions,incremental:!0},{noScroll:!0})},200))}clearDecorations(t){this._selectedDecoration.clear(),W(this._highlightDecorations),this._highlightDecorations=[],this._searchResultsWithHighlight=[],this._highlightedLines.clear(),t||(this._cachedSearchTerm=void 0)}clearActiveDecoration(){this._selectedDecoration.clear()}findNext(t,n,i){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");let s=this._lastSearchOptions?this._didOptionsChange(this._lastSearchOptions,n):!0;this._lastSearchOptions=n,n?.decorations&&(this._cachedSearchTerm===void 0||t!==this._cachedSearchTerm||s)&&this._highlightAllMatches(t,n);let a=this._findNextAndSelect(t,n,i);return this._fireResults(n),this._cachedSearchTerm=t,a}_highlightAllMatches(t,n){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!t||t.length===0){this.clearDecorations();return}n=n||{},this.clearDecorations(!0);let i,s=this._find(t,0,0,n);for(;s&&(i?.row!==s.row||i?.col!==s.col)&&!(this._searchResultsWithHighlight.length>=this._highlightLimit);)i=s,this._searchResultsWithHighlight.push(i),s=this._find(t,i.col+i.term.length>=this._terminal.cols?i.row+1:i.row,i.col+i.term.length>=this._terminal.cols?0:i.col+1,n);for(let a of this._searchResultsWithHighlight){let d=this._createResultDecorations(a,n.decorations,!1);if(d)for(let l of d)this._storeDecoration(l,a)}}_storeDecoration(t,n){this._highlightedLines.add(t.marker.line),this._highlightDecorations.push({decoration:t,match:n,dispose(){t.dispose()}})}_find(t,n,i,s){if(!this._terminal||!t||t.length===0){this._terminal?.clearSelection(),this.clearDecorations();return}if(i>this._terminal.cols)throw new Error(`Invalid col: ${i} to search in terminal of ${this._terminal.cols} cols`);let a;this._initLinesCache();let d={startRow:n,startCol:i};if(a=this._findInLine(t,d,s),!a)for(let l=n+1;l<this._terminal.buffer.active.baseY+this._terminal.rows&&(d.startRow=l,d.startCol=0,a=this._findInLine(t,d,s),!a);l++);return a}_findNextAndSelect(t,n,i){if(!this._terminal||!t||t.length===0)return this._terminal?.clearSelection(),this.clearDecorations(),!1;let s=this._terminal.getSelectionPosition();this._terminal.clearSelection();let a=0,d=0;s&&(this._cachedSearchTerm===t?(a=s.end.x,d=s.end.y):(a=s.start.x,d=s.start.y)),this._initLinesCache();let l={startRow:d,startCol:a},f=this._findInLine(t,l,n);if(!f)for(let p=d+1;p<this._terminal.buffer.active.baseY+this._terminal.rows&&(l.startRow=p,l.startCol=0,f=this._findInLine(t,l,n),!f);p++);if(!f&&d!==0)for(let p=0;p<d&&(l.startRow=p,l.startCol=0,f=this._findInLine(t,l,n),!f);p++);return!f&&s&&(l.startRow=s.start.y,l.startCol=0,f=this._findInLine(t,l,n)),this._selectResult(f,n?.decorations,i?.noScroll)}findPrevious(t,n,i){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");let s=this._lastSearchOptions?this._didOptionsChange(this._lastSearchOptions,n):!0;this._lastSearchOptions=n,n?.decorations&&(this._cachedSearchTerm===void 0||t!==this._cachedSearchTerm||s)&&this._highlightAllMatches(t,n);let a=this._findPreviousAndSelect(t,n,i);return this._fireResults(n),this._cachedSearchTerm=t,a}_didOptionsChange(t,n){return n?t.caseSensitive!==n.caseSensitive||t.regex!==n.regex||t.wholeWord!==n.wholeWord:!1}_fireResults(t){if(t?.decorations){let n=-1;if(this._selectedDecoration.value){let i=this._selectedDecoration.value.match;for(let s=0;s<this._searchResultsWithHighlight.length;s++){let a=this._searchResultsWithHighlight[s];if(a.row===i.row&&a.col===i.col&&a.size===i.size){n=s;break}}}this._onDidChangeResults.fire({resultIndex:n,resultCount:this._searchResultsWithHighlight.length})}}_findPreviousAndSelect(t,n,i){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!this._terminal||!t||t.length===0)return this._terminal?.clearSelection(),this.clearDecorations(),!1;let s=this._terminal.getSelectionPosition();this._terminal.clearSelection();let a=this._terminal.buffer.active.baseY+this._terminal.rows-1,d=this._terminal.cols,l=!0;this._initLinesCache();let f={startRow:a,startCol:d},p;if(s&&(f.startRow=a=s.start.y,f.startCol=d=s.start.x,this._cachedSearchTerm!==t&&(p=this._findInLine(t,f,n,!1),p||(f.startRow=a=s.end.y,f.startCol=d=s.end.x))),p||(p=this._findInLine(t,f,n,l)),!p){f.startCol=Math.max(f.startCol,this._terminal.cols);for(let m=a-1;m>=0&&(f.startRow=m,p=this._findInLine(t,f,n,l),!p);m--);}if(!p&&a!==this._terminal.buffer.active.baseY+this._terminal.rows-1)for(let m=this._terminal.buffer.active.baseY+this._terminal.rows-1;m>=a&&(f.startRow=m,p=this._findInLine(t,f,n,l),!p);m--);return this._selectResult(p,n?.decorations,i?.noScroll)}_initLinesCache(){let t=this._terminal;this._linesCache||(this._linesCache=new Array(t.buffer.active.length),this._linesCacheDisposables.value=ae(t.onLineFeed(()=>this._destroyLinesCache()),t.onCursorMove(()=>this._destroyLinesCache()),t.onResize(()=>this._destroyLinesCache()))),window.clearTimeout(this._linesCacheTimeoutId),this._linesCacheTimeoutId=window.setTimeout(()=>this._destroyLinesCache(),15e3)}_destroyLinesCache(){this._linesCache=void 0,this._linesCacheDisposables.clear(),this._linesCacheTimeoutId&&(window.clearTimeout(this._linesCacheTimeoutId),this._linesCacheTimeoutId=0)}_isWholeWord(t,n,i){return(t===0||" ~!@#$%^&*()+`-=[]{}|\\;:\"',./<>?".includes(n[t-1]))&&(t+i.length===n.length||" ~!@#$%^&*()+`-=[]{}|\\;:\"',./<>?".includes(n[t+i.length]))}_findInLine(t,n,i={},s=!1){let a=this._terminal,d=n.startRow,l=n.startCol;if(a.buffer.active.getLine(d)?.isWrapped){if(s){n.startCol+=a.cols;return}return n.startRow--,n.startCol+=a.cols,this._findInLine(t,n,i)}let p=this._linesCache?.[d];p||(p=this._translateBufferLineToStringWithWrap(d,!0),this._linesCache&&(this._linesCache[d]=p));let[m,I]=p,E=this._bufferColsToStringOffset(d,l),C=t,k=m;i.regex||(C=i.caseSensitive?t:t.toLowerCase(),k=i.caseSensitive?m:m.toLowerCase());let D=-1;if(i.regex){let w=RegExp(C,i.caseSensitive?"g":"gi"),y;if(s)for(;y=w.exec(k.slice(0,E));)D=w.lastIndex-y[0].length,t=y[0],w.lastIndex-=t.length-1;else y=w.exec(k.slice(E)),y&&y[0].length>0&&(D=E+(w.lastIndex-y[0].length),t=y[0])}else s?E-C.length>=0&&(D=k.lastIndexOf(C,E-C.length)):D=k.indexOf(C,E);if(D>=0){if(i.wholeWord&&!this._isWholeWord(D,k,t))return;let w=0;for(;w<I.length-1&&D>=I[w+1];)w++;let y=w;for(;y<I.length-1&&D+t.length>=I[y+1];)y++;let j=D-I[w],v=D+t.length-I[y],g=this._stringLengthToBufferSize(d+w,j),R=this._stringLengthToBufferSize(d+y,v)-g+a.cols*(y-w);return{term:t,col:g,row:d+w,size:R}}}_stringLengthToBufferSize(t,n){let i=this._terminal.buffer.active.getLine(t);if(!i)return 0;for(let s=0;s<n;s++){let a=i.getCell(s);if(!a)break;let d=a.getChars();d.length>1&&(n-=d.length-1);let l=i.getCell(s+1);l&&l.getWidth()===0&&n++}return n}_bufferColsToStringOffset(t,n){let i=this._terminal,s=t,a=0,d=i.buffer.active.getLine(s);for(;n>0&&d;){for(let l=0;l<n&&l<i.cols;l++){let f=d.getCell(l);if(!f)break;f.getWidth()&&(a+=f.getCode()===0?1:f.getChars().length)}if(s++,d=i.buffer.active.getLine(s),d&&!d.isWrapped)break;n-=i.cols}return a}_translateBufferLineToStringWithWrap(t,n){let i=this._terminal,s=[],a=[0],d=i.buffer.active.getLine(t);for(;d;){let l=i.buffer.active.getLine(t+1),f=l?l.isWrapped:!1,p=d.translateToString(!f&&n);if(f&&l){let m=d.getCell(d.length-1);m&&m.getCode()===0&&m.getWidth()===1&&l.getCell(0)?.getWidth()===2&&(p=p.slice(0,-1))}if(s.push(p),f)a.push(a[a.length-1]+p.length);else break;t++,d=l}return[s.join(""),a]}_selectResult(t,n,i){let s=this._terminal;if(this._selectedDecoration.clear(),!t)return s.clearSelection(),!1;if(s.select(t.col,t.row,t.size),n){let a=this._createResultDecorations(t,n,!0);a&&(this._selectedDecoration.value={decorations:a,match:t,dispose(){W(a)}})}if(!i&&(t.row>=s.buffer.active.viewportY+s.rows||t.row<s.buffer.active.viewportY)){let a=t.row-s.buffer.active.viewportY;a-=Math.floor(s.rows/2),s.scrollLines(a)}return!0}_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=this._terminal,a=[],d=t.col,l=t.size,f=-s.buffer.active.baseY-s.buffer.active.cursorY+t.row;for(;l>0;){let m=Math.min(s.cols-d,l);a.push([f,d,m]),d=0,l-=m,f++}let p=[];for(let m of a){let I=s.registerMarker(m[0]),E=s.registerDecoration({marker:I,x:m[1],width:m[2],backgroundColor:i?n.activeMatchBackground:n.matchBackground,overviewRulerOptions:this._highlightedLines.has(I.line)?void 0:{color:i?n.activeMatchColorOverviewRuler:n.matchOverviewRuler,position:"center"}});if(E){let C=[];C.push(I),C.push(E.onRender(k=>this._applyStyles(k,i?n.activeMatchBorder:n.matchBorder,!1))),C.push(E.onDispose(()=>W(C))),p.push(E)}}return p.length===0?void 0:p}};export{Fe as SearchAddon};
|
|
43
|
+
`).trim(),p=/(file:|vscode-file:\/\/vscode-app)?(\/[^:]*:\d+:\d+)/.exec(u);ve.register(l,p?.[2]??u,l)}return l},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*gt<=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 Oe=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 Ze=Object.freeze(function(r,e){let t=setTimeout(r.bind(e),0);return{dispose(){clearTimeout(t)}}}),yt;(n=>{function r(i){return i===n.None||i===n.Cancelled||i instanceof Ae?!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:Ze})})(yt||={});var Ae=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?Ze:(this._emitter||(this._emitter=new P),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=null)}};var Y="en",Fe=!1,We=!1,_e=!1,xt=!1,It=!1,tt=!1,wt=!1,Et=!1,Dt=!1,kt=!1,ge,ye=Y,et=Y,Ct,j,q=globalThis,M;typeof q.vscode<"u"&&typeof q.vscode.process<"u"?M=q.vscode.process:typeof process<"u"&&typeof process?.versions?.node=="string"&&(M=process);var nt=typeof M?.versions?.electron=="string",St=nt&&M?.type==="renderer";if(typeof M=="object"){Fe=M.platform==="win32",We=M.platform==="darwin",_e=M.platform==="linux",xt=_e&&!!M.env.SNAP&&!!M.env.SNAP_REVISION,wt=nt,Dt=!!M.env.CI||!!M.env.BUILD_ARTIFACTSTAGINGDIRECTORY,ge=Y,ye=Y;let r=M.env.VSCODE_NLS_CONFIG;if(r)try{let e=JSON.parse(r);ge=e.userLocale,et=e.osLocale,ye=e.resolvedLanguage||Y,Ct=e.languagePack?.translationsConfigFile}catch{}It=!0}else typeof navigator=="object"&&!St?(j=navigator.userAgent,Fe=j.indexOf("Windows")>=0,We=j.indexOf("Macintosh")>=0,Et=(j.indexOf("Macintosh")>=0||j.indexOf("iPad")>=0||j.indexOf("iPhone")>=0)&&!!navigator.maxTouchPoints&&navigator.maxTouchPoints>0,_e=j.indexOf("Linux")>=0,kt=j?.indexOf("Mobi")>=0,tt=!0,ye=globalThis._VSCODE_NLS_LANGUAGE||Y,ge=navigator.language.toLowerCase(),et=ge):console.error("Unable to resolve platform.");var Me=0;We?Me=1:Fe?Me=3:_e&&(Me=2);var Rt=tt&&typeof q.importScripts=="function",Tn=Rt?q.origin:void 0;var W=j,z=ye,Pt;(n=>{function r(){return z}n.value=r;function e(){return z.length===2?z==="en":z.length>=3?z[0]==="e"&&z[1]==="n"&&z[2]==="-":!1}n.isDefaultVariant=e;function t(){return z==="en"}n.isDefault=t})(Pt||={});var Lt=typeof q.postMessage=="function"&&!q.importScripts,it=(()=>{if(Lt){let r=[];q.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}),q.postMessage({vscodeScheduleAsyncWork:n},"*")}}return r=>setTimeout(r)})();var Ot=!!(W&&W.indexOf("Chrome")>=0),vn=!!(W&&W.indexOf("Firefox")>=0),bn=!!(!Ot&&W&&W.indexOf("Safari")>=0),gn=!!(W&&W.indexOf("Edg/")>=0),_n=!!(W&&W.indexOf("Android")>=0);var At=Symbol("MicrotaskDelay");function xe(r,e=0,t){let n=setTimeout(()=>{r(),t&&i.dispose()},e),i=N(()=>{clearTimeout(n),t?.deleteAndLeak(i)});return t?.add(i),i}var Mt,Ne;(function(){typeof globalThis.requestIdleCallback!="function"||typeof globalThis.cancelIdleCallback!="function"?Ne=(r,e)=>{it(()=>{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)}}}:Ne=(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))}}},Mt=r=>Ne(globalThis,r)})();var Ft;(t=>{async function r(n){let i,s=await Promise.all(n.map(a=>a.then(l=>l,l=>{i||(i=l)})));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})(Ft||={});var L=class L{static fromArray(e){return new L(t=>{t.emitMany(e)})}static fromPromise(e){return new L(async t=>{t.emitMany(await e)})}static fromPromises(e){return new L(async t=>{await Promise.all(e.map(async n=>t.emitOne(await n)))})}static merge(e){return new L(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 P,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 L(async n=>{for await(let i of e)n.emitOne(t(i))})}map(e){return L.map(this,e)}static filter(e,t){return new L(async n=>{for await(let i of e)t(i)&&n.emitOne(i)})}filter(e){return L.filter(this,e)}static coalesce(e){return L.filter(e,t=>!!t)}coalesce(){return L.coalesce(this)}static async toPromise(e){let t=[];for await(let n of e)t.push(n);return t}toPromise(){return L.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())}};L.EMPTY=L.fromArray([]);var rt=L;var Ie=class extends O{constructor(t){super();this._terminal=t;this._linesCacheTimeout=this._register(new F);this._linesCacheDisposables=this._register(new F);this._register(N(()=>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 l=this._terminal.buffer.active.getLine(t+1),u=l?l.isWrapped:!1,p=a.translateToString(!u&&n);if(u&&l){let f=a.getCell(a.length-1);f&&f.getCode()===0&&f.getWidth()===1&&l.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=l}return[i.join(""),s]}};var st=class extends O{constructor(t){super();this._highlightedLines=new Set;this._highlightDecorations=[];this._searchResultsWithHighlight=[];this._selectedDecoration=this._register(new F);this._highlightTimeout=this._register(new F);this._lineCache=this._register(new F);this._onDidChangeResults=this._register(new P);this._highlightLimit=t?.highlightLimit??1e3}get onDidChangeResults(){return this._onDidChangeResults.event}activate(t){this._terminal=t,this._lineCache.value=new Ie(t),this._register(this._terminal.onWriteParsed(()=>this._updateMatches())),this._register(this._terminal.onResize(()=>this._updateMatches())),this._register(N(()=>this.clearDecorations()))}_updateMatches(){this._highlightTimeout.clear(),this._cachedSearchTerm&&this._lastSearchOptions?.decorations&&(this._highlightTimeout.value=xe(()=>{let t=this._cachedSearchTerm;this._cachedSearchTerm=void 0,this.findPrevious(t,{...this._lastSearchOptions,incremental:!0},{noScroll:!0})},200))}clearDecorations(t){this._selectedDecoration.clear(),Q(this._highlightDecorations),this._highlightDecorations=[],this._searchResultsWithHighlight=[],this._highlightedLines.clear(),t||(this._cachedSearchTerm=void 0)}clearActiveDecoration(){this._selectedDecoration.clear()}findNext(t,n,i){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");let s=this._lastSearchOptions?this._didOptionsChange(this._lastSearchOptions,n):!0;this._lastSearchOptions=n,n?.decorations&&(this._cachedSearchTerm===void 0||t!==this._cachedSearchTerm||s)&&this._highlightAllMatches(t,n);let a=this._findNextAndSelect(t,n,i);return this._fireResults(n),this._cachedSearchTerm=t,a}_highlightAllMatches(t,n){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!t||t.length===0){this.clearDecorations();return}n=n||{},this.clearDecorations(!0);let i,s=this._find(t,0,0,n);for(;s&&(i?.row!==s.row||i?.col!==s.col)&&!(this._searchResultsWithHighlight.length>=this._highlightLimit);)i=s,this._searchResultsWithHighlight.push(i),s=this._find(t,i.col+i.term.length>=this._terminal.cols?i.row+1:i.row,i.col+i.term.length>=this._terminal.cols?0:i.col+1,n);for(let a of this._searchResultsWithHighlight){let l=this._createResultDecorations(a,n.decorations,!1);if(l)for(let u of l)this._storeDecoration(u,a)}}_storeDecoration(t,n){this._highlightedLines.add(t.marker.line),this._highlightDecorations.push({decoration:t,match:n,dispose(){t.dispose()}})}_find(t,n,i,s){if(!this._terminal||!t||t.length===0){this._terminal?.clearSelection(),this.clearDecorations();return}if(i>this._terminal.cols)throw new Error(`Invalid col: ${i} to search in terminal of ${this._terminal.cols} cols`);let a;this._lineCache.value.initLinesCache();let l={startRow:n,startCol:i};if(a=this._findInLine(t,l,s),!a)for(let u=n+1;u<this._terminal.buffer.active.baseY+this._terminal.rows&&(l.startRow=u,l.startCol=0,a=this._findInLine(t,l,s),!a);u++);return a}_findNextAndSelect(t,n,i){if(!this._terminal||!t||t.length===0)return this._terminal?.clearSelection(),this.clearDecorations(),!1;let s=this._terminal.getSelectionPosition();this._terminal.clearSelection();let a=0,l=0;s&&(this._cachedSearchTerm===t?(a=s.end.x,l=s.end.y):(a=s.start.x,l=s.start.y)),this._lineCache.value.initLinesCache();let u={startRow:l,startCol:a},p=this._findInLine(t,u,n);if(!p)for(let f=l+1;f<this._terminal.buffer.active.baseY+this._terminal.rows&&(u.startRow=f,u.startCol=0,p=this._findInLine(t,u,n),!p);f++);if(!p&&l!==0)for(let f=0;f<l&&(u.startRow=f,u.startCol=0,p=this._findInLine(t,u,n),!p);f++);return!p&&s&&(u.startRow=s.start.y,u.startCol=0,p=this._findInLine(t,u,n)),this._selectResult(p,n?.decorations,i?.noScroll)}findPrevious(t,n,i){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");let s=this._lastSearchOptions?this._didOptionsChange(this._lastSearchOptions,n):!0;this._lastSearchOptions=n,n?.decorations&&(this._cachedSearchTerm===void 0||t!==this._cachedSearchTerm||s)&&this._highlightAllMatches(t,n);let a=this._findPreviousAndSelect(t,n,i);return this._fireResults(n),this._cachedSearchTerm=t,a}_didOptionsChange(t,n){return n?t.caseSensitive!==n.caseSensitive||t.regex!==n.regex||t.wholeWord!==n.wholeWord:!1}_fireResults(t){if(t?.decorations){let n=-1;if(this._selectedDecoration.value){let i=this._selectedDecoration.value.match;for(let s=0;s<this._searchResultsWithHighlight.length;s++){let a=this._searchResultsWithHighlight[s];if(a.row===i.row&&a.col===i.col&&a.size===i.size){n=s;break}}}this._onDidChangeResults.fire({resultIndex:n,resultCount:this._searchResultsWithHighlight.length})}}_findPreviousAndSelect(t,n,i){if(!this._terminal)throw new Error("Cannot use addon until it has been loaded");if(!this._terminal||!t||t.length===0)return this._terminal?.clearSelection(),this.clearDecorations(),!1;let s=this._terminal.getSelectionPosition();this._terminal.clearSelection();let a=this._terminal.buffer.active.baseY+this._terminal.rows-1,l=this._terminal.cols,u=!0;this._lineCache.value.initLinesCache();let p={startRow:a,startCol:l},f;if(s&&(p.startRow=a=s.start.y,p.startCol=l=s.start.x,this._cachedSearchTerm!==t&&(f=this._findInLine(t,p,n,!1),f||(p.startRow=a=s.end.y,p.startCol=l=s.end.x))),f||(f=this._findInLine(t,p,n,u)),!f){p.startCol=Math.max(p.startCol,this._terminal.cols);for(let T=a-1;T>=0&&(p.startRow=T,f=this._findInLine(t,p,n,u),!f);T--);}if(!f&&a!==this._terminal.buffer.active.baseY+this._terminal.rows-1)for(let T=this._terminal.buffer.active.baseY+this._terminal.rows-1;T>=a&&(p.startRow=T,f=this._findInLine(t,p,n,u),!f);T--);return this._selectResult(f,n?.decorations,i?.noScroll)}_isWholeWord(t,n,i){return(t===0||" ~!@#$%^&*()+`-=[]{}|\\;:\"',./<>?".includes(n[t-1]))&&(t+i.length===n.length||" ~!@#$%^&*()+`-=[]{}|\\;:\"',./<>?".includes(n[t+i.length]))}_findInLine(t,n,i={},s=!1){let a=this._terminal,l=n.startRow,u=n.startCol;if(a.buffer.active.getLine(l)?.isWrapped){if(s){n.startCol+=a.cols;return}return n.startRow--,n.startCol+=a.cols,this._findInLine(t,n,i)}let f=this._lineCache.value.getLineFromCache(l);f||(f=this._lineCache.value.translateBufferLineToStringWithWrap(l,!0),this._lineCache.value.setLineInCache(l,f));let[T,I]=f,w=this._bufferColsToStringOffset(l,u),S=t,A=T;i.regex||(S=i.caseSensitive?t:t.toLowerCase(),A=i.caseSensitive?T:T.toLowerCase());let E=-1;if(i.regex){let D=RegExp(S,i.caseSensitive?"g":"gi"),x;if(s)for(;x=D.exec(A.slice(0,w));)E=D.lastIndex-x[0].length,t=x[0],D.lastIndex-=t.length-1;else x=D.exec(A.slice(w)),x&&x[0].length>0&&(E=w+(D.lastIndex-x[0].length),t=x[0])}else s?w-S.length>=0&&(E=A.lastIndexOf(S,w-S.length)):E=A.indexOf(S,w);if(E>=0){if(i.wholeWord&&!this._isWholeWord(E,A,t))return;let D=0;for(;D<I.length-1&&E>=I[D+1];)D++;let x=D;for(;x<I.length-1&&E+t.length>=I[x+1];)x++;let J=E-I[D],v=E+t.length-I[x],g=this._stringLengthToBufferSize(l+D,J),R=this._stringLengthToBufferSize(l+x,v)-g+a.cols*(x-D);return{term:t,col:g,row:l+D,size:R}}}_stringLengthToBufferSize(t,n){let i=this._terminal.buffer.active.getLine(t);if(!i)return 0;for(let s=0;s<n;s++){let a=i.getCell(s);if(!a)break;let l=a.getChars();l.length>1&&(n-=l.length-1);let u=i.getCell(s+1);u&&u.getWidth()===0&&n++}return n}_bufferColsToStringOffset(t,n){let i=this._terminal,s=t,a=0,l=i.buffer.active.getLine(s);for(;n>0&&l;){for(let u=0;u<n&&u<i.cols;u++){let p=l.getCell(u);if(!p)break;p.getWidth()&&(a+=p.getCode()===0?1:p.getChars().length)}if(s++,l=i.buffer.active.getLine(s),l&&!l.isWrapped)break;n-=i.cols}return a}_selectResult(t,n,i){let s=this._terminal;if(this._selectedDecoration.clear(),!t)return s.clearSelection(),!1;if(s.select(t.col,t.row,t.size),n){let a=this._createResultDecorations(t,n,!0);a&&(this._selectedDecoration.value={decorations:a,match:t,dispose(){Q(a)}})}if(!i&&(t.row>=s.buffer.active.viewportY+s.rows||t.row<s.buffer.active.viewportY)){let a=t.row-s.buffer.active.viewportY;a-=Math.floor(s.rows/2),s.scrollLines(a)}return!0}_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=this._terminal,a=[],l=t.col,u=t.size,p=-s.buffer.active.baseY-s.buffer.active.cursorY+t.row;for(;u>0;){let T=Math.min(s.cols-l,u);a.push([p,l,T]),l=0,u-=T,p++}let f=[];for(let T of a){let I=s.registerMarker(T[0]),w=s.registerDecoration({marker:I,x:T[1],width:T[2],backgroundColor:i?n.activeMatchBackground:n.matchBackground,overviewRulerOptions:this._highlightedLines.has(I.line)?void 0:{color:i?n.activeMatchColorOverviewRuler:n.matchOverviewRuler,position:"center"}});if(w){let S=[];S.push(I),S.push(w.onRender(A=>this._applyStyles(A,i?n.activeMatchBorder:n.matchBorder,!1))),S.push(w.onDispose(()=>Q(S))),f.push(w)}}return f.length===0?void 0:f}};export{st as SearchAddon};
|
|
44
44
|
//# sourceMappingURL=addon-search.mjs.map
|