add max find result count for which to show decorations (#3745)
This commit is contained in:
@@ -122,15 +122,7 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
if (searchOptions?.decorations) {
|
if (searchOptions?.decorations) {
|
||||||
this._highlightAllMatches(term, searchOptions);
|
this._highlightAllMatches(term, searchOptions);
|
||||||
}
|
}
|
||||||
const next = this._findNextAndSelect(term, searchOptions);
|
return this._fireResults(this._findNextAndSelect(term, searchOptions), 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _highlightAllMatches(term: string, searchOptions: ISearchOptions): void {
|
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,
|
result.col + result.term.length >= this._terminal.cols ? 0 : result.col + 1,
|
||||||
searchOptions
|
searchOptions
|
||||||
);
|
);
|
||||||
|
if (this._searchResults.size > 2000) {
|
||||||
|
this.clearDecorations();
|
||||||
|
this._resultIndex = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this._searchResults.forEach(result => {
|
this._searchResults.forEach(result => {
|
||||||
const resultDecoration = this._createResultDecoration(result, searchOptions.decorations!);
|
const resultDecoration = this._createResultDecoration(result, searchOptions.decorations!);
|
||||||
@@ -300,15 +297,20 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
if (searchOptions?.decorations) {
|
if (searchOptions?.decorations) {
|
||||||
this._highlightAllMatches(term, searchOptions);
|
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 (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 });
|
this._onDidChangeResults.fire({ resultIndex: this._resultIndex, resultCount: this._searchResults.size });
|
||||||
|
} else if (this._resultIndex === -1) {
|
||||||
|
this._onDidChangeResults.fire({ resultIndex: -1, resultCount: -1 });
|
||||||
} else {
|
} else {
|
||||||
this._onDidChangeResults.fire(undefined);
|
this._onDidChangeResults.fire(undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return previous;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions): boolean {
|
private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions): boolean {
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ declare module 'xterm-addon-search' {
|
|||||||
* When decorations are enabled, fires when
|
* When decorations are enabled, fires when
|
||||||
* the search results or the selected result changes,
|
* the search results or the selected result changes,
|
||||||
* returning undefined if there are no matches.
|
* 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>;
|
readonly onDidChangeResults: IEvent<{ resultIndex: number, resultCount: number } | undefined>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user