diff --git a/addons/addon-search/src/SearchAddon.ts b/addons/addon-search/src/SearchAddon.ts index 84ec40f7..93d57bce 100644 --- a/addons/addon-search/src/SearchAddon.ts +++ b/addons/addon-search/src/SearchAddon.ts @@ -7,6 +7,7 @@ import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/ import type { SearchAddon as ISearchApi, ISearchOptions, ISearchDecorationOptions } from '@xterm/addon-search'; import { Emitter, Event } from 'vs/base/common/event'; import { Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle'; +import { disposableTimeout } from 'vs/base/common/async'; import { SearchLineCache } from './SearchLineCache'; interface IInternalSearchOptions { @@ -34,8 +35,6 @@ export interface ISearchResult { size: number; } - - interface IHighlight extends IDisposable { decoration: IDecoration; match: ISearchResult; @@ -57,8 +56,6 @@ const enum Constants { */ NON_WORD_CHARACTERS = ' ~!@#$%^&*()+`-=[]{}|\\;:"\',./<>?', - - /** * Default maximum number of search results to highlight simultaneously. This limit prevents * performance degradation when searching for very common terms that would result in excessive @@ -73,10 +70,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp private _highlightedLines: Set = new Set(); private _highlightDecorations: IHighlight[] = []; private _searchResultsWithHighlight: ISearchResult[] = []; - private _selectedDecoration: MutableDisposable = this._register(new MutableDisposable()); + private _selectedDecoration = this._register(new MutableDisposable()); private _highlightLimit: number; private _lastSearchOptions: ISearchOptions | undefined; - private _highlightTimeout: number | undefined; + private _highlightTimeout = this._register(new MutableDisposable()); private _lineCache = this._register(new MutableDisposable()); private readonly _onDidChangeResults = this._register(new Emitter()); @@ -97,11 +94,9 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp } private _updateMatches(): void { - if (this._highlightTimeout) { - window.clearTimeout(this._highlightTimeout); - } + this._highlightTimeout.clear(); if (this._cachedSearchTerm && this._lastSearchOptions?.decorations) { - this._highlightTimeout = setTimeout(() => { + this._highlightTimeout.value = disposableTimeout(() => { const term = this._cachedSearchTerm; this._cachedSearchTerm = undefined; this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true }, { noScroll: true }); diff --git a/addons/addon-search/src/SearchLineCache.ts b/addons/addon-search/src/SearchLineCache.ts index f4752c55..94d9fb72 100644 --- a/addons/addon-search/src/SearchLineCache.ts +++ b/addons/addon-search/src/SearchLineCache.ts @@ -5,6 +5,7 @@ import type { Terminal } from '@xterm/xterm'; import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle'; +import { disposableTimeout } from 'vs/base/common/async'; export type LineCacheEntry = [ /** @@ -35,7 +36,7 @@ export class SearchLineCache extends Disposable { * _linesCache is also invalidated when the terminal cursor moves. */ private _linesCache: LineCacheEntry[] | undefined; - private _linesCacheTimeoutId = 0; + private _linesCacheTimeout = this._register(new MutableDisposable()); private _linesCacheDisposables = this._register(new MutableDisposable()); constructor(private _terminal: Terminal) { @@ -56,17 +57,13 @@ export class SearchLineCache extends Disposable { ); } - window.clearTimeout(this._linesCacheTimeoutId); - this._linesCacheTimeoutId = window.setTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE); + this._linesCacheTimeout.value = disposableTimeout(() => this._destroyLinesCache(), Constants.LINES_CACHE_TIME_TO_LIVE); } private _destroyLinesCache(): void { this._linesCache = undefined; this._linesCacheDisposables.clear(); - if (this._linesCacheTimeoutId) { - window.clearTimeout(this._linesCacheTimeoutId); - this._linesCacheTimeoutId = 0; - } + this._linesCacheTimeout.clear(); } public getLineFromCache(row: number): LineCacheEntry | undefined {