From db0dd584799dcb160a1edc1d24da9f96ba86e48b Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 15 Oct 2018 18:17:40 +0200 Subject: [PATCH] storage - be more "daten-sparsam" --- .../parts/search/browser/searchView.ts | 34 +++++++++++++------ .../search/node/searchHistoryService.ts | 7 +++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/parts/search/browser/searchView.ts b/src/vs/workbench/parts/search/browser/searchView.ts index e75063cbf46..a00c799ff6b 100644 --- a/src/vs/workbench/parts/search/browser/searchView.ts +++ b/src/vs/workbench/parts/search/browser/searchView.ts @@ -33,7 +33,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { TreeResourceNavigator, WorkbenchTree } from 'vs/platform/list/browser/listService'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { IProgressService } from 'vs/platform/progress/common/progress'; -import { IPatternInfo, IQueryOptions, ISearchComplete, ISearchConfiguration, ISearchHistoryService, ISearchProgressItem, ISearchQuery, VIEW_ID } from 'vs/platform/search/common/search'; +import { IPatternInfo, IQueryOptions, ISearchComplete, ISearchConfiguration, ISearchHistoryService, ISearchProgressItem, ISearchQuery, VIEW_ID, ISearchHistoryValues } from 'vs/platform/search/common/search'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { diffInserted, diffInsertedOutline, diffRemoved, diffRemovedOutline, editorFindMatchHighlight, editorFindMatchHighlightBorder, listActiveSelectionForeground } from 'vs/platform/theme/common/colorRegistry'; @@ -1518,17 +1518,29 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { const isReplaceShown = this.searchAndReplaceWidget.isReplaceShown(); this.viewletState['view.showReplace'] = isReplaceShown; - const searchHistory = this.searchWidget.getSearchHistory(); - const replaceHistory = this.searchWidget.getReplaceHistory(); - const patternExcludesHistory = this.inputPatternExcludes.getHistory(); - const patternIncludesHistory = this.inputPatternIncludes.getHistory(); + const history: ISearchHistoryValues = Object.create(null); - this.searchHistoryService.save({ - search: searchHistory, - replace: replaceHistory, - exclude: patternExcludesHistory, - include: patternIncludesHistory - }); + const searchHistory = this.searchWidget.getSearchHistory(); + if (searchHistory && searchHistory.length) { + history.search = searchHistory; + } + + const replaceHistory = this.searchWidget.getReplaceHistory(); + if (replaceHistory && replaceHistory.length) { + history.replace = replaceHistory; + } + + const patternExcludesHistory = this.inputPatternExcludes.getHistory(); + if (patternExcludesHistory && patternExcludesHistory.length) { + history.exclude = patternExcludesHistory; + } + + const patternIncludesHistory = this.inputPatternIncludes.getHistory(); + if (patternIncludesHistory && patternIncludesHistory.length) { + history.include = patternIncludesHistory; + } + + this.searchHistoryService.save(history); super.saveState(); } diff --git a/src/vs/workbench/services/search/node/searchHistoryService.ts b/src/vs/workbench/services/search/node/searchHistoryService.ts index c2e01ad1de9..3b925ffd48b 100644 --- a/src/vs/workbench/services/search/node/searchHistoryService.ts +++ b/src/vs/workbench/services/search/node/searchHistoryService.ts @@ -6,6 +6,7 @@ import { Emitter, Event } from 'vs/base/common/event'; import { ISearchHistoryValues, ISearchHistoryService } from 'vs/platform/search/common/search'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; +import { isEmptyObject } from 'vs/base/common/types'; export class SearchHistoryService implements ISearchHistoryService { public _serviceBrand: any; @@ -40,6 +41,10 @@ export class SearchHistoryService implements ISearchHistoryService { } public save(history: ISearchHistoryValues): void { - this.storageService.store(SearchHistoryService.SEARCH_HISTORY_KEY, JSON.stringify(history), StorageScope.WORKSPACE); + if (isEmptyObject(history)) { + this.storageService.remove(SearchHistoryService.SEARCH_HISTORY_KEY, StorageScope.WORKSPACE); + } else { + this.storageService.store(SearchHistoryService.SEARCH_HISTORY_KEY, JSON.stringify(history), StorageScope.WORKSPACE); + } } } \ No newline at end of file