undo creating new drawings

This commit is contained in:
Kartik K. Agaram 2022-06-10 11:45:53 -07:00
parent fcacb6e63d
commit 79a1241370
2 changed files with 8 additions and 1 deletions

View File

@ -219,11 +219,13 @@ function App.draw()
button('draw', {x=4,y=y+4, w=12,h=12, color={1,1,0},
icon = icon.insert_drawing,
onpress1 = function()
Drawing.before = snapshot()
Drawing.before = snapshot(line_index-1, line_index)
table.insert(Lines, line_index, {mode='drawing', y=y, h=256/2, points={}, shapes={}, pending={}})
if Cursor1.line >= line_index then
Cursor1.line = Cursor1.line+1
end
save_to_disk(Lines, Filename)
record_undo_event({before=Drawing.before, after=snapshot(line_index-1, line_index+1)})
end})
if Search_term == nil then
if line_index == Cursor1.line then

View File

@ -42,6 +42,11 @@ function snapshot(s,e)
elseif e == nil then
e = s
end
assert(#Lines > 0)
if s < 1 then s = 1 end
if s > #Lines then s = #Lines end
if e < 1 then e = 1 end
if e > #Lines then e = #Lines end
-- compare with App.initialize_globals
local event = {
screen_top=deepcopy(Screen_top1),