blob: 3d3fdd0becf6a4ec69d78ed43432c6cc6539d767 [file] [log] [blame]
Bram Moolenaar9aa15692017-08-19 15:05:32 +02001" Tests for 'virtualedit'.
2
3func Test_yank_move_change()
Bram Moolenaard41babe2017-08-30 17:01:35 +02004 new
Bram Moolenaar9aa15692017-08-19 15:05:32 +02005 call setline(1, [
6 \ "func foo() error {",
7 \ "\tif n, err := bar();",
8 \ "\terr != nil {",
9 \ "\t\treturn err",
10 \ "\t}",
11 \ "\tn = n * n",
12 \ ])
13 set virtualedit=all
14 set ts=4
15 function! MoveSelectionDown(count) abort
16 normal! m`
17 silent! exe "'<,'>move'>+".a:count
18 norm! ``
19 endfunction
20
21 xmap ]e :<C-U>call MoveSelectionDown(v:count1)<CR>
22 2
23 normal 2gg
24 normal J
25 normal jVj
26 normal ]e
27 normal ce
28 bwipe!
29 set virtualedit=
30 set ts=8
31endfunc
Bram Moolenaard41babe2017-08-30 17:01:35 +020032
33func Test_paste_end_of_line()
34 new
35 set virtualedit=all
36 call setline(1, ['456', '123'])
37 normal! gg0"ay$
38 exe "normal! 2G$lllA\<C-O>:normal! \"agP\r"
39 call assert_equal('123456', getline(2))
40
41 bwipe!
42 set virtualedit=
43endfunc
Bram Moolenaardb0eede2018-04-25 22:38:17 +020044
Bram Moolenaar630afe82018-06-28 19:26:28 +020045func Test_replace_end_of_line()
46 new
47 set virtualedit=all
48 call setline(1, range(20))
49 exe "normal! gg2jv10lr-"
50 call assert_equal(["1", "-----------", "3"], getline(2,4))
Bram Moolenaar30276f22019-01-24 17:59:39 +010051 call setline(1, range(20))
52 exe "normal! gg2jv10lr\<c-k>hh"
53 call assert_equal(["1", "───────────", "3"], getline(2,4))
Bram Moolenaar630afe82018-06-28 19:26:28 +020054
55 bwipe!
56 set virtualedit=
57endfunc
58
Bram Moolenaardb0eede2018-04-25 22:38:17 +020059func Test_edit_CTRL_G()
60 new
61 set virtualedit=insert
62 call setline(1, ['123', '1', '12'])
63 exe "normal! ggA\<c-g>jx\<c-g>jx"
64 call assert_equal(['123', '1 x', '12 x'], getline(1,'$'))
65
66 set virtualedit=all
67 %d_
68 call setline(1, ['1', '12'])
69 exe "normal! ggllix\<c-g>jx"
70 call assert_equal(['1 x', '12x'], getline(1,'$'))
71
72
73 bwipe!
74 set virtualedit=
75endfunc
Bram Moolenaar77ccc002019-10-31 03:21:25 +010076
77func Test_edit_change()
78 new
79 set virtualedit=all
zeertzjq048761b2024-02-24 14:21:39 +010080
Bram Moolenaar77ccc002019-10-31 03:21:25 +010081 call setline(1, "\t⒌")
82 normal Cx
83 call assert_equal('x', getline(1))
zeertzjq048761b2024-02-24 14:21:39 +010084
85 call setline(1, "\ta̳")
86 normal Cx
87 call assert_equal('x', getline(1))
88
89 call setline(1, "\tβ̳")
90 normal Cx
91 call assert_equal('x', getline(1))
92
93 if has('arabic')
94 call setline(1, "\tلا")
95 normal Cx
96 call assert_equal('x', getline(1))
97 endif
98
Bram Moolenaar3e72dca2021-05-29 16:30:12 +020099 " Do a visual block change
100 call setline(1, ['a', 'b', 'c'])
101 exe "normal gg3l\<C-V>2jcx"
102 call assert_equal(['a x', 'b x', 'c x'], getline(1, '$'))
zeertzjq048761b2024-02-24 14:21:39 +0100103
Bram Moolenaar77ccc002019-10-31 03:21:25 +0100104 bwipe!
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100105 set virtualedit=
106endfunc
107
Bram Moolenaarc99cbf82023-03-04 14:13:10 +0000108func Test_edit_special_char()
109 new
110 se ve=all
111 norm a0
112 sil! exe "norm o00000\<Nul>k<a0s"
113
114 bwipe!
115 set virtualedit=
116endfunc
117
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100118" Tests for pasting at the beginning, end and middle of a tab character
119" in virtual edit mode.
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100120func Test_paste_in_tab()
121 new
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100122 call append(0, '')
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100123 set virtualedit=all
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100124
125 " Tests for pasting a register with characterwise mode type
126 call setreg('"', 'xyz', 'c')
127
128 " paste (p) unnamed register at the beginning of a tab
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100129 call setline(1, "a\tb")
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100130 call cursor(1, 2, 0)
131 normal p
132 call assert_equal('a xyz b', getline(1))
133
134 " paste (P) unnamed register at the beginning of a tab
135 call setline(1, "a\tb")
136 call cursor(1, 2, 0)
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100137 normal P
138 call assert_equal("axyz\tb", getline(1))
139
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100140 " paste (p) unnamed register at the end of a tab
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100141 call setline(1, "a\tb")
142 call cursor(1, 2, 6)
143 normal p
144 call assert_equal("a\txyzb", getline(1))
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100145
146 " paste (P) unnamed register at the end of a tab
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100147 call setline(1, "a\tb")
148 call cursor(1, 2, 6)
149 normal P
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100150 call assert_equal('a xyz b', getline(1))
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100151
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100152 " Tests for pasting a register with blockwise mode type
153 call setreg('"', 'xyz', 'b')
154
155 " paste (p) unnamed register at the beginning of a tab
156 call setline(1, "a\tb")
157 call cursor(1, 2, 0)
158 normal p
159 call assert_equal('a xyz b', getline(1))
160
161 " paste (P) unnamed register at the beginning of a tab
162 call setline(1, "a\tb")
163 call cursor(1, 2, 0)
164 normal P
165 call assert_equal("axyz\tb", getline(1))
166
167 " paste (p) unnamed register at the end of a tab
168 call setline(1, "a\tb")
169 call cursor(1, 2, 6)
170 normal p
171 call assert_equal("a\txyzb", getline(1))
172
173 " paste (P) unnamed register at the end of a tab
174 call setline(1, "a\tb")
175 call cursor(1, 2, 6)
176 normal P
177 call assert_equal('a xyz b', getline(1))
178
179 " Tests for pasting with gp and gP in virtual edit mode
180
181 " paste (gp) unnamed register at the beginning of a tab
182 call setline(1, "a\tb")
183 call cursor(1, 2, 0)
184 normal gp
185 call assert_equal('a xyz b', getline(1))
186 call assert_equal([0, 1, 12, 0, 12], getcurpos())
187
188 " paste (gP) unnamed register at the beginning of a tab
189 call setline(1, "a\tb")
190 call cursor(1, 2, 0)
191 normal gP
192 call assert_equal("axyz\tb", getline(1))
193 call assert_equal([0, 1, 5, 0, 5], getcurpos())
194
195 " paste (gp) unnamed register at the end of a tab
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100196 call setline(1, "a\tb")
197 call cursor(1, 2, 6)
198 normal gp
199 call assert_equal("a\txyzb", getline(1))
200 call assert_equal([0, 1, 6, 0, 12], getcurpos())
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100201
202 " paste (gP) unnamed register at the end of a tab
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100203 call setline(1, "a\tb")
204 call cursor(1, 2, 6)
205 normal gP
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100206 call assert_equal('a xyz b', getline(1))
207 call assert_equal([0, 1, 12, 0, 12], getcurpos())
208
209 " Tests for pasting a named register
210 let @r = 'xyz'
211
212 " paste (gp) named register in the middle of a tab
213 call setline(1, "a\tb")
214 call cursor(1, 2, 2)
215 normal "rgp
216 call assert_equal('a xyz b', getline(1))
217 call assert_equal([0, 1, 8, 0, 8], getcurpos())
218
219 " paste (gP) named register in the middle of a tab
220 call setline(1, "a\tb")
221 call cursor(1, 2, 2)
222 normal "rgP
223 call assert_equal('a xyz b', getline(1))
224 call assert_equal([0, 1, 7, 0, 7], getcurpos())
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100225
226 bwipe!
227 set virtualedit=
Bram Moolenaar77ccc002019-10-31 03:21:25 +0100228endfunc
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100229
230" Test for yanking a few spaces within a tab to a register
231func Test_yank_in_tab()
232 new
233 let @r = ''
234 call setline(1, "a\tb")
235 set virtualedit=all
236 call cursor(1, 2, 2)
237 normal "ry5l
238 call assert_equal(' ', @r)
239
240 bwipe!
241 set virtualedit=
242endfunc
243
Bram Moolenaar079119b2019-12-03 22:59:23 +0100244" Insert "keyword keyw", ESC, C CTRL-N, shows "keyword ykeyword".
245" Repeating CTRL-N fixes it. (Mary Ellen Foster)
246func Test_ve_completion()
247 new
248 set completeopt&vim
249 set virtualedit=all
250 exe "normal ikeyword keyw\<Esc>C\<C-N>"
251 call assert_equal('keyword keyword', getline(1))
252 bwipe!
253 set virtualedit=
254endfunc
255
Christian Brabandtee17b6f2023-09-09 11:23:50 +0200256" Using "C" then <CR> moves the last remaining character to the next
Bram Moolenaar079119b2019-12-03 22:59:23 +0100257" line. (Mary Ellen Foster)
258func Test_ve_del_to_eol()
259 new
260 set virtualedit=all
261 call append(0, 'all your base are belong to us')
262 call search('are', 'w')
263 exe "normal C\<CR>are belong to vim"
264 call assert_equal(['all your base ', 'are belong to vim'], getline(1, 2))
265 bwipe!
266 set virtualedit=
267endfunc
268
269" When past the end of a line that ends in a single character "b" skips
270" that word.
271func Test_ve_b_past_eol()
272 new
273 set virtualedit=all
274 call append(0, '1 2 3 4 5 6')
275 normal gg^$15lbC7
276 call assert_equal('1 2 3 4 5 7', getline(1))
277 bwipe!
278 set virtualedit=
279endfunc
280
281" Make sure 'i', 'C', 'a', 'A' and 'D' works
282func Test_ve_ins_del()
283 new
284 set virtualedit=all
285 call append(0, ["'i'", "'C'", "'a'", "'A'", "'D'"])
286 call cursor(1, 1)
287 normal $4lix
288 call assert_equal("'i' x", getline(1))
289 call cursor(2, 1)
290 normal $4lCx
291 call assert_equal("'C' x", getline(2))
292 call cursor(3, 1)
293 normal $4lax
294 call assert_equal("'a' x", getline(3))
295 call cursor(4, 1)
296 normal $4lAx
297 call assert_equal("'A'x", getline(4))
298 call cursor(5, 1)
299 normal $4lDix
300 call assert_equal("'D' x", getline(5))
301 bwipe!
302 set virtualedit=
303endfunc
304
305" Test for yank bug reported by Mark Waggoner.
306func Test_yank_block()
307 new
308 set virtualedit=block
309 call append(0, repeat(['this is a test'], 3))
310 exe "normal gg^2w\<C-V>3jy"
311 call assert_equal("a\na\na\n ", @")
312 bwipe!
313 set virtualedit=
314endfunc
315
316" Test "r" beyond the end of the line
317func Test_replace_after_eol()
318 new
319 set virtualedit=all
320 call append(0, '"r"')
321 normal gg$5lrxa
322 call assert_equal('"r" x', getline(1))
Bram Moolenaar3e72dca2021-05-29 16:30:12 +0200323 " visual block replace
324 %d _
325 call setline(1, ['a', '', 'b'])
326 exe "normal 2l\<C-V>2jrx"
327 call assert_equal(['a x', ' x', 'b x'], getline(1, '$'))
328 " visual characterwise selection replace after eol
329 %d _
330 call setline(1, 'a')
331 normal 4lv2lrx
332 call assert_equal('a xxx', getline(1))
Bram Moolenaar079119b2019-12-03 22:59:23 +0100333 bwipe!
334 set virtualedit=
335endfunc
336
337" Test "r" on a tab
338" Note that for this test, 'ts' must be 8 (the default).
339func Test_replace_on_tab()
340 new
341 set virtualedit=all
342 call append(0, "'r'\t")
343 normal gg^5lrxAy
344 call assert_equal("'r' x y", getline(1))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100345 call setline(1, 'aaaaaaaaaaaa')
346 exe "normal! gg2lgR\<Tab>"
347 call assert_equal("aa\taaaa", getline(1))
Bram Moolenaar079119b2019-12-03 22:59:23 +0100348 bwipe!
349 set virtualedit=
350endfunc
351
352" Test to make sure 'x' can delete control characters
353func Test_ve_del_ctrl_chars()
354 new
355 set virtualedit=all
356 call append(0, "a\<C-V>b\<CR>sd")
357 set display=uhex
358 normal gg^xxxxxxi[text]
359 set display=
360 call assert_equal('[text]', getline(1))
361 bwipe!
362 set virtualedit=
363endfunc
364
365" Test for ^Y/^E due to bad w_virtcol value, reported by
366" Roy <royl@netropolis.net>.
367func Test_ins_copy_char()
368 new
369 set virtualedit=all
370 call append(0, 'abcv8efi.him2kl')
371 exe "normal gg^O\<Esc>3li\<C-E>\<Esc>4li\<C-E>\<Esc>4li\<C-E> <--"
372 exe "normal j^o\<Esc>4li\<C-Y>\<Esc>4li\<C-Y>\<Esc>4li\<C-Y> <--"
373 call assert_equal(' v i m <--', getline(1))
374 call assert_equal(' 8 . 2 <--', getline(3))
375 bwipe!
376 set virtualedit=
377endfunc
378
379" Test for yanking and pasting using the small delete register
380func Test_yank_paste_small_del_reg()
381 new
382 set virtualedit=all
383 call append(0, "foo, bar")
384 normal ggdewve"-p
385 call assert_equal(', foo', getline(1))
386 bwipe!
387 set virtualedit=
388endfunc
389
Bram Moolenaar004a6782020-04-11 17:09:31 +0200390" Test for delete that breaks a tab into spaces
391func Test_delete_break_tab()
392 new
393 call setline(1, "one\ttwo")
394 set virtualedit=all
395 normal v3ld
396 call assert_equal(' two', getline(1))
397 set virtualedit&
398 close!
399endfunc
400
Bram Moolenaar845e0ee2020-06-20 16:05:32 +0200401" Test for using <BS>, <C-W> and <C-U> in virtual edit mode
402" to erase character, word and line.
403func Test_ve_backspace()
404 new
405 call setline(1, 'sample')
406 set virtualedit=all
407 set backspace=indent,eol,start
408 exe "normal 15|i\<BS>\<BS>"
409 call assert_equal([0, 1, 7, 5], getpos('.'))
410 exe "normal 15|i\<C-W>"
411 call assert_equal([0, 1, 6, 0], getpos('.'))
412 exe "normal 15|i\<C-U>"
413 call assert_equal([0, 1, 1, 0], getpos('.'))
414 set backspace&
415 set virtualedit&
416 close!
417endfunc
418
Bram Moolenaar3e72dca2021-05-29 16:30:12 +0200419" Test for delete (x) on EOL character and after EOL
420func Test_delete_past_eol()
421 new
422 call setline(1, "ab")
423 set virtualedit=all
424 exe "normal 2lx"
425 call assert_equal('ab', getline(1))
426 exe "normal 10lx"
427 call assert_equal('ab', getline(1))
428 set virtualedit&
429 bw!
430endfunc
431
Gary Johnson53ba05b2021-07-26 22:19:10 +0200432" After calling s:TryVirtualeditReplace(), line 1 will contain one of these
433" two strings, depending on whether virtual editing is on or off.
434let s:result_ve_on = 'a x'
435let s:result_ve_off = 'x'
436
Gary Johnson51ad8502021-08-03 18:33:08 +0200437" Utility function for Test_global_local_virtualedit()
Gary Johnson53ba05b2021-07-26 22:19:10 +0200438func s:TryVirtualeditReplace()
439 call setline(1, 'a')
440 normal gg7l
441 normal rx
442endfunc
443
444" Test for :set and :setlocal
Gary Johnson51ad8502021-08-03 18:33:08 +0200445func Test_global_local_virtualedit()
Gary Johnson53ba05b2021-07-26 22:19:10 +0200446 new
447
448 " Verify that 'virtualedit' is initialized to empty, can be set globally to
449 " all and to empty, and can be set locally to all and to empty.
450 call s:TryVirtualeditReplace()
451 call assert_equal(s:result_ve_off, getline(1))
452 set ve=all
453 call s:TryVirtualeditReplace()
454 call assert_equal(s:result_ve_on, getline(1))
455 set ve=
456 call s:TryVirtualeditReplace()
457 call assert_equal(s:result_ve_off, getline(1))
458 setlocal ve=all
459 call s:TryVirtualeditReplace()
460 call assert_equal(s:result_ve_on, getline(1))
461 setlocal ve=
462 call s:TryVirtualeditReplace()
463 call assert_equal(s:result_ve_off, getline(1))
464
Gary Johnson51ad8502021-08-03 18:33:08 +0200465 " Verify that :set affects multiple windows.
466 split
Gary Johnson53ba05b2021-07-26 22:19:10 +0200467 set ve=all
468 call s:TryVirtualeditReplace()
469 call assert_equal(s:result_ve_on, getline(1))
470 wincmd p
471 call s:TryVirtualeditReplace()
472 call assert_equal(s:result_ve_on, getline(1))
473 set ve=
474 wincmd p
475 call s:TryVirtualeditReplace()
476 call assert_equal(s:result_ve_off, getline(1))
477 bwipe!
478
Gary Johnson51ad8502021-08-03 18:33:08 +0200479 " Verify that :setlocal affects only the current window.
Gary Johnson53ba05b2021-07-26 22:19:10 +0200480 new
Gary Johnson51ad8502021-08-03 18:33:08 +0200481 split
Gary Johnson53ba05b2021-07-26 22:19:10 +0200482 setlocal ve=all
Gary Johnson53ba05b2021-07-26 22:19:10 +0200483 call s:TryVirtualeditReplace()
484 call assert_equal(s:result_ve_on, getline(1))
Gary Johnson51ad8502021-08-03 18:33:08 +0200485 wincmd p
486 call s:TryVirtualeditReplace()
487 call assert_equal(s:result_ve_off, getline(1))
Gary Johnson53ba05b2021-07-26 22:19:10 +0200488 bwipe!
489 call s:TryVirtualeditReplace()
490 call assert_equal(s:result_ve_off, getline(1))
491
492 " Verify that the buffer 'virtualedit' state follows the global value only
493 " when empty and that "none" works as expected.
494 "
495 " 'virtualedit' State
496 " +--------+--------------------------+
497 " | Local | Global |
498 " | | |
499 " +--------+--------+--------+--------+
500 " | | "" | "all" | "none" |
501 " +--------+--------+--------+--------+
502 " | "" | off | on | off |
503 " | "all" | on | on | on |
504 " | "none" | off | off | off |
505 " +--------+--------+--------+--------+
506 new
507
508 setglobal ve=
509 setlocal ve=
510 call s:TryVirtualeditReplace()
511 call assert_equal(s:result_ve_off, getline(1))
512 setlocal ve=all
513 call s:TryVirtualeditReplace()
514 call assert_equal(s:result_ve_on, getline(1))
515 setlocal ve=none
516 call s:TryVirtualeditReplace()
517 call assert_equal(s:result_ve_off, getline(1))
518
519 setglobal ve=all
520 setlocal ve=
521 call s:TryVirtualeditReplace()
522 call assert_equal(s:result_ve_on, getline(1))
523 setlocal ve=all
524 call s:TryVirtualeditReplace()
525 call assert_equal(s:result_ve_on, getline(1))
526 setlocal ve=none
527 call s:TryVirtualeditReplace()
528 call assert_equal(s:result_ve_off, getline(1))
529 setlocal ve=NONE
530 call s:TryVirtualeditReplace()
531 call assert_equal(s:result_ve_off, getline(1))
532
533 setglobal ve=none
534 setlocal ve=
535 call s:TryVirtualeditReplace()
536 call assert_equal(s:result_ve_off, getline(1))
537 setlocal ve=all
538 call s:TryVirtualeditReplace()
539 call assert_equal(s:result_ve_on, getline(1))
540 setlocal ve=none
541 call s:TryVirtualeditReplace()
542 call assert_equal(s:result_ve_off, getline(1))
543
544 bwipe!
545
Gary Johnson51ad8502021-08-03 18:33:08 +0200546 " Verify that the 'virtualedit' state is copied to new windows.
547 new
548 call s:TryVirtualeditReplace()
549 call assert_equal(s:result_ve_off, getline(1))
550 split
551 setlocal ve=all
552 call s:TryVirtualeditReplace()
553 call assert_equal(s:result_ve_on, getline(1))
554 split
555 call s:TryVirtualeditReplace()
556 call assert_equal(s:result_ve_on, getline(1))
557 setlocal ve=
558 split
559 call s:TryVirtualeditReplace()
560 call assert_equal(s:result_ve_off, getline(1))
561 bwipe!
562
Gary Johnson53ba05b2021-07-26 22:19:10 +0200563 setlocal virtualedit&
564 set virtualedit&
565endfunc
566
Bram Moolenaar8fe5b9c2023-01-28 16:37:37 +0000567func Test_virtualedit_setlocal()
568 enew
569 setglobal virtualedit=all
570 setlocal virtualedit=all
571 normal! l
572 redraw
573 setlocal virtualedit=none
574 call assert_equal(1, wincol())
575
576 setlocal virtualedit&
577 set virtualedit&
578endfunc
579
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100580func Test_virtualedit_mouse()
581 let save_mouse = &mouse
582 set mouse=a
583 set virtualedit=all
zeertzjq03cd6972023-09-20 20:08:40 +0200584 botright new
585 let row = win_screenpos(0)[0]
586 20vsplit
587 wincmd p
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100588
589 call setline(1, ["text\tword"])
590 redraw
zeertzjq03cd6972023-09-20 20:08:40 +0200591 call test_setmouse(row, 21 + 4)
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100592 call feedkeys("\<LeftMouse>", "xt")
593 call assert_equal([0, 1, 4, 0, 4], getcurpos())
zeertzjq03cd6972023-09-20 20:08:40 +0200594 call test_setmouse(row, 21 + 5)
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100595 call feedkeys("\<LeftMouse>", "xt")
596 call assert_equal([0, 1, 5, 0, 5], getcurpos())
zeertzjq03cd6972023-09-20 20:08:40 +0200597 call test_setmouse(row, 21 + 6)
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100598 call feedkeys("\<LeftMouse>", "xt")
599 call assert_equal([0, 1, 5, 1, 6], getcurpos())
zeertzjq03cd6972023-09-20 20:08:40 +0200600 call test_setmouse(row, 21 + 7)
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100601 call feedkeys("\<LeftMouse>", "xt")
602 call assert_equal([0, 1, 5, 2, 7], getcurpos())
zeertzjq03cd6972023-09-20 20:08:40 +0200603 call test_setmouse(row, 21 + 8)
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100604 call feedkeys("\<LeftMouse>", "xt")
605 call assert_equal([0, 1, 5, 3, 8], getcurpos())
zeertzjq03cd6972023-09-20 20:08:40 +0200606 call test_setmouse(row, 21 + 9)
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100607 call feedkeys("\<LeftMouse>", "xt")
608 call assert_equal([0, 1, 6, 0, 9], getcurpos())
zeertzjq03cd6972023-09-20 20:08:40 +0200609 call test_setmouse(row, 21 + 12)
zeertzjqe500ae82023-08-17 22:35:26 +0200610 call feedkeys("\<LeftMouse>", "xt")
611 call assert_equal([0, 1, 9, 0, 12], getcurpos())
zeertzjq03cd6972023-09-20 20:08:40 +0200612 call test_setmouse(row, 21 + 13)
zeertzjqe500ae82023-08-17 22:35:26 +0200613 call feedkeys("\<LeftMouse>", "xt")
614 call assert_equal([0, 1, 10, 0, 13], getcurpos())
zeertzjq03cd6972023-09-20 20:08:40 +0200615 call test_setmouse(row, 21 + 15)
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100616 call feedkeys("\<LeftMouse>", "xt")
617 call assert_equal([0, 1, 10, 2, 15], getcurpos())
zeertzjq46a05822023-09-24 23:30:03 +0200618 call test_setmouse(row, 21 + 20)
619 call feedkeys("\<LeftMouse>", "xt")
620 call assert_equal([0, 1, 10, 7, 20], getcurpos())
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100621
zeertzjqdb54e982023-09-21 16:33:09 +0200622 setlocal nowrap
623 call setline(2, repeat('a', 19))
624 normal! j14zl
625 redraw
626 call test_setmouse(row, 21 + 1)
627 call feedkeys("\<LeftMouse>", "xt")
628 call assert_equal([0, 1, 10, 2, 15], getcurpos())
629 call test_setmouse(row, 21 + 11)
630 call feedkeys("\<LeftMouse>", "xt")
631 call assert_equal([0, 1, 10, 12, 25], getcurpos())
632 call test_setmouse(row + 1, 21 + 1)
633 call feedkeys("\<LeftMouse>", "xt")
634 call assert_equal([0, 2, 15, 0, 15], getcurpos())
635 call test_setmouse(row + 1, 21 + 11)
636 call feedkeys("\<LeftMouse>", "xt")
637 call assert_equal([0, 2, 20, 5, 25], getcurpos())
638
639 setlocal number numberwidth=2
640 redraw
641 call test_setmouse(row, 21 + 3)
642 call feedkeys("\<LeftMouse>", "xt")
643 call assert_equal([0, 1, 10, 2, 15], getcurpos())
644 call test_setmouse(row, 21 + 13)
645 call feedkeys("\<LeftMouse>", "xt")
646 call assert_equal([0, 1, 10, 12, 25], getcurpos())
647 call test_setmouse(row + 1, 21 + 3)
648 call feedkeys("\<LeftMouse>", "xt")
649 call assert_equal([0, 2, 15, 0, 15], getcurpos())
650 call test_setmouse(row + 1, 21 + 13)
651 call feedkeys("\<LeftMouse>", "xt")
652 call assert_equal([0, 2, 20, 5, 25], getcurpos())
653 setlocal nonumber
654
655 if has('signs')
656 sign define Sign1 text=口
657 sign place 1 name=Sign1 line=1
658 sign place 2 name=Sign1 line=2
659 redraw
660 call test_setmouse(row, 21 + 3)
661 call feedkeys("\<LeftMouse>", "xt")
662 call assert_equal([0, 1, 10, 2, 15], getcurpos())
663 call test_setmouse(row, 21 + 13)
664 call feedkeys("\<LeftMouse>", "xt")
665 call assert_equal([0, 1, 10, 12, 25], getcurpos())
666 call test_setmouse(row + 1, 21 + 3)
667 call feedkeys("\<LeftMouse>", "xt")
668 call assert_equal([0, 2, 15, 0, 15], getcurpos())
669 call test_setmouse(row + 1, 21 + 13)
670 call feedkeys("\<LeftMouse>", "xt")
671 call assert_equal([0, 2, 20, 5, 25], getcurpos())
672 sign unplace 1
673 sign unplace 2
674 sign undefine Sign1
675 endif
676
zeertzjq46a05822023-09-24 23:30:03 +0200677 wincmd h
678 4wincmd >
679 normal! gg24I.
680 redraw
681 call test_setmouse(row + 1, 12)
682 call feedkeys("\<LeftMouse>", "xt")
683 call assert_equal([0, 1, 24 + 9, 0, 24 + 12], getcurpos())
684 call test_setmouse(row + 1, 13)
685 call feedkeys("\<LeftMouse>", "xt")
686 call assert_equal([0, 1, 24 + 10, 0, 24 + 13], getcurpos())
687 call test_setmouse(row + 1, 15)
688 call feedkeys("\<LeftMouse>", "xt")
689 call assert_equal([0, 1, 24 + 10, 2, 24 + 15], getcurpos())
690 call test_setmouse(row + 1, 20)
691 call feedkeys("\<LeftMouse>", "xt")
692 call assert_equal([0, 1, 24 + 10, 7, 24 + 20], getcurpos())
693
Bram Moolenaar8f49e692022-08-09 14:19:40 +0100694 bwipe!
695 let &mouse = save_mouse
696 set virtualedit&
697endfunc
698
Bram Moolenaar94722c52023-01-28 19:19:03 +0000699" this was replacing the NUL at the end of the line
Bram Moolenaarc2499132022-09-16 22:16:59 +0100700func Test_virtualedit_replace_after_tab()
701 new
702 s/\v/ 0
703 set ve=all
704 let @" = ''
705 sil! norm vPvr0
Bram Moolenaar94722c52023-01-28 19:19:03 +0000706
Bram Moolenaarc2499132022-09-16 22:16:59 +0100707 call assert_equal("\t0", getline(1))
708 set ve&
709 bwipe!
710endfunc
711
zeertzjq2ffdae72024-05-02 13:06:24 +0200712" Test that setpos('.') and cursor() behave the same for v:maxcol
713func Test_virtualedit_set_cursor_pos_maxcol()
714 new
715 set virtualedit=all
716
717 call setline(1, 'foobar')
718 exe "normal! V\<Esc>"
719 call assert_equal([0, 1, 1, 0], getpos("'<"))
720 call assert_equal([0, 1, v:maxcol, 0], getpos("'>"))
721 let pos = getpos("'>")
722
723 call cursor(1, 1)
724 call setpos('.', pos)
725 call assert_equal([0, 1, 7, 0], getpos('.'))
726
727 call cursor(1, 1)
728 call cursor(pos[1:])
729 call assert_equal([0, 1, 7, 0], getpos('.'))
730
731 set virtualedit&
732 bwipe!
733endfunc
Bram Moolenaarc2499132022-09-16 22:16:59 +0100734
Bram Moolenaar54c8d222019-12-02 20:41:39 +0100735" vim: shiftwidth=2 sts=2 expandtab