Implement Undo and Redo (#354)

* Implement undo and redo

* Create more save points and hook up menu entry

* Fix operation ordering

* Remove debug statement

* Fix folder changed order

* Don't store overlays in the history chain

* Keep selection
This commit is contained in:
TrueDoctor
2021-08-26 12:20:00 +02:00
committed by Keavon Chambers
parent 47fbb8d0fa
commit 0ccb181e2c
6 changed files with 133 additions and 38 deletions
+18
View File
@@ -272,6 +272,24 @@ impl Document {
self.set_transform_relative_to_scope(layer, None, transform)
}
fn remove_overlays(&mut self, path: &mut Vec<LayerId>) {
if self.layer(path).unwrap().overlay {
self.delete(path).unwrap()
}
let ids = self.folder(path).map(|folder| folder.layer_ids.clone()).unwrap_or_default();
for id in ids {
path.push(id);
self.remove_overlays(path);
path.pop();
}
}
pub fn clone_without_overlays(&self) -> Self {
let mut document = self.clone();
document.remove_overlays(&mut vec![]);
document
}
/// Mutate the document by applying the `operation` to it. If the operation necessitates a
/// reaction from the frontend, responses may be returned.
pub fn handle_operation(&mut self, operation: &Operation) -> Result<Option<Vec<DocumentResponse>>, DocumentError> {