mock up history
All checks were successful
Test Rust project / test (ubuntu-latest, stable) (push) Successful in 56s
All checks were successful
Test Rust project / test (ubuntu-latest, stable) (push) Successful in 56s
This commit is contained in:
@@ -236,12 +236,27 @@ impl Grid {
|
|||||||
&mut self.grid_history[self.current_grid]
|
&mut self.grid_history[self.current_grid]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn undo(&mut self) {
|
||||||
|
self.current_grid.saturating_sub(1);
|
||||||
|
}
|
||||||
|
fn redo(&mut self) {
|
||||||
|
self.current_grid += 1;
|
||||||
|
}
|
||||||
|
|
||||||
fn transact_on_grid<F>(&mut self, mut action: F)
|
fn transact_on_grid<F>(&mut self, mut action: F)
|
||||||
where
|
where
|
||||||
F: FnMut(&mut CellGrid) -> (),
|
F: FnMut(&mut CellGrid) -> (),
|
||||||
{
|
{
|
||||||
let old = self.get_grid().clone();
|
// push on a new reality
|
||||||
self.grid_history.push(old);
|
let new = self.get_grid().clone();
|
||||||
|
self.grid_history.push(new);
|
||||||
|
self.current_grid += 1;
|
||||||
|
|
||||||
|
// delete the other fork of the history
|
||||||
|
for i in self.current_grid+1..self.grid_history.len() {
|
||||||
|
self.grid_history.remove(i);
|
||||||
|
}
|
||||||
|
|
||||||
action(&mut self.grid_history[self.current_grid]);
|
action(&mut self.grid_history[self.current_grid]);
|
||||||
|
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user