MCPcopy Create free account
hub / github.com/esengine/esengine / refreshTree

Function refreshTree

packages/editor-app/src/components/FileTree.tsx:360–428  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

358 };
359
360 const refreshTree = async () => {
361 if (!rootPath) return;
362
363 // 保存当前展开状态
364 const expandedPaths = new Set<string>();
365 const collectExpandedPaths = (nodes: TreeNode[]) => {
366 for (const node of nodes) {
367 if (node.type === 'folder' && node.expanded) {
368 expandedPaths.add(node.path);
369 if (node.children) {
370 collectExpandedPaths(node.children);
371 }
372 }
373 }
374 };
375 collectExpandedPaths(tree);
376
377 // 重新加载根目录,获取最新的文件结构
378 try {
379 const entries = await TauriAPI.listDirectory(rootPath);
380 const children = entriesToNodes(entries);
381
382 const rootName = rootPath.split(/[/\\]/).filter((p) => p).pop() || 'Project';
383 let rootNode: TreeNode = {
384 name: rootName,
385 path: rootPath,
386 type: 'folder',
387 children: children,
388 expanded: true,
389 loaded: true
390 };
391
392 // 恢复展开状态
393 if (expandedPaths.size > 0) {
394 const restoreExpandedState = async (node: TreeNode): Promise<TreeNode> => {
395 if (node.type === 'folder' && expandedPaths.has(node.path)) {
396 let children = node.children || [];
397 if (!node.loaded && node.children) {
398 children = await loadChildren(node);
399 }
400 const restoredChildren = await Promise.all(
401 children.map((child) => restoreExpandedState(child))
402 );
403 return {
404 ...node,
405 expanded: true,
406 loaded: true,
407 children: restoredChildren
408 };
409 } else if (node.type === 'folder' && node.children) {
410 const restoredChildren = await Promise.all(
411 node.children.map((child) => restoreExpandedState(child))
412 );
413 return {
414 ...node,
415 children: restoredChildren
416 };
417 }

Callers 3

handleRenameFunction · 0.85
handleDeleteConfirmFunction · 0.85
handlePromptConfirmFunction · 0.85

Calls 7

collectExpandedPathsFunction · 0.85
entriesToNodesFunction · 0.85
restoreExpandedStateFunction · 0.85
popMethod · 0.80
listDirectoryMethod · 0.65
filterMethod · 0.65
errorMethod · 0.45

Tested by

no test coverage detected