Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce event listeners created when rendering explorer items #163394

Merged
merged 2 commits into from Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -452,6 +452,7 @@ export class ExplorerView extends ViewPane implements IExplorerView {
}
});
this._register(this.tree);
this._register(this.themeService.onDidColorThemeChange(() => this.tree.rerender()));

// Bind configuration
const onDidChangeCompressionConfiguration = Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('explorer.compactFolders'));
Expand Down
47 changes: 18 additions & 29 deletions src/vs/workbench/contrib/files/browser/views/explorerViewer.ts
Expand Up @@ -384,37 +384,26 @@ export class FilesRenderer implements ICompressibleTreeRenderer<ExplorerItem, Fu
extraClasses.push('cut');
}

const setResourceData = () => {
// Offset nested children unless folders have both chevrons and icons, otherwise alignment breaks
const theme = this.themeService.getFileIconTheme();

// Hack to always render chevrons for file nests, or else may not be able to identify them.
const twistieContainer = (templateData.container.parentElement?.parentElement?.querySelector('.monaco-tl-twistie') as HTMLElement);
if (twistieContainer) {
if (stat.hasNests && theme.hidesExplorerArrows) {
twistieContainer.classList.add('force-twistie');
} else {
twistieContainer.classList.remove('force-twistie');
}
}
// Offset nested children unless folders have both chevrons and icons, otherwise alignment breaks
const theme = this.themeService.getFileIconTheme();

// when explorer arrows are hidden or there are no folder icons, nests get misaligned as they are forced to have arrows and files typically have icons
// Apply some CSS magic to get things looking as reasonable as possible.
const themeIsUnhappyWithNesting = theme.hasFileIcons && (theme.hidesExplorerArrows || !theme.hasFolderIcons);
const realignNestedChildren = stat.nestedParent && themeIsUnhappyWithNesting;

templateData.label.setResource({ resource: stat.resource, name: label }, {
fileKind: stat.isRoot ? FileKind.ROOT_FOLDER : stat.isDirectory ? FileKind.FOLDER : FileKind.FILE,
extraClasses: realignNestedChildren ? [...extraClasses, 'align-nest-icon-with-parent-icon'] : extraClasses,
fileDecorations: this.config.explorer.decorations,
matches: createMatches(filterData),
separator: this.labelService.getSeparator(stat.resource.scheme, stat.resource.authority),
domId
});
};
// Hack to always render chevrons for file nests, or else may not be able to identify them.
const twistieContainer = templateData.container.parentElement?.parentElement?.querySelector('.monaco-tl-twistie');
twistieContainer?.classList.toggle('force-twistie', stat.hasNests && theme.hidesExplorerArrows);

templateData.elementDisposables.add(this.themeService.onDidFileIconThemeChange(() => setResourceData()));
setResourceData();
// when explorer arrows are hidden or there are no folder icons, nests get misaligned as they are forced to have arrows and files typically have icons
// Apply some CSS magic to get things looking as reasonable as possible.
const themeIsUnhappyWithNesting = theme.hasFileIcons && (theme.hidesExplorerArrows || !theme.hasFolderIcons);
const realignNestedChildren = stat.nestedParent && themeIsUnhappyWithNesting;

templateData.label.setResource({ resource: stat.resource, name: label }, {
fileKind: stat.isRoot ? FileKind.ROOT_FOLDER : stat.isDirectory ? FileKind.FOLDER : FileKind.FILE,
extraClasses: realignNestedChildren ? [...extraClasses, 'align-nest-icon-with-parent-icon'] : extraClasses,
fileDecorations: this.config.explorer.decorations,
matches: createMatches(filterData),
separator: this.labelService.getSeparator(stat.resource.scheme, stat.resource.authority),
domId
});

templateData.elementDisposables.add(templateData.label.onDidRender(() => {
try {
Expand Down