Skip to content

Commit

Permalink
Small edit history fix (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Sep 18, 2024
1 parent b9f4a3e commit 26c990d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/edit-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ class EditHistory {
this.events.fire('edit.canUndo', this.canUndo());
this.events.fire('edit.canRedo', this.canRedo());
}

clear() {
this.history.forEach((editOp) => {
editOp.destroy?.();
});
this.history = [];
this.cursor = 0;
}
}

export { EditHistory, EditOp };
6 changes: 6 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ const registerEditorEvents = (events: Events, editHistory: EditHistory, scene: S
return msg;
});

events.on('scene.clear', () => {
scene.clear();
editHistory.clear();
lastExportCursor = 0;
});

events.function('scene.dirty', () => {
return editHistory.cursor !== lastExportCursor;
});
Expand Down
2 changes: 1 addition & 1 deletion src/file-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const initFileHandler = async (scene: Scene, events: Events, dropTarget: HTMLEle
}
}

scene.clear();
events.fire('scene.clear');

return true;
});
Expand Down

0 comments on commit 26c990d

Please sign in to comment.