From 6ef1bdd7ce04d733100e57eca0d989447bdad1d9 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 21 Mar 2022 16:37:46 -0700 Subject: [PATCH] Debounce onData listener --- addons/xterm-addon-search/src/SearchAddon.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 12e82103..3dd2992d 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -53,6 +53,7 @@ export class SearchAddon implements ITerminalAddon { private _searchResults: Map = new Map(); private _onDataDisposable: IDisposable | undefined; private _lastSearchOptions: ISearchOptions | undefined; + private _highlightTimeout: number | undefined; /** * translateBufferLineToStringWithWrap is a fairly expensive call. * We memoize the calls into an array that has a time based ttl. @@ -67,7 +68,10 @@ export class SearchAddon implements ITerminalAddon { this._terminal = terminal; this._onDataDisposable = this._terminal.onData(() => { this._dataChanged = true; - setTimeout(() => { + if (this._highlightTimeout) { + window.clearTimeout(this._highlightTimeout); + } + this._highlightTimeout = setTimeout(() => { if (this._lastSearchOptions?.decorations && this._cachedSearchTerm && this._resultDecorations.size > 0 && this._lastSearchOptions) { this._highlightAllMatches(this._cachedSearchTerm, this._lastSearchOptions); }