From 670886240f78314b9925e94e1814a8ade5fbaf3e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 2 Jun 2022 15:45:25 -0700 Subject: after much struggle, a brute-force undo Incredibly inefficient, but I don't yet know how to efficiently encode undo mutations that can span multiple lines. There seems to be one bug related to creating new drawings; they're not spawning events and undoing past drawing creation has some weird artifacts. Redo seems to consistently work, though. --- drawing.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drawing.lua') diff --git a/drawing.lua b/drawing.lua index 6b5b6c2..f3433a0 100644 --- a/drawing.lua +++ b/drawing.lua @@ -206,6 +206,7 @@ function Drawing.in_drawing(drawing, x,y) end function Drawing.mouse_pressed(drawing, x,y, button) + Drawing.before = snapshot_everything() if Current_drawing_mode == 'freehand' then drawing.pending = {mode=Current_drawing_mode, points={{x=Drawing.coord(x-16), y=Drawing.coord(y-drawing.y)}}} elseif Current_drawing_mode == 'line' or Current_drawing_mode == 'manhattan' then @@ -347,6 +348,7 @@ function Drawing.mouse_released(x,y, button) end end save_to_disk(Lines, Filename) + record_undo_event({before=Drawing.before, after=snapshot_everything()}) end function Drawing.keychord_pressed(chord) -- cgit 1.4.1-2-gfad0