about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-09-17 09:24:52 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-09-17 09:24:52 -0700
commit5c5a8a88abab1a5e3c68888d156bf539f2a743fa (patch)
treeee90ad127879a529e8cbd22673ae987b661ccd7d
parente1168f4eff674c2571746aefcc438ed77d5e2941 (diff)
parentc43d884b6ffb94803bee9f9e788e4b3a2f74f23b (diff)
downloadtext.love-5c5a8a88abab1a5e3c68888d156bf539f2a743fa.tar.gz
Merge lines.love
-rw-r--r--source_edit.lua29
1 files changed, 20 insertions, 9 deletions
diff --git a/source_edit.lua b/source_edit.lua
index 506aa41..310853a 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -111,10 +111,11 @@ function edit.check_locs(State)
   -- if State is inconsistent (i.e. file changed by some other program),
   --   throw away all cursor state entirely
   if edit.invalid1(State, State.screen_top1)
-      or edit.invalid1(State, State.cursor1)
+      or edit.invalid_cursor1(State)
       or not edit.cursor_on_text(State)
       or not Text.le1(State.screen_top1, State.cursor1) then
     State.screen_top1 = {line=1, pos=1}
+    State.cursor1 = {line=1, pos=1}
     edit.put_cursor_on_next_text_line(State)
   end
 end
@@ -126,6 +127,16 @@ function edit.invalid1(State, loc1)
   return loc1.pos > #State.lines[loc1.line].data
 end
 
+-- cursor loc in particular differs from other locs in one way:
+-- pos might occur just after end of line
+function edit.invalid_cursor1(State)
+  local cursor1 = State.cursor1
+  if cursor1.line > #State.lines then return true end
+  local l = State.lines[cursor1.line]
+  if l.mode ~= 'text' then return false end  -- pos is irrelevant to validity for a drawing line
+  return cursor1.pos > #State.lines[cursor1.line].data + 1
+end
+
 function edit.cursor_on_text(State)
   return State.cursor1.line <= #State.lines
       and State.lines[State.cursor1.line].mode == 'text'
@@ -133,14 +144,14 @@ end
 
 function edit.put_cursor_on_next_text_line(State)
   while true do
-  if State.cursor1.line >= #State.lines then
-    break
-  end
-  if State.lines[State.cursor1.line].mode == 'text' then
-    break
-  end
-  State.cursor1.line = State.cursor1.line+1
-  State.cursor1.pos = 1
+    if State.cursor1.line >= #State.lines then
+      break
+    end
+    if State.lines[State.cursor1.line].mode == 'text' then
+      break
+    end
+    State.cursor1.line = State.cursor1.line+1
+    State.cursor1.pos = 1
   end
 end
 
m <vc@akkartik.com> 2022-06-10 11:48:32 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2022-06-10 11:48:32 -0700 stop saving the entire file when modifying drawings' href='/akkartik/text.love/commit/undo.lua?id=c875f7be46d76650e1c6a16668f77df7227d57d3'>c875f7b ^
4f76ea3 ^

007b965 ^
79a1241 ^
5b91af1 ^
79a1241 ^
5b91af1 ^
6708862 ^

5b91af1 ^


6708862 ^
5b91af1 ^
6708862 ^
4f76ea3 ^

6708862 ^

4f76ea3 ^
0fcbe31 ^
6708862 ^



4f76ea3 ^







007b965 ^
4f76ea3 ^


007b965 ^
4f76ea3 ^




6708862 ^











4f76ea3 ^



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