Make update interface slightly more usable
This commit is contained in:
parent
4b1dd4caed
commit
114ea2309e
|
|
@ -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,
|
// This is a linear history,
|
||||||
// so we first check if there are newer versions, if so
|
// 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
|
// 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() {
|
if self.has_newer_versions() {
|
||||||
self.versions = self.versions.take(self.curr_version + 1);
|
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.versions.push_back(new_version);
|
||||||
self.curr_version = self.curr_version + 1;
|
self.curr_version = self.curr_version + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Do inplace update, which will be irreversible
|
// Do inplace update, which will be irreversible
|
||||||
pub fn irreversible_update(&mut self, update_fn: impl FnOnce(&mut Canvas)) {
|
pub fn irreversible_update(&mut self, update_fn: impl FnOnce(&mut Canvas)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue