about summary refs log tree commit diff stats
path: root/edit.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2024-10-29 15:43:35 -0700
committerKartik K. Agaram <vc@akkartik.com>2024-10-29 15:58:00 -0700
commitc1a3616964bfdeb11144c0e7289fc16ba563e84a (patch)
tree18a6b93c13b61070de189527a4357bfb4c2d9893 /edit.lua
parent1609d79516b2e8f790648fd67614d9edb9c2e24c (diff)
downloadview.love-c1a3616964bfdeb11144c0e7289fc16ba563e84a.tar.gz
bugfix in search UI
This one is ancient and it affects every single one of my forks,
including the whole lines2 lineage. The corner case: searching for empty
string.

In the process I've also cleaned up edit.check_locs on initialization to
only modify cursor if it can find a legal place for it.

In general I should be more careful about mutating the cursor. Just
adding 1 to it is irresponsible.
Diffstat (limited to 'edit.lua')
-rw-r--r--edit.lua33
1 files changed, 27 insertions, 6 deletions
diff --git a/edit.lua b/edit.lua
index 551db10..9e80cc3 100644
--- a/edit.lua
+++ b/edit.lua
@@ -140,15 +140,36 @@ function edit.cursor_on_text(State)
 end
 
 function edit.put_cursor_on_next_text_line(State)
-  while true do
-    if State.cursor1.line >= #State.lines then
+  local line = State.cursor1.line
+  while line < #State.lines do
+    line = line+1
+    if State.lines[line].mode == 'text' then
+      State.cursor1.line = line
+      State.cursor1.pos = 1
       break
     end
-    if State.lines[State.cursor1.line].mode == 'text' then
+  end
+end
+
+function edit.put_cursor_on_next_text_line_wrapping_around_if_necessary(State)
+  local line = State.cursor1.line
+  local max = #State.lines
+  for _ = 1, max-1 do
+    line = (line+1) % max
+    if State.lines[line].mode == 'text' then
+      State.cursor1.line = line
+      State.cursor1.pos = 1
       break
     end
-    State.cursor1.line = State.cursor1.line+1
-    State.cursor1.pos = 1
+  end
+end
+
+function edit.put_cursor_on_next_text_loc_wrapping_around_if_necessary(State)
+  local cursor_line = State.lines[State.cursor1.line].data
+  if State.cursor1.pos <= utf8.len(cursor_line) then
+    State.cursor1.pos = State.cursor1.pos + 1
+  else
+    edit.put_cursor_on_next_text_line_wrapping_around_if_necessary(State)
   end
 end
 
@@ -405,7 +426,7 @@ function edit.keychord_press(State, chord, key)
       State.screen_top = deepcopy(State.search_backup.screen_top)
       Text.search_next(State)
     elseif chord == 'down' then
-      State.cursor1.pos = State.cursor1.pos+1
+      edit.put_cursor_on_next_text_loc_wrapping_around_if_necessary(State)
       Text.search_next(State)
     elseif chord == 'up' then
       Text.search_previous(State)
u/blame/html/000organization.cc.html?h=hlt&id=8846a7f85cc04b77b2fe8a67b6d317723437b00c'>^
ac07e589 ^
ac07e589 ^

6e1eeeeb ^
672e3e50 ^

a654e4ec ^



e5c11a51 ^









6e1eeeeb ^
e5c11a51 ^











a654e4ec ^

672e3e50 ^
e5c11a51 ^
c8a3ccbe ^
a654e4ec ^
204dae92 ^
















































































84ca523f ^



204dae92 ^
36f616b5 ^


bb1a1ac2 ^






























6e1eeeeb ^
bb1a1ac2 ^



204dae92 ^
bb1a1ac2 ^





































672e3e50 ^


a654e4ec ^
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