Skip to content

Commit

Permalink
attempt to fix uniqueID issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr committed Jan 24, 2025
1 parent 4726a6e commit be486ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/editor/lib/commands/EntityCloneCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 5 additions & 11 deletions src/editor/lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit be486ea

Please sign in to comment.