Skip to content

Commit

Permalink
add debounce to search refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamah committed Oct 16, 2024
1 parent c227dc2 commit 7d871a6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export class SearchView extends ViewPane {
searchModel.replaceActive = this.viewModel.isReplaceActive();
searchModel.replaceString = this.searchWidget.getReplaceValue();
this._onSearchResultChangedDisposable?.dispose();
this._onSearchResultChangedDisposable = this._register(searchModel.onSearchResultChanged(async (event) => this.onSearchResultsChanged(event)));
this._onSearchResultChangedDisposable = this._register(this._getSearchResultChangedDisposable(searchModel));

// this call will also dispose of the old model
this.searchViewModelWorkbenchService.searchModel = searchModel;
Expand Down Expand Up @@ -526,14 +526,32 @@ export class SearchView extends ViewPane {
this.toggleQueryDetails(true, true, true);
}

this._onSearchResultChangedDisposable = this._register(this.viewModel.onSearchResultChanged(async (event) => await this.onSearchResultsChanged(event)));
this._onSearchResultChangedDisposable = this._register(this._getSearchResultChangedDisposable());

this._register(this.onDidChangeBodyVisibility(visible => this.onVisibilityChanged(visible)));

this.updateIndentStyles(this.themeService.getFileIconTheme());
this._register(this.themeService.onDidFileIconThemeChange(this.updateIndentStyles, this));
}

private _getSearchResultChangedDisposable(searchModel: ISearchModel = this.viewModel): IDisposable {
return Event.debounce(searchModel.onSearchResultChanged, (last, event) => {
const elements = event.elements.concat(...last?.elements ?? []);
const added = event.added || last?.added;
const removed = event.removed || last?.removed;
const clearingAll = event.clearingAll || last?.clearingAll;

return {
elements,
added,
removed,
clearingAll
};
}, 80, true)(event => {
this.onSearchResultsChanged(event);
});
}

private updateIndentStyles(theme: IFileIconTheme): void {
this.resultsElement.classList.toggle('hide-arrows', this.isTreeLayoutViewVisible && theme.hidesExplorerArrows);
}
Expand Down Expand Up @@ -1654,7 +1672,7 @@ export class SearchView extends ViewPane {
progressComplete();

// Do final render, then expand if just 1 file with less than 50 matches
this.onSearchResultsChanged();
await this.onSearchResultsChanged();

const collapseResults = this.searchConfig.collapseResults;
if (collapseResults !== 'alwaysCollapse' && this.viewModel.searchResult.matches().length === 1) {
Expand Down

0 comments on commit 7d871a6

Please sign in to comment.