@lvce-editor/explorer-view 2.40.0 → 2.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1194,6 +1194,16 @@ const getFileIcons = async (dirents, fileIconCache) => {
1194
1194
  };
1195
1195
  };
1196
1196
 
1197
+ const getIndex = (dirents, uri) => {
1198
+ for (let i = 0; i < dirents.length; i++) {
1199
+ const dirent = dirents[i];
1200
+ if (dirent.path === uri) {
1201
+ return i;
1202
+ }
1203
+ }
1204
+ return -1;
1205
+ };
1206
+
1197
1207
  const getParentFolder = (dirents, index, root) => {
1198
1208
  if (index < 0) {
1199
1209
  return root;
@@ -1407,32 +1417,33 @@ const mergeTrees = (a, b) => {
1407
1417
  };
1408
1418
  };
1409
1419
 
1420
+ const treeToArrayInternal = (map, root, items, path, depth) => {
1421
+ const children = map[path];
1422
+ if (!children) {
1423
+ return;
1424
+ }
1425
+ const count = children.length;
1426
+ for (let i = 0; i < count; i++) {
1427
+ const child = children[i];
1428
+ const childPath = join2(path, child.name);
1429
+ const absolutePath = `${root}${childPath}`;
1430
+ items.push({
1431
+ depth,
1432
+ posInSet: i + 1,
1433
+ setSize: count,
1434
+ icon: '',
1435
+ path: absolutePath,
1436
+ selected: false,
1437
+ name: child.name,
1438
+ type: child.type
1439
+ });
1440
+ treeToArrayInternal(map, root, items, childPath, depth + 1);
1441
+ }
1442
+ };
1443
+
1410
1444
  const treeToArray = (map, root) => {
1411
1445
  const items = [];
1412
- const processChildren = (path, depth) => {
1413
- const children = map[path];
1414
- if (!children) {
1415
- return;
1416
- }
1417
- const count = children.length;
1418
- for (let i = 0; i < count; i++) {
1419
- const child = children[i];
1420
- const childPath = join2(path, child.name);
1421
- const absolutePath = `${root}${childPath}`;
1422
- items.push({
1423
- depth,
1424
- posInSet: i + 1,
1425
- setSize: count,
1426
- icon: '',
1427
- path: absolutePath,
1428
- selected: false,
1429
- name: child.name,
1430
- type: child.type
1431
- });
1432
- processChildren(childPath, depth + 1);
1433
- }
1434
- };
1435
- processChildren('', 0);
1446
+ treeToArrayInternal(map, root, items, '', 1);
1436
1447
  return items;
1437
1448
  };
1438
1449
 
@@ -1472,7 +1483,7 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1472
1483
  const merged = mergeTrees(tree, childTree);
1473
1484
  const newItems = treeToArray(merged, root);
1474
1485
  const dirents = newItems;
1475
- const newFocusedIndex = newItems.findIndex(dirent => dirent.path === absolutePath);
1486
+ const newFocusedIndex = getIndex(newItems, absolutePath);
1476
1487
  const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, dirents.length);
1477
1488
  const visible = dirents.slice(minLineY, maxLineY);
1478
1489
  const {
@@ -1522,16 +1533,6 @@ const createNewDirentsRename = async (renamedDirent, editingValue, pathSeparator
1522
1533
  return true;
1523
1534
  };
1524
1535
 
1525
- const getIndex = (dirents, uri) => {
1526
- for (let i = 0; i < dirents.length; i++) {
1527
- const dirent = dirents[i];
1528
- if (dirent.path === uri) {
1529
- return i;
1530
- }
1531
- }
1532
- return -1;
1533
- };
1534
-
1535
1536
  const updateTree2 = (tree, update) => {
1536
1537
  const updatedTree = {
1537
1538
  ...tree,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.40.0",
3
+ "version": "2.41.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",