about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-06-03 10:36:05 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-06-03 10:36:05 -0700
commit3114176ebd5b9895b5f67c759a2a705f673a4ac0 (patch)
treef8a6a60a8cd0165f5aa7b70fea1c267f469fcca6
parent541519a9986fe5c85d6b03fc8cf993ba8e950b0c (diff)
downloadlines.love-3114176ebd5b9895b5f67c759a2a705f673a4ac0.tar.gz
change how we handle clicks above top margin
-rw-r--r--app.lua1
-rw-r--r--edit.lua11
-rw-r--r--select.lua3
-rw-r--r--text_tests.lua43
4 files changed, 34 insertions, 24 deletions
diff --git a/app.lua b/app.lua
index 1d4a72b..584b17b 100644
--- a/app.lua
+++ b/app.lua
@@ -361,6 +361,7 @@ function App.run_tests()
   for _,name in ipairs(sorted_names) do
     App.initialize_for_test()
 --?     print('=== '..name)
+--?     _G[name]()
     xpcall(_G[name], function(err) prepend_debug_info_to_test_failure(name, err) end)
   end
   -- clean up all test methods
diff --git a/edit.lua b/edit.lua
index 3e92a54..ddd17c1 100644
--- a/edit.lua
+++ b/edit.lua
@@ -227,6 +227,17 @@ function edit.mouse_press(State, x,y, mouse_button)
     return
   end
 
+  if y < State.top then
+    State.old_cursor1 = State.cursor1
+    State.old_selection1 = State.selection1
+    State.mousepress_shift = App.shift_down()
+    State.selection1 = {
+        line=1,
+        pos=1,
+    }
+    return
+  end
+
   for line_index,line in ipairs(State.lines) do
     if line.mode == 'text' then
       if Text.in_line(State, line_index, x,y) then
diff --git a/select.lua b/select.lua
index dbd551b..c2fe7ad 100644
--- a/select.lua
+++ b/select.lua
@@ -74,6 +74,9 @@ function Text.mouse_pos(State)
 end
 
 function Text.to_pos(State, x,y)
+  if y < State.line_cache[State.screen_top1.line].starty then
+    return State.screen_top1.line, State.screen_top1.pos
+  end
   for line_index,line in ipairs(State.lines) do
     if line.mode == 'text' then
       if Text.in_line(State, line_index, x,y) then
diff --git a/text_tests.lua b/text_tests.lua
index eec3098..d5368a8 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -1,4 +1,6 @@
 -- major tests for text editing flows
+-- Arguably this should be called edit_tests.lua,
+-- but that would mess up the git blame at this point.
 
 function test_initial_state()
   App.screen.init{width=120, height=60}
@@ -828,6 +830,23 @@ function test_select_text_using_mouse()
   check_eq(Editor_state.cursor1.pos, 4, 'cursor:pos')
 end
 
+function test_select_text_using_mouse_starting_above_text()
+  App.screen.init{width=50, height=60}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc', 'def', 'xyz'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=1}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  Editor_state.selection1 = {}
+  edit.draw(Editor_state)  -- populate line_cache.starty for each line Editor_state.line_cache
+  -- press mouse above first line of text
+  edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
+  check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
+  check_eq(Editor_state.selection1.line, 1, 'selection:line')
+  check_eq(Editor_state.selection1.pos, 1, 'selection:pos')
+end
+
 function test_select_text_using_mouse_and_shift()
   App.screen.init{width=50, height=60}
   Editor_state = edit.initialize_test_state()
@@ -904,30 +923,6 @@ function test_select_all_text()
   check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos')
 end
 
---? function test_select_all_text_then_mouse_press_outside_text()
---?   -- display a single line of text
---?   App.screen.init{width=75, height=80}
---?   Editor_state = edit.initialize_test_state()
---?   Editor_state.lines = load_array{'abc def'}
---?   Text.redraw_all(Editor_state)
---?   Editor_state.cursor1 = {line=1, pos=1}
---?   Editor_state.screen_top1 = {line=1, pos=1}
---?   Editor_state.screen_bottom1 = {}
---?   edit.draw(Editor_state)
---?   -- select all
---?   App.fake_key_press('lctrl')
---?   edit.run_after_keychord(Editor_state, 'C-a')
---?   App.fake_key_release('lctrl')
---?   edit.key_release(Editor_state, 'lctrl')
---?   -- selection
---?   check_eq(Editor_state.selection1.line, 1, 'selection:line')
---?   check_eq(Editor_state.selection1.pos, 1, 'selection:pos')
---?   check_eq(Editor_state.cursor1.line, 1, 'cursor:line')
---?   check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos')
---?   -- part of a mouse click outside the selected line
---?   edit.run_after_mouse_press(Editor_state, 45, Margin_top + Editor_state.line_height + 10, --[[mouse button]] 1)
---? end
-
 function test_cut_without_selection()
   -- display a few lines
   App.screen.init{width=Editor_state.left+30, height=60}
