Skip to content

Commit 5d73637

Browse files
saves SCM widget input on window reload (microsoft#107261)
* saving SCM widget input * Use a better key Co-authored-by: João Moreno <joao.moreno@microsoft.com> Co-authored-by: João Moreno <joao.moreno@microsoft.com>
1 parent f1e631a commit 5d73637

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

src/vs/workbench/api/browser/mainThreadSCM.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ export class MainThreadSCM implements MainThreadSCMShape {
303303
setTimeout(() => this._proxy.$setSelectedSourceControl(handle), 0);
304304
}
305305

306+
if (repository.input.value) {
307+
setTimeout(() => this._proxy.$onInputBoxValueChange(handle, repository.input.value), 0);
308+
}
309+
306310
this._repositoryDisposables.set(handle, disposable);
307311
}
308312

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ class SCMInputWidget extends Disposable {
13111311
if (value === textModel.getValue()) { // circuit breaker
13121312
return;
13131313
}
1314-
textModel.setValue(value);
1314+
textModel.setValue(input.value);
13151315
this.inputEditor.setPosition(textModel.getFullModelRange().getEndPosition());
13161316
}));
13171317

@@ -1381,7 +1381,7 @@ class SCMInputWidget extends Disposable {
13811381
@IKeybindingService private keybindingService: IKeybindingService,
13821382
@IConfigurationService private configurationService: IConfigurationService,
13831383
@IInstantiationService instantiationService: IInstantiationService,
1384-
@IContextViewService private readonly contextViewService: IContextViewService,
1384+
@IContextViewService private readonly contextViewService: IContextViewService
13851385
) {
13861386
super();
13871387

src/vs/workbench/contrib/scm/common/scmService.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,35 @@ import { Event, Emitter } from 'vs/base/common/event';
88
import { ISCMService, ISCMProvider, ISCMInput, ISCMRepository, IInputValidator } from './scm';
99
import { ILogService } from 'vs/platform/log/common/log';
1010
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
11+
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
1112

1213
class SCMInput implements ISCMInput {
1314

1415
private _value = '';
1516

1617
get value(): string {
18+
if (this.root) {
19+
const key = `scm/input:${this.repository.provider.label}:${this.root.path}`;
20+
let storedValue = this.storageService.get(key, StorageScope.WORKSPACE);
21+
if (storedValue) {
22+
return storedValue;
23+
}
24+
}
1725
return this._value;
1826
}
1927

2028
set value(value: string) {
2129
if (value === this._value) {
2230
return;
2331
}
24-
2532
this._value = value;
33+
if (this.root) {
34+
const key = `scm/input:${this.repository.provider.label}:${this.root.path}`;
35+
this.storageService.store(key, value, StorageScope.WORKSPACE);
36+
}
2637
this._onDidChange.fire(value);
2738
}
28-
39+
private root;
2940
private readonly _onDidChange = new Emitter<string>();
3041
readonly onDidChange: Event<string> = this._onDidChange.event;
3142

@@ -55,7 +66,8 @@ class SCMInput implements ISCMInput {
5566
}
5667

5768
private readonly _onDidChangeVisibility = new Emitter<boolean>();
58-
readonly onDidChangeVisibility: Event<boolean> = this._onDidChangeVisibility.event;
69+
readonly onDidChangeVisibility: Event<boolean> = this._onDidChangeVisibility
70+
.event;
5971

6072
private _validateInput: IInputValidator = () => Promise.resolve(undefined);
6173

@@ -71,7 +83,13 @@ class SCMInput implements ISCMInput {
7183
private readonly _onDidChangeValidateInput = new Emitter<void>();
7284
readonly onDidChangeValidateInput: Event<void> = this._onDidChangeValidateInput.event;
7385

74-
constructor(readonly repository: ISCMRepository) { }
86+
constructor(
87+
readonly repository: ISCMRepository,
88+
@IStorageService private storageService: IStorageService
89+
) {
90+
this.root = this.repository.provider.rootUri;
91+
this._value = this.value;
92+
}
7593
}
7694

7795
class SCMRepository implements ISCMRepository {
@@ -84,11 +102,12 @@ class SCMRepository implements ISCMRepository {
84102
private readonly _onDidChangeSelection = new Emitter<boolean>();
85103
readonly onDidChangeSelection: Event<boolean> = this._onDidChangeSelection.event;
86104

87-
readonly input: ISCMInput = new SCMInput(this);
105+
readonly input: ISCMInput = new SCMInput(this, this.storageService);
88106

89107
constructor(
90108
public readonly provider: ISCMProvider,
91-
private disposable: IDisposable
109+
private disposable: IDisposable,
110+
@IStorageService private storageService: IStorageService
92111
) { }
93112

94113
setSelected(selected: boolean): void {
@@ -128,7 +147,8 @@ export class SCMService implements ISCMService {
128147

129148
constructor(
130149
@ILogService private readonly logService: ILogService,
131-
@IContextKeyService contextKeyService: IContextKeyService
150+
@IContextKeyService contextKeyService: IContextKeyService,
151+
@IStorageService private storageService: IStorageService
132152
) {
133153
this.providerCount = contextKeyService.createKey('scm.providerCount', 0);
134154
}
@@ -161,7 +181,7 @@ export class SCMService implements ISCMService {
161181
this.providerCount.set(this._repositories.length);
162182
});
163183

164-
const repository = new SCMRepository(provider, disposable);
184+
const repository = new SCMRepository(provider, disposable, this.storageService);
165185
const selectedDisposable = Event.map(Event.filter(repository.onDidChangeSelection, selected => selected), _ => repository)(this.select, this);
166186

167187
this._repositories.push(repository);

0 commit comments

Comments
 (0)