From be486eab2eafddc72f4e5439e540eaa32623687d Mon Sep 17 00:00:00 2001 From: Kieran Farr Date: Fri, 24 Jan 2025 11:52:34 -0800 Subject: [PATCH] attempt to fix uniqueID issue --- src/editor/lib/commands/EntityCloneCommand.js | 10 +++++----- src/editor/lib/entity.js | 16 +++++----------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/editor/lib/commands/EntityCloneCommand.js b/src/editor/lib/commands/EntityCloneCommand.js index f55833807..eea885686 100644 --- a/src/editor/lib/commands/EntityCloneCommand.js +++ b/src/editor/lib/commands/EntityCloneCommand.js @@ -10,17 +10,17 @@ export class EntityCloneCommand extends Command { this.name = 'Clone Entity'; this.updatable = false; if (!entity.id) { - entity.id = createUniqueId(); + entity.id = createUniqueId(); // if entity to clone doesn't have an id, create one } - this.entityIdToClone = entity.id; - this.entityId = null; + this.entityIdToClone = entity.id; // save the id of the entity to clone + this.entityId = null; // this will be the id of the newly cloned entity } execute(nextCommandCallback) { const entityToClone = document.getElementById(this.entityIdToClone); if (entityToClone) { - const clone = cloneEntityImpl(entityToClone, this.entityId); - this.entityId = clone.id; + const clone = cloneEntityImpl(entityToClone, this.entityId); // why is this.entityId passed? will this always be null? + this.entityId = clone.id; // use ID set by cloneEntityImpl function nextCommandCallback?.(clone); return clone; } diff --git a/src/editor/lib/entity.js b/src/editor/lib/entity.js index c122e85cc..807516940 100644 --- a/src/editor/lib/entity.js +++ b/src/editor/lib/entity.js @@ -155,20 +155,14 @@ export function cloneEntityImpl(entity, newId = undefined) { { once: true } ); + // In cloneEntityImpl if (newId) { clone.id = newId; + } else if (entity.id) { + clone.id = + entity.id.length === 21 ? createUniqueId() : getUniqueId(entity.id); } else { - if (entity.id) { - if (entity.id.length === 21) { - // nanoid generated id, create a new one - clone.id = createUniqueId(); - } else { - // Get a valid unique ID for the entity - clone.id = getUniqueId(entity.id); - } - } else { - entity.id = createUniqueId(); - } + clone.id = createUniqueId(); } insertAfter(clone, entity); return clone;