From fee9d7ee0710fe7f8a4d30c8abef23a5788f2422 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Apr 2026 13:54:56 +0000 Subject: [PATCH] fix: address 2 bugs from Devin Review on workspaceStore - Fix updateChildrenPaths: use startsWith+slice instead of String.replace() to prevent incorrect substring matching when renaming files/folders - Fix duplicateFile: deep-clone children with new IDs and paths when duplicating folders to avoid shared references Co-Authored-By: Thuong Huynh --- src/stores/workspaceStore.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/stores/workspaceStore.ts b/src/stores/workspaceStore.ts index c9cdda8..82532ad 100644 --- a/src/stores/workspaceStore.ts +++ b/src/stores/workspaceStore.ts @@ -192,7 +192,7 @@ function updateChildrenPaths(children: FileNode[], oldPath: string, newPath: str return children.map((child) => { const updatedChild: FileNode = { ...child, - path: child.path.replace(oldPath, newPath), + path: child.path.startsWith(oldPath) ? newPath + child.path.slice(oldPath.length) : child.path, }; if (updatedChild.children) { updatedChild.children = updateChildrenPaths(updatedChild.children, oldPath, newPath); @@ -201,6 +201,20 @@ function updateChildrenPaths(children: FileNode[], oldPath: string, newPath: str }); } +function deepCloneFileNode(node: FileNode, newParentPath: string): FileNode { + const cloned: FileNode = { + ...node, + id: genId('file'), + path: `${newParentPath}/${node.name}`, + }; + if (node.children) { + cloned.children = node.children.map((child) => + deepCloneFileNode(child, cloned.path) + ); + } + return cloned; +} + function addChildToFolder( nodes: FileNode[], parentPath: string, @@ -492,6 +506,11 @@ export const useWorkspaceStore = create((set, get) => ({ name: dupName, path: `${parentPath}/${dupName}`, }; + if (node.children) { + newNode.children = node.children.map((child) => + deepCloneFileNode(child, newNode.path) + ); + } if (!parentPath) { return { files: [...s.files, newNode] }; }