Bram Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 1 | " Tests for 'conceal'. |
Bram Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 2 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 3 | CheckFeature conceal |
Bram Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 4 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 5 | source util/screendump.vim |
Bram Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 6 | |
| 7 | func Test_conceal_two_windows() |
zeertzjq | 2069191 | 2022-01-23 12:42:55 +0000 | [diff] [blame] | 8 | CheckScreendump |
| 9 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 10 | 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 Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 26 | call writefile(code, 'XTest_conceal', 'D') |
Bram Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 27 | " 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 Moolenaar | 644b49f | 2021-09-16 22:32:15 +0200 | [diff] [blame] | 62 | call term_sendkeys(buf, "14|a") |
Bram Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 63 | call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {}) |
Bram Moolenaar | 644b49f | 2021-09-16 22:32:15 +0200 | [diff] [blame] | 64 | call term_sendkeys(buf, "\<Esc>") |
| 65 | call VerifyScreenDump(buf, 'Test_conceal_two_windows_07in', {}) |
| 66 | call term_sendkeys(buf, "/e") |
Bram Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 67 | 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 Moolenaar | 465e8b5 | 2019-01-11 20:42:28 +0100 | [diff] [blame] | 94 | " 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 Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 108 | " clean up |
| 109 | call StopVimInTerminal(buf) |
Bram Moolenaar | 429ab17 | 2019-01-11 15:54:45 +0100 | [diff] [blame] | 110 | endfunc |
Bram Moolenaar | bbee8d5 | 2019-01-14 21:51:40 +0100 | [diff] [blame] | 111 | |
| 112 | func Test_conceal_with_cursorline() |
zeertzjq | 2069191 | 2022-01-23 12:42:55 +0000 | [diff] [blame] | 113 | CheckScreendump |
| 114 | |
Bram Moolenaar | bbee8d5 | 2019-01-14 21:51:40 +0100 | [diff] [blame] | 115 | " 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 Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 117 | 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 Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 126 | call writefile(code, 'XTest_conceal_cul', 'D') |
Bram Moolenaar | bbee8d5 | 2019-01-14 21:51:40 +0100 | [diff] [blame] | 127 | 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 Moolenaar | bbee8d5 | 2019-01-14 21:51:40 +0100 | [diff] [blame] | 138 | endfunc |
Bram Moolenaar | 5babc6e | 2019-09-14 21:55:51 +0200 | [diff] [blame] | 139 | |
Alexey Radkov | aaa16b0 | 2023-01-04 11:15:30 +0000 | [diff] [blame] | 140 | func 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) |
| 170 | endfunc |
| 171 | |
zeertzjq | 21b0a3d | 2024-03-13 20:06:34 +0100 | [diff] [blame] | 172 | " Check that 'cursorline' and 'wincolor' apply to the whole line in presence |
| 173 | " of wrapped lines containing concealed text. |
| 174 | func 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) |
| 196 | endfunc |
| 197 | |
| 198 | " Same as Test_conceal_wrapped_cursorline_wincolor(), but with 'rightleft'. |
| 199 | func Test_conceal_wrapped_cursorline_wincolor_rightleft() |
Julio B | 5df961a | 2024-03-31 18:43:51 +0200 | [diff] [blame] | 200 | CheckFeature rightleft |
zeertzjq | 21b0a3d | 2024-03-13 20:06:34 +0100 | [diff] [blame] | 201 | 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) |
| 222 | endfunc |
| 223 | |
Bram Moolenaar | 5babc6e | 2019-09-14 21:55:51 +0200 | [diff] [blame] | 224 | func Test_conceal_resize_term() |
zeertzjq | 2069191 | 2022-01-23 12:42:55 +0000 | [diff] [blame] | 225 | CheckScreendump |
| 226 | |
Bram Moolenaar | 5babc6e | 2019-09-14 21:55:51 +0200 | [diff] [blame] | 227 | 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 Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 233 | call writefile(code, 'XTest_conceal_resize', 'D') |
Bram Moolenaar | 5babc6e | 2019-09-14 21:55:51 +0200 | [diff] [blame] | 234 | 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 Moolenaar | 5babc6e | 2019-09-14 21:55:51 +0200 | [diff] [blame] | 238 | call VerifyScreenDump(buf, 'Test_conceal_resize_02', {}) |
| 239 | |
| 240 | " clean up |
| 241 | call StopVimInTerminal(buf) |
Bram Moolenaar | 5babc6e | 2019-09-14 21:55:51 +0200 | [diff] [blame] | 242 | endfunc |
Bram Moolenaar | 213ed00 | 2019-12-11 20:12:26 +0100 | [diff] [blame] | 243 | |
Bram Moolenaar | 7500866 | 2022-10-04 22:40:56 +0100 | [diff] [blame] | 244 | func 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) |
| 268 | endfunc |
| 269 | |
Bram Moolenaar | 213ed00 | 2019-12-11 20:12:26 +0100 | [diff] [blame] | 270 | " 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. |
| 273 | func 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 Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 355 | call writefile(code, 'XTest_conceal_curpos', 'D') |
Bram Moolenaar | 213ed00 | 2019-12-11 20:12:26 +0100 | [diff] [blame] | 356 | |
| 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 Moolenaar | 213ed00 | 2019-12-11 20:12:26 +0100 | [diff] [blame] | 366 | endfunc |
| 367 | |
Bram Moolenaar | fc838d6 | 2020-06-25 22:23:48 +0200 | [diff] [blame] | 368 | func 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 |
| 388 | endfunc |
| 389 | |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 390 | func Test_conceal_mouse_click() |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 391 | call NewWindow(10, 40) |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 392 | set mouse=a |
| 393 | setlocal conceallevel=2 concealcursor=nc |
| 394 | syn match Concealed "this" conceal |
| 395 | hi link Concealed Search |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 396 | |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 397 | " 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 |
zeertzjq | e500ae8 | 2023-08-17 22:35:26 +0200 | [diff] [blame] | 401 | |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 402 | call setline(1, 'conceal this click here') |
| 403 | call assert_equal([ |
| 404 | \ 'conceal click here ', |
| 405 | \ ], ScreenLines(1, 40)) |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 406 | |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 407 | " 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()) |
zeertzjq | deb2204 | 2024-03-17 19:44:30 +0100 | [diff] [blame] | 466 | " 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 | |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 513 | 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 Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 555 | endfunc |
| 556 | |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 557 | " Test that cursor is drawn at the correct column when it is after end of the |
| 558 | " line with 'virtualedit' and concealing. |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 559 | func Run_test_conceal_virtualedit_after_eol(wrap) |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 560 | CheckScreendump |
| 561 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 562 | let code =<< trim eval [CODE] |
| 563 | let &wrap = {a:wrap} |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 564 | 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) |
| 583 | endfunc |
| 584 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 585 | func Test_conceal_virtualedit_after_eol() |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 586 | CheckScreendump |
| 587 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 588 | call Run_test_conceal_virtualedit_after_eol(1) |
| 589 | call Run_test_conceal_virtualedit_after_eol(0) |
| 590 | endfunc |
| 591 | |
| 592 | " Same as Run_test_conceal_virtualedit_after_eol(), but with 'rightleft'. |
| 593 | func Run_test_conceal_virtualedit_after_eol_rightleft(wrap) |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 594 | CheckScreendump |
| 595 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 596 | let code =<< trim eval [CODE] |
| 597 | let &wrap = {a:wrap} |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 598 | 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) |
| 617 | endfunc |
| 618 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 619 | func 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) |
| 625 | endfunc |
| 626 | |
| 627 | " Test that cursor position is correct when double-width chars are concealed. |
| 628 | func Run_test_conceal_double_width(wrap) |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 629 | CheckScreendump |
| 630 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 631 | 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) |
| 650 | endfunc |
| 651 | |
| 652 | func Test_conceal_double_width() |
| 653 | CheckScreendump |
| 654 | |
| 655 | call Run_test_conceal_double_width(1) |
| 656 | call Run_test_conceal_double_width(0) |
| 657 | endfunc |
| 658 | |
| 659 | " Test that line wrapping is correct when double-width chars are concealed. |
| 660 | func 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) |
| 681 | endfunc |
| 682 | |
Bram Moolenaar | 213ed00 | 2019-12-11 20:12:26 +0100 | [diff] [blame] | 683 | " vim: shiftwidth=2 sts=2 expandtab |