blob: 2ce7384b9ba43b3a841709ceb7d853945270cf4b [file] [log] [blame]
Bram Moolenaar429ab172019-01-11 15:54:45 +01001" Tests for 'conceal'.
Bram Moolenaar429ab172019-01-11 15:54:45 +01002
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02003source check.vim
4CheckFeature conceal
Bram Moolenaar429ab172019-01-11 15:54:45 +01005
6source screendump.vim
Bram Moolenaarb9081882022-07-09 04:56:24 +01007source view_util.vim
Bram Moolenaar429ab172019-01-11 15:54:45 +01008
9func Test_conceal_two_windows()
zeertzjq20691912022-01-23 12:42:55 +000010 CheckScreendump
11
Bram Moolenaarc79745a2019-05-20 22:12:34 +020012 let code =<< trim [CODE]
13 let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
14 call setline(1, lines)
15 syntax match test /|hidden|/ conceal
16 set conceallevel=2
17 set concealcursor=
18 exe "normal /here\r"
19 new
20 call setline(1, lines)
21 call setline(4, "Second window")
22 syntax match test /|hidden|/ conceal
23 set conceallevel=2
24 set concealcursor=nc
25 exe "normal /here\r"
26 [CODE]
27
Bram Moolenaar45bbaef2022-09-08 16:39:22 +010028 call writefile(code, 'XTest_conceal', 'D')
Bram Moolenaar429ab172019-01-11 15:54:45 +010029 " Check that cursor line is concealed
30 let buf = RunVimInTerminal('-S XTest_conceal', {})
31 call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {})
32
33 " Check that with concealed text vertical cursor movement is correct.
34 call term_sendkeys(buf, "k")
35 call VerifyScreenDump(buf, 'Test_conceal_two_windows_02', {})
36
37 " Check that with cursor line is not concealed
38 call term_sendkeys(buf, "j")
39 call term_sendkeys(buf, ":set concealcursor=\r")
40 call VerifyScreenDump(buf, 'Test_conceal_two_windows_03', {})
41
42 " Check that with cursor line is not concealed when moving cursor down
43 call term_sendkeys(buf, "j")
44 call VerifyScreenDump(buf, 'Test_conceal_two_windows_04', {})
45
46 " Check that with cursor line is not concealed when switching windows
47 call term_sendkeys(buf, "\<C-W>\<C-W>")
48 call VerifyScreenDump(buf, 'Test_conceal_two_windows_05', {})
49
50 " Check that with cursor line is only concealed in Normal mode
51 call term_sendkeys(buf, ":set concealcursor=n\r")
52 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06n', {})
53 call term_sendkeys(buf, "a")
54 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06i', {})
55 call term_sendkeys(buf, "\<Esc>/e")
56 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06c', {})
57 call term_sendkeys(buf, "\<Esc>v")
58 call VerifyScreenDump(buf, 'Test_conceal_two_windows_06v', {})
59 call term_sendkeys(buf, "\<Esc>")
60
61 " Check that with cursor line is only concealed in Insert mode
62 call term_sendkeys(buf, ":set concealcursor=i\r")
63 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07n', {})
Bram Moolenaar644b49f2021-09-16 22:32:15 +020064 call term_sendkeys(buf, "14|a")
Bram Moolenaar429ab172019-01-11 15:54:45 +010065 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {})
Bram Moolenaar644b49f2021-09-16 22:32:15 +020066 call term_sendkeys(buf, "\<Esc>")
67 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07in', {})
68 call term_sendkeys(buf, "/e")
Bram Moolenaar429ab172019-01-11 15:54:45 +010069 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07c', {})
70 call term_sendkeys(buf, "\<Esc>v")
71 call VerifyScreenDump(buf, 'Test_conceal_two_windows_07v', {})
72 call term_sendkeys(buf, "\<Esc>")
73
74 " Check that with cursor line is only concealed in Command mode
75 call term_sendkeys(buf, ":set concealcursor=c\r")
76 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08n', {})
77 call term_sendkeys(buf, "a")
78 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08i', {})
79 call term_sendkeys(buf, "\<Esc>/e")
80 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08c', {})
81 call term_sendkeys(buf, "\<Esc>v")
82 call VerifyScreenDump(buf, 'Test_conceal_two_windows_08v', {})
83 call term_sendkeys(buf, "\<Esc>")
84
85 " Check that with cursor line is only concealed in Visual mode
86 call term_sendkeys(buf, ":set concealcursor=v\r")
87 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09n', {})
88 call term_sendkeys(buf, "a")
89 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09i', {})
90 call term_sendkeys(buf, "\<Esc>/e")
91 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09c', {})
92 call term_sendkeys(buf, "\<Esc>v")
93 call VerifyScreenDump(buf, 'Test_conceal_two_windows_09v', {})
94 call term_sendkeys(buf, "\<Esc>")
95
Bram Moolenaar465e8b52019-01-11 20:42:28 +010096 " Check moving the cursor while in insert mode.
97 call term_sendkeys(buf, ":set concealcursor=\r")
98 call term_sendkeys(buf, "a")
99 call VerifyScreenDump(buf, 'Test_conceal_two_windows_10', {})
100 call term_sendkeys(buf, "\<Down>")
101 call VerifyScreenDump(buf, 'Test_conceal_two_windows_11', {})
102 call term_sendkeys(buf, "\<Esc>")
103
104 " Check the "o" command
105 call VerifyScreenDump(buf, 'Test_conceal_two_windows_12', {})
106 call term_sendkeys(buf, "o")
107 call VerifyScreenDump(buf, 'Test_conceal_two_windows_13', {})
108 call term_sendkeys(buf, "\<Esc>")
109
Bram Moolenaar429ab172019-01-11 15:54:45 +0100110 " clean up
111 call StopVimInTerminal(buf)
Bram Moolenaar429ab172019-01-11 15:54:45 +0100112endfunc
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100113
114func Test_conceal_with_cursorline()
zeertzjq20691912022-01-23 12:42:55 +0000115 CheckScreendump
116
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100117 " Opens a help window, where 'conceal' is set, switches to the other window
118 " where 'cursorline' needs to be updated when the cursor moves.
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200119 let code =<< trim [CODE]
120 set cursorline
121 normal othis is a test
122 new
123 call setline(1, ["one", "two", "three", "four", "five"])
124 set ft=help
125 normal M
126 [CODE]
127
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100128 call writefile(code, 'XTest_conceal_cul', 'D')
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100129 let buf = RunVimInTerminal('-S XTest_conceal_cul', {})
130 call VerifyScreenDump(buf, 'Test_conceal_cul_01', {})
131
132 call term_sendkeys(buf, ":wincmd w\r")
133 call VerifyScreenDump(buf, 'Test_conceal_cul_02', {})
134
135 call term_sendkeys(buf, "k")
136 call VerifyScreenDump(buf, 'Test_conceal_cul_03', {})
137
138 " clean up
139 call StopVimInTerminal(buf)
Bram Moolenaarbbee8d52019-01-14 21:51:40 +0100140endfunc
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200141
Alexey Radkovaaa16b02023-01-04 11:15:30 +0000142func Test_conceal_with_cursorcolumn()
143 CheckScreendump
144
145 " Check that cursorcolumn and colorcolumn don't get broken in presence of
146 " wrapped lines containing concealed text
147 let code =<< trim [CODE]
148 let lines = ["one one one |hidden| one one one one one one one one",
149 \ "two two two two |hidden| here two two",
150 \ "three |hidden| three three three three three three three three"]
151 call setline(1, lines)
152 set wrap linebreak
153 set showbreak=\ >>>\
154 syntax match test /|hidden|/ conceal
155 set conceallevel=2
156 set concealcursor=
157 exe "normal /here\r"
158 set cursorcolumn
159 set colorcolumn=50
160 [CODE]
161
162 call writefile(code, 'XTest_conceal_cuc', 'D')
163 let buf = RunVimInTerminal('-S XTest_conceal_cuc', {'rows': 10, 'cols': 40})
164 call VerifyScreenDump(buf, 'Test_conceal_cuc_01', {})
165
166 " move cursor to the end of line (the cursor jumps to the next screen line)
167 call term_sendkeys(buf, "$")
168 call VerifyScreenDump(buf, 'Test_conceal_cuc_02', {})
169
170 " clean up
171 call StopVimInTerminal(buf)
172endfunc
173
zeertzjq21b0a3d2024-03-13 20:06:34 +0100174" Check that 'cursorline' and 'wincolor' apply to the whole line in presence
175" of wrapped lines containing concealed text.
176func Test_conceal_wrapped_cursorline_wincolor()
177 CheckScreendump
178
179 let code =<< trim [CODE]
180 call setline(1, 'one one one |hidden| one one one one one one one one')
181 syntax match test /|hidden|/ conceal
182 set conceallevel=2 concealcursor=n cursorline
183 normal! g$
184 [CODE]
185
186 call writefile(code, 'XTest_conceal_cul_wcr', 'D')
187 let buf = RunVimInTerminal('-S XTest_conceal_cul_wcr', {'rows': 4, 'cols': 40})
188 call VerifyScreenDump(buf, 'Test_conceal_cul_wcr_01', {})
189
190 call term_sendkeys(buf, ":set wincolor=ErrorMsg\n")
191 call VerifyScreenDump(buf, 'Test_conceal_cul_wcr_02', {})
192
193 call term_sendkeys(buf, ":set nocursorline\n")
194 call VerifyScreenDump(buf, 'Test_conceal_cul_wcr_03', {})
195
196 " clean up
197 call StopVimInTerminal(buf)
198endfunc
199
200" Same as Test_conceal_wrapped_cursorline_wincolor(), but with 'rightleft'.
201func Test_conceal_wrapped_cursorline_wincolor_rightleft()
Julio B5df961a2024-03-31 18:43:51 +0200202 CheckFeature rightleft
zeertzjq21b0a3d2024-03-13 20:06:34 +0100203 CheckScreendump
204
205 let code =<< trim [CODE]
206 call setline(1, 'one one one |hidden| one one one one one one one one')
207 syntax match test /|hidden|/ conceal
208 set conceallevel=2 concealcursor=n cursorline rightleft
209 normal! g$
210 [CODE]
211
212 call writefile(code, 'XTest_conceal_cul_wcr_rl', 'D')
213 let buf = RunVimInTerminal('-S XTest_conceal_cul_wcr_rl', {'rows': 4, 'cols': 40})
214 call VerifyScreenDump(buf, 'Test_conceal_cul_wcr_rl_01', {})
215
216 call term_sendkeys(buf, ":set wincolor=ErrorMsg\n")
217 call VerifyScreenDump(buf, 'Test_conceal_cul_wcr_rl_02', {})
218
219 call term_sendkeys(buf, ":set nocursorline\n")
220 call VerifyScreenDump(buf, 'Test_conceal_cul_wcr_rl_03', {})
221
222 " clean up
223 call StopVimInTerminal(buf)
224endfunc
225
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200226func Test_conceal_resize_term()
zeertzjq20691912022-01-23 12:42:55 +0000227 CheckScreendump
228
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200229 let code =<< trim [CODE]
230 call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
231 setl cocu=n cole=3
232 syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
233 normal fb
234 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100235 call writefile(code, 'XTest_conceal_resize', 'D')
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200236 let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6})
237 call VerifyScreenDump(buf, 'Test_conceal_resize_01', {})
238
239 call win_execute(buf->win_findbuf()[0], 'wincmd +')
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200240 call VerifyScreenDump(buf, 'Test_conceal_resize_02', {})
241
242 " clean up
243 call StopVimInTerminal(buf)
Bram Moolenaar5babc6e2019-09-14 21:55:51 +0200244endfunc
Bram Moolenaar213ed002019-12-11 20:12:26 +0100245
Bram Moolenaar75008662022-10-04 22:40:56 +0100246func Test_conceal_linebreak()
247 CheckScreendump
248
249 let code =<< trim [CODE]
250 vim9script
251 &wrap = true
252 &conceallevel = 2
253 &concealcursor = 'nc'
254 &linebreak = true
255 &showbreak = '+ '
256 var line: string = 'a`a`a`a`'
257 .. 'a'->repeat(&columns - 15)
258 .. ' b`b`'
259 .. 'b'->repeat(&columns - 10)
260 .. ' cccccc'
261 ['x'->repeat(&columns), '', line]->setline(1)
262 syntax region CodeSpan matchgroup=Delimiter start=/\z(`\+\)/ end=/\z1/ concealends
263 [CODE]
264 call writefile(code, 'XTest_conceal_linebreak', 'D')
265 let buf = RunVimInTerminal('-S XTest_conceal_linebreak', {'rows': 8})
266 call VerifyScreenDump(buf, 'Test_conceal_linebreak_1', {})
267
268 " clean up
269 call StopVimInTerminal(buf)
270endfunc
271
Bram Moolenaar213ed002019-12-11 20:12:26 +0100272" Tests for correct display (cursor column position) with +conceal and
273" tabulators. Need to run this test in a separate Vim instance. Otherwise the
274" screen is not updated (lazy redraw) and the cursor position is wrong.
275func Test_conceal_cursor_pos()
276 let code =<< trim [CODE]
277 :let l = ['start:', '.concealed. text', "|concealed|\ttext"]
278 :let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
279 :let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
280 :call append(0, l)
281 :call cursor(1, 1)
282 :" Conceal settings.
283 :set conceallevel=2
284 :set concealcursor=nc
285 :syntax match test /|/ conceal
286 :" Save current cursor position. Only works in <expr> mode, can't be used
287 :" with :normal because it moves the cursor to the command line. Thanks
288 :" to ZyX <zyx.vim@gmail.com> for the idea to use an <expr> mapping.
289 :let curpos = []
290 :nnoremap <expr> GG ":let curpos += ['".screenrow().":".screencol()."']\n"
291 :normal ztj
292 GGk
293 :" We should end up in the same column when running these commands on the
294 :" two lines.
295 :normal ft
296 GGk
297 :normal $
298 GGk
299 :normal 0j
300 GGk
301 :normal ft
302 GGk
303 :normal $
304 GGk
305 :normal 0j0j
306 GGk
307 :" Same for next test block.
308 :normal ft
309 GGk
310 :normal $
311 GGk
312 :normal 0j
313 GGk
314 :normal ft
315 GGk
316 :normal $
317 GGk
318 :normal 0j0j
319 GGk
320 :" And check W with multiple tabs and conceals in a line.
321 :normal W
322 GGk
323 :normal W
324 GGk
325 :normal W
326 GGk
327 :normal $
328 GGk
329 :normal 0j
330 GGk
331 :normal W
332 GGk
333 :normal W
334 GGk
335 :normal W
336 GGk
337 :normal $
338 GGk
339 :set lbr
340 :normal $
341 GGk
342 :set list listchars=tab:>-
343 :normal 0
344 GGk
345 :normal W
346 GGk
347 :normal W
348 GGk
349 :normal W
350 GGk
351 :normal $
352 GGk
353 :call writefile(curpos, 'Xconceal_curpos.out')
354 :q!
355
356 [CODE]
Bram Moolenaar45bbaef2022-09-08 16:39:22 +0100357 call writefile(code, 'XTest_conceal_curpos', 'D')
Bram Moolenaar213ed002019-12-11 20:12:26 +0100358
359 if RunVim([], [], '-s XTest_conceal_curpos')
360 call assert_equal([
361 \ '2:1', '2:17', '2:20', '3:1', '3:17', '3:20', '5:8', '5:25',
362 \ '5:28', '6:8', '6:25', '6:28', '8:1', '8:9', '8:17', '8:25',
363 \ '8:27', '9:1', '9:9', '9:17', '9:25', '9:26', '9:26', '9:1',
364 \ '9:9', '9:17', '9:25', '9:26'], readfile('Xconceal_curpos.out'))
365 endif
366
367 call delete('Xconceal_curpos.out')
Bram Moolenaar213ed002019-12-11 20:12:26 +0100368endfunc
369
Bram Moolenaarfc838d62020-06-25 22:23:48 +0200370func Test_conceal_eol()
371 new!
372 setlocal concealcursor=n conceallevel=1
373 call setline(1, ["x", ""])
374 call matchaddpos('Conceal', [[2, 1, 1]], 2, -1, {'conceal': 1})
375 redraw!
376
377 call assert_notequal(screenchar(1, 1), screenchar(2, 2))
378 call assert_equal(screenattr(1, 1), screenattr(1, 2))
379 call assert_equal(screenattr(1, 2), screenattr(2, 2))
380 call assert_equal(screenattr(2, 1), screenattr(2, 2))
381
382 set list
383 redraw!
384
385 call assert_equal(screenattr(1, 1), screenattr(2, 2))
386 call assert_notequal(screenattr(1, 1), screenattr(1, 2))
387 call assert_notequal(screenattr(1, 2), screenattr(2, 1))
388
389 set nolist
390endfunc
391
Bram Moolenaarb9081882022-07-09 04:56:24 +0100392func Test_conceal_mouse_click()
zeertzjqd0c1b772024-03-16 15:03:33 +0100393 call NewWindow(10, 40)
Bram Moolenaarb9081882022-07-09 04:56:24 +0100394 set mouse=a
395 setlocal conceallevel=2 concealcursor=nc
396 syn match Concealed "this" conceal
397 hi link Concealed Search
Bram Moolenaarb9081882022-07-09 04:56:24 +0100398
zeertzjqd0c1b772024-03-16 15:03:33 +0100399 " Test with both 'nocursorline' and 'cursorline', as they use two different
400 " code paths to set virtual columns for the cells to clear.
401 for cul in [v:false, v:true]
402 let &l:cursorline = cul
zeertzjqe500ae82023-08-17 22:35:26 +0200403
zeertzjqd0c1b772024-03-16 15:03:33 +0100404 call setline(1, 'conceal this click here')
405 call assert_equal([
406 \ 'conceal click here ',
407 \ ], ScreenLines(1, 40))
Bram Moolenaarb9081882022-07-09 04:56:24 +0100408
zeertzjqd0c1b772024-03-16 15:03:33 +0100409 " Click on the space between "this" and "click" puts cursor there.
410 call test_setmouse(1, 9)
411 call feedkeys("\<LeftMouse>", "tx")
412 call assert_equal([0, 1, 13, 0, 13], getcurpos())
413 " Click on 'h' of "here" puts cursor there.
414 call test_setmouse(1, 16)
415 call feedkeys("\<LeftMouse>", "tx")
416 call assert_equal([0, 1, 20, 0, 20], getcurpos())
417 " Click on 'e' of "here" puts cursor there.
418 call test_setmouse(1, 19)
419 call feedkeys("\<LeftMouse>", "tx")
420 call assert_equal([0, 1, 23, 0, 23], getcurpos())
421 " Click after end of line puts cursor on 'e' without 'virtualedit'.
422 call test_setmouse(1, 20)
423 call feedkeys("\<LeftMouse>", "tx")
424 call assert_equal([0, 1, 23, 0, 24], getcurpos())
425 call test_setmouse(1, 21)
426 call feedkeys("\<LeftMouse>", "tx")
427 call assert_equal([0, 1, 23, 0, 25], getcurpos())
428 call test_setmouse(1, 22)
429 call feedkeys("\<LeftMouse>", "tx")
430 call assert_equal([0, 1, 23, 0, 26], getcurpos())
431 call test_setmouse(1, 31)
432 call feedkeys("\<LeftMouse>", "tx")
433 call assert_equal([0, 1, 23, 0, 35], getcurpos())
434 call test_setmouse(1, 32)
435 call feedkeys("\<LeftMouse>", "tx")
436 call assert_equal([0, 1, 23, 0, 36], getcurpos())
437
438 set virtualedit=all
439 redraw
440 " Click on the space between "this" and "click" puts cursor there.
441 call test_setmouse(1, 9)
442 call feedkeys("\<LeftMouse>", "tx")
443 call assert_equal([0, 1, 13, 0, 13], getcurpos())
444 " Click on 'h' of "here" puts cursor there.
445 call test_setmouse(1, 16)
446 call feedkeys("\<LeftMouse>", "tx")
447 call assert_equal([0, 1, 20, 0, 20], getcurpos())
448 " Click on 'e' of "here" puts cursor there.
449 call test_setmouse(1, 19)
450 call feedkeys("\<LeftMouse>", "tx")
451 call assert_equal([0, 1, 23, 0, 23], getcurpos())
452 " Click after end of line puts cursor there with 'virtualedit'.
453 call test_setmouse(1, 20)
454 call feedkeys("\<LeftMouse>", "tx")
455 call assert_equal([0, 1, 24, 0, 24], getcurpos())
456 call test_setmouse(1, 21)
457 call feedkeys("\<LeftMouse>", "tx")
458 call assert_equal([0, 1, 24, 1, 25], getcurpos())
459 call test_setmouse(1, 22)
460 call feedkeys("\<LeftMouse>", "tx")
461 call assert_equal([0, 1, 24, 2, 26], getcurpos())
462 call test_setmouse(1, 31)
463 call feedkeys("\<LeftMouse>", "tx")
464 call assert_equal([0, 1, 24, 11, 35], getcurpos())
465 call test_setmouse(1, 32)
466 call feedkeys("\<LeftMouse>", "tx")
467 call assert_equal([0, 1, 24, 12, 36], getcurpos())
zeertzjqdeb22042024-03-17 19:44:30 +0100468 " Behavior should also be the same with 'colorcolumn'.
469 setlocal colorcolumn=30
470 redraw
471 call test_setmouse(1, 31)
472 call feedkeys("\<LeftMouse>", "tx")
473 call assert_equal([0, 1, 24, 11, 35], getcurpos())
474 call test_setmouse(1, 32)
475 call feedkeys("\<LeftMouse>", "tx")
476 call assert_equal([0, 1, 24, 12, 36], getcurpos())
477 setlocal colorcolumn&
478
479 if has('rightleft')
480 setlocal rightleft
481 call assert_equal([
482 \ ' ereh kcilc laecnoc',
483 \ ], ScreenLines(1, 40))
484 " Click on the space between "this" and "click" puts cursor there.
485 call test_setmouse(1, 41 - 9)
486 call feedkeys("\<LeftMouse>", "tx")
487 call assert_equal([0, 1, 13, 0, 13], getcurpos())
488 " Click on 'h' of "here" puts cursor there.
489 call test_setmouse(1, 41 - 16)
490 call feedkeys("\<LeftMouse>", "tx")
491 call assert_equal([0, 1, 20, 0, 20], getcurpos())
492 " Click on 'e' of "here" puts cursor there.
493 call test_setmouse(1, 41 - 19)
494 call feedkeys("\<LeftMouse>", "tx")
495 call assert_equal([0, 1, 23, 0, 23], getcurpos())
496 " Click after end of line puts cursor there with 'virtualedit'.
497 call test_setmouse(1, 41 - 20)
498 call feedkeys("\<LeftMouse>", "tx")
499 call assert_equal([0, 1, 24, 0, 24], getcurpos())
500 call test_setmouse(1, 41 - 21)
501 call feedkeys("\<LeftMouse>", "tx")
502 call assert_equal([0, 1, 24, 1, 25], getcurpos())
503 call test_setmouse(1, 41 - 22)
504 call feedkeys("\<LeftMouse>", "tx")
505 call assert_equal([0, 1, 24, 2, 26], getcurpos())
506 call test_setmouse(1, 41 - 31)
507 call feedkeys("\<LeftMouse>", "tx")
508 call assert_equal([0, 1, 24, 11, 35], getcurpos())
509 call test_setmouse(1, 41 - 32)
510 call feedkeys("\<LeftMouse>", "tx")
511 call assert_equal([0, 1, 24, 12, 36], getcurpos())
512 setlocal rightleft&
513 endif
514
zeertzjqd0c1b772024-03-16 15:03:33 +0100515 set virtualedit&
516
517 " Test with a wrapped line.
518 call setline(1, ['conceal this click here']->repeat(3)->join())
519 call assert_equal([
520 \ 'conceal click here conceal cli ',
521 \ 'ck here conceal click here ',
522 \ ], ScreenLines([1, 2], 40))
523 " Click on boguscols puts cursor on the last char of a screen line.
524 for col in range(33, 40)
525 call test_setmouse(1, col)
526 call feedkeys("\<LeftMouse>", "tx")
527 call assert_equal([0, 1, 40, 0, 40], getcurpos())
528 endfor
529
530 " Also test with the last char of a screen line concealed.
531 setlocal number signcolumn=yes
532 call assert_equal([
533 \ ' 1 conceal click here conceal ',
534 \ ' click here conceal click h ',
535 \ ' ere ',
536 \ ], ScreenLines([1, 3], 40))
537 call test_setmouse(1, 34)
538 call feedkeys("\<LeftMouse>", "tx")
539 call assert_equal([0, 1, 32, 0, 32], getcurpos())
540 call test_setmouse(2, 7)
541 call feedkeys("\<LeftMouse>", "tx")
542 call assert_equal([0, 1, 37, 0, 37], getcurpos())
543 " Click on boguscols puts cursor on the last char of a screen line.
544 for col in range(35, 40)
545 call test_setmouse(1, col)
546 call feedkeys("\<LeftMouse>", "tx")
547 call assert_equal([0, 1, 34, 0, 34], getcurpos())
548 call test_setmouse(2, col)
549 call feedkeys("\<LeftMouse>", "tx")
550 call assert_equal([0, 1, 68, 0, 68], getcurpos())
551 endfor
552 setlocal number& signcolumn&
553 endfor
554
555 call CloseWindow()
556 set mouse&
Bram Moolenaarb9081882022-07-09 04:56:24 +0100557endfunc
558
zeertzjq253ff4d2024-03-13 20:38:26 +0100559" Test that cursor is drawn at the correct column when it is after end of the
560" line with 'virtualedit' and concealing.
zeertzjq010e1532024-03-14 18:22:17 +0100561func Run_test_conceal_virtualedit_after_eol(wrap)
562 let code =<< trim eval [CODE]
563 let &wrap = {a:wrap}
zeertzjq253ff4d2024-03-13 20:38:26 +0100564 call setline(1, 'abcdefgh|hidden|ijklmnpop')
565 syntax match test /|hidden|/ conceal
566 set conceallevel=2 concealcursor=n virtualedit=all
567 normal! $
568 [CODE]
569 call writefile(code, 'XTest_conceal_ve_after_eol', 'D')
570 let buf = RunVimInTerminal('-S XTest_conceal_ve_after_eol', {'rows': 3})
571 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_1', {})
572 call term_sendkeys(buf, "l")
573 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_2', {})
574 call term_sendkeys(buf, "l")
575 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_3', {})
576 call term_sendkeys(buf, "l")
577 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_4', {})
578 call term_sendkeys(buf, "rr")
579 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_5', {})
580
581 " clean up
582 call StopVimInTerminal(buf)
583endfunc
584
zeertzjq010e1532024-03-14 18:22:17 +0100585func Test_conceal_virtualedit_after_eol()
zeertzjq253ff4d2024-03-13 20:38:26 +0100586 CheckScreendump
587
zeertzjq010e1532024-03-14 18:22:17 +0100588 call Run_test_conceal_virtualedit_after_eol(1)
589 call Run_test_conceal_virtualedit_after_eol(0)
590endfunc
591
592" Same as Run_test_conceal_virtualedit_after_eol(), but with 'rightleft'.
593func Run_test_conceal_virtualedit_after_eol_rightleft(wrap)
594 let code =<< trim eval [CODE]
595 let &wrap = {a:wrap}
zeertzjq253ff4d2024-03-13 20:38:26 +0100596 call setline(1, 'abcdefgh|hidden|ijklmnpop')
597 syntax match test /|hidden|/ conceal
598 set conceallevel=2 concealcursor=n virtualedit=all rightleft
599 normal! $
600 [CODE]
601 call writefile(code, 'XTest_conceal_ve_after_eol_rl', 'D')
602 let buf = RunVimInTerminal('-S XTest_conceal_ve_after_eol_rl', {'rows': 3})
603 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_rl_1', {})
604 call term_sendkeys(buf, "h")
605 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_rl_2', {})
606 call term_sendkeys(buf, "h")
607 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_rl_3', {})
608 call term_sendkeys(buf, "h")
609 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_rl_4', {})
610 call term_sendkeys(buf, "rr")
611 call VerifyScreenDump(buf, 'Test_conceal_ve_after_eol_rl_5', {})
612
613 " clean up
614 call StopVimInTerminal(buf)
615endfunc
616
zeertzjq010e1532024-03-14 18:22:17 +0100617func Test_conceal_virtualedit_after_eol_rightleft()
618 CheckFeature rightleft
619 CheckScreendump
620
621 call Run_test_conceal_virtualedit_after_eol_rightleft(1)
622 call Run_test_conceal_virtualedit_after_eol_rightleft(0)
623endfunc
624
625" Test that cursor position is correct when double-width chars are concealed.
626func Run_test_conceal_double_width(wrap)
627 let code =<< trim eval [CODE]
628 let &wrap = {a:wrap}
629 call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar'])
630 syntax match test /口=口/ conceal cchar=β
631 set conceallevel=2 concealcursor=n colorcolumn=30
632 normal! $
633 [CODE]
634 call writefile(code, 'XTest_conceal_double_width', 'D')
635 let buf = RunVimInTerminal('-S XTest_conceal_double_width', {'rows': 4})
636 call VerifyScreenDump(buf, 'Test_conceal_double_width_1', {})
637 call term_sendkeys(buf, "gM")
638 call VerifyScreenDump(buf, 'Test_conceal_double_width_2', {})
639 call term_sendkeys(buf, ":set conceallevel=3\<CR>")
640 call VerifyScreenDump(buf, 'Test_conceal_double_width_3', {})
641 call term_sendkeys(buf, "$")
642 call VerifyScreenDump(buf, 'Test_conceal_double_width_4', {})
643
644 " clean up
645 call StopVimInTerminal(buf)
646endfunc
647
648func Test_conceal_double_width()
649 CheckScreendump
650
651 call Run_test_conceal_double_width(1)
652 call Run_test_conceal_double_width(0)
653endfunc
654
655" Test that line wrapping is correct when double-width chars are concealed.
656func Test_conceal_double_width_wrap()
657 CheckScreendump
658
659 let code =<< trim [CODE]
660 call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc')
661 syntax match test /口=口/ conceal cchar=β
662 set conceallevel=2 concealcursor=n
663 normal! $
664 [CODE]
665 call writefile(code, 'XTest_conceal_double_width_wrap', 'D')
666 let buf = RunVimInTerminal('-S XTest_conceal_double_width_wrap', {'rows': 4, 'cols': 20})
667 call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_1', {})
668 call term_sendkeys(buf, "gM")
669 call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_2', {})
670 call term_sendkeys(buf, ":set conceallevel=3\<CR>")
671 call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_3', {})
672 call term_sendkeys(buf, "$")
673 call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_4', {})
674
675 " clean up
676 call StopVimInTerminal(buf)
677endfunc
678
Bram Moolenaar213ed002019-12-11 20:12:26 +0100679" vim: shiftwidth=2 sts=2 expandtab