Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search result count again #180453

Merged
merged 1 commit into from Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1555,6 +1555,8 @@ export class SettingsEditor2 extends EditorPane {

if (!this.searchResultModel) {
this.searchResultModel = this.instantiationService.createInstance(SearchResultModel, this.viewState, this.workspaceTrustManagementService.isWorkspaceTrusted());
// Must be called before this.renderTree()
// to make sure the search results count is set.
this.searchResultModel.setResult(type, result);
this.tocTreeModel.currentSearchModel = this.searchResultModel;
this.onSearchModeToggled();
Expand Down Expand Up @@ -1596,9 +1598,7 @@ export class SettingsEditor2 extends EditorPane {
this.rootElement.classList.remove('no-results');
this.splitView.el.style.visibility = 'visible';
return;
}

if (this.tocTreeModel && this.tocTreeModel.settingsTreeRoot) {
} else {
const count = this.searchResultModel.getUniqueResultsCount();
let resultString: string;
switch (count) {
Expand Down
Expand Up @@ -808,6 +808,7 @@ export class SearchResultModel extends SettingsTreeModel {
private rawSearchResults: ISearchResult[] | null = null;
private cachedUniqueSearchResults: ISearchResult[] | null = null;
private newExtensionSearchResults: ISearchResult | null = null;
private searchResultCount: number | null = null;

readonly id = 'searchResultModel';

Expand Down Expand Up @@ -853,13 +854,6 @@ export class SearchResultModel extends SettingsTreeModel {
return this.rawSearchResults || [];
}

getUniqueResultsCount(): number {
const uniqueResults = this.getUniqueResults();
const localResultsCount = uniqueResults[0]?.filterMatches.length ?? 0;
const remoteResultsCount = uniqueResults[1]?.filterMatches.length ?? 0;
return localResultsCount + remoteResultsCount;
}

setResult(order: SearchResultIdx, result: ISearchResult | null): void {
this.cachedUniqueSearchResults = null;
this.newExtensionSearchResults = null;
Expand Down Expand Up @@ -890,6 +884,7 @@ export class SearchResultModel extends SettingsTreeModel {

this.root.children = this.root.children
.filter(child => child instanceof SettingsTreeSettingElement && child.matchesAllTags(this._viewState.tagFilters) && child.matchesScope(this._viewState.settingsTarget, isRemote) && child.matchesAnyExtension(this._viewState.extensionFilters) && child.matchesAnyId(this._viewState.idFilters) && child.matchesAnyFeature(this._viewState.featureFilters) && child.matchesAllLanguages(this._viewState.languageFilter));
this.searchResultCount = this.root.children.length;

if (this.newExtensionSearchResults?.filterMatches.length) {
let resultExtensionIds = this.newExtensionSearchResults.filterMatches
Expand All @@ -906,6 +901,10 @@ export class SearchResultModel extends SettingsTreeModel {
}
}

getUniqueResultsCount(): number {
return this.searchResultCount ?? 0;
}

private getFlatSettings(): ISetting[] {
const flatSettings: ISetting[] = [];
arrays.coalesce(this.getUniqueResults())
Expand Down