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
+0200 add Apple Silicon to supporting platforms (#18772)' href='/ahoang/Nim/commit/readme.md?h=devel&id=3469f3a39320cf35d02d11b78c7db0be79e992f8'>3469f3a39 ^
57dc4ca22 ^
ae8eb1ec3 ^
03b05bd34 ^
a16e6bd22 ^
1a7fdb09d ^



93f74e4f9 ^
dce0b3b00 ^
a16e6bd22 ^
03b05bd34 ^
a16e6bd22 ^
03b05bd34 ^



9e170f115 ^
93f74e4f9 ^
d60fae576 ^




ae8eb1ec3 ^
823b3c250 ^
03b05bd34 ^
ae8eb1ec3 ^
a16e6bd22 ^
86c65db18 ^
f97decaa2 ^


93f74e4f9 ^
c3229dc1c ^
6b302bb71 ^
dbcffcfcc ^
bc9749310 ^
3c870d3bb ^

dbcffcfcc ^
506418ef5 ^
ae8eb1ec3 ^
506418ef5 ^
dbcffcfcc ^

506418ef5 ^
ae8eb1ec3 ^
03b05bd34 ^
a16e6bd22 ^
51b71e35f ^
fe7a2d60f ^
9fc291831 ^

03b05bd34 ^
c3229dc1c ^
03b05bd34 ^

93f74e4f9 ^
a16e6bd22 ^
03b05bd34 ^
1a7fdb09d ^
93f74e4f9 ^
03b05bd34 ^
49d810f34 ^
03b05bd34 ^

ae0e5604f ^
49d810f34 ^
46ee026e7 ^
f97decaa2 ^

342834d7f ^


da4215af6 ^
0fff332b8 ^
342834d7f ^
46ee026e7 ^
c3229dc1c ^
c8da41721 ^
03b05bd34 ^

510392bc6 ^
46ee026e7 ^
da4215af6 ^
11a664dfb ^



46ee026e7 ^

03b05bd34 ^
3cef2129b ^
93f74e4f9 ^
46ee026e7 ^

03b05bd34 ^
46ee026e7 ^
03b05bd34 ^

ae8eb1ec3 ^
03b05bd34 ^


ae8eb1ec3 ^
03b05bd34 ^




229a62384 ^
03b05bd34 ^
a55b90827 ^
03b05bd34 ^

da2fd42e6 ^
03b05bd34 ^

229a62384 ^
03b05bd34 ^




342834d7f ^
03b05bd34 ^




a16e6bd22 ^
342834d7f ^


6b38b37b4 ^
342834d7f ^


















6b38b37b4 ^
342834d7f ^
a16e6bd22 ^
03b05bd34 ^
ae8eb1ec3 ^
03b05bd34 ^


1a7fdb09d ^
03b05bd34 ^
40a9c33ef ^
03b05bd34 ^




908b2cc2e ^
03b05bd34 ^
b67dea7a3 ^

9c34d6ee0 ^
03b05bd34 ^
83a9c3ba3 ^

60d437427 ^
03b05bd34 ^



dce0b3b00 ^

03b05bd34 ^
528069a96 ^
03b05bd34 ^



03b05bd34 ^

03b05bd34 ^
d1cf04a38 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236