From 5d73637a00163f682c1056ec110f03deb6b4bf67 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Fri, 25 Sep 2020 19:38:37 -0400 Subject: [PATCH] saves SCM widget input on window reload (#107261) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * saving SCM widget input * Use a better key Co-authored-by: João Moreno Co-authored-by: João Moreno --- src/vs/workbench/api/browser/mainThreadSCM.ts | 4 +++ .../contrib/scm/browser/scmViewPane.ts | 4 +-- .../contrib/scm/common/scmService.ts | 36 ++++++++++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadSCM.ts b/src/vs/workbench/api/browser/mainThreadSCM.ts index 1b2718a458f..2f0b06a143d 100644 --- a/src/vs/workbench/api/browser/mainThreadSCM.ts +++ b/src/vs/workbench/api/browser/mainThreadSCM.ts @@ -303,6 +303,10 @@ export class MainThreadSCM implements MainThreadSCMShape { setTimeout(() => this._proxy.$setSelectedSourceControl(handle), 0); } + if (repository.input.value) { + setTimeout(() => this._proxy.$onInputBoxValueChange(handle, repository.input.value), 0); + } + this._repositoryDisposables.set(handle, disposable); } diff --git a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts index 1aa91aacd11..0220cf2a22e 100644 --- a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts +++ b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts @@ -1311,7 +1311,7 @@ class SCMInputWidget extends Disposable { if (value === textModel.getValue()) { // circuit breaker return; } - textModel.setValue(value); + textModel.setValue(input.value); this.inputEditor.setPosition(textModel.getFullModelRange().getEndPosition()); })); @@ -1381,7 +1381,7 @@ class SCMInputWidget extends Disposable { @IKeybindingService private keybindingService: IKeybindingService, @IConfigurationService private configurationService: IConfigurationService, @IInstantiationService instantiationService: IInstantiationService, - @IContextViewService private readonly contextViewService: IContextViewService, + @IContextViewService private readonly contextViewService: IContextViewService ) { super(); diff --git a/src/vs/workbench/contrib/scm/common/scmService.ts b/src/vs/workbench/contrib/scm/common/scmService.ts index 6319bf1d441..1cb479864bd 100644 --- a/src/vs/workbench/contrib/scm/common/scmService.ts +++ b/src/vs/workbench/contrib/scm/common/scmService.ts @@ -8,12 +8,20 @@ import { Event, Emitter } from 'vs/base/common/event'; import { ISCMService, ISCMProvider, ISCMInput, ISCMRepository, IInputValidator } from './scm'; import { ILogService } from 'vs/platform/log/common/log'; import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; class SCMInput implements ISCMInput { private _value = ''; get value(): string { + if (this.root) { + const key = `scm/input:${this.repository.provider.label}:${this.root.path}`; + let storedValue = this.storageService.get(key, StorageScope.WORKSPACE); + if (storedValue) { + return storedValue; + } + } return this._value; } @@ -21,11 +29,14 @@ class SCMInput implements ISCMInput { if (value === this._value) { return; } - this._value = value; + if (this.root) { + const key = `scm/input:${this.repository.provider.label}:${this.root.path}`; + this.storageService.store(key, value, StorageScope.WORKSPACE); + } this._onDidChange.fire(value); } - + private root; private readonly _onDidChange = new Emitter(); readonly onDidChange: Event = this._onDidChange.event; @@ -55,7 +66,8 @@ class SCMInput implements ISCMInput { } private readonly _onDidChangeVisibility = new Emitter(); - readonly onDidChangeVisibility: Event = this._onDidChangeVisibility.event; + readonly onDidChangeVisibility: Event = this._onDidChangeVisibility + .event; private _validateInput: IInputValidator = () => Promise.resolve(undefined); @@ -71,7 +83,13 @@ class SCMInput implements ISCMInput { private readonly _onDidChangeValidateInput = new Emitter(); readonly onDidChangeValidateInput: Event = this._onDidChangeValidateInput.event; - constructor(readonly repository: ISCMRepository) { } + constructor( + readonly repository: ISCMRepository, + @IStorageService private storageService: IStorageService + ) { + this.root = this.repository.provider.rootUri; + this._value = this.value; + } } class SCMRepository implements ISCMRepository { @@ -84,11 +102,12 @@ class SCMRepository implements ISCMRepository { private readonly _onDidChangeSelection = new Emitter(); readonly onDidChangeSelection: Event = this._onDidChangeSelection.event; - readonly input: ISCMInput = new SCMInput(this); + readonly input: ISCMInput = new SCMInput(this, this.storageService); constructor( public readonly provider: ISCMProvider, - private disposable: IDisposable + private disposable: IDisposable, + @IStorageService private storageService: IStorageService ) { } setSelected(selected: boolean): void { @@ -128,7 +147,8 @@ export class SCMService implements ISCMService { constructor( @ILogService private readonly logService: ILogService, - @IContextKeyService contextKeyService: IContextKeyService + @IContextKeyService contextKeyService: IContextKeyService, + @IStorageService private storageService: IStorageService ) { this.providerCount = contextKeyService.createKey('scm.providerCount', 0); } @@ -161,7 +181,7 @@ export class SCMService implements ISCMService { this.providerCount.set(this._repositories.length); }); - const repository = new SCMRepository(provider, disposable); + const repository = new SCMRepository(provider, disposable, this.storageService); const selectedDisposable = Event.map(Event.filter(repository.onDidChangeSelection, selected => selected), _ => repository)(this.select, this); this._repositories.push(repository); -- GitLab