consistently schedule_save after all mutations

This commit is contained in:
Kartik K. Agaram 2024-07-16 21:32:13 -07:00
parent 57deb762f0
commit c7c54a00b6
4 changed files with 15 additions and 15 deletions

View File

@ -184,8 +184,8 @@ function edit.draw(State)
if State.cursor1.line >= line_index then
State.cursor1.line = State.cursor1.line+1
end
schedule_save(State)
record_undo_event(State, {before=Drawing.before, after=snapshot(State, line_index-1, line_index+1)})
schedule_save(State)
end,
})
end
@ -295,11 +295,11 @@ function edit.mouse_release(State, x,y, mouse_button)
State.mouse_down = nil
if State.lines.current_drawing then
Drawing.mouse_release(State, x,y, mouse_button)
schedule_save(State)
if Drawing.before then
record_undo_event(State, {before=Drawing.before, after=snapshot(State, State.lines.current_drawing_index)})
Drawing.before = nil
end
schedule_save(State)
else
--? print_and_log('edit.mouse_release: no current drawing')
if y < State.top then
@ -490,8 +490,8 @@ function edit.keychord_press(State, chord, key)
if Text.cursor_out_of_screen(State) then
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
end
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
schedule_save(State)
-- dispatch to drawing or text
elseif App.mouse_down(1) or chord:sub(1,2) == 'C-' then
local drawing_index, drawing = Drawing.current_drawing(State)

View File

@ -189,8 +189,8 @@ function edit.draw(State, hide_cursor, show_line_numbers)
if State.cursor1.line >= line_index then
State.cursor1.line = State.cursor1.line+1
end
schedule_save(State)
record_undo_event(State, {before=Drawing.before, after=snapshot(State, line_index-1, line_index+1)})
schedule_save(State)
end,
})
end
@ -299,11 +299,11 @@ function edit.mouse_release(State, x,y, mouse_button)
State.mouse_down = nil
if State.lines.current_drawing then
Drawing.mouse_release(State, x,y, mouse_button)
schedule_save(State)
if Drawing.before then
record_undo_event(State, {before=Drawing.before, after=snapshot(State, State.lines.current_drawing_index)})
Drawing.before = nil
end
schedule_save(State)
else
--? print_and_log('edit.mouse_release: no current drawing')
if y < State.top then
@ -491,8 +491,8 @@ function edit.keychord_press(State, chord, key)
if Text.cursor_out_of_screen(State) then
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
end
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
schedule_save(State)
-- dispatch to drawing or text
elseif App.mouse_down(1) or chord:sub(1,2) == 'C-' then
local drawing_index, drawing = Drawing.current_drawing(State)

View File

@ -234,8 +234,8 @@ function Text.keychord_press(State, chord)
if State.cursor_y > App.screen.height - State.line_height then
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
end
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
schedule_save(State)
elseif chord == 'tab' then
local before = snapshot(State, State.cursor1.line)
--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
@ -245,8 +245,8 @@ function Text.keychord_press(State, chord)
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
end
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)})
schedule_save(State)
elseif chord == 'backspace' then
if State.selection1.line then
Text.delete_selection(State, State.left, State.right)
@ -293,8 +293,8 @@ function Text.keychord_press(State, chord)
end
Text.clear_screen_line_cache(State, State.cursor1.line)
assert(Text.le1(State.screen_top1, State.cursor1), ('screen_top (line=%d,pos=%d) is below cursor (line=%d,pos=%d)'):format(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos))
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)})
schedule_save(State)
elseif chord == 'delete' then
if State.selection1.line then
Text.delete_selection(State, State.left, State.right)
@ -327,8 +327,8 @@ function Text.keychord_press(State, chord)
table.remove(State.line_cache, State.cursor1.line+1)
end
Text.clear_screen_line_cache(State, State.cursor1.line)
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)})
schedule_save(State)
--== shortcuts that move the cursor
elseif chord == 'left' then
Text.left(State)

View File

@ -151,7 +151,7 @@ end
-- Don't handle any keys here that would trigger text_input above.
function Text.keychord_press(State, chord)
--? print('chord', chord, State.selection1.line, State.selection1.pos)
--== shortcuts that mutate text
--== shortcuts that mutate text (must schedule_save)
if chord == 'return' then
local before_line = State.cursor1.line
local before = snapshot(State, before_line)
@ -160,8 +160,8 @@ function Text.keychord_press(State, chord)
if State.cursor_y > App.screen.height - State.line_height then
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
end
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
schedule_save(State)
elseif chord == 'tab' then
local before = snapshot(State, State.cursor1.line)
--? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
@ -171,8 +171,8 @@ function Text.keychord_press(State, chord)
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
--? print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
end
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)})
schedule_save(State)
elseif chord == 'backspace' then
if State.selection1.line then
Text.delete_selection(State, State.left, State.right)
@ -219,8 +219,8 @@ function Text.keychord_press(State, chord)
end
Text.clear_screen_line_cache(State, State.cursor1.line)
assert(Text.le1(State.screen_top1, State.cursor1), ('screen_top (line=%d,pos=%d) is below cursor (line=%d,pos=%d)'):format(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos))
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)})
schedule_save(State)
elseif chord == 'delete' then
if State.selection1.line then
Text.delete_selection(State, State.left, State.right)
@ -253,8 +253,8 @@ function Text.keychord_press(State, chord)
table.remove(State.line_cache, State.cursor1.line+1)
end
Text.clear_screen_line_cache(State, State.cursor1.line)
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, State.cursor1.line)})
schedule_save(State)
--== shortcuts that move the cursor
elseif chord == 'left' then
Text.left(State)