Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix selection after duplicating (PR #1000 🚀) #1000

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading