diff --git a/src/vs/editor/contrib/suggest/suggestMemory.ts b/src/vs/editor/contrib/suggest/suggestMemory.ts index c99f226fa631a39793cca28bacb231c8e45a50aa..de61296507badd950ec350f344a3c2ed739b7966 100644 --- a/src/vs/editor/contrib/suggest/suggestMemory.ts +++ b/src/vs/editor/contrib/suggest/suggestMemory.ts @@ -11,7 +11,7 @@ import { IPosition } from 'vs/editor/common/core/position'; import { RunOnceScheduler } from 'vs/base/common/async'; import { CompletionItemKind, completionKindFromLegacyString } from 'vs/editor/common/modes'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { IDisposable } from 'vs/base/common/lifecycle'; +import { Disposable } from 'vs/base/common/lifecycle'; export abstract class Memory { @@ -194,26 +194,24 @@ export class PrefixMemory extends Memory { export type MemMode = 'first' | 'recentlyUsed' | 'recentlyUsedByPrefix'; -export class SuggestMemories { +export class SuggestMemories extends Disposable { private readonly _storagePrefix = 'suggest/memories'; private _mode: MemMode; private _strategy: Memory; private readonly _persistSoon: RunOnceScheduler; - private readonly _listener: IDisposable; constructor( editor: ICodeEditor, @IStorageService private readonly _storageService: IStorageService, ) { - this._persistSoon = new RunOnceScheduler(() => this._flush(), 3000); - this._setMode(editor.getConfiguration().contribInfo.suggestSelection); - this._listener = editor.onDidChangeConfiguration(e => e.contribInfo && this._setMode(editor.getConfiguration().contribInfo.suggestSelection)); - } + super(); - dispose(): void { - this._listener.dispose(); + this._persistSoon = this._register(new RunOnceScheduler(() => this._flush(), 3000)); + this._setMode(editor.getConfiguration().contribInfo.suggestSelection); + this._register(editor.onDidChangeConfiguration(e => e.contribInfo && this._setMode(editor.getConfiguration().contribInfo.suggestSelection))); + this._register(_storageService.onWillClose(() => this._flush())); } private _setMode(mode: MemMode): void { diff --git a/src/vs/platform/storage/electron-browser/storageService.ts b/src/vs/platform/storage/electron-browser/storageService.ts index cda86b126783264ed5a83c4af970a24c52f24669..a03f7df34a9828f048927bb89f48df12e97354ad 100644 --- a/src/vs/platform/storage/electron-browser/storageService.ts +++ b/src/vs/platform/storage/electron-browser/storageService.ts @@ -189,9 +189,11 @@ export class DelegatingStorageService extends Disposable implements IStorageServ } close(reason: ShutdownReason): Promise { + const promise = this.storageService.close(reason); + this.closed = true; - return this.storageService.close(reason); + return promise; } private convertScope(scope: StorageScope): StorageLegacyScope { diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index f06243bf399c4269c2635dce3d3688d34ceb5902..cc6b1a664b5e9b04c6b1c8083504485d0a61a9d5 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -1132,7 +1132,7 @@ export class Workbench extends Disposable implements IPartService { // Restore sidebar if we are being shutdown as a matter of a reload if (reason === ShutdownReason.RELOAD) { - this.storageService.store(Workbench.sidebarRestoreStorageKey, 'true', StorageScope.WORKSPACE); + this.storageService.store(Workbench.sidebarRestoreStorageKey, true, StorageScope.WORKSPACE); } // Preserve zen mode only on reload. Real quit gets out of zen mode so novice users do not get stuck in zen mode. @@ -1335,8 +1335,7 @@ export class Workbench extends Disposable implements IPartService { this.shouldCenterLayout = active; let smartActive = active; if (this.editorPart.groups.length > 1 && this.configurationService.getValue('workbench.editor.centeredLayoutAutoResize')) { - // Respect the auto resize setting - do not go into centered layout if there is more than 1 group. - smartActive = false; + smartActive = false; // Respect the auto resize setting - do not go into centered layout if there is more than 1 group. } // Enter Centered Editor Layout diff --git a/src/vs/workbench/parts/search/browser/searchView.ts b/src/vs/workbench/parts/search/browser/searchView.ts index 30dcd435a9d8c7029e7bc0aadf8138aef4719b74..e75063cbf46301c582a19edce57082e0133470ed 100644 --- a/src/vs/workbench/parts/search/browser/searchView.ts +++ b/src/vs/workbench/parts/search/browser/searchView.ts @@ -64,7 +64,6 @@ const $ = dom.$; export class SearchView extends Viewlet implements IViewlet, IPanel { private static readonly MAX_TEXT_RESULTS = 10000; - private static readonly SHOW_REPLACE_STORAGE_KEY = 'vs.search.show.replace'; private static readonly WIDE_CLASS_NAME = 'wide'; private static readonly WIDE_VIEW_SIZE = 600; @@ -120,7 +119,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { @IProgressService private progressService: IProgressService, @INotificationService private notificationService: INotificationService, @IDialogService private dialogService: IDialogService, - @IStorageService private storageService: IStorageService, + @IStorageService storageService: IStorageService, @IContextViewService private contextViewService: IContextViewService, @IInstantiationService private instantiationService: IInstantiationService, @IConfigurationService configurationService: IConfigurationService, @@ -310,6 +309,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { const history = this.searchHistoryService.load(); let searchHistory = history.search || this.viewletState['query.searchHistory'] || []; let replaceHistory = history.replace || this.viewletState['query.replaceHistory'] || []; + let showReplace = typeof this.viewletState['view.showReplace'] === 'boolean' ? this.viewletState['view.showReplace'] : true; this.searchWidget = this._register(this.instantiationService.createInstance(SearchWidget, container, { value: contentPattern, @@ -320,7 +320,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { replaceHistory: replaceHistory })); - if (this.storageService.getBoolean(SearchView.SHOW_REPLACE_STORAGE_KEY, StorageScope.WORKSPACE, true)) { + if (showReplace) { this.searchWidget.toggleReplace(true); } @@ -367,13 +367,6 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { private onReplaceToggled(): void { this.layout(this.size); - - const isReplaceShown = this.searchAndReplaceWidget.isReplaceShown(); - if (!isReplaceShown) { - this.storageService.store(SearchView.SHOW_REPLACE_STORAGE_KEY, false, StorageScope.WORKSPACE); - } else { - this.storageService.remove(SearchView.SHOW_REPLACE_STORAGE_KEY, StorageScope.WORKSPACE); - } } private onSearchResultsChanged(event?: IChangeEvent): TPromise { @@ -1522,6 +1515,9 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { this.viewletState['query.folderIncludes'] = patternIncludes; this.viewletState['query.useExcludesAndIgnoreFiles'] = useExcludesAndIgnoreFiles; + 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();