WIP: Eraser implementation #7

Draft
Franciman wants to merge 8 commits from eraserhead into master
1 changed files with 10 additions and 4 deletions
Showing only changes of commit 114ea2309e - Show all commits

View File

@ -45,7 +45,7 @@ impl VersionedCanvas {
}
}
pub fn update(&mut self, update_fn: impl FnOnce(&Canvas) -> Canvas) {
pub fn update(&mut self, update_fn: impl FnOnce(&mut Canvas)) {
// This is a linear history,
// so we first check if there are newer versions, if so
// this means we are in the past, so a change in the past destroys the future
@ -53,10 +53,16 @@ impl VersionedCanvas {
if self.has_newer_versions() {
self.versions = self.versions.take(self.curr_version + 1);
}
let new_version = update_fn(self.get());
let mut new_version = self.get().clone();
update_fn(&mut new_version);
// Only push new version if there has been an actual change in the vector
if !new_version.elements.ptr_eq(&self.get().elements) {
self.versions.push_back(new_version);
self.curr_version = self.curr_version + 1;
}
}
// Do inplace update, which will be irreversible
pub fn irreversible_update(&mut self, update_fn: impl FnOnce(&mut Canvas)) {