about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-11 20:47:04 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-11 20:47:04 -0700
commite51ce129696320b729506a2c3f7c76bba402924e (patch)
tree58a9191c94c3e592c02aed0009cfce8a3ae39c02 /main.lua
parent24a0d162ef8c1889b40853d212b2ed852dc3afb6 (diff)
downloadtext.love-e51ce129696320b729506a2c3f7c76bba402924e.tar.gz
bugfix: autosave and undo in a couple of cases
This fixes part of #4, but not the BSOD.
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua6
1 files changed, 6 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index 83280ae..b3e0483 100644
--- a/main.lua
+++ b/main.lua
@@ -448,7 +448,11 @@ function App.keychord_pressed(chord)
   -- dispatch to drawing or text
   elseif love.mouse.isDown('1') or chord:sub(1,2) == 'C-' then
     -- DON'T reset line.y here
+    local drawing_index, drawing = Drawing.current_drawing()
+    local before = snapshot(drawing_index)
     Drawing.keychord_pressed(chord)
+    record_undo_event({before=before, after=snapshot(drawing_index)})
+    save_to_disk(Lines, Filename)
   elseif chord == 'escape' and love.mouse.isDown('1') then
     local _,drawing = Drawing.current_drawing()
     if drawing then
@@ -465,6 +469,7 @@ function App.keychord_pressed(chord)
       Current_drawing_mode = Previous_drawing_mode
       Previous_drawing_mode = nil
     else
+      local before = snapshot(Lines.current_drawing_index)
       local drawing = Lines.current_drawing
       local p = drawing.points[drawing.pending.target_point]
       if chord == 'escape' then
@@ -474,6 +479,7 @@ function App.keychord_pressed(chord)
         local byte_offset = utf8.offset(p.name, len-1)
         p.name = string.sub(p.name, 1, byte_offset)
       end
+      record_undo_event({before=before, after=snapshot(Lines.current_drawing_index)})
     end
     save_to_disk(Lines, Filename)
   else