test_conceal.vim 23 KB

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