Skip to content

Commit b417b76

Browse files
committed
1 parent 3f43f45 commit b417b76

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class InputRenderer implements ICompressibleTreeRenderer<ISCMInput, FuzzyScore,
259259
static readonly TEMPLATE_ID = 'input';
260260
get templateId(): string { return InputRenderer.TEMPLATE_ID; }
261261

262+
private inputWidgets = new Map<ISCMInput, SCMInputWidget>();
262263
private contentHeights = new WeakMap<ISCMInput, number>();
263264

264265
constructor(
@@ -285,6 +286,10 @@ class InputRenderer implements ICompressibleTreeRenderer<ISCMInput, FuzzyScore,
285286
templateData.inputWidget.input = input;
286287
disposables.add({ dispose: () => templateData.inputWidget.input = undefined });
287288

289+
// Remember widget
290+
this.inputWidgets.set(input, templateData.inputWidget);
291+
disposables.add({ dispose: () => this.inputWidgets.delete(input) });
292+
288293
// Rerender the element whenever the editor content height changes
289294
const onDidChangeContentHeight = () => {
290295
const contentHeight = templateData.inputWidget.getContentHeight();
@@ -333,6 +338,10 @@ class InputRenderer implements ICompressibleTreeRenderer<ISCMInput, FuzzyScore,
333338
getHeight(input: ISCMInput): number {
334339
return (this.contentHeights.get(input) ?? InputRenderer.DEFAULT_HEIGHT) + 10;
335340
}
341+
342+
getRenderedInputWidget(input: ISCMInput): SCMInputWidget | undefined {
343+
return this.inputWidgets.get(input);
344+
}
336345
}
337346

338347
interface ResourceGroupTemplate {
@@ -845,6 +854,7 @@ class ViewModel {
845854
private repositories: ISequence<ISCMRepository>,
846855
private tree: WorkbenchCompressibleObjectTree<TreeElement, FuzzyScore>,
847856
private menus: SCMMenus,
857+
private inputRenderer: InputRenderer,
848858
private _mode: ViewModelMode,
849859
private _sortKey: ViewModelSortKey,
850860
@IEditorService protected editorService: IEditorService,
@@ -1023,6 +1033,19 @@ class ViewModel {
10231033
}
10241034
}
10251035

1036+
focus() {
1037+
for (const repository of this.repositories.elements) {
1038+
const widget = this.inputRenderer.getRenderedInputWidget(repository.input);
1039+
1040+
if (widget) {
1041+
widget.focus();
1042+
return;
1043+
}
1044+
}
1045+
1046+
this.tree.domFocus();
1047+
}
1048+
10261049
getViewActions(): IAction[] {
10271050
if (this.repositories.elements.length !== 1) {
10281051
return [];
@@ -1387,6 +1410,10 @@ class SCMInputWidget extends Disposable {
13871410
this.renderValidation();
13881411
}
13891412

1413+
focus(): void {
1414+
this.inputEditor.focus();
1415+
}
1416+
13901417
private renderValidation(): void {
13911418
this.validationDisposable.dispose();
13921419

@@ -1546,7 +1573,7 @@ export class SCMViewPane extends ViewPane {
15461573
viewMode = storageMode;
15471574
}
15481575

1549-
this.viewModel = this.instantiationService.createInstance(ViewModel, repositories, this.tree, this.menus, viewMode, ViewModelSortKey.Path);
1576+
this.viewModel = this.instantiationService.createInstance(ViewModel, repositories, this.tree, this.menus, inputRenderer, viewMode, ViewModelSortKey.Path);
15501577
this._register(this.viewModel);
15511578

15521579
addClass(this.listContainer, 'file-icon-themable-tree');
@@ -1594,7 +1621,7 @@ export class SCMViewPane extends ViewPane {
15941621
super.focus();
15951622

15961623
if (this.isExpanded()) {
1597-
this.tree.domFocus();
1624+
this.viewModel.focus();
15981625
}
15991626
}
16001627

0 commit comments

Comments
 (0)