This commit is contained in:
Kartik K. Agaram 2022-06-02 16:44:18 -07:00
parent 477216a051
commit 22817492a3
4 changed files with 16 additions and 16 deletions

View File

@ -206,7 +206,7 @@ function Drawing.in_drawing(drawing, x,y)
end
function Drawing.mouse_pressed(drawing, x,y, button)
Drawing.before = snapshot_everything()
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
@ -349,7 +349,7 @@ function Drawing.mouse_released(x,y, button)
end
save_to_disk(Lines, Filename)
if Drawing.before then
record_undo_event({before=Drawing.before, after=snapshot_everything()})
record_undo_event({before=Drawing.before, after=snapshot()})
Drawing.before = nil
end
end

View File

@ -142,7 +142,7 @@ 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_everything()
Drawing.before = snapshot()
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

View File

@ -1250,7 +1250,7 @@ end
function Text.insert_at_cursor(t)
if Selection1.line then Text.delete_selection() end
-- Collect what you did in an event that can be undone.
local before = snapshot_everything()
local before = snapshot()
local byte_offset
if Cursor1.pos > 1 then
byte_offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos)
@ -1262,7 +1262,7 @@ function Text.insert_at_cursor(t)
Lines[Cursor1.line].screen_line_starting_pos = nil
Cursor1.pos = Cursor1.pos+1
-- finalize undo event
record_undo_event({before=before, after=snapshot_everything()})
record_undo_event({before=before, after=snapshot()})
end
-- Don't handle any keys here that would trigger love.textinput above.
@ -1270,7 +1270,7 @@ function Text.keychord_pressed(chord)
--? print(chord)
--== shortcuts that mutate text
if chord == 'return' then
local before = snapshot_everything()
local before = snapshot()
local byte_offset = utf8.offset(Lines[Cursor1.line].data, Cursor1.pos)
table.insert(Lines, Cursor1.line+1, {mode='text', data=string.sub(Lines[Cursor1.line].data, byte_offset)})
local scroll_down = (Cursor_y + math.floor(15*Zoom)) > App.screen.height
@ -1283,18 +1283,18 @@ function Text.keychord_pressed(chord)
Screen_top1.line = Cursor1.line
Text.scroll_up_while_cursor_on_screen()
end
record_undo_event({before=before, after=snapshot_everything()})
record_undo_event({before=before, after=snapshot()})
elseif chord == 'tab' then
local before = snapshot_everything()
local before = snapshot()
Text.insert_at_cursor('\t')
save_to_disk(Lines, Filename)
record_undo_event({before=before, after=snapshot_everything()})
record_undo_event({before=before, after=snapshot()})
elseif chord == 'backspace' then
local before = snapshot_everything()
local before = snapshot()
if Selection1.line then
Text.delete_selection()
save_to_disk(Lines, Filename)
record_undo_event({before=before, after=snapshot_everything()})
record_undo_event({before=before, after=snapshot()})
return
end
if Cursor1.pos > 1 then
@ -1328,13 +1328,13 @@ function Text.keychord_pressed(chord)
end
assert(Text.le1(Screen_top1, Cursor1))
save_to_disk(Lines, Filename)
record_undo_event({before=before, after=snapshot_everything()})
record_undo_event({before=before, after=snapshot()})
elseif chord == 'delete' then
local before = snapshot_everything()
local before = snapshot()
if Selection1.line then
Text.delete_selection()
save_to_disk(Lines, Filename)
record_undo_event({before=before, after=snapshot_everything()})
record_undo_event({before=before, after=snapshot()})
return
end
if Cursor1.pos <= utf8.len(Lines[Cursor1.line].data) then
@ -1360,7 +1360,7 @@ function Text.keychord_pressed(chord)
end
end
save_to_disk(Lines, Filename)
record_undo_event({before=before, after=snapshot_everything()})
record_undo_event({before=before, after=snapshot()})
-- undo/redo really belongs in main.lua, but it's here so I can test the
-- text-specific portions of it
elseif chord == 'M-z' then

View File

@ -33,7 +33,7 @@ function redo_event()
end
-- Make copies of objects; the rest of the app may mutate them in place, but undo requires immutable histories.
function snapshot_everything()
function snapshot()
-- compare with App.initialize_globals
local event = {
screen_top=deepcopy(Screen_top1),