@xterm/addon-search 0.17.0-beta.96 → 0.17.0-beta.97
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 +6 -6
- package/lib/addon-search.mjs.map +3 -3
- package/package.json +3 -3
- package/src/SearchLineCache.ts +23 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xterm/addon-search",
|
|
3
|
-
"version": "0.17.0-beta.
|
|
3
|
+
"version": "0.17.0-beta.97",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "The xterm.js authors",
|
|
6
6
|
"url": "https://xtermjs.org/"
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"prepublishOnly": "npm run package",
|
|
22
22
|
"start": "node ../../demo/start"
|
|
23
23
|
},
|
|
24
|
-
"commit": "
|
|
24
|
+
"commit": "756c35323797b8e9de10520d8e012569e97f1b59",
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@xterm/xterm": "^6.1.0-beta.
|
|
26
|
+
"@xterm/xterm": "^6.1.0-beta.97"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/SearchLineCache.ts
CHANGED
|
@@ -38,6 +38,9 @@ export class SearchLineCache extends Disposable {
|
|
|
38
38
|
private _linesCache: LineCacheEntry[] | undefined;
|
|
39
39
|
private _linesCacheTimeout = this._register(new MutableDisposable());
|
|
40
40
|
private _linesCacheDisposables = this._register(new MutableDisposable());
|
|
41
|
+
// Track access to avoid recreating a timeout on every init call which occurs once per search
|
|
42
|
+
// result (findNext/findPrevious -> _highlightAllMatches -> find loop).
|
|
43
|
+
private _lastAccessTimestamp = 0;
|
|
41
44
|
|
|
42
45
|
constructor(private readonly _terminal: Terminal) {
|
|
43
46
|
super();
|
|
@@ -57,15 +60,34 @@ export class SearchLineCache extends Disposable {
|
|
|
57
60
|
);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
this.
|
|
63
|
+
this._lastAccessTimestamp = Date.now();
|
|
64
|
+
if (!this._linesCacheTimeout.value) {
|
|
65
|
+
this._scheduleLinesCacheTimeout(Constants.LINES_CACHE_TIME_TO_LIVE);
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
private _destroyLinesCache(): void {
|
|
64
70
|
this._linesCache = undefined;
|
|
71
|
+
this._lastAccessTimestamp = 0;
|
|
65
72
|
this._linesCacheDisposables.clear();
|
|
66
73
|
this._linesCacheTimeout.clear();
|
|
67
74
|
}
|
|
68
75
|
|
|
76
|
+
private _scheduleLinesCacheTimeout(delay: number): void {
|
|
77
|
+
this._linesCacheTimeout.value = disposableTimeout(() => {
|
|
78
|
+
if (!this._linesCache) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const now = Date.now();
|
|
82
|
+
const elapsed = now - this._lastAccessTimestamp;
|
|
83
|
+
if (elapsed >= Constants.LINES_CACHE_TIME_TO_LIVE) {
|
|
84
|
+
this._destroyLinesCache();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this._scheduleLinesCacheTimeout(Constants.LINES_CACHE_TIME_TO_LIVE - elapsed);
|
|
88
|
+
}, delay);
|
|
89
|
+
}
|
|
90
|
+
|
|
69
91
|
public getLineFromCache(row: number): LineCacheEntry | undefined {
|
|
70
92
|
return this._linesCache?.[row];
|
|
71
93
|
}
|