1 -- major tests for text editing flows
3 function test_initial_state()
4 App
.screen
.init
{width
=120, height
=60}
5 Editor_state
= edit
.initialize_test_state()
6 Editor_state
.lines
= load_array
{}
7 Text
.redraw_all(Editor_state
)
8 edit
.draw(Editor_state
)
9 check_eq(#Editor_state
.lines
, 1, '#lines')
10 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
11 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
12 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top:line')
13 check_eq(Editor_state
.screen_top1
.pos
, 1, 'screen_top:pos')
16 function test_backspace_from_start_of_final_line()
17 -- display final line of text with cursor at start of it
18 App
.screen
.init
{width
=120, height
=60}
19 Editor_state
= edit
.initialize_test_state()
20 Editor_state
.lines
= load_array
{'abc', 'def'}
21 Editor_state
.screen_top1
= {line
=2, pos
=1}
22 Editor_state
.cursor1
= {line
=2, pos
=1}
23 Text
.redraw_all(Editor_state
)
24 -- backspace scrolls up
25 edit
.run_after_keychord(Editor_state
, 'backspace')
26 check_eq(#Editor_state
.lines
, 1, '#lines')
27 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor')
28 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
31 function test_insert_first_character()
32 App
.screen
.init
{width
=120, height
=60}
33 Editor_state
= edit
.initialize_test_state()
34 Editor_state
.lines
= load_array
{}
35 Text
.redraw_all(Editor_state
)
36 edit
.draw(Editor_state
)
37 edit
.run_after_text_input(Editor_state
, 'a')
38 local y
= Editor_state
.top
39 App
.screen
.check(y
, 'a', 'screen:1')
42 function test_press_ctrl()
43 -- press ctrl while the cursor is on text
44 App
.screen
.init
{width
=50, height
=80}
45 Editor_state
= edit
.initialize_test_state()
46 Editor_state
.lines
= load_array
{''}
47 Text
.redraw_all(Editor_state
)
48 Editor_state
.cursor1
= {line
=1, pos
=1}
49 Editor_state
.screen_top1
= {line
=1, pos
=1}
50 Editor_state
.screen_bottom1
= {}
51 edit
.run_after_keychord(Editor_state
, 'C-m')
54 function test_move_left()
55 App
.screen
.init
{width
=120, height
=60}
56 Editor_state
= edit
.initialize_test_state()
57 Editor_state
.lines
= load_array
{'a'}
58 Text
.redraw_all(Editor_state
)
59 Editor_state
.cursor1
= {line
=1, pos
=2}
60 edit
.draw(Editor_state
)
61 edit
.run_after_keychord(Editor_state
, 'left')
62 check_eq(Editor_state
.cursor1
.pos
, 1, 'check')
65 function test_move_right()
66 App
.screen
.init
{width
=120, height
=60}
67 Editor_state
= edit
.initialize_test_state()
68 Editor_state
.lines
= load_array
{'a'}
69 Text
.redraw_all(Editor_state
)
70 Editor_state
.cursor1
= {line
=1, pos
=1}
71 edit
.draw(Editor_state
)
72 edit
.run_after_keychord(Editor_state
, 'right')
73 check_eq(Editor_state
.cursor1
.pos
, 2, 'check')
76 function test_move_left_to_previous_line()
77 App
.screen
.init
{width
=120, height
=60}
78 Editor_state
= edit
.initialize_test_state()
79 Editor_state
.lines
= load_array
{'abc', 'def'}
80 Text
.redraw_all(Editor_state
)
81 Editor_state
.cursor1
= {line
=2, pos
=1}
82 edit
.draw(Editor_state
)
83 edit
.run_after_keychord(Editor_state
, 'left')
84 check_eq(Editor_state
.cursor1
.line
, 1, 'line')
85 check_eq(Editor_state
.cursor1
.pos
, 4, 'pos') -- past end of line
88 function test_move_right_to_next_line()
89 App
.screen
.init
{width
=120, height
=60}
90 Editor_state
= edit
.initialize_test_state()
91 Editor_state
.lines
= load_array
{'abc', 'def'}
92 Text
.redraw_all(Editor_state
)
93 Editor_state
.cursor1
= {line
=1, pos
=4} -- past end of line
94 edit
.draw(Editor_state
)
95 edit
.run_after_keychord(Editor_state
, 'right')
96 check_eq(Editor_state
.cursor1
.line
, 2, 'line')
97 check_eq(Editor_state
.cursor1
.pos
, 1, 'pos')
100 function test_move_to_start_of_word()
101 App
.screen
.init
{width
=120, height
=60}
102 Editor_state
= edit
.initialize_test_state()
103 Editor_state
.lines
= load_array
{'abc'}
104 Text
.redraw_all(Editor_state
)
105 Editor_state
.cursor1
= {line
=1, pos
=3}
106 edit
.draw(Editor_state
)
107 edit
.run_after_keychord(Editor_state
, 'M-left')
108 check_eq(Editor_state
.cursor1
.pos
, 1, 'check')
111 function test_move_to_start_of_previous_word()
112 App
.screen
.init
{width
=120, height
=60}
113 Editor_state
= edit
.initialize_test_state()
114 Editor_state
.lines
= load_array
{'abc def'}
115 Text
.redraw_all(Editor_state
)
116 Editor_state
.cursor1
= {line
=1, pos
=4} -- at the space between words
117 edit
.draw(Editor_state
)
118 edit
.run_after_keychord(Editor_state
, 'M-left')
119 check_eq(Editor_state
.cursor1
.pos
, 1, 'check')
122 function test_skip_to_previous_word()
123 App
.screen
.init
{width
=120, height
=60}
124 Editor_state
= edit
.initialize_test_state()
125 Editor_state
.lines
= load_array
{'abc def'}
126 Text
.redraw_all(Editor_state
)
127 Editor_state
.cursor1
= {line
=1, pos
=5} -- at the start of second word
128 edit
.draw(Editor_state
)
129 edit
.run_after_keychord(Editor_state
, 'M-left')
130 check_eq(Editor_state
.cursor1
.pos
, 1, 'check')
133 function test_skip_past_tab_to_previous_word()
134 App
.screen
.init
{width
=120, height
=60}
135 Editor_state
= edit
.initialize_test_state()
136 Editor_state
.lines
= load_array
{'abc def\tghi'}
137 Text
.redraw_all(Editor_state
)
138 Editor_state
.cursor1
= {line
=1, pos
=10} -- within third word
139 edit
.draw(Editor_state
)
140 edit
.run_after_keychord(Editor_state
, 'M-left')
141 check_eq(Editor_state
.cursor1
.pos
, 9, 'check')
144 function test_skip_multiple_spaces_to_previous_word()
145 App
.screen
.init
{width
=120, height
=60}
146 Editor_state
= edit
.initialize_test_state()
147 Editor_state
.lines
= load_array
{'abc def'}
148 Text
.redraw_all(Editor_state
)
149 Editor_state
.cursor1
= {line
=1, pos
=6} -- at the start of second word
150 edit
.draw(Editor_state
)
151 edit
.run_after_keychord(Editor_state
, 'M-left')
152 check_eq(Editor_state
.cursor1
.pos
, 1, 'check')
155 function test_move_to_start_of_word_on_previous_line()
156 App
.screen
.init
{width
=120, height
=60}
157 Editor_state
= edit
.initialize_test_state()
158 Editor_state
.lines
= load_array
{'abc def', 'ghi'}
159 Text
.redraw_all(Editor_state
)
160 Editor_state
.cursor1
= {line
=2, pos
=1}
161 edit
.draw(Editor_state
)
162 edit
.run_after_keychord(Editor_state
, 'M-left')
163 check_eq(Editor_state
.cursor1
.line
, 1, 'line')
164 check_eq(Editor_state
.cursor1
.pos
, 5, 'pos')
167 function test_move_past_end_of_word()
168 App
.screen
.init
{width
=120, height
=60}
169 Editor_state
= edit
.initialize_test_state()
170 Editor_state
.lines
= load_array
{'abc def'}
171 Text
.redraw_all(Editor_state
)
172 Editor_state
.cursor1
= {line
=1, pos
=1}
173 edit
.draw(Editor_state
)
174 edit
.run_after_keychord(Editor_state
, 'M-right')
175 check_eq(Editor_state
.cursor1
.pos
, 4, 'check')
178 function test_skip_to_next_word()
179 App
.screen
.init
{width
=120, height
=60}
180 Editor_state
= edit
.initialize_test_state()
181 Editor_state
.lines
= load_array
{'abc def'}
182 Text
.redraw_all(Editor_state
)
183 Editor_state
.cursor1
= {line
=1, pos
=4} -- at the space between words
184 edit
.draw(Editor_state
)
185 edit
.run_after_keychord(Editor_state
, 'M-right')
186 check_eq(Editor_state
.cursor1
.pos
, 8, 'check')
189 function test_skip_past_tab_to_next_word()
190 App
.screen
.init
{width
=120, height
=60}
191 Editor_state
= edit
.initialize_test_state()
192 Editor_state
.lines
= load_array
{'abc\tdef'}
193 Text
.redraw_all(Editor_state
)
194 Editor_state
.cursor1
= {line
=1, pos
=1} -- at the space between words
195 edit
.draw(Editor_state
)
196 edit
.run_after_keychord(Editor_state
, 'M-right')
197 check_eq(Editor_state
.cursor1
.pos
, 4, 'check')
200 function test_skip_multiple_spaces_to_next_word()
201 App
.screen
.init
{width
=120, height
=60}
202 Editor_state
= edit
.initialize_test_state()
203 Editor_state
.lines
= load_array
{'abc def'}
204 Text
.redraw_all(Editor_state
)
205 Editor_state
.cursor1
= {line
=1, pos
=4} -- at the start of second word
206 edit
.draw(Editor_state
)
207 edit
.run_after_keychord(Editor_state
, 'M-right')
208 check_eq(Editor_state
.cursor1
.pos
, 9, 'check')
211 function test_move_past_end_of_word_on_next_line()
212 App
.screen
.init
{width
=120, height
=60}
213 Editor_state
= edit
.initialize_test_state()
214 Editor_state
.lines
= load_array
{'abc def', 'ghi'}
215 Text
.redraw_all(Editor_state
)
216 Editor_state
.cursor1
= {line
=1, pos
=8}
217 edit
.draw(Editor_state
)
218 edit
.run_after_keychord(Editor_state
, 'M-right')
219 check_eq(Editor_state
.cursor1
.line
, 2, 'line')
220 check_eq(Editor_state
.cursor1
.pos
, 4, 'pos')
223 function test_click_moves_cursor()
224 App
.screen
.init
{width
=50, height
=60}
225 Editor_state
= edit
.initialize_test_state()
226 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
227 Text
.redraw_all(Editor_state
)
228 Editor_state
.cursor1
= {line
=1, pos
=1}
229 Editor_state
.screen_top1
= {line
=1, pos
=1}
230 Editor_state
.screen_bottom1
= {}
231 Editor_state
.selection1
= {}
232 edit
.draw(Editor_state
) -- populate line_cache.starty for each line Editor_state.line_cache
233 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
234 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
235 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
236 -- selection is empty to avoid perturbing future edits
237 check_nil(Editor_state
.selection1
.line
, 'selection:line')
238 check_nil(Editor_state
.selection1
.pos
, 'selection:pos')
241 function test_click_to_left_of_line()
242 -- display a line with the cursor in the middle
243 App
.screen
.init
{width
=50, height
=80}
244 Editor_state
= edit
.initialize_test_state()
245 Editor_state
.lines
= load_array
{'abc'}
246 Text
.redraw_all(Editor_state
)
247 Editor_state
.cursor1
= {line
=1, pos
=3}
248 Editor_state
.screen_top1
= {line
=1, pos
=1}
249 Editor_state
.screen_bottom1
= {}
250 -- click to the left of the line
251 edit
.draw(Editor_state
)
252 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
-4,Editor_state
.top
+5, 1)
253 -- cursor moves to start of line
254 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
255 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
256 check_nil(Editor_state
.selection1
.line
, 'selection is empty to avoid perturbing future edits')
259 function test_click_takes_margins_into_account()
260 -- display two lines with cursor on one of them
261 App
.screen
.init
{width
=100, height
=80}
262 Editor_state
= edit
.initialize_test_state()
263 Editor_state
.left
= 50 -- occupy only right side of screen
264 Editor_state
.lines
= load_array
{'abc', 'def'}
265 Text
.redraw_all(Editor_state
)
266 Editor_state
.cursor1
= {line
=2, pos
=1}
267 Editor_state
.screen_top1
= {line
=1, pos
=1}
268 Editor_state
.screen_bottom1
= {}
269 -- click on the other line
270 edit
.draw(Editor_state
)
271 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
273 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
274 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
275 check_nil(Editor_state
.selection1
.line
, 'selection is empty to avoid perturbing future edits')
278 function test_click_on_empty_line()
279 -- display two lines with the first one empty
280 App
.screen
.init
{width
=50, height
=80}
281 Editor_state
= edit
.initialize_test_state()
282 Editor_state
.lines
= load_array
{'', 'def'}
283 Text
.redraw_all(Editor_state
)
284 Editor_state
.cursor1
= {line
=2, pos
=1}
285 Editor_state
.screen_top1
= {line
=1, pos
=1}
286 Editor_state
.screen_bottom1
= {}
287 -- click on the empty line
288 edit
.draw(Editor_state
)
289 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
291 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor')
294 function test_draw_text()
295 App
.screen
.init
{width
=120, height
=60}
296 Editor_state
= edit
.initialize_test_state()
297 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi'}
298 Text
.redraw_all(Editor_state
)
299 Editor_state
.cursor1
= {line
=1, pos
=1}
300 Editor_state
.screen_top1
= {line
=1, pos
=1}
301 Editor_state
.screen_bottom1
= {}
302 edit
.draw(Editor_state
)
303 local y
= Editor_state
.top
304 App
.screen
.check(y
, 'abc', 'screen:1')
305 y
= y
+ Editor_state
.line_height
306 App
.screen
.check(y
, 'def', 'screen:2')
307 y
= y
+ Editor_state
.line_height
308 App
.screen
.check(y
, 'ghi', 'screen:3')
311 function test_draw_wrapping_text()
312 App
.screen
.init
{width
=50, height
=60}
313 Editor_state
= edit
.initialize_test_state()
314 Editor_state
.lines
= load_array
{'abc', 'defgh', 'xyz'}
315 Text
.redraw_all(Editor_state
)
316 Editor_state
.cursor1
= {line
=1, pos
=1}
317 Editor_state
.screen_top1
= {line
=1, pos
=1}
318 Editor_state
.screen_bottom1
= {}
319 edit
.draw(Editor_state
)
320 local y
= Editor_state
.top
321 App
.screen
.check(y
, 'abc', 'screen:1')
322 y
= y
+ Editor_state
.line_height
323 App
.screen
.check(y
, 'de', 'screen:2')
324 y
= y
+ Editor_state
.line_height
325 App
.screen
.check(y
, 'fgh', 'screen:3')
328 function test_draw_word_wrapping_text()
329 App
.screen
.init
{width
=60, height
=60}
330 Editor_state
= edit
.initialize_test_state()
331 Editor_state
.lines
= load_array
{'abc def ghi', 'jkl'}
332 Text
.redraw_all(Editor_state
)
333 Editor_state
.cursor1
= {line
=1, pos
=1}
334 Editor_state
.screen_top1
= {line
=1, pos
=1}
335 Editor_state
.screen_bottom1
= {}
336 edit
.draw(Editor_state
)
337 local y
= Editor_state
.top
338 App
.screen
.check(y
, 'abc ', 'screen:1')
339 y
= y
+ Editor_state
.line_height
340 App
.screen
.check(y
, 'def ', 'screen:2')
341 y
= y
+ Editor_state
.line_height
342 App
.screen
.check(y
, 'ghi', 'screen:3')
345 function test_click_on_wrapping_line()
346 -- display two screen lines with cursor on one of them
347 App
.screen
.init
{width
=50, height
=80}
348 Editor_state
= edit
.initialize_test_state()
349 Editor_state
.lines
= load_array
{'abc def ghi jkl mno pqr stu'}
350 Text
.redraw_all(Editor_state
)
351 Editor_state
.cursor1
= {line
=1, pos
=20}
352 Editor_state
.screen_top1
= {line
=1, pos
=1}
353 Editor_state
.screen_bottom1
= {}
354 -- click on the other line
355 edit
.draw(Editor_state
)
356 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
358 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
359 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
360 check_nil(Editor_state
.selection1
.line
, 'selection is empty to avoid perturbing future edits')
363 function test_click_on_wrapping_line_takes_margins_into_account()
364 -- display two screen lines with cursor on one of them
365 App
.screen
.init
{width
=100, height
=80}
366 Editor_state
= edit
.initialize_test_state()
367 Editor_state
.left
= 50 -- occupy only right side of screen
368 Editor_state
.lines
= load_array
{'abc def ghi jkl mno pqr stu'}
369 Text
.redraw_all(Editor_state
)
370 Editor_state
.cursor1
= {line
=1, pos
=20}
371 Editor_state
.screen_top1
= {line
=1, pos
=1}
372 Editor_state
.screen_bottom1
= {}
373 -- click on the other line
374 edit
.draw(Editor_state
)
375 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
377 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
378 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
379 check_nil(Editor_state
.selection1
.line
, 'selection is empty to avoid perturbing future edits')
382 function test_draw_text_wrapping_within_word()
383 -- arrange a screen line that needs to be split within a word
384 App
.screen
.init
{width
=60, height
=60}
385 Editor_state
= edit
.initialize_test_state()
386 Editor_state
.lines
= load_array
{'abcd e fghijk', 'xyz'}
387 Text
.redraw_all(Editor_state
)
388 Editor_state
.cursor1
= {line
=1, pos
=1}
389 Editor_state
.screen_top1
= {line
=1, pos
=1}
390 Editor_state
.screen_bottom1
= {}
391 edit
.draw(Editor_state
)
392 local y
= Editor_state
.top
393 App
.screen
.check(y
, 'abcd ', 'screen:1')
394 y
= y
+ Editor_state
.line_height
395 App
.screen
.check(y
, 'e fgh', 'screen:2')
396 y
= y
+ Editor_state
.line_height
397 App
.screen
.check(y
, 'ijk', 'screen:3')
400 function test_draw_wrapping_text_containing_non_ascii()
401 -- draw a long line containing non-ASCII
402 App
.screen
.init
{width
=60, height
=60}
403 Editor_state
= edit
.initialize_test_state()
404 Editor_state
.lines
= load_array
{'madam I’m adam', 'xyz'} -- notice the non-ASCII apostrophe
405 Text
.redraw_all(Editor_state
)
406 Editor_state
.cursor1
= {line
=1, pos
=1}
407 Editor_state
.screen_top1
= {line
=1, pos
=1}
408 Editor_state
.screen_bottom1
= {}
409 edit
.draw(Editor_state
)
410 local y
= Editor_state
.top
411 App
.screen
.check(y
, 'mad', 'screen:1')
412 y
= y
+ Editor_state
.line_height
413 App
.screen
.check(y
, 'am I', 'screen:2')
414 y
= y
+ Editor_state
.line_height
415 App
.screen
.check(y
, '’m a', 'screen:3')
418 function test_click_past_end_of_screen_line()
419 -- display a wrapping line
420 App
.screen
.init
{width
=75, height
=80}
421 Editor_state
= edit
.initialize_test_state()
423 Editor_state
.lines
= load_array
{"madam I'm adam"}
424 Text
.redraw_all(Editor_state
)
425 Editor_state
.cursor1
= {line
=1, pos
=1}
426 Editor_state
.screen_top1
= {line
=1, pos
=1}
427 Editor_state
.screen_bottom1
= {}
428 edit
.draw(Editor_state
)
429 local y
= Editor_state
.top
430 App
.screen
.check(y
, 'madam ', 'baseline/screen:1')
431 y
= y
+ Editor_state
.line_height
432 App
.screen
.check(y
, "I'm ad", 'baseline/screen:2')
433 y
= y
+ Editor_state
.line_height
434 -- click past end of second screen line
435 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
436 -- cursor moves to end of screen line
437 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
438 check_eq(Editor_state
.cursor1
.pos
, 12, 'cursor:pos')
441 function test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen()
442 -- display a wrapping line from its second screen line
443 App
.screen
.init
{width
=75, height
=80}
444 Editor_state
= edit
.initialize_test_state()
446 Editor_state
.lines
= load_array
{"madam I'm adam"}
447 Text
.redraw_all(Editor_state
)
448 Editor_state
.cursor1
= {line
=1, pos
=8}
449 Editor_state
.screen_top1
= {line
=1, pos
=7}
450 Editor_state
.screen_bottom1
= {}
451 edit
.draw(Editor_state
)
452 local y
= Editor_state
.top
453 App
.screen
.check(y
, "I'm ad", 'baseline/screen:2')
454 y
= y
+ Editor_state
.line_height
455 -- click past end of second screen line
456 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
457 -- cursor moves to end of screen line
458 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
459 check_eq(Editor_state
.cursor1
.pos
, 12, 'cursor:pos')
462 function test_click_past_end_of_wrapping_line()
463 -- display a wrapping line
464 App
.screen
.init
{width
=75, height
=80}
465 Editor_state
= edit
.initialize_test_state()
467 Editor_state
.lines
= load_array
{"madam I'm adam"}
468 Text
.redraw_all(Editor_state
)
469 Editor_state
.cursor1
= {line
=1, pos
=1}
470 Editor_state
.screen_top1
= {line
=1, pos
=1}
471 Editor_state
.screen_bottom1
= {}
472 edit
.draw(Editor_state
)
473 local y
= Editor_state
.top
474 App
.screen
.check(y
, 'madam ', 'baseline/screen:1')
475 y
= y
+ Editor_state
.line_height
476 App
.screen
.check(y
, "I'm ad", 'baseline/screen:2')
477 y
= y
+ Editor_state
.line_height
478 App
.screen
.check(y
, 'am', 'baseline/screen:3')
479 y
= y
+ Editor_state
.line_height
480 -- click past the end of it
481 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
482 -- cursor moves to end of line
483 check_eq(Editor_state
.cursor1
.pos
, 15, 'cursor') -- one more than the number of UTF-8 code-points
486 function test_click_past_end_of_wrapping_line_containing_non_ascii()
487 -- display a wrapping line containing non-ASCII
488 App
.screen
.init
{width
=75, height
=80}
489 Editor_state
= edit
.initialize_test_state()
491 Editor_state
.lines
= load_array
{'madam I’m adam'} -- notice the non-ASCII apostrophe
492 Text
.redraw_all(Editor_state
)
493 Editor_state
.cursor1
= {line
=1, pos
=1}
494 Editor_state
.screen_top1
= {line
=1, pos
=1}
495 Editor_state
.screen_bottom1
= {}
496 edit
.draw(Editor_state
)
497 local y
= Editor_state
.top
498 App
.screen
.check(y
, 'madam ', 'baseline/screen:1')
499 y
= y
+ Editor_state
.line_height
500 App
.screen
.check(y
, 'I’m ad', 'baseline/screen:2')
501 y
= y
+ Editor_state
.line_height
502 App
.screen
.check(y
, 'am', 'baseline/screen:3')
503 y
= y
+ Editor_state
.line_height
504 -- click past the end of it
505 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
506 -- cursor moves to end of line
507 check_eq(Editor_state
.cursor1
.pos
, 15, 'cursor') -- one more than the number of UTF-8 code-points
510 function test_click_past_end_of_word_wrapping_line()
511 -- display a long line wrapping at a word boundary on a screen of more realistic length
512 App
.screen
.init
{width
=160, height
=80}
513 Editor_state
= edit
.initialize_test_state()
515 -- 123456789012345678901
516 Editor_state
.lines
= load_array
{'the quick brown fox jumped over the lazy dog'}
517 Text
.redraw_all(Editor_state
)
518 Editor_state
.cursor1
= {line
=1, pos
=1}
519 Editor_state
.screen_top1
= {line
=1, pos
=1}
520 Editor_state
.screen_bottom1
= {}
521 edit
.draw(Editor_state
)
522 local y
= Editor_state
.top
523 App
.screen
.check(y
, 'the quick brown fox ', 'baseline/screen:1')
524 y
= y
+ Editor_state
.line_height
525 -- click past the end of the screen line
526 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
527 -- cursor moves to end of screen line
528 check_eq(Editor_state
.cursor1
.pos
, 20, 'cursor')
531 function test_select_text()
532 -- display a line of text
533 App
.screen
.init
{width
=75, height
=80}
534 Editor_state
= edit
.initialize_test_state()
535 Editor_state
.lines
= load_array
{'abc def'}
536 Text
.redraw_all(Editor_state
)
537 Editor_state
.cursor1
= {line
=1, pos
=1}
538 Editor_state
.screen_top1
= {line
=1, pos
=1}
539 Editor_state
.screen_bottom1
= {}
540 edit
.draw(Editor_state
)
542 App
.fake_key_press('lshift')
543 edit
.run_after_keychord(Editor_state
, 'S-right')
544 App
.fake_key_release('lshift')
545 edit
.key_release(Editor_state
, 'lshift')
546 -- selection persists even after shift is released
547 check_eq(Editor_state
.selection1
.line
, 1, 'selection:line')
548 check_eq(Editor_state
.selection1
.pos
, 1, 'selection:pos')
549 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
550 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
553 function test_cursor_movement_without_shift_resets_selection()
554 -- display a line of text with some part selected
555 App
.screen
.init
{width
=75, height
=80}
556 Editor_state
= edit
.initialize_test_state()
557 Editor_state
.lines
= load_array
{'abc'}
558 Text
.redraw_all(Editor_state
)
559 Editor_state
.cursor1
= {line
=1, pos
=1}
560 Editor_state
.selection1
= {line
=1, pos
=2}
561 Editor_state
.screen_top1
= {line
=1, pos
=1}
562 Editor_state
.screen_bottom1
= {}
563 edit
.draw(Editor_state
)
564 -- press an arrow key without shift
565 edit
.run_after_keychord(Editor_state
, 'right')
566 -- no change to data, selection is reset
567 check_nil(Editor_state
.selection1
.line
, 'check')
568 check_eq(Editor_state
.lines
[1].data
, 'abc', 'data')
571 function test_edit_deletes_selection()
572 -- display a line of text with some part selected
573 App
.screen
.init
{width
=75, height
=80}
574 Editor_state
= edit
.initialize_test_state()
575 Editor_state
.lines
= load_array
{'abc'}
576 Text
.redraw_all(Editor_state
)
577 Editor_state
.cursor1
= {line
=1, pos
=1}
578 Editor_state
.selection1
= {line
=1, pos
=2}
579 Editor_state
.screen_top1
= {line
=1, pos
=1}
580 Editor_state
.screen_bottom1
= {}
581 edit
.draw(Editor_state
)
583 edit
.run_after_text_input(Editor_state
, 'x')
584 -- selected text is deleted and replaced with the key
585 check_eq(Editor_state
.lines
[1].data
, 'xbc', 'check')
588 function test_edit_with_shift_key_deletes_selection()
589 -- display a line of text with some part selected
590 App
.screen
.init
{width
=75, height
=80}
591 Editor_state
= edit
.initialize_test_state()
592 Editor_state
.lines
= load_array
{'abc'}
593 Text
.redraw_all(Editor_state
)
594 Editor_state
.cursor1
= {line
=1, pos
=1}
595 Editor_state
.selection1
= {line
=1, pos
=2}
596 Editor_state
.screen_top1
= {line
=1, pos
=1}
597 Editor_state
.screen_bottom1
= {}
598 edit
.draw(Editor_state
)
599 -- mimic precise keypresses for a capital letter
600 App
.fake_key_press('lshift')
601 edit
.keychord_press(Editor_state
, 'd', 'd')
602 edit
.text_input(Editor_state
, 'D')
603 edit
.key_release(Editor_state
, 'd')
604 App
.fake_key_release('lshift')
605 -- selected text is deleted and replaced with the key
606 check_nil(Editor_state
.selection1
.line
, 'check')
607 check_eq(Editor_state
.lines
[1].data
, 'Dbc', 'data')
610 function test_copy_does_not_reset_selection()
611 -- display a line of text with a selection
612 App
.screen
.init
{width
=75, height
=80}
613 Editor_state
= edit
.initialize_test_state()
614 Editor_state
.lines
= load_array
{'abc'}
615 Text
.redraw_all(Editor_state
)
616 Editor_state
.cursor1
= {line
=1, pos
=1}
617 Editor_state
.selection1
= {line
=1, pos
=2}
618 Editor_state
.screen_top1
= {line
=1, pos
=1}
619 Editor_state
.screen_bottom1
= {}
620 edit
.draw(Editor_state
)
622 edit
.run_after_keychord(Editor_state
, 'C-c')
623 check_eq(App
.clipboard
, 'a', 'clipboard')
624 -- selection is reset since shift key is not pressed
625 check(Editor_state
.selection1
.line
, 'check')
629 -- display a line of text with some part selected
630 App
.screen
.init
{width
=75, height
=80}
631 Editor_state
= edit
.initialize_test_state()
632 Editor_state
.lines
= load_array
{'abc'}
633 Text
.redraw_all(Editor_state
)
634 Editor_state
.cursor1
= {line
=1, pos
=1}
635 Editor_state
.selection1
= {line
=1, pos
=2}
636 Editor_state
.screen_top1
= {line
=1, pos
=1}
637 Editor_state
.screen_bottom1
= {}
638 edit
.draw(Editor_state
)
640 edit
.run_after_keychord(Editor_state
, 'C-x')
641 check_eq(App
.clipboard
, 'a', 'clipboard')
642 -- selected text is deleted
643 check_eq(Editor_state
.lines
[1].data
, 'bc', 'data')
646 function test_paste_replaces_selection()
647 -- display a line of text with a selection
648 App
.screen
.init
{width
=75, height
=80}
649 Editor_state
= edit
.initialize_test_state()
650 Editor_state
.lines
= load_array
{'abc', 'def'}
651 Text
.redraw_all(Editor_state
)
652 Editor_state
.cursor1
= {line
=2, pos
=1}
653 Editor_state
.selection1
= {line
=1, pos
=1}
654 Editor_state
.screen_top1
= {line
=1, pos
=1}
655 Editor_state
.screen_bottom1
= {}
656 edit
.draw(Editor_state
)
658 App
.clipboard
= 'xyz'
660 edit
.run_after_keychord(Editor_state
, 'C-v')
661 -- selection is reset since shift key is not pressed
662 -- selection includes the newline, so it's also deleted
663 check_eq(Editor_state
.lines
[1].data
, 'xyzdef', 'check')
666 function test_deleting_selection_may_scroll()
667 -- display lines 2/3/4
668 App
.screen
.init
{width
=120, height
=60}
669 Editor_state
= edit
.initialize_test_state()
670 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
671 Text
.redraw_all(Editor_state
)
672 Editor_state
.cursor1
= {line
=3, pos
=2}
673 Editor_state
.screen_top1
= {line
=2, pos
=1}
674 Editor_state
.screen_bottom1
= {}
675 edit
.draw(Editor_state
)
676 local y
= Editor_state
.top
677 App
.screen
.check(y
, 'def', 'baseline/screen:1')
678 y
= y
+ Editor_state
.line_height
679 App
.screen
.check(y
, 'ghi', 'baseline/screen:2')
680 y
= y
+ Editor_state
.line_height
681 App
.screen
.check(y
, 'jkl', 'baseline/screen:3')
682 -- set up a selection starting above the currently displayed page
683 Editor_state
.selection1
= {line
=1, pos
=2}
685 edit
.run_after_keychord(Editor_state
, 'backspace')
687 check_eq(Editor_state
.screen_top1
.line
, 1, 'check')
688 check_eq(Editor_state
.lines
[1].data
, 'ahi', 'data')
691 function test_edit_wrapping_text()
692 App
.screen
.init
{width
=50, height
=60}
693 Editor_state
= edit
.initialize_test_state()
694 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
695 Text
.redraw_all(Editor_state
)
696 Editor_state
.cursor1
= {line
=2, pos
=4}
697 Editor_state
.screen_top1
= {line
=1, pos
=1}
698 Editor_state
.screen_bottom1
= {}
699 edit
.draw(Editor_state
)
700 edit
.run_after_text_input(Editor_state
, 'g')
701 local y
= Editor_state
.top
702 App
.screen
.check(y
, 'abc', 'screen:1')
703 y
= y
+ Editor_state
.line_height
704 App
.screen
.check(y
, 'de', 'screen:2')
705 y
= y
+ Editor_state
.line_height
706 App
.screen
.check(y
, 'fg', 'screen:3')
709 function test_insert_newline()
710 -- display a few lines
711 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
712 Editor_state
= edit
.initialize_test_state()
713 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
714 Text
.redraw_all(Editor_state
)
715 Editor_state
.cursor1
= {line
=1, pos
=2}
716 Editor_state
.screen_top1
= {line
=1, pos
=1}
717 Editor_state
.screen_bottom1
= {}
718 edit
.draw(Editor_state
)
719 local y
= Editor_state
.top
720 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
721 y
= y
+ Editor_state
.line_height
722 App
.screen
.check(y
, 'def', 'baseline/screen:2')
723 y
= y
+ Editor_state
.line_height
724 App
.screen
.check(y
, 'ghi', 'baseline/screen:3')
725 -- hitting the enter key splits the line
726 edit
.run_after_keychord(Editor_state
, 'return')
727 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
728 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
729 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
731 App
.screen
.check(y
, 'a', 'screen:1')
732 y
= y
+ Editor_state
.line_height
733 App
.screen
.check(y
, 'bc', 'screen:2')
734 y
= y
+ Editor_state
.line_height
735 App
.screen
.check(y
, 'def', 'screen:3')
738 function test_insert_newline_at_start_of_line()
740 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
741 Editor_state
= edit
.initialize_test_state()
742 Editor_state
.lines
= load_array
{'abc'}
743 Text
.redraw_all(Editor_state
)
744 Editor_state
.cursor1
= {line
=1, pos
=1}
745 Editor_state
.screen_top1
= {line
=1, pos
=1}
746 Editor_state
.screen_bottom1
= {}
747 -- hitting the enter key splits the line
748 edit
.run_after_keychord(Editor_state
, 'return')
749 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
750 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
751 check_eq(Editor_state
.lines
[1].data
, '', 'data:1')
752 check_eq(Editor_state
.lines
[2].data
, 'abc', 'data:2')
755 function test_insert_from_clipboard()
756 -- display a few lines
757 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
758 Editor_state
= edit
.initialize_test_state()
759 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
760 Text
.redraw_all(Editor_state
)
761 Editor_state
.cursor1
= {line
=1, pos
=2}
762 Editor_state
.screen_top1
= {line
=1, pos
=1}
763 Editor_state
.screen_bottom1
= {}
764 edit
.draw(Editor_state
)
765 local y
= Editor_state
.top
766 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
767 y
= y
+ Editor_state
.line_height
768 App
.screen
.check(y
, 'def', 'baseline/screen:2')
769 y
= y
+ Editor_state
.line_height
770 App
.screen
.check(y
, 'ghi', 'baseline/screen:3')
771 -- paste some text including a newline, check that new line is created
772 App
.clipboard
= 'xy\nz'
773 edit
.run_after_keychord(Editor_state
, 'C-v')
774 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
775 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
776 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
778 App
.screen
.check(y
, 'axy', 'screen:1')
779 y
= y
+ Editor_state
.line_height
780 App
.screen
.check(y
, 'zbc', 'screen:2')
781 y
= y
+ Editor_state
.line_height
782 App
.screen
.check(y
, 'def', 'screen:3')
785 function test_select_text_using_mouse()
786 App
.screen
.init
{width
=50, height
=60}
787 Editor_state
= edit
.initialize_test_state()
788 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
789 Text
.redraw_all(Editor_state
)
790 Editor_state
.cursor1
= {line
=1, pos
=1}
791 Editor_state
.screen_top1
= {line
=1, pos
=1}
792 Editor_state
.screen_bottom1
= {}
793 Editor_state
.selection1
= {}
794 edit
.draw(Editor_state
) -- populate line_cache.starty for each line Editor_state.line_cache
795 -- press and hold on first location
796 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
797 -- drag and release somewhere else
798 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+Editor_state
.line_height
+5, 1)
799 check_eq(Editor_state
.selection1
.line
, 1, 'selection:line')
800 check_eq(Editor_state
.selection1
.pos
, 2, 'selection:pos')
801 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
802 check_eq(Editor_state
.cursor1
.pos
, 4, 'cursor:pos')
805 function test_select_text_using_mouse_and_shift()
806 App
.screen
.init
{width
=50, height
=60}
807 Editor_state
= edit
.initialize_test_state()
808 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
809 Text
.redraw_all(Editor_state
)
810 Editor_state
.cursor1
= {line
=1, pos
=1}
811 Editor_state
.screen_top1
= {line
=1, pos
=1}
812 Editor_state
.screen_bottom1
= {}
813 Editor_state
.selection1
= {}
814 edit
.draw(Editor_state
) -- populate line_cache.starty for each line Editor_state.line_cache
815 -- click on first location
816 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
817 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
818 -- hold down shift and click somewhere else
819 App
.fake_key_press('lshift')
820 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+5, 1)
821 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+Editor_state
.line_height
+5, 1)
822 App
.fake_key_release('lshift')
823 check_eq(Editor_state
.selection1
.line
, 1, 'selection:line')
824 check_eq(Editor_state
.selection1
.pos
, 2, 'selection:pos')
825 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
826 check_eq(Editor_state
.cursor1
.pos
, 4, 'cursor:pos')
829 function test_select_text_repeatedly_using_mouse_and_shift()
830 App
.screen
.init
{width
=50, height
=60}
831 Editor_state
= edit
.initialize_test_state()
832 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
833 Text
.redraw_all(Editor_state
)
834 Text
.redraw_all(Editor_state
)
835 Editor_state
.cursor1
= {line
=1, pos
=1}
836 Editor_state
.screen_top1
= {line
=1, pos
=1}
837 Editor_state
.screen_bottom1
= {}
838 Editor_state
.selection1
= {}
839 edit
.draw(Editor_state
) -- populate line_cache.starty for each line Editor_state.line_cache
840 -- click on first location
841 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
842 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
843 -- hold down shift and click on a second location
844 App
.fake_key_press('lshift')
845 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+5, 1)
846 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+Editor_state
.line_height
+5, 1)
847 -- hold down shift and click at a third location
848 App
.fake_key_press('lshift')
849 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+5, 1)
850 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+Editor_state
.line_height
+5, 1)
851 App
.fake_key_release('lshift')
852 -- selection is between first and third location. forget the second location, not the first.
853 check_eq(Editor_state
.selection1
.line
, 1, 'selection:line')
854 check_eq(Editor_state
.selection1
.pos
, 2, 'selection:pos')
855 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
856 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
859 function test_cut_without_selection()
860 -- display a few lines
861 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
862 Editor_state
= edit
.initialize_test_state()
863 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
864 Text
.redraw_all(Editor_state
)
865 Editor_state
.cursor1
= {line
=1, pos
=2}
866 Editor_state
.screen_top1
= {line
=1, pos
=1}
867 Editor_state
.screen_bottom1
= {}
868 Editor_state
.selection1
= {}
869 edit
.draw(Editor_state
)
870 -- try to cut without selecting text
871 edit
.run_after_keychord(Editor_state
, 'C-x')
873 check_nil(Editor_state
.selection1
.line
, 'check')
876 function test_pagedown()
877 App
.screen
.init
{width
=120, height
=45}
878 Editor_state
= edit
.initialize_test_state()
879 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi'}
880 Text
.redraw_all(Editor_state
)
881 Editor_state
.cursor1
= {line
=1, pos
=1}
882 Editor_state
.screen_top1
= {line
=1, pos
=1}
883 Editor_state
.screen_bottom1
= {}
884 -- initially the first two lines are displayed
885 edit
.draw(Editor_state
)
886 local y
= Editor_state
.top
887 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
888 y
= y
+ Editor_state
.line_height
889 App
.screen
.check(y
, 'def', 'baseline/screen:2')
890 -- after pagedown the bottom line becomes the top
891 edit
.run_after_keychord(Editor_state
, 'pagedown')
892 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
893 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor')
895 App
.screen
.check(y
, 'def', 'screen:1')
896 y
= y
+ Editor_state
.line_height
897 App
.screen
.check(y
, 'ghi', 'screen:2')
900 function test_pagedown_often_shows_start_of_wrapping_line()
901 -- draw a few lines ending in part of a wrapping line
902 App
.screen
.init
{width
=50, height
=60}
903 Editor_state
= edit
.initialize_test_state()
904 Editor_state
.lines
= load_array
{'abc', 'def ghi jkl', 'mno'}
905 Text
.redraw_all(Editor_state
)
906 Editor_state
.cursor1
= {line
=1, pos
=1}
907 Editor_state
.screen_top1
= {line
=1, pos
=1}
908 Editor_state
.screen_bottom1
= {}
909 edit
.draw(Editor_state
)
910 local y
= Editor_state
.top
911 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
912 y
= y
+ Editor_state
.line_height
913 App
.screen
.check(y
, 'def ', 'baseline/screen:2')
914 y
= y
+ Editor_state
.line_height
915 App
.screen
.check(y
, 'ghi ', 'baseline/screen:3')
916 -- after pagedown we start drawing from the bottom _line_ (multiple screen lines)
917 edit
.run_after_keychord(Editor_state
, 'pagedown')
918 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top:line')
919 check_eq(Editor_state
.screen_top1
.pos
, 1, 'screen_top:pos')
920 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
921 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
923 App
.screen
.check(y
, 'def ', 'screen:1')
924 y
= y
+ Editor_state
.line_height
925 App
.screen
.check(y
, 'ghi ', 'screen:2')
926 y
= y
+ Editor_state
.line_height
927 App
.screen
.check(y
, 'jkl', 'screen:3')
930 function test_pagedown_can_start_from_middle_of_long_wrapping_line()
931 -- draw a few lines starting from a very long wrapping line
932 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
933 Editor_state
= edit
.initialize_test_state()
934 Editor_state
.lines
= load_array
{'abc def ghi jkl mno pqr stu vwx yza bcd efg hij', 'XYZ'}
935 Text
.redraw_all(Editor_state
)
936 Editor_state
.cursor1
= {line
=1, pos
=2}
937 Editor_state
.screen_top1
= {line
=1, pos
=1}
938 Editor_state
.screen_bottom1
= {}
939 edit
.draw(Editor_state
)
940 local y
= Editor_state
.top
941 App
.screen
.check(y
, 'abc ', 'baseline/screen:1')
942 y
= y
+ Editor_state
.line_height
943 App
.screen
.check(y
, 'def ', 'baseline/screen:2')
944 y
= y
+ Editor_state
.line_height
945 App
.screen
.check(y
, 'ghi ', 'baseline/screen:3')
946 -- after pagedown we scroll down the very long wrapping line
947 edit
.run_after_keychord(Editor_state
, 'pagedown')
948 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top:line')
949 check_eq(Editor_state
.screen_top1
.pos
, 9, 'screen_top:pos')
951 App
.screen
.check(y
, 'ghi ', 'screen:1')
952 y
= y
+ Editor_state
.line_height
953 App
.screen
.check(y
, 'jkl ', 'screen:2')
954 y
= y
+ Editor_state
.line_height
955 App
.screen
.check(y
, 'mn', 'screen:3')
958 function test_pagedown_never_moves_up()
959 -- draw the final screen line of a wrapping line
960 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
961 Editor_state
= edit
.initialize_test_state()
962 Editor_state
.lines
= load_array
{'abc def ghi'}
963 Text
.redraw_all(Editor_state
)
964 Editor_state
.cursor1
= {line
=1, pos
=9}
965 Editor_state
.screen_top1
= {line
=1, pos
=9}
966 Editor_state
.screen_bottom1
= {}
967 edit
.draw(Editor_state
)
968 -- pagedown makes no change
969 edit
.run_after_keychord(Editor_state
, 'pagedown')
970 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top:line')
971 check_eq(Editor_state
.screen_top1
.pos
, 9, 'screen_top:pos')
974 function test_down_arrow_moves_cursor()
975 App
.screen
.init
{width
=120, height
=60}
976 Editor_state
= edit
.initialize_test_state()
977 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
978 Text
.redraw_all(Editor_state
)
979 Editor_state
.cursor1
= {line
=1, pos
=1}
980 Editor_state
.screen_top1
= {line
=1, pos
=1}
981 Editor_state
.screen_bottom1
= {}
982 -- initially the first three lines are displayed
983 edit
.draw(Editor_state
)
984 local y
= Editor_state
.top
985 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
986 y
= y
+ Editor_state
.line_height
987 App
.screen
.check(y
, 'def', 'baseline/screen:2')
988 y
= y
+ Editor_state
.line_height
989 App
.screen
.check(y
, 'ghi', 'baseline/screen:3')
990 -- after hitting the down arrow, the cursor moves down by 1 line
991 edit
.run_after_keychord(Editor_state
, 'down')
992 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
993 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor')
994 -- the screen is unchanged
996 App
.screen
.check(y
, 'abc', 'screen:1')
997 y
= y
+ Editor_state
.line_height
998 App
.screen
.check(y
, 'def', 'screen:2')
999 y
= y
+ Editor_state
.line_height
1000 App
.screen
.check(y
, 'ghi', 'screen:3')
1003 function test_down_arrow_scrolls_down_by_one_line()
1004 -- display the first three lines with the cursor on the bottom line
1005 App
.screen
.init
{width
=120, height
=60}
1006 Editor_state
= edit
.initialize_test_state()
1007 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1008 Text
.redraw_all(Editor_state
)
1009 Editor_state
.cursor1
= {line
=3, pos
=1}
1010 Editor_state
.screen_top1
= {line
=1, pos
=1}
1011 Editor_state
.screen_bottom1
= {}
1012 edit
.draw(Editor_state
)
1013 local y
= Editor_state
.top
1014 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1015 y
= y
+ Editor_state
.line_height
1016 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1017 y
= y
+ Editor_state
.line_height
1018 App
.screen
.check(y
, 'ghi', 'baseline/screen:3')
1019 -- after hitting the down arrow the screen scrolls down by one line
1020 edit
.run_after_keychord(Editor_state
, 'down')
1021 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
1022 check_eq(Editor_state
.cursor1
.line
, 4, 'cursor')
1023 y
= Editor_state
.top
1024 App
.screen
.check(y
, 'def', 'screen:1')
1025 y
= y
+ Editor_state
.line_height
1026 App
.screen
.check(y
, 'ghi', 'screen:2')
1027 y
= y
+ Editor_state
.line_height
1028 App
.screen
.check(y
, 'jkl', 'screen:3')
1031 function test_down_arrow_scrolls_down_by_one_screen_line()
1032 -- display the first three lines with the cursor on the bottom line
1033 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1034 Editor_state
= edit
.initialize_test_state()
1035 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1036 Text
.redraw_all(Editor_state
)
1037 Editor_state
.cursor1
= {line
=3, pos
=1}
1038 Editor_state
.screen_top1
= {line
=1, pos
=1}
1039 Editor_state
.screen_bottom1
= {}
1040 edit
.draw(Editor_state
)
1041 local y
= Editor_state
.top
1042 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1043 y
= y
+ Editor_state
.line_height
1044 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1045 y
= y
+ Editor_state
.line_height
1046 App
.screen
.check(y
, 'ghi ', 'baseline/screen:3') -- line wrapping includes trailing whitespace
1047 -- after hitting the down arrow the screen scrolls down by one line
1048 edit
.run_after_keychord(Editor_state
, 'down')
1049 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
1050 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1051 check_eq(Editor_state
.cursor1
.pos
, 5, 'cursor:pos')
1052 y
= Editor_state
.top
1053 App
.screen
.check(y
, 'def', 'screen:1')
1054 y
= y
+ Editor_state
.line_height
1055 App
.screen
.check(y
, 'ghi ', 'screen:2')
1056 y
= y
+ Editor_state
.line_height
1057 App
.screen
.check(y
, 'jkl', 'screen:3')
1060 function test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word()
1061 -- display the first three lines with the cursor on the bottom line
1062 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1063 Editor_state
= edit
.initialize_test_state()
1064 Editor_state
.lines
= load_array
{'abc', 'def', 'ghijkl', 'mno'}
1065 Text
.redraw_all(Editor_state
)
1066 Editor_state
.cursor1
= {line
=3, pos
=1}
1067 Editor_state
.screen_top1
= {line
=1, pos
=1}
1068 Editor_state
.screen_bottom1
= {}
1069 edit
.draw(Editor_state
)
1070 local y
= Editor_state
.top
1071 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1072 y
= y
+ Editor_state
.line_height
1073 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1074 y
= y
+ Editor_state
.line_height
1075 App
.screen
.check(y
, 'ghij', 'baseline/screen:3')
1076 -- after hitting the down arrow the screen scrolls down by one line
1077 edit
.run_after_keychord(Editor_state
, 'down')
1078 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
1079 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1080 check_eq(Editor_state
.cursor1
.pos
, 5, 'cursor:pos')
1081 y
= Editor_state
.top
1082 App
.screen
.check(y
, 'def', 'screen:1')
1083 y
= y
+ Editor_state
.line_height
1084 App
.screen
.check(y
, 'ghij', 'screen:2')
1085 y
= y
+ Editor_state
.line_height
1086 App
.screen
.check(y
, 'kl', 'screen:3')
1089 function test_pagedown_followed_by_down_arrow_does_not_scroll_screen_up()
1090 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1091 Editor_state
= edit
.initialize_test_state()
1092 Editor_state
.lines
= load_array
{'abc', 'def', 'ghijkl', 'mno'}
1093 Text
.redraw_all(Editor_state
)
1094 Editor_state
.cursor1
= {line
=3, pos
=1}
1095 Editor_state
.screen_top1
= {line
=1, pos
=1}
1096 Editor_state
.screen_bottom1
= {}
1097 edit
.draw(Editor_state
)
1098 local y
= Editor_state
.top
1099 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1100 y
= y
+ Editor_state
.line_height
1101 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1102 y
= y
+ Editor_state
.line_height
1103 App
.screen
.check(y
, 'ghij', 'baseline/screen:3')
1104 -- after hitting pagedown the screen scrolls down to start of a long line
1105 edit
.run_after_keychord(Editor_state
, 'pagedown')
1106 check_eq(Editor_state
.screen_top1
.line
, 3, 'baseline2/screen_top')
1107 check_eq(Editor_state
.cursor1
.line
, 3, 'baseline2/cursor:line')
1108 check_eq(Editor_state
.cursor1
.pos
, 1, 'baseline2/cursor:pos')
1109 -- after hitting down arrow the screen doesn't scroll down further, and certainly doesn't scroll up
1110 edit
.run_after_keychord(Editor_state
, 'down')
1111 check_eq(Editor_state
.screen_top1
.line
, 3, 'screen_top')
1112 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1113 check_eq(Editor_state
.cursor1
.pos
, 5, 'cursor:pos')
1114 y
= Editor_state
.top
1115 App
.screen
.check(y
, 'ghij', 'screen:1')
1116 y
= y
+ Editor_state
.line_height
1117 App
.screen
.check(y
, 'kl', 'screen:2')
1118 y
= y
+ Editor_state
.line_height
1119 App
.screen
.check(y
, 'mno', 'screen:3')
1122 function test_up_arrow_moves_cursor()
1123 -- display the first 3 lines with the cursor on the bottom line
1124 App
.screen
.init
{width
=120, height
=60}
1125 Editor_state
= edit
.initialize_test_state()
1126 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1127 Text
.redraw_all(Editor_state
)
1128 Editor_state
.cursor1
= {line
=3, pos
=1}
1129 Editor_state
.screen_top1
= {line
=1, pos
=1}
1130 Editor_state
.screen_bottom1
= {}
1131 edit
.draw(Editor_state
)
1132 local y
= Editor_state
.top
1133 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1134 y
= y
+ Editor_state
.line_height
1135 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1136 y
= y
+ Editor_state
.line_height
1137 App
.screen
.check(y
, 'ghi', 'baseline/screen:3')
1138 -- after hitting the up arrow the cursor moves up by 1 line
1139 edit
.run_after_keychord(Editor_state
, 'up')
1140 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
1141 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor')
1142 -- the screen is unchanged
1143 y
= Editor_state
.top
1144 App
.screen
.check(y
, 'abc', 'screen:1')
1145 y
= y
+ Editor_state
.line_height
1146 App
.screen
.check(y
, 'def', 'screen:2')
1147 y
= y
+ Editor_state
.line_height
1148 App
.screen
.check(y
, 'ghi', 'screen:3')
1151 function test_up_arrow_scrolls_up_by_one_line()
1152 -- display the lines 2/3/4 with the cursor on line 2
1153 App
.screen
.init
{width
=120, height
=60}
1154 Editor_state
= edit
.initialize_test_state()
1155 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1156 Text
.redraw_all(Editor_state
)
1157 Editor_state
.cursor1
= {line
=2, pos
=1}
1158 Editor_state
.screen_top1
= {line
=2, pos
=1}
1159 Editor_state
.screen_bottom1
= {}
1160 edit
.draw(Editor_state
)
1161 local y
= Editor_state
.top
1162 App
.screen
.check(y
, 'def', 'baseline/screen:1')
1163 y
= y
+ Editor_state
.line_height
1164 App
.screen
.check(y
, 'ghi', 'baseline/screen:2')
1165 y
= y
+ Editor_state
.line_height
1166 App
.screen
.check(y
, 'jkl', 'baseline/screen:3')
1167 -- after hitting the up arrow the screen scrolls up by one line
1168 edit
.run_after_keychord(Editor_state
, 'up')
1169 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
1170 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor')
1171 y
= Editor_state
.top
1172 App
.screen
.check(y
, 'abc', 'screen:1')
1173 y
= y
+ Editor_state
.line_height
1174 App
.screen
.check(y
, 'def', 'screen:2')
1175 y
= y
+ Editor_state
.line_height
1176 App
.screen
.check(y
, 'ghi', 'screen:3')
1179 function test_up_arrow_scrolls_up_by_one_screen_line()
1180 -- display lines starting from second screen line of a line
1181 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1182 Editor_state
= edit
.initialize_test_state()
1183 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1184 Text
.redraw_all(Editor_state
)
1185 Editor_state
.cursor1
= {line
=3, pos
=6}
1186 Editor_state
.screen_top1
= {line
=3, pos
=5}
1187 Editor_state
.screen_bottom1
= {}
1188 edit
.draw(Editor_state
)
1189 local y
= Editor_state
.top
1190 App
.screen
.check(y
, 'jkl', 'baseline/screen:1')
1191 y
= y
+ Editor_state
.line_height
1192 App
.screen
.check(y
, 'mno', 'baseline/screen:2')
1193 -- after hitting the up arrow the screen scrolls up to first screen line
1194 edit
.run_after_keychord(Editor_state
, 'up')
1195 y
= Editor_state
.top
1196 App
.screen
.check(y
, 'ghi ', 'screen:1')
1197 y
= y
+ Editor_state
.line_height
1198 App
.screen
.check(y
, 'jkl', 'screen:2')
1199 y
= y
+ Editor_state
.line_height
1200 App
.screen
.check(y
, 'mno', 'screen:3')
1201 check_eq(Editor_state
.screen_top1
.line
, 3, 'screen_top:line')
1202 check_eq(Editor_state
.screen_top1
.pos
, 1, 'screen_top:pos')
1203 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1204 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1207 function test_up_arrow_scrolls_up_to_final_screen_line()
1208 -- display lines starting just after a long line
1209 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1210 Editor_state
= edit
.initialize_test_state()
1211 Editor_state
.lines
= load_array
{'abc def', 'ghi', 'jkl', 'mno'}
1212 Text
.redraw_all(Editor_state
)
1213 Editor_state
.cursor1
= {line
=2, pos
=1}
1214 Editor_state
.screen_top1
= {line
=2, pos
=1}
1215 Editor_state
.screen_bottom1
= {}
1216 edit
.draw(Editor_state
)
1217 local y
= Editor_state
.top
1218 App
.screen
.check(y
, 'ghi', 'baseline/screen:1')
1219 y
= y
+ Editor_state
.line_height
1220 App
.screen
.check(y
, 'jkl', 'baseline/screen:2')
1221 y
= y
+ Editor_state
.line_height
1222 App
.screen
.check(y
, 'mno', 'baseline/screen:3')
1223 -- after hitting the up arrow the screen scrolls up to final screen line of previous line
1224 edit
.run_after_keychord(Editor_state
, 'up')
1225 y
= Editor_state
.top
1226 App
.screen
.check(y
, 'def', 'screen:1')
1227 y
= y
+ Editor_state
.line_height
1228 App
.screen
.check(y
, 'ghi', 'screen:2')
1229 y
= y
+ Editor_state
.line_height
1230 App
.screen
.check(y
, 'jkl', 'screen:3')
1231 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top:line')
1232 check_eq(Editor_state
.screen_top1
.pos
, 5, 'screen_top:pos')
1233 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
1234 check_eq(Editor_state
.cursor1
.pos
, 5, 'cursor:pos')
1237 function test_up_arrow_scrolls_up_to_empty_line()
1238 -- display a screenful of text with an empty line just above it outside the screen
1239 App
.screen
.init
{width
=120, height
=60}
1240 Editor_state
= edit
.initialize_test_state()
1241 Editor_state
.lines
= load_array
{'', 'abc', 'def', 'ghi', 'jkl'}
1242 Text
.redraw_all(Editor_state
)
1243 Editor_state
.cursor1
= {line
=2, pos
=1}
1244 Editor_state
.screen_top1
= {line
=2, pos
=1}
1245 Editor_state
.screen_bottom1
= {}
1246 edit
.draw(Editor_state
)
1247 local y
= Editor_state
.top
1248 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1249 y
= y
+ Editor_state
.line_height
1250 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1251 y
= y
+ Editor_state
.line_height
1252 App
.screen
.check(y
, 'ghi', 'baseline/screen:3')
1253 -- after hitting the up arrow the screen scrolls up by one line
1254 edit
.run_after_keychord(Editor_state
, 'up')
1255 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
1256 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor')
1257 y
= Editor_state
.top
1259 y
= y
+ Editor_state
.line_height
1260 App
.screen
.check(y
, 'abc', 'screen:2')
1261 y
= y
+ Editor_state
.line_height
1262 App
.screen
.check(y
, 'def', 'screen:3')
1265 function test_pageup()
1266 App
.screen
.init
{width
=120, height
=45}
1267 Editor_state
= edit
.initialize_test_state()
1268 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi'}
1269 Text
.redraw_all(Editor_state
)
1270 Editor_state
.cursor1
= {line
=2, pos
=1}
1271 Editor_state
.screen_top1
= {line
=2, pos
=1}
1272 Editor_state
.screen_bottom1
= {}
1273 -- initially the last two lines are displayed
1274 edit
.draw(Editor_state
)
1275 local y
= Editor_state
.top
1276 App
.screen
.check(y
, 'def', 'baseline/screen:1')
1277 y
= y
+ Editor_state
.line_height
1278 App
.screen
.check(y
, 'ghi', 'baseline/screen:2')
1279 -- after pageup the cursor goes to first line
1280 edit
.run_after_keychord(Editor_state
, 'pageup')
1281 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
1282 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor')
1283 y
= Editor_state
.top
1284 App
.screen
.check(y
, 'abc', 'screen:1')
1285 y
= y
+ Editor_state
.line_height
1286 App
.screen
.check(y
, 'def', 'screen:2')
1289 function test_pageup_scrolls_up_by_screen_line()
1290 -- display the first three lines with the cursor on the bottom line
1291 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1292 Editor_state
= edit
.initialize_test_state()
1293 Editor_state
.lines
= load_array
{'abc def', 'ghi', 'jkl', 'mno'}
1294 Text
.redraw_all(Editor_state
)
1295 Editor_state
.cursor1
= {line
=2, pos
=1}
1296 Editor_state
.screen_top1
= {line
=2, pos
=1}
1297 Editor_state
.screen_bottom1
= {}
1298 edit
.draw(Editor_state
)
1299 local y
= Editor_state
.top
1300 App
.screen
.check(y
, 'ghi', 'baseline/screen:1')
1301 y
= y
+ Editor_state
.line_height
1302 App
.screen
.check(y
, 'jkl', 'baseline/screen:2')
1303 y
= y
+ Editor_state
.line_height
1304 App
.screen
.check(y
, 'mno', 'baseline/screen:3') -- line wrapping includes trailing whitespace
1305 -- after hitting the page-up key the screen scrolls up to top
1306 edit
.run_after_keychord(Editor_state
, 'pageup')
1307 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
1308 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
1309 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1310 y
= Editor_state
.top
1311 App
.screen
.check(y
, 'abc ', 'screen:1')
1312 y
= y
+ Editor_state
.line_height
1313 App
.screen
.check(y
, 'def', 'screen:2')
1314 y
= y
+ Editor_state
.line_height
1315 App
.screen
.check(y
, 'ghi', 'screen:3')
1318 function test_pageup_scrolls_up_from_middle_screen_line()
1319 -- display a few lines starting from the middle of a line (Editor_state.cursor1.pos > 1)
1320 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1321 Editor_state
= edit
.initialize_test_state()
1322 Editor_state
.lines
= load_array
{'abc def', 'ghi jkl', 'mno'}
1323 Text
.redraw_all(Editor_state
)
1324 Editor_state
.cursor1
= {line
=2, pos
=5}
1325 Editor_state
.screen_top1
= {line
=2, pos
=5}
1326 Editor_state
.screen_bottom1
= {}
1327 edit
.draw(Editor_state
)
1328 local y
= Editor_state
.top
1329 App
.screen
.check(y
, 'jkl', 'baseline/screen:2')
1330 y
= y
+ Editor_state
.line_height
1331 App
.screen
.check(y
, 'mno', 'baseline/screen:3') -- line wrapping includes trailing whitespace
1332 -- after hitting the page-up key the screen scrolls up to top
1333 edit
.run_after_keychord(Editor_state
, 'pageup')
1334 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
1335 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
1336 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1337 y
= Editor_state
.top
1338 App
.screen
.check(y
, 'abc ', 'screen:1')
1339 y
= y
+ Editor_state
.line_height
1340 App
.screen
.check(y
, 'def', 'screen:2')
1341 y
= y
+ Editor_state
.line_height
1342 App
.screen
.check(y
, 'ghi ', 'screen:3')
1345 function test_enter_on_bottom_line_scrolls_down()
1346 -- display a few lines with cursor on bottom line
1347 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1348 Editor_state
= edit
.initialize_test_state()
1349 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1350 Text
.redraw_all(Editor_state
)
1351 Editor_state
.cursor1
= {line
=3, pos
=2}
1352 Editor_state
.screen_top1
= {line
=1, pos
=1}
1353 Editor_state
.screen_bottom1
= {}
1354 edit
.draw(Editor_state
)
1355 local y
= Editor_state
.top
1356 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1357 y
= y
+ Editor_state
.line_height
1358 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1359 y
= y
+ Editor_state
.line_height
1360 App
.screen
.check(y
, 'ghi', 'baseline/screen:3')
1361 -- after hitting the enter key the screen scrolls down
1362 edit
.run_after_keychord(Editor_state
, 'return')
1363 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
1364 check_eq(Editor_state
.cursor1
.line
, 4, 'cursor:line')
1365 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1366 y
= Editor_state
.top
1367 App
.screen
.check(y
, 'def', 'screen:1')
1368 y
= y
+ Editor_state
.line_height
1369 App
.screen
.check(y
, 'g', 'screen:2')
1370 y
= y
+ Editor_state
.line_height
1371 App
.screen
.check(y
, 'hi', 'screen:3')
1374 function test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom()
1375 -- display just the bottom line on screen
1376 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1377 Editor_state
= edit
.initialize_test_state()
1378 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1379 Text
.redraw_all(Editor_state
)
1380 Editor_state
.cursor1
= {line
=4, pos
=2}
1381 Editor_state
.screen_top1
= {line
=4, pos
=1}
1382 Editor_state
.screen_bottom1
= {}
1383 edit
.draw(Editor_state
)
1384 local y
= Editor_state
.top
1385 App
.screen
.check(y
, 'jkl', 'baseline/screen:1')
1386 -- after hitting the enter key the screen does not scroll down
1387 edit
.run_after_keychord(Editor_state
, 'return')
1388 check_eq(Editor_state
.screen_top1
.line
, 4, 'screen_top')
1389 check_eq(Editor_state
.cursor1
.line
, 5, 'cursor:line')
1390 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1391 y
= Editor_state
.top
1392 App
.screen
.check(y
, 'j', 'screen:1')
1393 y
= y
+ Editor_state
.line_height
1394 App
.screen
.check(y
, 'kl', 'screen:2')
1397 function test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom()
1398 -- display just an empty bottom line on screen
1399 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1400 Editor_state
= edit
.initialize_test_state()
1401 Editor_state
.lines
= load_array
{'abc', ''}
1402 Text
.redraw_all(Editor_state
)
1403 Editor_state
.cursor1
= {line
=2, pos
=1}
1404 Editor_state
.screen_top1
= {line
=2, pos
=1}
1405 Editor_state
.screen_bottom1
= {}
1406 edit
.draw(Editor_state
)
1407 -- after hitting the inserting_text key the screen does not scroll down
1408 edit
.run_after_text_input(Editor_state
, 'a')
1409 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
1410 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
1411 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
1412 local y
= Editor_state
.top
1413 App
.screen
.check(y
, 'a', 'screen:1')
1416 function test_typing_on_bottom_line_scrolls_down()
1417 -- display a few lines with cursor on bottom line
1418 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1419 Editor_state
= edit
.initialize_test_state()
1420 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1421 Text
.redraw_all(Editor_state
)
1422 Editor_state
.cursor1
= {line
=3, pos
=4}
1423 Editor_state
.screen_top1
= {line
=1, pos
=1}
1424 Editor_state
.screen_bottom1
= {}
1425 edit
.draw(Editor_state
)
1426 local y
= Editor_state
.top
1427 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1428 y
= y
+ Editor_state
.line_height
1429 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1430 y
= y
+ Editor_state
.line_height
1431 App
.screen
.check(y
, 'ghi', 'baseline/screen:3')
1432 -- after typing something the line wraps and the screen scrolls down
1433 edit
.run_after_text_input(Editor_state
, 'j')
1434 edit
.run_after_text_input(Editor_state
, 'k')
1435 edit
.run_after_text_input(Editor_state
, 'l')
1436 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
1437 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1438 check_eq(Editor_state
.cursor1
.pos
, 7, 'cursor:pos')
1439 y
= Editor_state
.top
1440 App
.screen
.check(y
, 'def', 'screen:1')
1441 y
= y
+ Editor_state
.line_height
1442 App
.screen
.check(y
, 'ghij', 'screen:2')
1443 y
= y
+ Editor_state
.line_height
1444 App
.screen
.check(y
, 'kl', 'screen:3')
1447 function test_left_arrow_scrolls_up_in_wrapped_line()
1448 -- display lines starting from second screen line of a line
1449 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1450 Editor_state
= edit
.initialize_test_state()
1451 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1452 Text
.redraw_all(Editor_state
)
1453 Editor_state
.screen_top1
= {line
=3, pos
=5}
1454 Editor_state
.screen_bottom1
= {}
1455 -- cursor is at top of screen
1456 Editor_state
.cursor1
= {line
=3, pos
=5}
1457 edit
.draw(Editor_state
)
1458 local y
= Editor_state
.top
1459 App
.screen
.check(y
, 'jkl', 'baseline/screen:1')
1460 y
= y
+ Editor_state
.line_height
1461 App
.screen
.check(y
, 'mno', 'baseline/screen:2')
1462 -- after hitting the left arrow the screen scrolls up to first screen line
1463 edit
.run_after_keychord(Editor_state
, 'left')
1464 y
= Editor_state
.top
1465 App
.screen
.check(y
, 'ghi ', 'screen:1')
1466 y
= y
+ Editor_state
.line_height
1467 App
.screen
.check(y
, 'jkl', 'screen:2')
1468 y
= y
+ Editor_state
.line_height
1469 App
.screen
.check(y
, 'mno', 'screen:3')
1470 check_eq(Editor_state
.screen_top1
.line
, 3, 'screen_top:line')
1471 check_eq(Editor_state
.screen_top1
.pos
, 1, 'screen_top:pos')
1472 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1473 check_eq(Editor_state
.cursor1
.pos
, 4, 'cursor:pos')
1476 function test_right_arrow_scrolls_down_in_wrapped_line()
1477 -- display the first three lines with the cursor on the bottom line
1478 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1479 Editor_state
= edit
.initialize_test_state()
1480 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1481 Text
.redraw_all(Editor_state
)
1482 Editor_state
.screen_top1
= {line
=1, pos
=1}
1483 Editor_state
.screen_bottom1
= {}
1484 -- cursor is at bottom right of screen
1485 Editor_state
.cursor1
= {line
=3, pos
=5}
1486 edit
.draw(Editor_state
)
1487 local y
= Editor_state
.top
1488 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1489 y
= y
+ Editor_state
.line_height
1490 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1491 y
= y
+ Editor_state
.line_height
1492 App
.screen
.check(y
, 'ghi ', 'baseline/screen:3') -- line wrapping includes trailing whitespace
1493 -- after hitting the right arrow the screen scrolls down by one line
1494 edit
.run_after_keychord(Editor_state
, 'right')
1495 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
1496 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1497 check_eq(Editor_state
.cursor1
.pos
, 6, 'cursor:pos')
1498 y
= Editor_state
.top
1499 App
.screen
.check(y
, 'def', 'screen:1')
1500 y
= y
+ Editor_state
.line_height
1501 App
.screen
.check(y
, 'ghi ', 'screen:2')
1502 y
= y
+ Editor_state
.line_height
1503 App
.screen
.check(y
, 'jkl', 'screen:3')
1506 function test_home_scrolls_up_in_wrapped_line()
1507 -- display lines starting from second screen line of a line
1508 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1509 Editor_state
= edit
.initialize_test_state()
1510 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1511 Text
.redraw_all(Editor_state
)
1512 Editor_state
.screen_top1
= {line
=3, pos
=5}
1513 Editor_state
.screen_bottom1
= {}
1514 -- cursor is at top of screen
1515 Editor_state
.cursor1
= {line
=3, pos
=5}
1516 edit
.draw(Editor_state
)
1517 local y
= Editor_state
.top
1518 App
.screen
.check(y
, 'jkl', 'baseline/screen:1')
1519 y
= y
+ Editor_state
.line_height
1520 App
.screen
.check(y
, 'mno', 'baseline/screen:2')
1521 -- after hitting home the screen scrolls up to first screen line
1522 edit
.run_after_keychord(Editor_state
, 'home')
1523 y
= Editor_state
.top
1524 App
.screen
.check(y
, 'ghi ', 'screen:1')
1525 y
= y
+ Editor_state
.line_height
1526 App
.screen
.check(y
, 'jkl', 'screen:2')
1527 y
= y
+ Editor_state
.line_height
1528 App
.screen
.check(y
, 'mno', 'screen:3')
1529 check_eq(Editor_state
.screen_top1
.line
, 3, 'screen_top:line')
1530 check_eq(Editor_state
.screen_top1
.pos
, 1, 'screen_top:pos')
1531 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1532 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1535 function test_end_scrolls_down_in_wrapped_line()
1536 -- display the first three lines with the cursor on the bottom line
1537 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1538 Editor_state
= edit
.initialize_test_state()
1539 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1540 Text
.redraw_all(Editor_state
)
1541 Editor_state
.screen_top1
= {line
=1, pos
=1}
1542 Editor_state
.screen_bottom1
= {}
1543 -- cursor is at bottom right of screen
1544 Editor_state
.cursor1
= {line
=3, pos
=5}
1545 edit
.draw(Editor_state
)
1546 local y
= Editor_state
.top
1547 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1548 y
= y
+ Editor_state
.line_height
1549 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1550 y
= y
+ Editor_state
.line_height
1551 App
.screen
.check(y
, 'ghi ', 'baseline/screen:3') -- line wrapping includes trailing whitespace
1552 -- after hitting end the screen scrolls down by one line
1553 edit
.run_after_keychord(Editor_state
, 'end')
1554 check_eq(Editor_state
.screen_top1
.line
, 2, 'screen_top')
1555 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1556 check_eq(Editor_state
.cursor1
.pos
, 8, 'cursor:pos')
1557 y
= Editor_state
.top
1558 App
.screen
.check(y
, 'def', 'screen:1')
1559 y
= y
+ Editor_state
.line_height
1560 App
.screen
.check(y
, 'ghi ', 'screen:2')
1561 y
= y
+ Editor_state
.line_height
1562 App
.screen
.check(y
, 'jkl', 'screen:3')
1565 function test_position_cursor_on_recently_edited_wrapping_line()
1566 -- draw a line wrapping over 2 screen lines
1567 App
.screen
.init
{width
=100, height
=200}
1568 Editor_state
= edit
.initialize_test_state()
1569 Editor_state
.lines
= load_array
{'abc def ghi jkl mno pqr ', 'xyz'}
1570 Text
.redraw_all(Editor_state
)
1571 Editor_state
.cursor1
= {line
=1, pos
=25}
1572 Editor_state
.screen_top1
= {line
=1, pos
=1}
1573 Editor_state
.screen_bottom1
= {}
1574 edit
.draw(Editor_state
)
1575 local y
= Editor_state
.top
1576 App
.screen
.check(y
, 'abc def ghi ', 'baseline1/screen:1')
1577 y
= y
+ Editor_state
.line_height
1578 App
.screen
.check(y
, 'jkl mno pqr ', 'baseline1/screen:2')
1579 y
= y
+ Editor_state
.line_height
1580 App
.screen
.check(y
, 'xyz', 'baseline1/screen:3')
1581 -- add to the line until it's wrapping over 3 screen lines
1582 edit
.run_after_text_input(Editor_state
, 's')
1583 edit
.run_after_text_input(Editor_state
, 't')
1584 edit
.run_after_text_input(Editor_state
, 'u')
1585 check_eq(Editor_state
.cursor1
.pos
, 28, 'cursor:pos')
1586 y
= Editor_state
.top
1587 App
.screen
.check(y
, 'abc def ghi ', 'baseline2/screen:1')
1588 y
= y
+ Editor_state
.line_height
1589 App
.screen
.check(y
, 'jkl mno pqr ', 'baseline2/screen:2')
1590 y
= y
+ Editor_state
.line_height
1591 App
.screen
.check(y
, 'stu', 'baseline2/screen:3')
1592 -- try to move the cursor earlier in the third screen line by clicking the mouse
1593 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+Editor_state
.line_height
*2+5, 1)
1594 -- cursor should move
1595 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
1596 check_eq(Editor_state
.cursor1
.pos
, 26, 'cursor:pos')
1599 function test_backspace_can_scroll_up()
1600 -- display the lines 2/3/4 with the cursor on line 2
1601 App
.screen
.init
{width
=120, height
=60}
1602 Editor_state
= edit
.initialize_test_state()
1603 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1604 Text
.redraw_all(Editor_state
)
1605 Editor_state
.cursor1
= {line
=2, pos
=1}
1606 Editor_state
.screen_top1
= {line
=2, pos
=1}
1607 Editor_state
.screen_bottom1
= {}
1608 edit
.draw(Editor_state
)
1609 local y
= Editor_state
.top
1610 App
.screen
.check(y
, 'def', 'baseline/screen:1')
1611 y
= y
+ Editor_state
.line_height
1612 App
.screen
.check(y
, 'ghi', 'baseline/screen:2')
1613 y
= y
+ Editor_state
.line_height
1614 App
.screen
.check(y
, 'jkl', 'baseline/screen:3')
1615 -- after hitting backspace the screen scrolls up by one line
1616 edit
.run_after_keychord(Editor_state
, 'backspace')
1617 check_eq(Editor_state
.screen_top1
.line
, 1, 'screen_top')
1618 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor')
1619 y
= Editor_state
.top
1620 App
.screen
.check(y
, 'abcdef', 'screen:1')
1621 y
= y
+ Editor_state
.line_height
1622 App
.screen
.check(y
, 'ghi', 'screen:2')
1623 y
= y
+ Editor_state
.line_height
1624 App
.screen
.check(y
, 'jkl', 'screen:3')
1627 function test_backspace_can_scroll_up_screen_line()
1628 -- display lines starting from second screen line of a line
1629 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1630 Editor_state
= edit
.initialize_test_state()
1631 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1632 Text
.redraw_all(Editor_state
)
1633 Editor_state
.cursor1
= {line
=3, pos
=5}
1634 Editor_state
.screen_top1
= {line
=3, pos
=5}
1635 Editor_state
.screen_bottom1
= {}
1636 edit
.draw(Editor_state
)
1637 local y
= Editor_state
.top
1638 App
.screen
.check(y
, 'jkl', 'baseline/screen:1')
1639 y
= y
+ Editor_state
.line_height
1640 App
.screen
.check(y
, 'mno', 'baseline/screen:2')
1641 -- after hitting backspace the screen scrolls up by one screen line
1642 edit
.run_after_keychord(Editor_state
, 'backspace')
1643 y
= Editor_state
.top
1644 App
.screen
.check(y
, 'ghij', 'screen:1')
1645 y
= y
+ Editor_state
.line_height
1646 App
.screen
.check(y
, 'kl', 'screen:2')
1647 y
= y
+ Editor_state
.line_height
1648 App
.screen
.check(y
, 'mno', 'screen:3')
1649 check_eq(Editor_state
.screen_top1
.line
, 3, 'screen_top:line')
1650 check_eq(Editor_state
.screen_top1
.pos
, 1, 'screen_top:pos')
1651 check_eq(Editor_state
.cursor1
.line
, 3, 'cursor:line')
1652 check_eq(Editor_state
.cursor1
.pos
, 4, 'cursor:pos')
1655 function test_backspace_past_line_boundary()
1656 -- position cursor at start of a (non-first) line
1657 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1658 Editor_state
= edit
.initialize_test_state()
1659 Editor_state
.lines
= load_array
{'abc', 'def'}
1660 Text
.redraw_all(Editor_state
)
1661 Editor_state
.cursor1
= {line
=2, pos
=1}
1662 -- backspace joins with previous line
1663 edit
.run_after_keychord(Editor_state
, 'backspace')
1664 check_eq(Editor_state
.lines
[1].data
, 'abcdef', 'check')
1667 -- some tests for operating over selections created using Shift- chords
1668 -- we're just testing delete_selection, and it works the same for all keys
1670 function test_backspace_over_selection()
1671 -- select just one character within a line with cursor before selection
1672 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1673 Editor_state
= edit
.initialize_test_state()
1674 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1675 Text
.redraw_all(Editor_state
)
1676 Editor_state
.cursor1
= {line
=1, pos
=1}
1677 Editor_state
.selection1
= {line
=1, pos
=2}
1678 -- backspace deletes the selected character, even though it's after the cursor
1679 edit
.run_after_keychord(Editor_state
, 'backspace')
1680 check_eq(Editor_state
.lines
[1].data
, 'bc', 'data')
1681 -- cursor (remains) at start of selection
1682 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
1683 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1684 -- selection is cleared
1685 check_nil(Editor_state
.selection1
.line
, 'selection')
1688 function test_backspace_over_selection_reverse()
1689 -- select just one character within a line with cursor after selection
1690 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1691 Editor_state
= edit
.initialize_test_state()
1692 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1693 Text
.redraw_all(Editor_state
)
1694 Editor_state
.cursor1
= {line
=1, pos
=2}
1695 Editor_state
.selection1
= {line
=1, pos
=1}
1696 -- backspace deletes the selected character
1697 edit
.run_after_keychord(Editor_state
, 'backspace')
1698 check_eq(Editor_state
.lines
[1].data
, 'bc', 'data')
1699 -- cursor moves to start of selection
1700 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
1701 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1702 -- selection is cleared
1703 check_nil(Editor_state
.selection1
.line
, 'selection')
1706 function test_backspace_over_multiple_lines()
1707 -- select just one character within a line with cursor after selection
1708 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1709 Editor_state
= edit
.initialize_test_state()
1710 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1711 Text
.redraw_all(Editor_state
)
1712 Editor_state
.cursor1
= {line
=1, pos
=2}
1713 Editor_state
.selection1
= {line
=4, pos
=2}
1714 -- backspace deletes the region and joins the remaining portions of lines on either side
1715 edit
.run_after_keychord(Editor_state
, 'backspace')
1716 check_eq(Editor_state
.lines
[1].data
, 'akl', 'data:1')
1717 check_eq(Editor_state
.lines
[2].data
, 'mno', 'data:2')
1718 -- cursor remains at start of selection
1719 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
1720 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
1721 -- selection is cleared
1722 check_nil(Editor_state
.selection1
.line
, 'selection')
1725 function test_backspace_to_end_of_line()
1726 -- select region from cursor to end of line
1727 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1728 Editor_state
= edit
.initialize_test_state()
1729 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1730 Text
.redraw_all(Editor_state
)
1731 Editor_state
.cursor1
= {line
=1, pos
=2}
1732 Editor_state
.selection1
= {line
=1, pos
=4}
1733 -- backspace deletes rest of line without joining to any other line
1734 edit
.run_after_keychord(Editor_state
, 'backspace')
1735 check_eq(Editor_state
.lines
[1].data
, 'a', 'data:1')
1736 check_eq(Editor_state
.lines
[2].data
, 'def', 'data:2')
1737 -- cursor remains at start of selection
1738 check_eq(Editor_state
.cursor1
.line
, 1, 'cursor:line')
1739 check_eq(Editor_state
.cursor1
.pos
, 2, 'cursor:pos')
1740 -- selection is cleared
1741 check_nil(Editor_state
.selection1
.line
, 'selection')
1744 function test_backspace_to_start_of_line()
1745 -- select region from cursor to start of line
1746 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1747 Editor_state
= edit
.initialize_test_state()
1748 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1749 Text
.redraw_all(Editor_state
)
1750 Editor_state
.cursor1
= {line
=2, pos
=1}
1751 Editor_state
.selection1
= {line
=2, pos
=3}
1752 -- backspace deletes beginning of line without joining to any other line
1753 edit
.run_after_keychord(Editor_state
, 'backspace')
1754 check_eq(Editor_state
.lines
[1].data
, 'abc', 'data:1')
1755 check_eq(Editor_state
.lines
[2].data
, 'f', 'data:2')
1756 -- cursor remains at start of selection
1757 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
1758 check_eq(Editor_state
.cursor1
.pos
, 1, 'cursor:pos')
1759 -- selection is cleared
1760 check_nil(Editor_state
.selection1
.line
, 'selection')
1763 function test_undo_insert_text()
1764 App
.screen
.init
{width
=120, height
=60}
1765 Editor_state
= edit
.initialize_test_state()
1766 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
1767 Text
.redraw_all(Editor_state
)
1768 Editor_state
.cursor1
= {line
=2, pos
=4}
1769 Editor_state
.screen_top1
= {line
=1, pos
=1}
1770 Editor_state
.screen_bottom1
= {}
1771 -- insert a character
1772 edit
.draw(Editor_state
)
1773 edit
.run_after_text_input(Editor_state
, 'g')
1774 check_eq(Editor_state
.cursor1
.line
, 2, 'baseline/cursor:line')
1775 check_eq(Editor_state
.cursor1
.pos
, 5, 'baseline/cursor:pos')
1776 check_nil(Editor_state
.selection1
.line
, 'baseline/selection:line')
1777 check_nil(Editor_state
.selection1
.pos
, 'baseline/selection:pos')
1778 local y
= Editor_state
.top
1779 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1780 y
= y
+ Editor_state
.line_height
1781 App
.screen
.check(y
, 'defg', 'baseline/screen:2')
1782 y
= y
+ Editor_state
.line_height
1783 App
.screen
.check(y
, 'xyz', 'baseline/screen:3')
1785 edit
.run_after_keychord(Editor_state
, 'C-z')
1786 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
1787 check_eq(Editor_state
.cursor1
.pos
, 4, 'cursor:pos')
1788 check_nil(Editor_state
.selection1
.line
, 'selection:line')
1789 check_nil(Editor_state
.selection1
.pos
, 'selection:pos')
1790 y
= Editor_state
.top
1791 App
.screen
.check(y
, 'abc', 'screen:1')
1792 y
= y
+ Editor_state
.line_height
1793 App
.screen
.check(y
, 'def', 'screen:2')
1794 y
= y
+ Editor_state
.line_height
1795 App
.screen
.check(y
, 'xyz', 'screen:3')
1798 function test_undo_delete_text()
1799 App
.screen
.init
{width
=120, height
=60}
1800 Editor_state
= edit
.initialize_test_state()
1801 Editor_state
.lines
= load_array
{'abc', 'defg', 'xyz'}
1802 Text
.redraw_all(Editor_state
)
1803 Editor_state
.cursor1
= {line
=2, pos
=5}
1804 Editor_state
.screen_top1
= {line
=1, pos
=1}
1805 Editor_state
.screen_bottom1
= {}
1806 -- delete a character
1807 edit
.run_after_keychord(Editor_state
, 'backspace')
1808 check_eq(Editor_state
.cursor1
.line
, 2, 'baseline/cursor:line')
1809 check_eq(Editor_state
.cursor1
.pos
, 4, 'baseline/cursor:pos')
1810 check_nil(Editor_state
.selection1
.line
, 'baseline/selection:line')
1811 check_nil(Editor_state
.selection1
.pos
, 'baseline/selection:pos')
1812 local y
= Editor_state
.top
1813 App
.screen
.check(y
, 'abc', 'baseline/screen:1')
1814 y
= y
+ Editor_state
.line_height
1815 App
.screen
.check(y
, 'def', 'baseline/screen:2')
1816 y
= y
+ Editor_state
.line_height
1817 App
.screen
.check(y
, 'xyz', 'baseline/screen:3')
1819 --? -- after undo, the backspaced key is selected
1820 edit
.run_after_keychord(Editor_state
, 'C-z')
1821 check_eq(Editor_state
.cursor1
.line
, 2, 'cursor:line')
1822 check_eq(Editor_state
.cursor1
.pos
, 5, 'cursor:pos')
1823 check_nil(Editor_state
.selection1
.line
, 'selection:line')
1824 check_nil(Editor_state
.selection1
.pos
, 'selection:pos')
1825 --? check_eq(Editor_state.selection1.line, 2, 'selection:line')
1826 --? check_eq(Editor_state.selection1.pos, 4, 'selection:pos')
1827 y
= Editor_state
.top
1828 App
.screen
.check(y
, 'abc', 'screen:1')
1829 y
= y
+ Editor_state
.line_height
1830 App
.screen
.check(y
, 'defg', 'screen:2')
1831 y
= y
+ Editor_state
.line_height
1832 App
.screen
.check(y
, 'xyz', 'screen:3')
1835 function test_undo_restores_selection()
1836 -- display a line of text with some part selected
1837 App
.screen
.init
{width
=75, height
=80}
1838 Editor_state
= edit
.initialize_test_state()
1839 Editor_state
.lines
= load_array
{'abc'}
1840 Text
.redraw_all(Editor_state
)
1841 Editor_state
.cursor1
= {line
=1, pos
=1}
1842 Editor_state
.selection1
= {line
=1, pos
=2}
1843 Editor_state
.screen_top1
= {line
=1, pos
=1}
1844 Editor_state
.screen_bottom1
= {}
1845 edit
.draw(Editor_state
)
1846 -- delete selected text
1847 edit
.run_after_text_input(Editor_state
, 'x')
1848 check_eq(Editor_state
.lines
[1].data
, 'xbc', 'baseline')
1849 check_nil(Editor_state
.selection1
.line
, 'baseline:selection')
1851 edit
.run_after_keychord(Editor_state
, 'C-z')
1852 edit
.run_after_keychord(Editor_state
, 'C-z')
1853 -- selection is restored
1854 check_eq(Editor_state
.selection1
.line
, 1, 'line')
1855 check_eq(Editor_state
.selection1
.pos
, 2, 'pos')
1858 function test_search()
1859 App
.screen
.init
{width
=120, height
=60}
1860 Editor_state
= edit
.initialize_test_state()
1861 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', '’deg'} -- contains unicode quote in final line
1862 Text
.redraw_all(Editor_state
)
1863 Editor_state
.cursor1
= {line
=1, pos
=1}
1864 Editor_state
.screen_top1
= {line
=1, pos
=1}
1865 Editor_state
.screen_bottom1
= {}
1866 edit
.draw(Editor_state
)
1867 -- search for a string
1868 edit
.run_after_keychord(Editor_state
, 'C-f')
1869 edit
.run_after_text_input(Editor_state
, 'd')
1870 edit
.run_after_keychord(Editor_state
, 'return')
1871 check_eq(Editor_state
.cursor1
.line
, 2, '1/cursor:line')
1872 check_eq(Editor_state
.cursor1
.pos
, 1, '1/cursor:pos')
1874 Editor_state
.cursor1
= {line
=1, pos
=1}
1875 Editor_state
.screen_top1
= {line
=1, pos
=1}
1876 -- search for second occurrence
1877 edit
.run_after_keychord(Editor_state
, 'C-f')
1878 edit
.run_after_text_input(Editor_state
, 'de')
1879 edit
.run_after_keychord(Editor_state
, 'down')
1880 edit
.run_after_keychord(Editor_state
, 'return')
1881 check_eq(Editor_state
.cursor1
.line
, 4, '2/cursor:line')
1882 check_eq(Editor_state
.cursor1
.pos
, 2, '2/cursor:pos')
1885 function test_search_upwards()
1886 App
.screen
.init
{width
=120, height
=60}
1887 Editor_state
= edit
.initialize_test_state()
1888 Editor_state
.lines
= load_array
{'’abc', 'abd'} -- contains unicode quote
1889 Text
.redraw_all(Editor_state
)
1890 Editor_state
.cursor1
= {line
=2, pos
=1}
1891 Editor_state
.screen_top1
= {line
=1, pos
=1}
1892 Editor_state
.screen_bottom1
= {}
1893 edit
.draw(Editor_state
)
1894 -- search for a string
1895 edit
.run_after_keychord(Editor_state
, 'C-f')
1896 edit
.run_after_text_input(Editor_state
, 'a')
1897 -- search for previous occurrence
1898 edit
.run_after_keychord(Editor_state
, 'up')
1899 check_eq(Editor_state
.cursor1
.line
, 1, '2/cursor:line')
1900 check_eq(Editor_state
.cursor1
.pos
, 2, '2/cursor:pos')
1903 function test_search_wrap()
1904 App
.screen
.init
{width
=120, height
=60}
1905 Editor_state
= edit
.initialize_test_state()
1906 Editor_state
.lines
= load_array
{'’abc', 'def'} -- contains unicode quote in first line
1907 Text
.redraw_all(Editor_state
)
1908 Editor_state
.cursor1
= {line
=2, pos
=1}
1909 Editor_state
.screen_top1
= {line
=1, pos
=1}
1910 Editor_state
.screen_bottom1
= {}
1911 edit
.draw(Editor_state
)
1912 -- search for a string
1913 edit
.run_after_keychord(Editor_state
, 'C-f')
1914 edit
.run_after_text_input(Editor_state
, 'a')
1915 edit
.run_after_keychord(Editor_state
, 'return')
1917 check_eq(Editor_state
.cursor1
.line
, 1, '1/cursor:line')
1918 check_eq(Editor_state
.cursor1
.pos
, 2, '1/cursor:pos')
1921 function test_search_wrap_upwards()
1922 App
.screen
.init
{width
=120, height
=60}
1923 Editor_state
= edit
.initialize_test_state()
1924 Editor_state
.lines
= load_array
{'abc ’abd'} -- contains unicode quote
1925 Text
.redraw_all(Editor_state
)
1926 Editor_state
.cursor1
= {line
=1, pos
=1}
1927 Editor_state
.screen_top1
= {line
=1, pos
=1}
1928 Editor_state
.screen_bottom1
= {}
1929 edit
.draw(Editor_state
)
1930 -- search upwards for a string
1931 edit
.run_after_keychord(Editor_state
, 'C-f')
1932 edit
.run_after_text_input(Editor_state
, 'a')
1933 edit
.run_after_keychord(Editor_state
, 'up')
1935 check_eq(Editor_state
.cursor1
.line
, 1, '1/cursor:line')
1936 check_eq(Editor_state
.cursor1
.pos
, 6, '1/cursor:pos')