om> 2015-11-28 23:58:43 -0800 committer Kartik K. Agaram <vc@akkartik.com> 2015-11-28 23:58:43 -0800 2504 - support to-text in 'stash'' href='/akkartik/mu/commit/042name.cc?h=main&id=67bc24e7e283cba3aebd37f7282b9ee1f146d8c8'>67bc24e7 ^
ce2b0aec ^

b24eb476 ^
de49fb42 ^
b24eb476 ^
de49fb42 ^
b24eb476 ^
67bc24e7 ^
dd2e01e4 ^
06b3eb96 ^
b24eb476 ^
e06dbec0 ^
ce2b0aec ^

83d8299d ^
ce2b0aec ^
1b76245c ^
80b781cc ^
b24eb476 ^
1e38eee5 ^






80b781cc ^
b24eb476 ^
e06dbec0 ^
ce2b0aec ^

83d8299d ^
ce2b0aec ^
dd2e01e4 ^
ce2b0aec ^

80b781cc ^
b24eb476 ^
1e38eee5 ^






80b781cc ^

53188dd7 ^
1b76245c ^
ce2b0aec ^

e06dbec0 ^
c6034af3 ^
e06dbec0 ^
acc4792d ^
235958e8 ^

ce2b0aec ^
ab6ed192 ^
e06dbec0 ^
ce2b0aec ^

80b781cc ^
fc55fea0 ^
b24eb476 ^
f3760b0f ^
82ac0b7e ^

b24eb476 ^
82ac0b7e ^


d57bf669 ^
455fbac6 ^
c6034af3 ^
b0bf5321 ^
c6034af3 ^
a3d9828c ^
a3d9828c ^


4814bf94 ^
795f5244 ^
b24eb476 ^
3adc9e08 ^
1b76245c ^
a3d9828c ^


ce2b0aec ^
ab6ed192 ^
ce2b0aec ^

0f125d5f ^
ce2b0aec ^


ab6ed192 ^
ce2b0aec ^

0f125d5f ^
ce2b0aec ^

ce2b0aec ^

ce2b0aec ^
047296d8 ^
ce2b0aec ^


b8348923 ^

















3b0aa1ac ^
fc55fea0 ^
1ead3562 ^
bc643692 ^
fc55fea0 ^


ad68bbce ^
198ad741 ^
18e626df ^
3b0aa1ac ^
5f98a10c ^
1ead3562 ^
bc643692 ^
198ad741 ^

5f98a10c ^
198ad741 ^
18e626df ^
5f98a10c ^

1ead3562 ^
5497090a ^
ce2b0aec ^
5f98a10c ^
ce2b0aec ^
5f98a10c ^

1ead3562 ^
bc643692 ^
5497090a ^
ce2b0aec ^
5f98a10c ^
ce2b0aec ^
5f98a10c ^
1ead3562 ^
5497090a ^
ce2b0aec ^
5f98a10c ^

ce2b0aec ^
5f98a10c ^
1ead3562 ^
bc643692 ^
ce2b0aec ^
5f98a10c ^

ce2b0aec ^
53881567 ^

caec3c16 ^
3b0aa1ac ^
1ead3562 ^
b94ea5c8 ^
10ffce98 ^

a3d9828c ^
db5c9550 ^

72cc3ae1 ^
dd2e01e4 ^
db5c9550 ^
53881567 ^
80411d01 ^




8b9e9fb1 ^
80411d01 ^
6179649e ^

d57bf669 ^

80411d01 ^
c6354606 ^



6179649e ^
06b3eb96 ^

72cc3ae1 ^
8c9e97ae ^
3b0aa1ac ^
1ead3562 ^
7136ddd5 ^

72cc3ae1 ^


caec3c16 ^
7284d503 ^
caec3c16 ^

3b0aa1ac ^
1ead3562 ^
bc643692 ^


7bf9212f ^
caec3c16 ^
5497090a ^
6e793202 ^
7bf9212f ^

caec3c16 ^
dd2e01e4 ^
caec3c16 ^
e6692482 ^
e4630643 ^
acc4792d ^
e4630643 ^

ab6ed192 ^
6179649e ^

d57bf669 ^


c6354606 ^



6179649e ^
caec3c16 ^
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