@xterm/addon-search 0.16.0-beta.121 → 0.16.0-beta.123

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.121",
3
+ "version": "0.16.0-beta.123",
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.121"
25
+ "@xterm/xterm": "^5.6.0-beta.123"
26
26
  },
27
- "commit": "5c0107462e1c968a22b7dae58edf702d9bd5313e"
27
+ "commit": "eb1330ca181df394d21070a57b36232c8185df77"
28
28
  }
@@ -4,28 +4,14 @@
4
4
  */
5
5
 
6
6
  import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
7
- import type { SearchAddon as ISearchApi } from '@xterm/addon-search';
7
+ import type { SearchAddon as ISearchApi, ISearchOptions, ISearchDecorationOptions } from '@xterm/addon-search';
8
8
  import { Emitter, Event } from 'vs/base/common/event';
9
9
  import { combinedDisposable, Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
10
10
 
11
- export interface ISearchOptions {
12
- regex?: boolean;
13
- wholeWord?: boolean;
14
- caseSensitive?: boolean;
15
- incremental?: boolean;
16
- decorations?: ISearchDecorationOptions;
11
+ interface IInternalSearchOptions {
17
12
  noScroll?: boolean;
18
13
  }
19
14
 
20
- interface ISearchDecorationOptions {
21
- matchBackground?: string;
22
- matchBorder?: string;
23
- matchOverviewRuler: string;
24
- activeMatchBackground?: string;
25
- activeMatchBorder?: string;
26
- activeMatchColorOverviewRuler: string;
27
- }
28
-
29
15
  export interface ISearchPosition {
30
16
  startCol: number;
31
17
  startRow: number;
@@ -68,11 +54,32 @@ interface IMultiHighlight extends IDisposable {
68
54
  match: ISearchResult;
69
55
  }
70
56
 
71
- const NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?';
72
- const LINES_CACHE_TIME_TO_LIVE = 15 * 1000; // 15 secs
73
- const DEFAULT_HIGHLIGHT_LIMIT = 1000;
57
+ /**
58
+ * Configuration constants for the search addon functionality.
59
+ */
60
+ const enum Constants {
61
+ /**
62
+ * Characters that are considered non-word characters for search boundary detection. These
63
+ * characters are used to determine word boundaries when performing whole-word searches. Includes
64
+ * common punctuation, symbols, and whitespace characters.
65
+ */
66
+ NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?',
67
+
68
+ /**
69
+ * Time-to-live for cached search results in milliseconds. After this duration, cached search
70
+ * results will be invalidated to ensure they remain consistent with terminal content changes.
71
+ */
72
+ LINES_CACHE_TIME_TO_LIVE = 15000,
73
+
74
+ /**
75
+ * Default maximum number of search results to highlight simultaneously. This limit prevents
76
+ * performance degradation when searching for very common terms that would result in excessive
77
+ * highlighting decorations.
78
+ */
79
+ DEFAULT_HIGHLIGHT_LIMIT = 1000
80
+ }
74
81
 
75
- export class SearchAddon extends Disposable implements ITerminalAddon , ISearchApi {
82
+ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchApi {
76
83
  private _terminal: Terminal | undefined;
77
84
  private _cachedSearchTerm: string | undefined;
78
85
  private _highlightedLines: Set<number> = new Set();
@@ -97,7 +104,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
97
104
  constructor(options?: Partial<ISearchAddonOptions>) {
98
105
  super();
99
106
 
100
- this._highlightLimit = options?.highlightLimit ?? DEFAULT_HIGHLIGHT_LIMIT;
107
+ this._highlightLimit = options?.highlightLimit ?? Constants.DEFAULT_HIGHLIGHT_LIMIT;
101
108
  }
102
109
 
103
110
  public activate(terminal: Terminal): void {
@@ -115,7 +122,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
115
122
  this._highlightTimeout = setTimeout(() => {
116
123
  const term = this._cachedSearchTerm;
117
124
  this._cachedSearchTerm = undefined;
118
- this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true, noScroll: true });
125
+ this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true }, { noScroll: true });
119
126
  }, 200);
120
127
  }
121
128
  }
