about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2024-07-08 00:22:56 -0700
committerKartik K. Agaram <vc@akkartik.com>2024-07-08 00:24:14 -0700
commit0fcbe310a21dc581a29d22366e20629fc9e321ac (patch)
tree27205c6ec50480ae4c7748a8dd5f57b69efa848e
parent91a08eec2b39a38db9a6952a5701617da549d970 (diff)
downloadtext.love-0fcbe310a21dc581a29d22366e20629fc9e321ac.tar.gz
simplify some code now that lines contains no derived data
-rw-r--r--source_undo.lua10
-rw-r--r--undo.lua10
2 files changed, 2 insertions, 18 deletions
diff --git a/source_undo.lua b/source_undo.lua
index e5dea93..8f21a9c 100644
--- a/source_undo.lua
+++ b/source_undo.lua
@@ -57,16 +57,8 @@ function snapshot(State, s,e)
     end_line=e,
     -- no filename; undo history is cleared when filename changes
   }
-  -- deep copy lines without cached stuff like text fragments
   for i=s,e do
-    local line = State.lines[i]
-    if line.mode == 'text' then
-      table.insert(event.lines, {mode='text', data=line.data})  -- I've forgotten: should we deepcopy(line.data)?
-    elseif line.mode == 'drawing' then
-      table.insert(event.lines, {mode='drawing', h=line.h, points=deepcopy(line.points), shapes=deepcopy(line.shapes), pending={}})
-    else
-      assert(false, ('unknown line mode %s'):format(line.mode))
-    end
+    table.insert(event.lines, deepcopy(State.lines[i]))
   end
   return event
 end
diff --git a/undo.lua b/undo.lua
index e5dea93..8f21a9c 100644
--- a/undo.lua
+++ b/undo.lua
@@ -57,16 +57,8 @@ function snapshot(State, s,e)
     end_line=e,
     -- no filename; undo history is cleared when filename changes
   }
-  -- deep copy lines without cached stuff like text fragments
   for i=s,e do
-    local line = State.lines[i]
-    if line.mode == 'text' then
-      table.insert(event.lines, {mode='text', data=line.data})  -- I've forgotten: should we deepcopy(line.data)?
-    elseif line.mode == 'drawing' then
-      table.insert(event.lines, {mode='drawing', h=line.h, points=deepcopy(line.points), shapes=deepcopy(line.shapes), pending={}})
-    else
-      assert(false, ('unknown line mode %s'):format(line.mode))
-    end
+    table.insert(event.lines, deepcopy(State.lines[i]))
   end
   return event
 end