@xterm/addon-search 0.16.0-beta.125 → 0.16.0-beta.127

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xterm/addon-search",
3
- "version": "0.16.0-beta.125",
3
+ "version": "0.16.0-beta.127",
4
4
  "author": {
5
5
  "name": "The xterm.js authors",
6
6
  "url": "https://xtermjs.org/"
@@ -22,7 +22,7 @@
22
22
  "start": "node ../../demo/start"
23
23
  },
24
24
  "peerDependencies": {
25
- "@xterm/xterm": "^5.6.0-beta.125"
25
+ "@xterm/xterm": "^5.6.0-beta.127"
26
26
  },
27
- "commit": "15d90826f90ffbd45d1cd8b27bebc665a152cec6"
27
+ "commit": "ab43a3bd22082d2dc3045672df9a62473d9cec2f"
28
28
  }
@@ -4,38 +4,28 @@
4
4
  */
5
5
 
6
6
  import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
7
- import type { SearchAddon as ISearchApi, ISearchOptions, ISearchDecorationOptions } from '@xterm/addon-search';
7
+ import type { SearchAddon as ISearchApi, ISearchOptions, ISearchDecorationOptions, ISearchAddonOptions, ISearchResultChangeEvent } from '@xterm/addon-search';
8
8
  import { Emitter, Event } from 'vs/base/common/event';
9
9
  import { Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
10
+ import { disposableTimeout } from 'vs/base/common/async';
10
11
  import { SearchLineCache } from './SearchLineCache';
11
12
 
12
13
  interface IInternalSearchOptions {
13
- noScroll?: boolean;
14
+ noScroll: boolean;
14
15
  }
15
16
 
16
- export interface ISearchPosition {
17
+ interface ISearchPosition {
17
18
  startCol: number;
18
19
  startRow: number;
19
20
  }
20
21
 
21
- export interface ISearchResultChangeEvent {
22
- resultIndex: number;
23
- resultCount: number;
24
- }
25
-
26
- export interface ISearchAddonOptions {
27
- highlightLimit: number;
28
- }
29
-
30
- export interface ISearchResult {
22
+ interface ISearchResult {
31
23
  term: string;
32
24
  col: number;
33
25
  row: number;
34
26
  size: number;
35
27
  }
36
28
 
37
-
38
-
39
29
  interface IHighlight extends IDisposable {
40
30
  decoration: IDecoration;
41
31
  match: ISearchResult;
@@ -57,8 +47,6 @@ const enum Constants {
57
47
  */
58
48
  NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?',
59
49
 
60
-
61
-
62
50
  /**
63
51
  * Default maximum number of search results to highlight simultaneously. This limit prevents
64
52
  * performance degradation when searching for very common terms that would result in excessive
@@ -73,10 +61,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp
73
61
  private _highlightedLines: Set<number> = new Set();
74
62
  private _highlightDecorations: IHighlight[] = [];
75
63
  private _searchResultsWithHighlight: ISearchResult[] = [];
76
- private _selectedDecoration: MutableDisposable<IMultiHighlight> = this._register(new MutableDisposable());
64
+ private _selectedDecoration = this._register(new MutableDisposable<IMultiHighlight>());
77
65
  private _highlightLimit: number;
78
66
  private _lastSearchOptions: ISearchOptions | undefined;
79
- private _highlightTimeout: number | undefined;
67
+ private _highlightTimeout = this._register(new MutableDisposable<IDisposable>());
80
68
  private _lineCache = this._register(new MutableDisposable<SearchLineCache>());
81
69
 
82
70
  private readonly _onDidChangeResults = this._register(new Emitter<ISearchResultChangeEvent>());
@@ -97,11 +85,9 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp
97
85
  }
98
86
 
99
87
  private _updateMatches(): void {
100
- if (this._highlightTimeout) {
101
- window.clearTimeout(this._highlightTimeout);
102
- }
88
+ this._highlightTimeout.clear();
103
89
  if (this._cachedSearchTerm && this._lastSearchOptions?.decorations) {
104
- this._highlightTimeout = setTimeout(() => {
90
+ this._highlightTimeout.value = disposableTimeout(() => {
105
91
  const term = this._cachedSearchTerm;
106
92
  this._cachedSearchTerm = undefined;
107
93
  this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true }, { noScroll: true });
@@ -5,6 +5,7 @@
5
5
 
6
6
  import type { Terminal } from '@xterm/xterm';
7
7
  import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
8
+ import { disposableTimeout } from 'vs/base/common/async';
8
9
 
9
10
  export type LineCacheEntry = [
10
11
  /**
@@ -35,7 +36,7 @@ export class SearchLineCache extends Disposable {
35
36
  * _linesCache is also invalidated when the terminal cursor moves.
36
37
  */
37
38
  private _linesCache: LineCacheEntry[] | undefined;
38
- private _linesCacheTimeoutId = 0;
39
+ private _linesCacheTimeout = this._register(new MutableDisposable());
39
40
  private _linesCacheDisposables = this._register(new MutableDisposable());
40
41
 
41
42
  constructor(private _terminal: Terminal) {
@@ -56,17 +57,13 @@ export class SearchLineCache extends Disposable {
56
57
  );
57
58
  }
58
59
 
59
- window.clearTimeout(this._linesCacheTimeoutId);
60
- this._linesCacheTimeoutId = window.setTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE);
60
+ this._linesCacheTimeout.value = disposableTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE);
61
61
  }
62
62
 
63
63
  private _destroyLinesCache(): void {
64
64
  this._linesCache = undefined;
65
65
  this._linesCacheDisposables.clear();
66
- if (this._linesCacheTimeoutId) {
67
- window.clearTimeout(this._linesCacheTimeoutId);
68
- this._linesCacheTimeoutId = 0;
69
- }
66
+ this._linesCacheTimeout.clear();
70
67
  }
71
68
 
72
69
  public getLineFromCache(row: number): LineCacheEntry | undefined {