about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--source_edit.lua27
-rw-r--r--source_text.lua1
2 files changed, 17 insertions, 11 deletions
diff --git a/source_edit.lua b/source_edit.lua
index 606b913..2fc7e1b 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -123,8 +123,10 @@ function edit.check_locs(State)
 end
 
 function edit.invalid1(State, loc1)
-  return loc1.line > #State.lines
-      or loc1.pos > #State.lines[loc1.line].data
+  if loc1.line > #State.lines then return true end
+  local l = State.lines[loc1.line]
+  if l.mode ~= 'text' then return false end  -- pos is irrelevant to validity for a drawing line
+  return loc1.pos > #State.lines[loc1.line].data
 end
 
 function edit.cursor_on_text(State)
@@ -169,7 +171,7 @@ function edit.draw(State, hide_cursor)
       end
       if line.data == '' then
         -- button to insert new drawing
-        button(State, 'draw', {x=4,y=y+4, w=12,h=12, color={1,1,0},
+        button(State, 'draw', {x=State.left-Margin_left+4, y=y+4, w=12,h=12, color={1,1,0},
           icon = icon.insert_drawing,
           onpress1 = function()
                        Drawing.before = snapshot(State, line_index-1, line_index)
@@ -225,7 +227,7 @@ end
 
 function edit.mouse_press(State, x,y, mouse_button)
   if State.search_term then return end
---?   print('press', State.selection1.line, State.selection1.pos)
+--?   print('press', State.cursor1.line)
   if mouse_press_consumed_by_any_button_handler(State, x,y, mouse_button) then
     -- press on a button and it returned 'true' to short-circuit
     return
@@ -268,7 +270,7 @@ end
 
 function edit.mouse_release(State, x,y, mouse_button)
   if State.search_term then return end
---?   print('release')
+--?   print('release', State.cursor1.line)
   if State.lines.current_drawing then
     Drawing.mouse_release(State, x,y, mouse_button)
     schedule_save(State)
@@ -320,11 +322,12 @@ function edit.mouse_wheel_move(State, dx,dy)
 end
 
 function edit.text_input(State, t)
+--?   print('text input', t)
   if State.search_term then
     State.search_term = State.search_term..t
     State.search_text = nil
     Text.search_next(State)
-  elseif State.current_drawing_mode == 'name' then
+  elseif State.lines.current_drawing and State.current_drawing_mode == 'name' then
     local before = snapshot(State, State.lines.current_drawing_index)
     local drawing = State.lines.current_drawing
     local p = drawing.points[drawing.pending.target_point]
@@ -477,7 +480,7 @@ function edit.keychord_press(State, chord, key)
         line.show_help = false
       end
     end
-  elseif State.current_drawing_mode == 'name' then
+  elseif State.lines.current_drawing and State.current_drawing_mode == 'name' then
     if chord == 'return' then
       State.current_drawing_mode = State.previous_drawing_mode
       State.previous_drawing_mode = nil
@@ -490,10 +493,12 @@ function edit.keychord_press(State, chord, key)
         record_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})
       elseif chord == 'backspace' then
         local len = utf8.len(p.name)
-        local byte_offset = Text.offset(p.name, len-1)
-        if len == 1 then byte_offset = 0 end
-        p.name = string.sub(p.name, 1, byte_offset)
-        record_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})
+        if len > 0 then
+          local byte_offset = Text.offset(p.name, len-1)
+          if len == 1 then byte_offset = 0 end
+          p.name = string.sub(p.name, 1, byte_offset)
+          record_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})
+        end
       end
     end
     schedule_save(State)
diff --git a/source_text.lua b/source_text.lua
index fb4c389..4d13748 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -178,6 +178,7 @@ function Text.text_input(State, t)
 end
 
 function Text.insert_at_cursor(State, t)
+  assert(State.lines[State.cursor1.line].mode == 'text')
   local byte_offset = Text.offset(State.lines[State.cursor1.line].data, State.cursor1.pos)
   State.lines[State.cursor1.line].data = string.sub(State.lines[State.cursor1.line].data, 1, byte_offset-1)..t..string.sub(State.lines[State.cursor1.line].data, byte_offset)
   Text.clear_screen_line_cache(State, State.cursor1.line)
0e070e21a3293'>b24eb476 ^
3473c63a ^
f6c7b415 ^
3377364a ^
b24eb476 ^
3473c63a ^
067c8ed6 ^
37421f8a ^





37421f8a ^
af023b32 ^
b24eb476 ^


3473c63a ^
37e71785 ^
37421f8a ^


3adc9e08 ^
37421f8a ^



37421f8a ^
af023b32 ^

b24eb476 ^
3473c63a ^
05331766 ^
37e71785 ^
af023b32 ^
37421f8a ^




















1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^













1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^




37e71785 ^




1ead3562 ^
37e71785 ^

1ead3562 ^
37e71785 ^

1ead3562 ^
37e71785 ^




37421f8a ^



1ead3562 ^
37421f8a ^







1ead3562 ^
37421f8a ^






1ead3562 ^
37421f8a ^




1ead3562 ^
b0bf5321 ^

1ead3562 ^
37421f8a ^




1ead3562 ^
b0bf5321 ^





37421f8a ^





1ead3562 ^
b0bf5321 ^


1ead3562 ^
37421f8a ^
b0bf5321 ^

1ead3562 ^
37421f8a ^













1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^








b0bf5321 ^
37421f8a ^
1ead3562 ^
b0bf5321 ^


37421f8a ^
1ead3562 ^
b0bf5321 ^


37421f8a ^
1ead3562 ^
37421f8a ^














1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^













1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^

1ead3562 ^
37421f8a ^









1ead3562 ^
b0bf5321 ^


bff0fa45 ^
37421f8a ^









8d72e565 ^
37421f8a ^

d5fe534d ^
9dcbec39 ^
d5fe534d ^




37421f8a ^
d5fe534d ^


b24eb476 ^
d5fe534d ^












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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381