@xterm/addon-search 0.16.0-beta.9 → 0.16.0-beta.90

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.
@@ -5,8 +5,8 @@
5
5
 
6
6
  import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
7
7
  import type { SearchAddon as ISearchApi } from '@xterm/addon-search';
8
- import { EventEmitter } from 'common/EventEmitter';
9
- import { Disposable, toDisposable, disposeArray, MutableDisposable, getDisposeArrayDisposable } from 'common/Lifecycle';
8
+ import { Emitter } from 'vs/base/common/event';
9
+ import { combinedDisposable, Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
10
10
 
11
11
  export interface ISearchOptions {
12
12
  regex?: boolean;
@@ -67,7 +67,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
67
67
  private _cachedSearchTerm: string | undefined;
68
68
  private _highlightedLines: Set<number> = new Set();
69
69
  private _highlightDecorations: IHighlight[] = [];
70
- private _selectedDecoration: MutableDisposable<IHighlight> = this.register(new MutableDisposable());
70
+ private _selectedDecoration: MutableDisposable<IHighlight> = this._register(new MutableDisposable());
71
71
  private _highlightLimit: number;
72
72
  private _lastSearchOptions: ISearchOptions | undefined;
73
73
  private _highlightTimeout: number | undefined;
@@ -80,7 +80,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
80
80
  private _linesCacheTimeoutId = 0;
81
81
  private _linesCacheDisposables = new MutableDisposable();
82
82
 
83
- private readonly _onDidChangeResults = this.register(new EventEmitter<{ resultIndex: number, resultCount: number }>());
83
+ private readonly _onDidChangeResults = this._register(new Emitter<{ resultIndex: number, resultCount: number }>());
84
84
  public readonly onDidChangeResults = this._onDidChangeResults.event;
85
85
 
86
86
  constructor(options?: Partial<ISearchAddonOptions>) {
@@ -91,9 +91,9 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
91
91
 
92
92
  public activate(terminal: Terminal): void {
93
93
  this._terminal = terminal;
94
- this.register(this._terminal.onWriteParsed(() => this._updateMatches()));
95
- this.register(this._terminal.onResize(() => this._updateMatches()));
96
- this.register(toDisposable(() => this.clearDecorations()));
94
+ this._register(this._terminal.onWriteParsed(() => this._updateMatches()));
95
+ this._register(this._terminal.onResize(() => this._updateMatches()));
96
+ this._register(toDisposable(() => this.clearDecorations()));
97
97
  }
98
98
 
99
99
  private _updateMatches(): void {
@@ -111,7 +111,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
111
111
 
112
112
  public clearDecorations(retainCachedSearchTerm?: boolean): void {
113
113
  this._selectedDecoration.clear();
114
- disposeArray(this._highlightDecorations);
114
+ dispose(this._highlightDecorations);
115
115
  this._highlightDecorations = [];
116
116
  this._highlightedLines.clear();
117
117
  if (!retainCachedSearchTerm) {
@@ -426,11 +426,11 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
426
426
  const terminal = this._terminal!;
427
427
  if (!this._linesCache) {
428
428
  this._linesCache = new Array(terminal.buffer.active.length);
429
- this._linesCacheDisposables.value = getDisposeArrayDisposable([
429
+ this._linesCacheDisposables.value = combinedDisposable(
430
430
  terminal.onLineFeed(() => this._destroyLinesCache()),
431
431
  terminal.onCursorMove(() => this._destroyLinesCache()),
432
432
  terminal.onResize(() => this._destroyLinesCache())
433
- ]);
433
+ );
434
434
  }
435
435
 
436
436
  window.clearTimeout(this._linesCacheTimeoutId);
@@ -499,12 +499,16 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
499
499
  const [stringLine, offsets] = cache;
500
500
 
501
501
  const offset = this._bufferColsToStringOffset(row, col);
502
- const searchTerm = searchOptions.caseSensitive ? term : term.toLowerCase();
503
- const searchStringLine = searchOptions.caseSensitive ? stringLine : stringLine.toLowerCase();
502
+ let searchTerm = term;
503
+ let searchStringLine = stringLine;
504
+ if (!searchOptions.regex) {
505
+ searchTerm = searchOptions.caseSensitive ? term : term.toLowerCase();
506
+ searchStringLine = searchOptions.caseSensitive ? stringLine : stringLine.toLowerCase();
507
+ }
504
508
 
505
509
  let resultIndex = -1;
506
510
  if (searchOptions.regex) {
507
- const searchRegex = RegExp(searchTerm, 'g');
511
+ const searchRegex = RegExp(searchTerm, searchOptions.caseSensitive ? 'g' : 'gi');
508
512
  let foundTerm: RegExpExecArray | null;
509
513
  if (isReverseSearch) {
510
514
  // This loop will get the resultIndex of the _last_ regex match in the range 0..offset
@@ -678,7 +682,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
678
682
  const disposables: IDisposable[] = [];
679
683
  disposables.push(marker);
680
684
  disposables.push(decoration.onRender((e) => this._applyStyles(e, options.activeMatchBorder, true)));
681
- disposables.push(decoration.onDispose(() => disposeArray(disposables)));
685
+ disposables.push(decoration.onDispose(() => dispose(disposables)));
682
686
  this._selectedDecoration.value = { decoration, match: result, dispose() { decoration.dispose(); } };
683
687
  }
684
688
  }
@@ -740,7 +744,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
740
744
  const disposables: IDisposable[] = [];
741
745
  disposables.push(marker);
742
746
  disposables.push(findResultDecoration.onRender((e) => this._applyStyles(e, options.matchBorder, false)));
743
- disposables.push(findResultDecoration.onDispose(() => disposeArray(disposables)));
747
+ disposables.push(findResultDecoration.onDispose(() => dispose(disposables)));
744
748
  }
745
749
  return findResultDecoration;
746
750
  }