From 239f669041395f5ef80cffd48a94debbd171ba10 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Thu, 21 Apr 2022 16:04:08 -0700 Subject: [PATCH] add max find result count for which to show decorations (#3745) --- addons/xterm-addon-search/src/SearchAddon.ts | 26 ++++++++++--------- .../typings/xterm-addon-search.d.ts | 2 ++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 536e4873..c1de5653 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -122,15 +122,7 @@ export class SearchAddon implements ITerminalAddon { if (searchOptions?.decorations) { this._highlightAllMatches(term, searchOptions); } - const next = this._findNextAndSelect(term, searchOptions); - if (searchOptions?.decorations) { - if (next && this._resultIndex !== undefined && this._searchResults?.size) { - this._onDidChangeResults.fire({ resultIndex: this._resultIndex, resultCount: this._searchResults.size }); - } else { - this._onDidChangeResults.fire(undefined); - } - } - return next; + return this._fireResults(this._findNextAndSelect(term, searchOptions), searchOptions); } private _highlightAllMatches(term: string, searchOptions: ISearchOptions): void { @@ -157,6 +149,11 @@ export class SearchAddon implements ITerminalAddon { result.col + result.term.length >= this._terminal.cols ? 0 : result.col + 1, searchOptions ); + if (this._searchResults.size > 2000) { + this.clearDecorations(); + this._resultIndex = -1; + return; + } } this._searchResults.forEach(result => { const resultDecoration = this._createResultDecoration(result, searchOptions.decorations!); @@ -300,15 +297,20 @@ export class SearchAddon implements ITerminalAddon { if (searchOptions?.decorations) { this._highlightAllMatches(term, searchOptions); } - const previous = this._findPreviousAndSelect(term, searchOptions); + return this._fireResults(this._findPreviousAndSelect(term, searchOptions), searchOptions); + } + + private _fireResults(found: boolean, searchOptions?: ISearchOptions): boolean { if (searchOptions?.decorations) { - if (previous && this._resultIndex !== undefined && this._searchResults?.size) { + if (found && this._resultIndex !== undefined && this._searchResults?.size) { this._onDidChangeResults.fire({ resultIndex: this._resultIndex, resultCount: this._searchResults.size }); + } else if (this._resultIndex === -1) { + this._onDidChangeResults.fire({ resultIndex: -1, resultCount: -1 }); } else { this._onDidChangeResults.fire(undefined); } } - return previous; + return found; } private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions): boolean { diff --git a/addons/xterm-addon-search/typings/xterm-addon-search.d.ts b/addons/xterm-addon-search/typings/xterm-addon-search.d.ts index 1cb9740e..5dafb449 100644 --- a/addons/xterm-addon-search/typings/xterm-addon-search.d.ts +++ b/addons/xterm-addon-search/typings/xterm-addon-search.d.ts @@ -115,6 +115,8 @@ declare module 'xterm-addon-search' { * When decorations are enabled, fires when * the search results or the selected result changes, * returning undefined if there are no matches. + * -1 is returned for resultCount/resultIndex when the threshold of 2k results + * is exceeded and decorations are disposed of. */ readonly onDidChangeResults: IEvent<{ resultIndex: number, resultCount: number } | undefined>; }