From 53dcf2ffc94144c4846c675f02e327f7636d1b24 Mon Sep 17 00:00:00 2001 From: Rushmore75 Date: Fri, 6 Feb 2026 17:04:12 -0700 Subject: [PATCH] mock up history --- src/app/logic/calc.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app/logic/calc.rs b/src/app/logic/calc.rs index 4ad249b..3a59a16 100644 --- a/src/app/logic/calc.rs +++ b/src/app/logic/calc.rs @@ -236,12 +236,27 @@ impl 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(&mut self, mut action: F) where F: FnMut(&mut CellGrid) -> (), { - let old = self.get_grid().clone(); - self.grid_history.push(old); + // push on a new reality + 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]); self.dirty = true;