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