Skip to content

Commit 14a24d5

Browse files
lszomorujoaomoreno
andauthored
SCM - ActionBar rendering optimization (microsoft#180712)
* SCM - ActionBar rendering optimization * address PR comments --------- Co-authored-by: João Moreno <[email protected]>
1 parent 03540d6 commit 14a24d5

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { IContextViewService, IContextMenuService } from 'vs/platform/contextvie
1919
import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
2020
import { ICommandService } from 'vs/platform/commands/common/commands';
2121
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
22-
import { MenuItemAction, IMenuService, registerAction2, MenuId, IAction2Options, MenuRegistry, Action2 } from 'vs/platform/actions/common/actions';
22+
import { MenuItemAction, IMenuService, registerAction2, MenuId, IAction2Options, MenuRegistry, Action2, IMenu } from 'vs/platform/actions/common/actions';
2323
import { IAction, ActionRunner, Action, Separator } from 'vs/base/common/actions';
2424
import { ActionBar, IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
2525
import { IThemeService, IFileIconTheme } from 'vs/platform/theme/common/themeService';
@@ -356,6 +356,7 @@ interface ResourceTemplate {
356356
fileLabel: IResourceLabel;
357357
decorationIcon: HTMLElement;
358358
actionBar: ActionBar;
359+
actionBarMenu: IMenu | undefined;
359360
readonly elementDisposables: DisposableStore;
360361
readonly disposables: IDisposable;
361362
}
@@ -419,7 +420,7 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
419420
const decorationIcon = append(element, $('.decoration-icon'));
420421
const disposables = combinedDisposable(actionBar, fileLabel);
421422

422-
return { element, name, fileLabel, decorationIcon, actionBar, elementDisposables: new DisposableStore(), disposables };
423+
return { element, name, fileLabel, decorationIcon, actionBar, actionBarMenu: undefined, elementDisposables: new DisposableStore(), disposables };
423424
}
424425

425426
renderElement(node: ITreeNode<ISCMResource, FuzzyScore | LabelFuzzyScore> | ITreeNode<ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, FuzzyScore | LabelFuzzyScore>, index: number, template: ResourceTemplate): void {
@@ -430,29 +431,29 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
430431
const viewModel = this.viewModelProvider();
431432
const tooltip = !ResourceTree.isResourceNode(resourceOrFolder) && resourceOrFolder.decorations.tooltip || '';
432433

433-
template.actionBar.clear();
434-
template.actionBar.context = resourceOrFolder;
435-
436434
let matches: IMatch[] | undefined;
437435
let descriptionMatches: IMatch[] | undefined;
438436
let strikethrough: boolean | undefined;
439437

440438
if (ResourceTree.isResourceNode(resourceOrFolder)) {
441439
if (resourceOrFolder.element) {
442440
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.element.resourceGroup.provider);
443-
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceMenu(resourceOrFolder.element), template.actionBar));
441+
this._renderActionBar(template, resourceOrFolder, menus.getResourceMenu(resourceOrFolder.element));
442+
444443
template.element.classList.toggle('faded', resourceOrFolder.element.decorations.faded);
445444
strikethrough = resourceOrFolder.element.decorations.strikeThrough;
446445
} else {
447-
matches = createMatches(node.filterData as FuzzyScore | undefined);
448446
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.context.provider);
449-
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceFolderMenu(resourceOrFolder.context), template.actionBar));
447+
this._renderActionBar(template, resourceOrFolder, menus.getResourceFolderMenu(resourceOrFolder.context));
448+
449+
matches = createMatches(node.filterData as FuzzyScore | undefined);
450450
template.element.classList.remove('faded');
451451
}
452452
} else {
453-
[matches, descriptionMatches] = this._processFilterData(uri, node.filterData);
454453
const menus = this.scmViewService.menus.getRepositoryMenus(resourceOrFolder.resourceGroup.provider);
455-
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceMenu(resourceOrFolder), template.actionBar));
454+
this._renderActionBar(template, resourceOrFolder, menus.getResourceMenu(resourceOrFolder));
455+
456+
[matches, descriptionMatches] = this._processFilterData(uri, node.filterData);
456457
template.element.classList.toggle('faded', resourceOrFolder.decorations.faded);
457458
strikethrough = resourceOrFolder.decorations.strikeThrough;
458459
}
@@ -497,11 +498,8 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
497498
separator: this.labelService.getSeparator(folder.uri.scheme)
498499
});
499500

500-
template.actionBar.clear();
501-
template.actionBar.context = folder;
502-
503501
const menus = this.scmViewService.menus.getRepositoryMenus(folder.context.provider);
504-
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menus.getResourceFolderMenu(folder.context), template.actionBar));
502+
this._renderActionBar(template, folder, menus.getResourceFolderMenu(folder.context));
505503

506504
template.name.classList.remove('strike-through');
507505
template.element.classList.remove('faded');
@@ -520,6 +518,16 @@ class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IReso
520518
template.disposables.dispose();
521519
}
522520

521+
private _renderActionBar(template: ResourceTemplate, resourceOrFolder: ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, menu: IMenu): void {
522+
if (!template.actionBarMenu || template.actionBarMenu !== menu) {
523+
template.actionBar.clear();
524+
template.elementDisposables.add(connectPrimaryMenuToInlineActionBar(menu, template.actionBar));
525+
template.actionBarMenu = menu;
526+
}
527+
528+
template.actionBar.context = resourceOrFolder;
529+
}
530+
523531
private _processFilterData(uri: URI, filterData: FuzzyScore | LabelFuzzyScore | undefined): [IMatch[] | undefined, IMatch[] | undefined] {
524532
if (!filterData) {
525533
return [undefined, undefined];

0 commit comments

Comments
 (0)