Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed Mar 11, 2021
1 parent 9b2ee7f commit 0dcf930
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions src/vs/workbench/contrib/files/browser/views/explorerViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,7 @@ interface CachedParsedExpression {
* Makes sure that visible editors are always shown in the explorer even if they are filtered out by settings.
*/
export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
private hiddenExpressionPerRoot: Map<string, CachedParsedExpression>;
private uriVisibilityMap = new Map<URI, boolean>();
private hiddenExpressionPerRoot = new Map<string, CachedParsedExpression>();
private editorsAffectingFilter = new Set<IEditorInput>();
private _onDidChange = new Emitter<void>();
private toDispose: IDisposable[] = [];
Expand All @@ -545,7 +544,6 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
@IEditorService private readonly editorService: IEditorService,
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService
) {
this.hiddenExpressionPerRoot = new Map<string, CachedParsedExpression>();
this.toDispose.push(this.contextService.onDidChangeWorkspaceFolders(() => this.updateConfiguration()));
this.toDispose.push(this.configurationService.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('files.exclude')) {
Expand All @@ -555,26 +553,30 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
this.toDispose.push(this.editorService.onDidVisibleEditorsChange(() => {
const editors = this.editorService.visibleEditors;
let shouldFire = false;
this.uriVisibilityMap.forEach((visible, uri) => {
if (!visible) {
editors.forEach(e => {
if (e.resource && this.uriIdentityService.extUri.isEqualOrParent(e.resource, uri)) {
// A filtered resource suddenly became visible since user opened an editor
shouldFire = true;
}
});

for (const e of editors) {
if (!e.resource) {
continue;
}
});

this.editorsAffectingFilter.forEach(e => {
const stat = this.explorerService.findClosest(e.resource);
if (stat && stat.isExcluded) {
// A filtered resource suddenly became visible since user opened an editor
shouldFire = true;
break;
}
}

for (const e of this.editorsAffectingFilter) {
if (!editors.includes(e)) {
// Editor that was affecting filtering is no longer visible
shouldFire = true;
break;
}
});
}

if (shouldFire) {
this.editorsAffectingFilter.clear();
this.uriVisibilityMap.clear();
this._onDidChange.fire();
}
}));
Expand Down Expand Up @@ -603,21 +605,12 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {

if (shouldFire) {
this.editorsAffectingFilter.clear();
this.uriVisibilityMap.clear();
this._onDidChange.fire();
}
}

filter(stat: ExplorerItem, parentVisibility: TreeVisibility): boolean {
const cachedVisibility = this.uriVisibilityMap.get(stat.resource);
if (typeof cachedVisibility === 'boolean') {
return cachedVisibility;
}

const isVisible = this.isVisible(stat, parentVisibility);
this.uriVisibilityMap.set(stat.resource, isVisible);

return isVisible;
return this.isVisible(stat, parentVisibility);
}

private isVisible(stat: ExplorerItem, parentVisibility: TreeVisibility): boolean {
Expand All @@ -636,7 +629,8 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
stat.isExcluded = true;
const editors = this.editorService.visibleEditors;
const editor = editors.find(e => e.resource && this.uriIdentityService.extUri.isEqualOrParent(e.resource, stat.resource));
if (editor) {
const closestRoot = this.explorerService.findClosest(stat.resource)!.root;
if (editor && stat.root === closestRoot) {
this.editorsAffectingFilter.add(editor);
return true; // Show all opened files and their parents
}
Expand Down

0 comments on commit 0dcf930

Please sign in to comment.