Skip to content

Commit 365d20d

Browse files
authored
Merge pull request #54 from matthieu-crouzet/fix/collapse-all
fix: collapse all folders
2 parents ea8a898 + f6200b3 commit 365d20d

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

projects/ngx-monaco-tree-test/src/app/app.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ export class AppComponent {
146146
path: string,
147147
localTree: MonacoTreeElement[]
148148
) {
149-
const spited = path.split('/');
149+
const splitted = path.split('/');
150150
if (!filename) return;
151-
if (spited.length === 1) {
151+
if (splitted.length === 1) {
152152
const file = localTree.find((el) => el.name == path);
153153
if (!file) return;
154154
else if (file.content === undefined) {
@@ -163,9 +163,9 @@ export class AppComponent {
163163
});
164164
}
165165
} else {
166-
const file = localTree.find((el) => el.name == spited[0]);
166+
const file = localTree.find((el) => el.name == splitted[0]);
167167
if (!file || !file.content) return;
168-
this.create(type, filename, spited.slice(1).join('/'), file?.content);
168+
this.create(type, filename, splitted.slice(1).join('/'), file?.content);
169169
}
170170
}
171171

projects/ngx-monaco-tree/src/lib/monaco-tree-file/monaco-tree-file.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, ElementRef, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
1+
import {Component, ElementRef, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges, viewChildren} from '@angular/core';
22
import { extensions } from '../../utils/extension-icon';
33
import { files } from '../../utils/file-icon';
44
import { folders } from '../../utils/folder-icon';
@@ -43,6 +43,8 @@ export class MonacoTreeFileComponent implements OnChanges {
4343
@Output() contextMenuClick = new EventEmitter<ContextMenuAction>();
4444
@Output() dragDropFile = new EventEmitter<DragAndDropEvent>();
4545

46+
private children = viewChildren(MonacoTreeFileComponent);
47+
4648
open = false;
4749
position: [number, number]|undefined = undefined;
4850

@@ -154,6 +156,11 @@ export class MonacoTreeFileComponent implements OnChanges {
154156
this.contextMenuClick.emit([event[0], this.name + '/' + event[1]]);
155157
}
156158

159+
collapseAll() {
160+
this.children().forEach((child) => child.collapseAll());
161+
this.open = false;
162+
}
163+
157164
@HostListener('document:contextmenu', ['$event'])
158165
clickOut(event: MouseEvent) {
159166
if(!this.eRef.nativeElement.contains(event.target)) {

projects/ngx-monaco-tree/src/lib/ngx-monaco-tree.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
1+
import { Component, EventEmitter, Input, OnInit, Output, viewChildren } from '@angular/core';
22
import { MonacoTreeElement } from './ngx-monaco-tree.type';
33
import {ContextMenuAction, DragAndDropEvent} from "./monaco-tree-file/monaco-tree-file.type";
44
import {MonacoTreeFileComponent} from "./monaco-tree-file/monaco-tree-file.component";
@@ -32,6 +32,8 @@ export class NgxMonacoTreeComponent {
3232

3333
@Input() currentFile: string|null = null;
3434

35+
private children = viewChildren(MonacoTreeFileComponent);
36+
3537
handleClickFile(path: string) {
3638
this.clickFile.emit(path);
3739
this.currentFile = path;
@@ -54,7 +56,6 @@ export class NgxMonacoTreeComponent {
5456
}
5557

5658
handleCollapseAll() {
57-
const tree = JSON.parse(JSON.stringify(this.tree));
58-
this.tree = tree;
59+
this.children().forEach((child) => child.collapseAll());
5960
}
6061
}

0 commit comments

Comments
 (0)