From c875f7be46d76650e1c6a16668f77df7227d57d3 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 10 Jun 2022 11:48:32 -0700 Subject: [PATCH] stop saving the entire file when modifying drawings Now we just disallow that entirely. --- drawing.lua | 7 ------- main.lua | 8 ++++++++ undo.lua | 6 ++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/drawing.lua b/drawing.lua index acec83b..25fde99 100644 --- a/drawing.lua +++ b/drawing.lua @@ -206,7 +206,6 @@ function Drawing.in_drawing(drawing, x,y) end function Drawing.mouse_pressed(drawing, x,y, button) - Drawing.before = snapshot() 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 @@ -226,7 +225,6 @@ function Drawing.mouse_pressed(drawing, x,y, button) print(Current_drawing_mode) assert(false) end - Lines.current_drawing = drawing end -- a couple of operations on drawings need to constantly check the state of the mouse @@ -348,11 +346,6 @@ function Drawing.mouse_released(x,y, button) Lines.current_drawing = nil end end - save_to_disk(Lines, Filename) - if Drawing.before then - record_undo_event({before=Drawing.before, after=snapshot()}) - Drawing.before = nil - end end function Drawing.keychord_pressed(chord) diff --git a/main.lua b/main.lua index 53751bb..ddde651 100644 --- a/main.lua +++ b/main.lua @@ -290,6 +290,9 @@ function App.mousepressed(x,y, mouse_button) end elseif line.mode == 'drawing' then if Drawing.in_drawing(line, x, y) then + Lines.current_drawing_index = line_index + Lines.current_drawing = line + Drawing.before = snapshot(line_index) Drawing.mouse_pressed(line, x,y, button) end end @@ -300,6 +303,11 @@ function App.mousereleased(x,y, button) if Search_term then return end if Lines.current_drawing then Drawing.mouse_released(x,y, button) + save_to_disk(Lines, Filename) + if Drawing.before then + record_undo_event({before=Drawing.before, after=snapshot(Lines.current_drawing_index)}) + Drawing.before = nil + end else for line_index,line in ipairs(Lines) do if line.mode == 'text' then diff --git a/undo.lua b/undo.lua index 3007070..3504577 100644 --- a/undo.lua +++ b/undo.lua @@ -36,10 +36,8 @@ end -- Make copies of objects; the rest of the app may mutate them in place, but undo requires immutable histories. function snapshot(s,e) -- Snapshot everything by default, but subset if requested. - if s == nil and e == nil then - s = 1 - e = #Lines - elseif e == nil then + assert(s) + if e == nil then e = s end assert(#Lines > 0)