From ddc542de4ef0245a9a2b2542b4e5283151cab346 Mon Sep 17 00:00:00 2001 From: Nicolas Echezarreta Date: Tue, 17 Sep 2024 10:58:45 -0300 Subject: [PATCH] fix selection after duplicating (#1000) --- .../@dcl/inspector/src/components/Renderer/Renderer.tsx | 1 + packages/@dcl/inspector/src/hooks/sdk/useTree.ts | 1 + .../inspector/src/lib/sdk/operations/duplicate-entity.ts | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/@dcl/inspector/src/components/Renderer/Renderer.tsx b/packages/@dcl/inspector/src/components/Renderer/Renderer.tsx index 4af4fc77d..20ee5ed69 100644 --- a/packages/@dcl/inspector/src/components/Renderer/Renderer.tsx +++ b/packages/@dcl/inspector/src/components/Renderer/Renderer.tsx @@ -134,6 +134,7 @@ const Renderer: React.FC = () => { const pasteSelectedEntities = useCallback(() => { if (!sdk) return + sdk.operations.removeSelectedEntities() copyEntities.forEach((entity) => sdk.operations.duplicateEntity(entity)) void sdk.operations.dispatch() }, [sdk, copyEntities]) diff --git a/packages/@dcl/inspector/src/hooks/sdk/useTree.ts b/packages/@dcl/inspector/src/hooks/sdk/useTree.ts index b85f5c1c1..84aa81a98 100644 --- a/packages/@dcl/inspector/src/hooks/sdk/useTree.ts +++ b/packages/@dcl/inspector/src/hooks/sdk/useTree.ts @@ -150,6 +150,7 @@ export const useTree = () => { const duplicate = useCallback( async (entity: Entity) => { if (entity === ROOT || !sdk) return + sdk.operations.removeSelectedEntities() sdk.operations.duplicateEntity(entity) await sdk.operations.dispatch() handleUpdate() diff --git a/packages/@dcl/inspector/src/lib/sdk/operations/duplicate-entity.ts b/packages/@dcl/inspector/src/lib/sdk/operations/duplicate-entity.ts index 685b17d7a..3d50af856 100644 --- a/packages/@dcl/inspector/src/lib/sdk/operations/duplicate-entity.ts +++ b/packages/@dcl/inspector/src/lib/sdk/operations/duplicate-entity.ts @@ -19,8 +19,9 @@ export function duplicateEntity(engine: IEngine) { const Name = engine.getComponent(NameEngine.componentName) as typeof NameEngine const NetworkEntity = engine.getComponent(NetworkEntityEngine.componentId) as typeof NetworkEntityEngine - const { entities } = clone(entity, engine as any, Transform as any, Triggers as any) as { + const { entities, cloned } = clone(entity, engine as any, Transform as any, Triggers as any) as { entities: Map + cloned: Entity } for (const [original, duplicate] of Array.from(entities.entries()).reverse()) { @@ -40,9 +41,8 @@ export function duplicateEntity(engine: IEngine) { } } - const duplicate = entities.get(entity)! - updateSelectedEntity(engine)(duplicate) - return duplicate + updateSelectedEntity(engine)(cloned) + return cloned } }