Skip to content

Commit 432f666

Browse files
committed
Prevent flickering on hide/show
ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee <[email protected]>
1 parent 3234fd6 commit 432f666

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

src/OneExplorer/OneExplorer.ts

+41-9
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export abstract class Node {
105105
* @protected _parent
106106
* `undefined` only if it has no parent (tree root)
107107
*/
108-
protected _parent: Node | undefined;
108+
public _parent: Node | undefined;
109109
uri: vscode.Uri;
110110

111111
abstract icon: vscode.ThemeIcon;
@@ -124,25 +124,48 @@ export abstract class Node {
124124
*/
125125
abstract _buildChildren: () => void;
126126

127+
getVisibleChildren(): Node[] {
128+
return OneTreeDataProvider.didHideExtra
129+
? this.getChildren().filter((node) => !node.canHide)
130+
: this.getChildren();
131+
}
132+
127133
getChildren(): Node[] {
128134
if (this._childNodes) {
129135
return this._childNodes;
130136
}
131137

132138
this._buildChildren();
139+
133140
return this._childNodes!;
134141
}
135142

136143
resetChildren(): void {
137144
this._childNodes = undefined;
138145
}
139146

140-
get path(): string {
141-
return this.uri.fsPath;
147+
dropChild(child: Node): void{
148+
this._childNodes = this._childNodes?.filter(node=>node.path !== child.path);
142149
}
143150

144-
get parent(): Node | undefined {
145-
return this._parent;
151+
adoptChild(child:Node): void{
152+
if(!this._childNodes){
153+
this._childNodes = [child];
154+
}
155+
else{
156+
this._childNodes.push(child);
157+
}
158+
}
159+
160+
set parent(adopter: Node) {
161+
const dropper = this._parent;
162+
dropper!.dropChild(this);
163+
adopter.adoptChild(this);
164+
this._parent = adopter;
165+
}
166+
167+
get path(): string {
168+
return this.uri.fsPath;
146169
}
147170

148171
get name(): string {
@@ -798,6 +821,17 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
798821
this.refresh(undefined, false);
799822
}
800823

824+
init(): void {
825+
this._tree = this._workspaceRoots.map(
826+
(root) =>
827+
NodeFactory.create(
828+
NodeType.directory,
829+
root.fsPath,
830+
undefined
831+
) as DirectoryNode
832+
);
833+
}
834+
801835
/**
802836
* Refresh the tree under the given Node
803837
* @command one.explorer.refresh
@@ -1140,7 +1174,7 @@ input_path=${modelName}.${extName}
11401174
case NodeType.baseModel:
11411175
case NodeType.config:
11421176
return new OneNode(
1143-
node.getChildren().length > 0
1177+
node.getVisibleChildren().length > 0
11441178
? vscode.TreeItemCollapsibleState.Collapsed
11451179
: vscode.TreeItemCollapsibleState.None,
11461180
node
@@ -1161,9 +1195,7 @@ input_path=${modelName}.${extName}
11611195
return this.getTree();
11621196
}
11631197

1164-
return OneTreeDataProvider.didHideExtra
1165-
? element.getChildren().filter((node) => !node.canHide)
1166-
: element.getChildren();
1198+
return element.getVisibleChildren();
11671199
}
11681200

11691201
/**

0 commit comments

Comments
 (0)