@@ -142,7 +149,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
142
149
  * @param searchOptions Search options.
143
150
  * @returns Whether a result was found.
144
151
  */
145
- public findNext(term: string, searchOptions?: ISearchOptions): boolean {
152
+ public findNext(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean {
146
153
  if (!this._terminal) {
147
154
  throw new Error('Cannot use addon until it has been loaded');
148
155
  }
@@ -154,7 +161,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
154
161
  }
155
162
  }
156
163
 
157
- const found = this._findNextAndSelect(term, searchOptions);
164
+ const found = this._findNextAndSelect(term, searchOptions, internalSearchOptions);
158
165
  this._fireResults(searchOptions);
159
166
  this._cachedSearchTerm = term;
160
167
 
@@ -242,7 +249,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
242
249
  return result;
243
250
  }
244
251
 
245
- private _findNextAndSelect(term: string, searchOptions?: ISearchOptions): boolean {
252
+ private _findNextAndSelect(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean {
246
253
  if (!this._terminal || !term || term.length === 0) {
247
254
  this._terminal?.clearSelection();
248
255
  this.clearDecorations();
@@ -307,7 +314,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
307
314
  }
308
315
 
309
316
  // Set selection and scroll if a result was found
310
- return this._selectResult(result, searchOptions?.decorations, searchOptions?.noScroll);
317
+ return this._selectResult(result, searchOptions?.decorations, internalSearchOptions?.noScroll);
311
318
  }
312
319
  /**
313
320
  * Find the previous instance of the term, then scroll to and select it. If it
@@ -316,7 +323,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
316
323
  * @param searchOptions Search options.
317
324
  * @returns Whether a result was found.
318
325
  */
319
- public findPrevious(term: string, searchOptions?: ISearchOptions): boolean {
326
+ public findPrevious(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean {
320
327
  if (!this._terminal) {
321
328
  throw new Error('Cannot use addon until it has been loaded');
322
329
  }
@@ -328,7 +335,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
328
335
  }
329
336
  }
330
337
 
331
- const found = this._findPreviousAndSelect(term, searchOptions);
338
+ const found = this._findPreviousAndSelect(term, searchOptions, internalSearchOptions);
332
339
  this._fireResults(searchOptions);
333
340
  this._cachedSearchTerm = term;
334
341
 
@@ -368,7 +375,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
368
375
  }
369
376
  }
370
377
 
371
- private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions): boolean {
378
+ private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean {
372
379
  if (!this._terminal) {
373
380
  throw new Error('Cannot use addon until it has been loaded');
374
381
  }
@@ -433,7 +440,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
433
440
  }
434
441
 
435
442
  // Set selection and scroll if a result was found
436
- return this._selectResult(result, searchOptions?.decorations, searchOptions?.noScroll);
443
+ return this._selectResult(result, searchOptions?.decorations, internalSearchOptions?.noScroll);
437
444
  }
438
445
 
439
446
  /**
@@ -451,7 +458,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
451
458
  }
452
459
 
453
460
  window.clearTimeout(this._linesCacheTimeoutId);
454
- this._linesCacheTimeoutId = window.setTimeout(() => this._destroyLinesCache(), LINES_CACHE_TIME_TO_LIVE);
461
+ this._linesCacheTimeoutId = window.setTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE);
455
462
  }
456
463
 
457
464
  private _destroyLinesCache(): void {
@@ -471,8 +478,8 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
471
478
  * @param term the substring that starts at searchIndex
472
479
  */
473
480
  private _isWholeWord(searchIndex: number, line: string, term: string): boolean {
474
- return ((searchIndex === 0) || (NON_WORD_CHARACTERS.includes(line[searchIndex - 1]))) &&
475
- (((searchIndex + term.length) === line.length) || (NON_WORD_CHARACTERS.includes(line[searchIndex + term.length])));
481
+ return ((searchIndex === 0) || (Constants.NON_WORD_CHARACTERS.includes(line[searchIndex - 1]))) &&
482
+ (((searchIndex + term.length) === line.length) || (Constants.NON_WORD_CHARACTERS.includes(line[searchIndex + term.length])));
476
483
  }
477
484
 
478
485
  /**