From 5190e3007b00e6505282f9dbd237730d0f055e94 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Fri, 17 Aug 2018 20:11:45 -0700 Subject: [PATCH] Fix #56625 - parse setting name from JSON line And some other fixes --- .../preferences/browser/settingsEditor2.ts | 29 ++++++++++++------- .../preferences/browser/settingsTreeModels.ts | 2 +- .../parts/preferences/browser/tocTree.ts | 16 ++++++---- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/parts/preferences/browser/settingsEditor2.ts b/src/vs/workbench/parts/preferences/browser/settingsEditor2.ts index 14ef50470e2..cd7d9207aae 100644 --- a/src/vs/workbench/parts/preferences/browser/settingsEditor2.ts +++ b/src/vs/workbench/parts/preferences/browser/settingsEditor2.ts @@ -76,7 +76,7 @@ export class SettingsEditor2 extends BaseEditor { private delayedFilterLogging: Delayer; private localSearchDelayer: Delayer; private remoteSearchThrottle: ThrottledDelayer; - private searchCancelToken: CancellationTokenSource; + private searchInProgress: CancellationTokenSource; private delayRefreshOnLayout: Delayer; private lastLayedoutWidth: number; @@ -747,6 +747,11 @@ export class SettingsEditor2 extends BaseEditor { }); } + private parseSettingFromJSON(query: string): string { + const match = query.match(/"([a-zA-Z.]+)": /); + return match && match[1]; + } + private triggerSearch(query: string): TPromise { this.viewState.tagFilters = new Set(); if (query) { @@ -762,14 +767,16 @@ export class SettingsEditor2 extends BaseEditor { query = query.trim(); if (query && query !== '@') { - this.searchCancelToken = new CancellationTokenSource(); + query = this.parseSettingFromJSON(query) || query; + + this.searchInProgress = new CancellationTokenSource(); return TPromise.join([ - this.localSearchDelayer.trigger(() => this.localFilterPreferences(query, this.searchCancelToken.token)), - this.remoteSearchThrottle.trigger(() => this.remoteSearchPreferences(query, this.searchCancelToken.token), 500) + this.localSearchDelayer.trigger(() => this.searchInProgress ? this.localFilterPreferences(query, this.searchInProgress.token) : TPromise.wrap(null)), + this.remoteSearchThrottle.trigger(() => this.searchInProgress ? this.remoteSearchPreferences(query, this.searchInProgress.token) : TPromise.wrap(null), 500) ]).then(() => { - if (this.searchCancelToken) { - this.searchCancelToken.dispose(); - this.searchCancelToken = null; + if (this.searchInProgress) { + this.searchInProgress.dispose(); + this.searchInProgress = null; } }); } else { @@ -781,10 +788,10 @@ export class SettingsEditor2 extends BaseEditor { this.localSearchDelayer.cancel(); this.remoteSearchThrottle.cancel(); - if (this.searchCancelToken) { - this.searchCancelToken.cancel(); - this.searchCancelToken.dispose(); - this.searchCancelToken = null; + if (this.searchInProgress) { + this.searchInProgress.cancel(); + this.searchInProgress.dispose(); + this.searchInProgress = null; } this.viewState.filterToCategory = null; diff --git a/src/vs/workbench/parts/preferences/browser/settingsTreeModels.ts b/src/vs/workbench/parts/preferences/browser/settingsTreeModels.ts index a603d2906cc..9de906b243f 100644 --- a/src/vs/workbench/parts/preferences/browser/settingsTreeModels.ts +++ b/src/vs/workbench/parts/preferences/browser/settingsTreeModels.ts @@ -429,7 +429,7 @@ export class SearchResultModel extends SettingsTreeModel { settings: this.getFlatSettings() }); - if (this.newExtensionSearchResults) { + if (this.newExtensionSearchResults && this.newExtensionSearchResults.filterMatches.length) { const newExtElement = new SettingsTreeNewExtensionsElement(); newExtElement.parent = this._root; newExtElement.id = 'newExtensions'; diff --git a/src/vs/workbench/parts/preferences/browser/tocTree.ts b/src/vs/workbench/parts/preferences/browser/tocTree.ts index 48702ecc7b2..e15e90024d9 100644 --- a/src/vs/workbench/parts/preferences/browser/tocTree.ts +++ b/src/vs/workbench/parts/preferences/browser/tocTree.ts @@ -49,15 +49,21 @@ export class TOCTreeModel { } private updateGroupCount(group: SettingsTreeGroupElement): void { - group.count = this._currentSearchModel ? - this.getSearchResultChildrenCount(group) : - undefined; - group.children.forEach(child => { if (child instanceof SettingsTreeGroupElement) { this.updateGroupCount(child); } }); + + if (this._currentSearchModel) { + const childCount = group.children + .filter(child => child instanceof SettingsTreeGroupElement) + .reduce((acc, cur) => acc + (cur).count, 0); + + group.count = childCount + this.getSearchResultChildrenCount(group); + } else { + group.count = undefined; + } } private getSearchResultChildrenCount(group: SettingsTreeGroupElement): number { @@ -70,8 +76,6 @@ export class TOCTreeModel { return group.children.some(child => { if (child instanceof SettingsTreeSettingElement) { return child.setting.key === setting.key && child.matchesAllTags(this.viewState.tagFilters); - } else if (child instanceof SettingsTreeGroupElement) { - return this.groupContainsSetting(child, setting); } else { return false; } -- GitLab