Skip to content

Commit 671bd08

Browse files
authored
SCM - Fix issue with focusing the action button (microsoft#153825)
Fix issue with focusing the action button
1 parent 60eb5b7 commit 671bd08

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class ActionButtonRenderer implements ICompressibleTreeRenderer<ISCMActionButton
108108
static readonly TEMPLATE_ID = 'actionButton';
109109
get templateId(): string { return ActionButtonRenderer.TEMPLATE_ID; }
110110

111+
private actionButtons = new Map<ISCMActionButton, SCMActionButton>();
112+
111113
constructor(
112114
@ICommandService private commandService: ICommandService,
113115
@IContextMenuService private contextMenuService: IContextMenuService,
@@ -131,13 +133,25 @@ class ActionButtonRenderer implements ICompressibleTreeRenderer<ISCMActionButton
131133
renderElement(node: ITreeNode<ISCMActionButton, FuzzyScore>, index: number, templateData: ActionButtonTemplate, height: number | undefined): void {
132134
templateData.disposable.dispose();
133135

136+
const disposables = new DisposableStore();
137+
const actionButton = node.element;
134138
templateData.actionButton.setButton(node.element.button);
139+
140+
// Remember action button
141+
this.actionButtons.set(actionButton, templateData.actionButton);
142+
disposables.add({ dispose: () => this.actionButtons.delete(actionButton) });
143+
144+
templateData.disposable = disposables;
135145
}
136146

137147
renderCompressedElements(): void {
138148
throw new Error('Should never happen since node is incompressible');
139149
}
140150

151+
focusActionButton(actionButton: ISCMActionButton): void {
152+
this.actionButtons.get(actionButton)?.focus();
153+
}
154+
141155
disposeElement(node: ITreeNode<ISCMActionButton, FuzzyScore>, index: number, template: ActionButtonTemplate): void {
142156
template.disposable.dispose();
143157
}
@@ -2200,6 +2214,7 @@ export class SCMViewPane extends ViewPane {
22002214
get viewModel(): ViewModel { return this._viewModel; }
22012215
private listLabels!: ResourceLabels;
22022216
private inputRenderer!: InputRenderer;
2217+
private actionButtonRenderer!: ActionButtonRenderer;
22032218
private readonly disposables = new DisposableStore();
22042219

22052220
constructor(
@@ -2254,6 +2269,8 @@ export class SCMViewPane extends ViewPane {
22542269
this.inputRenderer = this.instantiationService.createInstance(InputRenderer, this.layoutCache, overflowWidgetsDomNode, (input, height) => this.tree.updateElementHeight(input, height));
22552270
const delegate = new ListDelegate(this.inputRenderer);
22562271

2272+
this.actionButtonRenderer = this.instantiationService.createInstance(ActionButtonRenderer);
2273+
22572274
this.listLabels = this.instantiationService.createInstance(ResourceLabels, { onDidChangeVisibility: this.onDidChangeBodyVisibility });
22582275
this._register(this.listLabels);
22592276

@@ -2264,7 +2281,7 @@ export class SCMViewPane extends ViewPane {
22642281
const renderers: ICompressibleTreeRenderer<any, any, any>[] = [
22652282
this.instantiationService.createInstance(RepositoryRenderer, getActionViewItemProvider(this.instantiationService)),
22662283
this.inputRenderer,
2267-
this.instantiationService.createInstance(ActionButtonRenderer),
2284+
this.actionButtonRenderer,
22682285
this.instantiationService.createInstance(ResourceGroupRenderer, getActionViewItemProvider(this.instantiationService)),
22692286
this._register(this.instantiationService.createInstance(ResourceRenderer, () => this._viewModel, this.listLabels, getActionViewItemProvider(this.instantiationService), actionRunner))
22702287
];
@@ -2394,6 +2411,7 @@ export class SCMViewPane extends ViewPane {
23942411
return;
23952412
} else if (isSCMActionButton(e.element)) {
23962413
this.scmViewService.focus(e.element.repository);
2414+
this.actionButtonRenderer.focusActionButton(e.element);
23972415

23982416
return;
23992417
}
@@ -2663,6 +2681,10 @@ export class SCMActionButton implements IDisposable {
26632681
this.disposables.value!.add(attachButtonStyler(this.button, this.themeService));
26642682
}
26652683

2684+
focus(): void {
2685+
this.button?.focus();
2686+
}
2687+
26662688
private clear(): void {
26672689
this.disposables.value = new DisposableStore();
26682690
this.button = undefined;

0 commit comments

Comments
 (0)