about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-12 16:30:41 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-12 16:30:41 -0700
commitb7000215d8921490cb08ed64439a02e9f69770b5 (patch)
treeeadb4e2ba35d5448dda7fc31ddf98e1d069f3d0c
parente990b1be924126080404859d41c8b0e4f638951b (diff)
downloadtext.love-b7000215d8921490cb08ed64439a02e9f69770b5.tar.gz
add state arg to schedule_save
-rw-r--r--edit.lua24
-rw-r--r--main_tests.lua2
-rw-r--r--text.lua12
3 files changed, 19 insertions, 19 deletions
diff --git a/edit.lua b/edit.lua
index 537fbf8..d1cc2aa 100644
--- a/edit.lua
+++ b/edit.lua
@@ -138,7 +138,7 @@ function edit.draw(State)
                      if State.cursor1.line >= line_index then
                        State.cursor1.line = State.cursor1.line+1
                      end
-                     schedule_save()
+                     schedule_save(State)
                      record_undo_event({before=Drawing.before, after=snapshot(line_index-1, line_index+1)})
                    end
       })
@@ -183,9 +183,9 @@ function edit.update(State, dt)
   end
 end
 
-function schedule_save()
-  if Editor_state.next_save == nil then
-    Editor_state.next_save = App.getTime() + 3  -- short enough that you're likely to still remember what you did
+function schedule_save(State)
+  if State.next_save == nil then
+    State.next_save = App.getTime() + 3  -- short enough that you're likely to still remember what you did
   end
 end
 
@@ -240,7 +240,7 @@ function edit.mouse_released(State, x,y, mouse_button)
 --?   print('release')
   if State.lines.current_drawing then
     Drawing.mouse_released(State, x,y, mouse_button)
-    schedule_save()
+    schedule_save(State)
     if Drawing.before then
       record_undo_event({before=Drawing.before, after=snapshot(State.lines.current_drawing_index)})
       Drawing.before = nil
@@ -289,7 +289,7 @@ function edit.textinput(State, t)
   else
     Text.textinput(t)
   end
-  schedule_save()
+  schedule_save(State)
 end
 
 function edit.keychord_pressed(State, chord, key)
@@ -348,7 +348,7 @@ function edit.keychord_pressed(State, chord, key)
       State.selection1 = deepcopy(src.selection)
       patch(State.lines, event.after, event.before)
       Text.redraw_all()  -- if we're scrolling, reclaim all fragments to avoid memory leaks
-      schedule_save()
+      schedule_save(State)
     end
   elseif chord == 'C-y' then
     for _,line in ipairs(State.lines) do line.y = nil end  -- just in case we scroll
@@ -360,7 +360,7 @@ function edit.keychord_pressed(State, chord, key)
       State.selection1 = deepcopy(src.selection)
       patch(State.lines, event.before, event.after)
       Text.redraw_all()  -- if we're scrolling, reclaim all fragments to avoid memory leaks
-      schedule_save()
+      schedule_save(State)
     end
   -- clipboard
   elseif chord == 'C-c' then
@@ -375,7 +375,7 @@ function edit.keychord_pressed(State, chord, key)
     if s then
       App.setClipboardText(s)
     end
-    schedule_save()
+    schedule_save(State)
   elseif chord == 'C-v' then
     for _,line in ipairs(State.lines) do line.y = nil end  -- just in case we scroll
     -- We don't have a good sense of when to scroll, so we'll be conservative
@@ -394,7 +394,7 @@ function edit.keychord_pressed(State, chord, key)
     if Text.cursor_past_screen_bottom() then
       Text.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.height-State.margin_right)
     end
-    schedule_save()
+    schedule_save(State)
     record_undo_event({before=before, after=snapshot(before_line, State.cursor1.line)})
   -- dispatch to drawing or text
   elseif App.mouse_down(1) or chord:sub(1,2) == 'C-' then
@@ -404,7 +404,7 @@ function edit.keychord_pressed(State, chord, key)
       local before = snapshot(drawing_index)
       Drawing.keychord_pressed(State, chord)
       record_undo_event({before=before, after=snapshot(drawing_index)})
-      schedule_save()
+      schedule_save(State)
     end
   elseif chord == 'escape' and not App.mouse_down(1) then
     for _,line in ipairs(State.lines) do
@@ -431,7 +431,7 @@ function edit.keychord_pressed(State, chord, key)
         record_undo_event({before=before, after=snapshot(State.lines.current_drawing_index)})
       end
     end
-    schedule_save()
+    schedule_save(State)
   else
     for _,line in ipairs(State.lines) do line.y = nil end  -- just in case we scroll
     Text.keychord_pressed(State, chord)
diff --git a/main_tests.lua b/main_tests.lua
index 7b5c4e8..114f3c6 100644
--- a/main_tests.lua
+++ b/main_tests.lua
@@ -43,7 +43,7 @@ function test_drop_file_saves_previous()
   -- initially editing a file called foo that hasn't been saved to filesystem yet
   Editor_state.lines = load_array{'abc', 'def'}
   Editor_state.filename = 'foo'
-  schedule_save()
+  schedule_save(Editor_state)
   -- now drag a new file bar from the filesystem
   App.filesystem['bar'] = 'abc\ndef\nghi\n'
   local fake_dropped_file = {
diff --git a/text.lua b/text.lua
index fea9fb8..33ea0f1 100644
--- a/text.lua
+++ b/text.lua
@@ -167,7 +167,7 @@ function Text.keychord_pressed(State, chord)
     if (State.cursor_y + State.line_height) > App.screen.height then
       Text.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.width-State.margin_right)
     end
-    schedule_save()
+    schedule_save(State)
     record_undo_event({before=before, after=snapshot(before_line, State.cursor1.line)})
   elseif chord == 'tab' then
     local before = snapshot(State.cursor1.line)
@@ -178,12 +178,12 @@ function Text.keychord_pressed(State, chord)
       Text.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.width-State.margin_right)
 --?       print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
     end
-    schedule_save()
+    schedule_save(State)
     record_undo_event({before=before, after=snapshot(State.cursor1.line)})
   elseif chord == 'backspace' then
     if State.selection1.line then
       Text.delete_selection(State.margin_left, App.screen.width-State.margin_right)
-      schedule_save()
+      schedule_save(State)
       return
     end
     local before
@@ -219,12 +219,12 @@ function Text.keychord_pressed(State, chord)
     end
     Text.clear_cache(State.lines[State.cursor1.line])
     assert(Text.le1(State.screen_top1, State.cursor1))
-    schedule_save()
+    schedule_save(State)
     record_undo_event({before=before, after=snapshot(State.cursor1.line)})
   elseif chord == 'delete' then
     if State.selection1.line then
       Text.delete_selection(State.margin_left, App.screen.width-State.margin_right)
-      schedule_save()
+      schedule_save(State)
       return
     end
     local before
@@ -254,7 +254,7 @@ function Text.keychord_pressed(State, chord)
       end
     end
     Text.clear_cache(State.lines[State.cursor1.line])
-    schedule_save()
+    schedule_save(State)
     record_undo_event({before=before, after=snapshot(State.cursor1.line)})
   --== shortcuts that move the cursor
   elseif chord == 'left' then