Skip to content

Commit

Permalink
use getDOMAttribute instead of getAttribute to store the old value to…
Browse files Browse the repository at this point in the history
… be sure we include only properties we set explicitely if we undo and then redo
  • Loading branch information
vincentfretin committed Aug 29, 2024
1 parent 94d64c2 commit 9612ac5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/editor/lib/commands/ComponentRemoveCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export class ComponentRemoveCommand extends Command {
}
this.entityId = entity.id;
this.component = payload.component;
this.value = entity.getAttribute(this.component);

const component =
entity.components[payload.component] ??
AFRAME.components[payload.component];
this.value = component.isSingleProperty
? component.schema.stringify(entity.getAttribute(payload.component))
: entity.getDOMAttribute(payload.component);
}

execute() {
Expand Down
7 changes: 3 additions & 4 deletions src/editor/lib/commands/EntityUpdateCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ export class EntityUpdateCommand extends Command {
console.log(this.component, this.oldValue, this.newValue);
}
} else {
// If component.schema.stringify is undefined then it's multi-property component and value is an object.
this.newValue = component.schema.stringify
this.newValue = component.isSingleProperty
? component.schema.stringify(payload.value)
: payload.value;
this.oldValue = component.schema.stringify
this.oldValue = component.isSingleProperty
? component.schema.stringify(
payload.entity.getAttribute(payload.component)
)
: payload.entity.getAttribute(payload.component);
: payload.entity.getDOMAttribute(payload.component);
if (this.editor.debugUndoRedo) {
console.log(this.component, this.oldValue, this.newValue);
}
Expand Down

0 comments on commit 9612ac5

Please sign in to comment.