Skip to content

Commit

Permalink
fix selection after duplicating (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoecheza authored Sep 17, 2024
1 parent 008bb68 commit ddc542d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions packages/@dcl/inspector/src/hooks/sdk/useTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity, Entity>
cloned: Entity
}

for (const [original, duplicate] of Array.from(entities.entries()).reverse()) {
Expand All @@ -40,9 +41,8 @@ export function duplicateEntity(engine: IEngine) {
}
}

const duplicate = entities.get(entity)!
updateSelectedEntity(engine)(duplicate)
return duplicate
updateSelectedEntity(engine)(cloned)
return cloned
}
}

Expand Down

0 comments on commit ddc542d

Please sign in to comment.