test_termcodes.vim 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. source check.vim
  2. " CheckNotGui
  3. " CheckUnix
  4. source shared.vim
  5. source mouse.vim
  6. source view_util.vim
  7. source term_util.vim
  8. func Test_term_mouse_left_click()
  9. new
  10. let save_mouse = &mouse
  11. let save_term = &term
  12. " let save_ttymouse = &ttymouse
  13. " call test_override('no_query_mouse', 1)
  14. " set mouse=a term=xterm
  15. set mouse=a
  16. call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer'])
  17. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
  18. let msg = 'ttymouse=' .. ttymouse_val
  19. " exe 'set ttymouse=' .. ttymouse_val
  20. go
  21. call assert_equal([0, 1, 1, 0], getpos('.'), msg)
  22. let row = 2
  23. let col = 6
  24. call MouseLeftClick(row, col)
  25. call MouseLeftRelease(row, col)
  26. call assert_equal([0, 2, 6, 0], getpos('.'), msg)
  27. endfor
  28. let &mouse = save_mouse
  29. " let &term = save_term
  30. " let &ttymouse = save_ttymouse
  31. " call test_override('no_query_mouse', 0)
  32. bwipe!
  33. endfunc
  34. func Test_xterm_mouse_right_click_extends_visual()
  35. if has('mac')
  36. " throw "Skipped: test right click in visual mode does not work on macOs (why?)"
  37. endif
  38. let save_mouse = &mouse
  39. let save_term = &term
  40. " let save_ttymouse = &ttymouse
  41. " call test_override('no_query_mouse', 1)
  42. " set mouse=a term=xterm
  43. set mouse=a
  44. for visual_mode in ["v", "V", "\<C-V>"]
  45. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  46. let msg = 'visual=' .. visual_mode .. ' ttymouse=' .. ttymouse_val
  47. " exe 'set ttymouse=' .. ttymouse_val
  48. call setline(1, repeat([repeat('-', 7)], 7))
  49. call MouseLeftClick(4, 4)
  50. call MouseLeftRelease(4, 4)
  51. exe "norm! " .. visual_mode
  52. " Right click extends top left of visual area.
  53. call MouseRightClick(2, 2)
  54. call MouseRightRelease(2, 2)
  55. " Right click extends bottom right of visual area.
  56. call MouseRightClick(6, 6)
  57. call MouseRightRelease(6, 6)
  58. norm! r1gv
  59. " Right click shrinks top left of visual area.
  60. call MouseRightClick(3, 3)
  61. call MouseRightRelease(3, 3)
  62. " Right click shrinks bottom right of visual area.
  63. call MouseRightClick(5, 5)
  64. call MouseRightRelease(5, 5)
  65. norm! r2
  66. if visual_mode ==# 'v'
  67. call assert_equal(['-------',
  68. \ '-111111',
  69. \ '1122222',
  70. \ '2222222',
  71. \ '2222211',
  72. \ '111111-',
  73. \ '-------'], getline(1, '$'), msg)
  74. elseif visual_mode ==# 'V'
  75. call assert_equal(['-------',
  76. \ '1111111',
  77. \ '2222222',
  78. \ '2222222',
  79. \ '2222222',
  80. \ '1111111',
  81. \ '-------'], getline(1, '$'), msg)
  82. else
  83. call assert_equal(['-------',
  84. \ '-11111-',
  85. \ '-12221-',
  86. \ '-12221-',
  87. \ '-12221-',
  88. \ '-11111-',
  89. \ '-------'], getline(1, '$'), msg)
  90. endif
  91. endfor
  92. endfor
  93. let &mouse = save_mouse
  94. " let &term = save_term
  95. " let &ttymouse = save_ttymouse
  96. " call test_override('no_query_mouse', 0)
  97. bwipe!
  98. endfunc
  99. " Test that <C-LeftMouse> jumps to help tag and <C-RightMouse> jumps back.
  100. func Test_xterm_mouse_ctrl_click()
  101. let save_mouse = &mouse
  102. let save_term = &term
  103. " let save_ttymouse = &ttymouse
  104. " set mouse=a term=xterm
  105. set mouse=a
  106. for ttymouse_val in g:Ttymouse_values
  107. let msg = 'ttymouse=' .. ttymouse_val
  108. " exe 'set ttymouse=' .. ttymouse_val
  109. " help
  110. help usr_toc.txt
  111. /usr_02.txt
  112. norm! zt
  113. let row = 1
  114. let col = 1
  115. call MouseCtrlLeftClick(row, col)
  116. call MouseLeftRelease(row, col)
  117. call assert_match('usr_02.txt$', bufname('%'), msg)
  118. call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg)
  119. call MouseCtrlRightClick(row, col)
  120. call MouseRightRelease(row, col)
  121. " call assert_match('help.txt$', bufname('%'), msg)
  122. call assert_match('usr_toc.txt$', bufname('%'), msg)
  123. call assert_equal('|usr_02.txt|', expand('<cWORD>'), msg)
  124. helpclose
  125. endfor
  126. let &mouse = save_mouse
  127. " let &term = save_term
  128. " let &ttymouse = save_ttymouse
  129. endfunc
  130. func Test_term_mouse_middle_click()
  131. CheckFeature clipboard_working
  132. new
  133. let save_mouse = &mouse
  134. let save_term = &term
  135. " let save_ttymouse = &ttymouse
  136. " call test_override('no_query_mouse', 1)
  137. let save_quotestar = @*
  138. let @* = 'abc'
  139. " set mouse=a term=xterm
  140. set mouse=a
  141. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  142. let msg = 'ttymouse=' .. ttymouse_val
  143. " exe 'set ttymouse=' .. ttymouse_val
  144. call setline(1, ['123456789', '123456789'])
  145. " Middle-click in the middle of the line pastes text where clicked.
  146. let row = 1
  147. let col = 6
  148. call MouseMiddleClick(row, col)
  149. call MouseMiddleRelease(row, col)
  150. call assert_equal(['12345abc6789', '123456789'], getline(1, '$'), msg)
  151. " Middle-click beyond end of the line pastes text at the end of the line.
  152. let col = 20
  153. call MouseMiddleClick(row, col)
  154. call MouseMiddleRelease(row, col)
  155. call assert_equal(['12345abc6789abc', '123456789'], getline(1, '$'), msg)
  156. " Middle-click beyond the last line pastes in the last line.
  157. let row = 5
  158. let col = 3
  159. call MouseMiddleClick(row, col)
  160. call MouseMiddleRelease(row, col)
  161. call assert_equal(['12345abc6789abc', '12abc3456789'], getline(1, '$'), msg)
  162. endfor
  163. let &mouse = save_mouse
  164. " let &term = save_term
  165. " let &ttymouse = save_ttymouse
  166. " call test_override('no_query_mouse', 0)
  167. let @* = save_quotestar
  168. bwipe!
  169. endfunc
  170. " TODO: for unclear reasons this test fails if it comes after
  171. " Test_xterm_mouse_ctrl_click()
  172. func Test_1xterm_mouse_wheel()
  173. new
  174. let save_mouse = &mouse
  175. let save_term = &term
  176. let save_wrap = &wrap
  177. " let save_ttymouse = &ttymouse
  178. " set mouse=a term=xterm nowrap
  179. set mouse=a nowrap
  180. call setline(1, range(100000000000000, 100000000000100))
  181. for ttymouse_val in g:Ttymouse_values
  182. let msg = 'ttymouse=' .. ttymouse_val
  183. " exe 'set ttymouse=' .. ttymouse_val
  184. go
  185. call assert_equal(1, line('w0'), msg)
  186. call assert_equal([0, 1, 1, 0], getpos('.'), msg)
  187. call MouseWheelDown(1, 1)
  188. call assert_equal(4, line('w0'), msg)
  189. call assert_equal([0, 4, 1, 0], getpos('.'), msg)
  190. call MouseWheelDown(1, 1)
  191. call assert_equal(7, line('w0'), msg)
  192. call assert_equal([0, 7, 1, 0], getpos('.'), msg)
  193. call MouseWheelUp(1, 1)
  194. call assert_equal(4, line('w0'), msg)
  195. call assert_equal([0, 7, 1, 0], getpos('.'), msg)
  196. call MouseWheelUp(1, 1)
  197. call assert_equal(1, line('w0'), msg)
  198. call assert_equal([0, 7, 1, 0], getpos('.'), msg)
  199. call MouseWheelRight(1, 1)
  200. call assert_equal(7, 1 + virtcol(".") - wincol(), msg)
  201. call assert_equal([0, 7, 7, 0], getpos('.'), msg)
  202. call MouseWheelRight(1, 1)
  203. call assert_equal(13, 1 + virtcol(".") - wincol(), msg)
  204. call assert_equal([0, 7, 13, 0], getpos('.'), msg)
  205. call MouseWheelLeft(1, 1)
  206. call assert_equal(7, 1 + virtcol(".") - wincol(), msg)
  207. call assert_equal([0, 7, 13, 0], getpos('.'), msg)
  208. call MouseWheelLeft(1, 1)
  209. call assert_equal(1, 1 + virtcol(".") - wincol(), msg)
  210. call assert_equal([0, 7, 13, 0], getpos('.'), msg)
  211. endfor
  212. let &mouse = save_mouse
  213. " let &term = save_term
  214. let &wrap = save_wrap
  215. " let &ttymouse = save_ttymouse
  216. bwipe!
  217. endfunc
  218. " Test that dragging beyond the window (at the bottom and at the top)
  219. " scrolls window content by the number of lines beyond the window.
  220. func Test_term_mouse_drag_beyond_window()
  221. let save_mouse = &mouse
  222. let save_term = &term
  223. " let save_ttymouse = &ttymouse
  224. " call test_override('no_query_mouse', 1)
  225. " set mouse=a term=xterm
  226. set mouse=a
  227. let col = 1
  228. call setline(1, range(1, 100))
  229. " Split into 3 windows, and go into the middle window
  230. " so we test dragging mouse below and above the window.
  231. 2split
  232. wincmd j
  233. 2split
  234. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  235. let msg = 'ttymouse=' .. ttymouse_val
  236. " exe 'set ttymouse=' .. ttymouse_val
  237. " Line #10 at the top.
  238. norm! 10zt
  239. redraw
  240. call assert_equal(10, winsaveview().topline, msg)
  241. call assert_equal(2, winheight(0), msg)
  242. let row = 4
  243. call MouseLeftClick(row, col)
  244. call assert_equal(10, winsaveview().topline, msg)
  245. " Drag downwards. We're still in the window so topline should
  246. " not change yet.
  247. let row += 1
  248. call MouseLeftDrag(row, col)
  249. call assert_equal(10, winsaveview().topline, msg)
  250. " We now leave the window at the bottom, so the window content should
  251. " scroll by 1 line, then 2 lines (etc) as we drag further away.
  252. let row += 1
  253. call MouseLeftDrag(row, col)
  254. call assert_equal(11, winsaveview().topline, msg)
  255. let row += 1
  256. call MouseLeftDrag(row, col)
  257. call assert_equal(13, winsaveview().topline, msg)
  258. " Now drag upwards.
  259. let row -= 1
  260. call MouseLeftDrag(row, col)
  261. call assert_equal(14, winsaveview().topline, msg)
  262. " We're now back in the window so the topline should not change.
  263. let row -= 1
  264. call MouseLeftDrag(row, col)
  265. call assert_equal(14, winsaveview().topline, msg)
  266. let row -= 1
  267. call MouseLeftDrag(row, col)
  268. call assert_equal(14, winsaveview().topline, msg)
  269. " We now leave the window at the top so the window content should
  270. " scroll by 1 line, then 2, then 3 (etc) in the opposite direction.
  271. let row -= 1
  272. call MouseLeftDrag(row, col)
  273. call assert_equal(13, winsaveview().topline, msg)
  274. let row -= 1
  275. call MouseLeftDrag(row, col)
  276. call assert_equal(11, winsaveview().topline, msg)
  277. let row -= 1
  278. call MouseLeftDrag(row, col)
  279. call assert_equal(8, winsaveview().topline, msg)
  280. call MouseLeftRelease(row, col)
  281. call assert_equal(8, winsaveview().topline, msg)
  282. call assert_equal(2, winheight(0), msg)
  283. endfor
  284. let &mouse = save_mouse
  285. " let &term = save_term
  286. " let &ttymouse = save_ttymouse
  287. " call test_override('no_query_mouse', 0)
  288. bwipe!
  289. endfunc
  290. func Test_term_mouse_drag_window_separator()
  291. let save_mouse = &mouse
  292. let save_term = &term
  293. " let save_ttymouse = &ttymouse
  294. " call test_override('no_query_mouse', 1)
  295. " set mouse=a term=xterm
  296. set mouse=a
  297. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  298. let msg = 'ttymouse=' .. ttymouse_val
  299. " exe 'set ttymouse=' .. ttymouse_val
  300. " Split horizontally and test dragging the horizontal window separator.
  301. split
  302. let rowseparator = winheight(0) + 1
  303. let row = rowseparator
  304. let col = 1
  305. " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
  306. if ttymouse_val !=# 'xterm2' || row <= 223
  307. call MouseLeftClick(row, col)
  308. let row -= 1
  309. call MouseLeftDrag(row, col)
  310. call assert_equal(rowseparator - 1, winheight(0) + 1, msg)
  311. let row += 1
  312. call MouseLeftDrag(row, col)
  313. call assert_equal(rowseparator, winheight(0) + 1, msg)
  314. call MouseLeftRelease(row, col)
  315. call assert_equal(rowseparator, winheight(0) + 1, msg)
  316. endif
  317. bwipe!
  318. " Split vertically and test dragging the vertical window separator.
  319. vsplit
  320. let colseparator = winwidth(0) + 1
  321. let row = 1
  322. let col = colseparator
  323. " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
  324. if ttymouse_val !=# 'xterm2' || col <= 223
  325. call MouseLeftClick(row, col)
  326. let col -= 1
  327. call MouseLeftDrag(row, col)
  328. call assert_equal(colseparator - 1, winwidth(0) + 1, msg)
  329. let col += 1
  330. call MouseLeftDrag(row, col)
  331. call assert_equal(colseparator, winwidth(0) + 1, msg)
  332. call MouseLeftRelease(row, col)
  333. call assert_equal(colseparator, winwidth(0) + 1, msg)
  334. endif
  335. bwipe!
  336. endfor
  337. let &mouse = save_mouse
  338. " let &term = save_term
  339. " let &ttymouse = save_ttymouse
  340. " call test_override('no_query_mouse', 0)
  341. endfunc
  342. func Test_term_mouse_drag_statusline()
  343. let save_mouse = &mouse
  344. let save_term = &term
  345. " let save_ttymouse = &ttymouse
  346. " call test_override('no_query_mouse', 1)
  347. let save_laststatus = &laststatus
  348. " set mouse=a term=xterm laststatus=2
  349. set mouse=a laststatus=2
  350. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  351. let msg = 'ttymouse=' .. ttymouse_val
  352. " exe 'set ttymouse=' .. ttymouse_val
  353. call assert_equal(1, &cmdheight, msg)
  354. let rowstatusline = winheight(0) + 1
  355. let row = rowstatusline
  356. let col = 1
  357. if ttymouse_val ==# 'xterm2' && row > 223
  358. " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
  359. continue
  360. endif
  361. call MouseLeftClick(row, col)
  362. let row -= 1
  363. call MouseLeftDrag(row, col)
  364. call assert_equal(2, &cmdheight, msg)
  365. call assert_equal(rowstatusline - 1, winheight(0) + 1, msg)
  366. let row += 1
  367. call MouseLeftDrag(row, col)
  368. call assert_equal(1, &cmdheight, msg)
  369. call assert_equal(rowstatusline, winheight(0) + 1, msg)
  370. call MouseLeftRelease(row, col)
  371. call assert_equal(1, &cmdheight, msg)
  372. call assert_equal(rowstatusline, winheight(0) + 1, msg)
  373. endfor
  374. let &mouse = save_mouse
  375. " let &term = save_term
  376. " let &ttymouse = save_ttymouse
  377. " call test_override('no_query_mouse', 0)
  378. let &laststatus = save_laststatus
  379. endfunc
  380. func Test_term_mouse_click_tab()
  381. let save_mouse = &mouse
  382. let save_term = &term
  383. " let save_ttymouse = &ttymouse
  384. " call test_override('no_query_mouse', 1)
  385. " set mouse=a term=xterm
  386. set mouse=a
  387. let row = 1
  388. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
  389. let msg = 'ttymouse=' .. ttymouse_val
  390. " exe 'set ttymouse=' .. ttymouse_val
  391. e Xfoo
  392. tabnew Xbar
  393. let a = split(execute(':tabs'), "\n")
  394. call assert_equal(['Tab page 1',
  395. \ '# Xfoo',
  396. \ 'Tab page 2',
  397. \ '> Xbar'], a, msg)
  398. " Test clicking on tab names in the tabline at the top.
  399. let col = 2
  400. redraw
  401. call MouseLeftClick(row, col)
  402. call MouseLeftRelease(row, col)
  403. let a = split(execute(':tabs'), "\n")
  404. call assert_equal(['Tab page 1',
  405. \ '> Xfoo',
  406. \ 'Tab page 2',
  407. \ '# Xbar'], a, msg)
  408. let col = 9
  409. call MouseLeftClick(row, col)
  410. call MouseLeftRelease(row, col)
  411. let a = split(execute(':tabs'), "\n")
  412. call assert_equal(['Tab page 1',
  413. \ '# Xfoo',
  414. \ 'Tab page 2',
  415. \ '> Xbar'], a, msg)
  416. %bwipe!
  417. endfor
  418. let &mouse = save_mouse
  419. " let &term = save_term
  420. " let &ttymouse = save_ttymouse
  421. " call test_override('no_query_mouse', 0)
  422. endfunc
  423. func Test_term_mouse_click_X_to_close_tab()
  424. let save_mouse = &mouse
  425. let save_term = &term
  426. " let save_ttymouse = &ttymouse
  427. " call test_override('no_query_mouse', 1)
  428. " set mouse=a term=xterm
  429. set mouse=a
  430. let row = 1
  431. let col = &columns
  432. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
  433. if ttymouse_val ==# 'xterm2' && col > 223
  434. " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
  435. continue
  436. endif
  437. let msg = 'ttymouse=' .. ttymouse_val
  438. " exe 'set ttymouse=' .. ttymouse_val
  439. e Xtab1
  440. tabnew Xtab2
  441. tabnew Xtab3
  442. tabn 2
  443. let a = split(execute(':tabs'), "\n")
  444. call assert_equal(['Tab page 1',
  445. \ ' Xtab1',
  446. \ 'Tab page 2',
  447. \ '> Xtab2',
  448. \ 'Tab page 3',
  449. \ '# Xtab3'], a, msg)
  450. " Click on "X" in tabline to close current tab i.e. Xtab2.
  451. redraw
  452. call MouseLeftClick(row, col)
  453. call MouseLeftRelease(row, col)
  454. let a = split(execute(':tabs'), "\n")
  455. call assert_equal(['Tab page 1',
  456. \ ' Xtab1',
  457. \ 'Tab page 2',
  458. \ '> Xtab3'], a, msg)
  459. %bwipe!
  460. endfor
  461. let &mouse = save_mouse
  462. " let &term = save_term
  463. " let &ttymouse = save_ttymouse
  464. " call test_override('no_query_mouse', 0)
  465. endfunc
  466. func Test_term_mouse_drag_to_move_tab()
  467. let save_mouse = &mouse
  468. let save_term = &term
  469. " let save_ttymouse = &ttymouse
  470. " call test_override('no_query_mouse', 1)
  471. " Set 'mousetime' to 1 to avoid recognizing a double-click in the loop
  472. " set mouse=a term=xterm mousetime=1
  473. set mouse=a mousetime=0
  474. let row = 1
  475. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  476. let msg = 'ttymouse=' .. ttymouse_val
  477. " exe 'set ttymouse=' .. ttymouse_val
  478. e Xtab1
  479. tabnew Xtab2
  480. let a = split(execute(':tabs'), "\n")
  481. call assert_equal(['Tab page 1',
  482. \ '# Xtab1',
  483. \ 'Tab page 2',
  484. \ '> Xtab2'], a, msg)
  485. redraw
  486. " Click in tab2 and drag it to tab1.
  487. " Check getcharmod() to verify that click is not
  488. " interpreted as a spurious double-click.
  489. call MouseLeftClick(row, 10)
  490. call assert_equal(0, getcharmod(), msg)
  491. for col in [9, 8, 7, 6]
  492. call MouseLeftDrag(row, col)
  493. endfor
  494. call MouseLeftRelease(row, col)
  495. let a = split(execute(':tabs'), "\n")
  496. call assert_equal(['Tab page 1',
  497. \ '> Xtab2',
  498. \ 'Tab page 2',
  499. \ '# Xtab1'], a, msg)
  500. " Switch to tab1
  501. tabnext
  502. let a = split(execute(':tabs'), "\n")
  503. call assert_equal(['Tab page 1',
  504. \ '# Xtab2',
  505. \ 'Tab page 2',
  506. \ '> Xtab1'], a, msg)
  507. " Click in tab2 and drag it to tab1.
  508. " This time it is non-current tab.
  509. call MouseLeftClick(row, 6)
  510. call assert_equal(0, getcharmod(), msg)
  511. for col in [7, 8, 9, 10]
  512. call MouseLeftDrag(row, col)
  513. endfor
  514. call MouseLeftRelease(row, col)
  515. let a = split(execute(':tabs'), "\n")
  516. call assert_equal(['Tab page 1',
  517. \ '# Xtab1',
  518. \ 'Tab page 2',
  519. \ '> Xtab2'], a, msg)
  520. " Click elsewhere so that click in next iteration is not
  521. " interpreted as unwanted double-click.
  522. call MouseLeftClick(row, 11)
  523. call MouseLeftRelease(row, 11)
  524. %bwipe!
  525. endfor
  526. let &mouse = save_mouse
  527. " let &term = save_term
  528. " let &ttymouse = save_ttymouse
  529. " call test_override('no_query_mouse', 0)
  530. set mousetime&
  531. endfunc
  532. func Test_term_mouse_double_click_to_create_tab()
  533. let save_mouse = &mouse
  534. let save_term = &term
  535. " let save_ttymouse = &ttymouse
  536. " call test_override('no_query_mouse', 1)
  537. " Set 'mousetime' to a small value, so that double-click works but we don't
  538. " have to wait long to avoid a triple-click.
  539. " set mouse=a term=xterm mousetime=200
  540. set mouse=a mousetime=200
  541. let row = 1
  542. let col = 10
  543. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  544. let msg = 'ttymouse=' .. ttymouse_val
  545. " exe 'set ttymouse=' .. ttymouse_val
  546. e Xtab1
  547. tabnew Xtab2
  548. let a = split(execute(':tabs'), "\n")
  549. call assert_equal(['Tab page 1',
  550. \ '# Xtab1',
  551. \ 'Tab page 2',
  552. \ '> Xtab2'], a, msg)
  553. redraw
  554. call MouseLeftClick(row, col)
  555. " Check getcharmod() to verify that first click is not
  556. " interpreted as a spurious double-click.
  557. call assert_equal(0, getcharmod(), msg)
  558. call MouseLeftRelease(row, col)
  559. call MouseLeftClick(row, col)
  560. call assert_equal(32, getcharmod(), msg) " double-click
  561. call MouseLeftRelease(row, col)
  562. let a = split(execute(':tabs'), "\n")
  563. call assert_equal(['Tab page 1',
  564. \ ' Xtab1',
  565. \ 'Tab page 2',
  566. \ '> [No Name]',
  567. \ 'Tab page 3',
  568. \ '# Xtab2'], a, msg)
  569. " Click elsewhere so that click in next iteration is not
  570. " interpreted as unwanted double click.
  571. call MouseLeftClick(row, col + 1)
  572. call MouseLeftRelease(row, col + 1)
  573. %bwipe!
  574. endfor
  575. let &mouse = save_mouse
  576. " let &term = save_term
  577. " let &ttymouse = save_ttymouse
  578. " call test_override('no_query_mouse', 0)
  579. set mousetime&
  580. endfunc
  581. " Test double/triple/quadruple click in normal mode to visually select.
  582. func Test_term_mouse_multiple_clicks_to_visually_select()
  583. let save_mouse = &mouse
  584. let save_term = &term
  585. " let save_ttymouse = &ttymouse
  586. " call test_override('no_query_mouse', 1)
  587. " 'mousetime' must be sufficiently large, or else the test is flaky when
  588. " using a ssh connection with X forwarding; i.e. ssh -X (issue #7563).
  589. " set mouse=a term=xterm mousetime=600
  590. set mouse=a mousetime=600
  591. new
  592. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  593. let msg = 'ttymouse=' .. ttymouse_val
  594. " exe 'set ttymouse=' .. ttymouse_val
  595. call setline(1, ['foo [foo bar] foo', 'foo'])
  596. " Double-click on word should visually select the word.
  597. call MouseLeftClick(1, 2)
  598. call assert_equal(0, getcharmod(), msg)
  599. call MouseLeftRelease(1, 2)
  600. call MouseLeftClick(1, 2)
  601. call assert_equal(32, getcharmod(), msg) " double-click
  602. call MouseLeftRelease(1, 2)
  603. call assert_equal('v', mode(), msg)
  604. norm! r1
  605. call assert_equal(['111 [foo bar] foo', 'foo'], getline(1, '$'), msg)
  606. " Double-click on opening square bracket should visually
  607. " select the whole [foo bar].
  608. call MouseLeftClick(1, 5)
  609. call assert_equal(0, getcharmod(), msg)
  610. call MouseLeftRelease(1, 5)
  611. call MouseLeftClick(1, 5)
  612. call assert_equal(32, getcharmod(), msg) " double-click
  613. call MouseLeftRelease(1, 5)
  614. call assert_equal('v', mode(), msg)
  615. norm! r2
  616. call assert_equal(['111 222222222 foo', 'foo'], getline(1, '$'), msg)
  617. " Triple-click should visually select the whole line.
  618. call MouseLeftClick(1, 3)
  619. call assert_equal(0, getcharmod(), msg)
  620. call MouseLeftRelease(1, 3)
  621. call MouseLeftClick(1, 3)
  622. call assert_equal(32, getcharmod(), msg) " double-click
  623. call MouseLeftRelease(1, 3)
  624. call MouseLeftClick(1, 3)
  625. call assert_equal(64, getcharmod(), msg) " triple-click
  626. call MouseLeftRelease(1, 3)
  627. call assert_equal('V', mode(), msg)
  628. norm! r3
  629. call assert_equal(['33333333333333333', 'foo'], getline(1, '$'), msg)
  630. " Quadruple-click should start visual block select.
  631. call MouseLeftClick(1, 2)
  632. call assert_equal(0, getcharmod(), msg)
  633. call MouseLeftRelease(1, 2)
  634. call MouseLeftClick(1, 2)
  635. call assert_equal(32, getcharmod(), msg) " double-click
  636. call MouseLeftRelease(1, 2)
  637. call MouseLeftClick(1, 2)
  638. call assert_equal(64, getcharmod(), msg) " triple-click
  639. call MouseLeftRelease(1, 2)
  640. call MouseLeftClick(1, 2)
  641. call assert_equal(96, getcharmod(), msg) " quadruple-click
  642. call MouseLeftRelease(1, 2)
  643. call assert_equal("\<c-v>", mode(), msg)
  644. norm! r4
  645. call assert_equal(['34333333333333333', 'foo'], getline(1, '$'), msg)
  646. " Double-click on a space character should visually select all the
  647. " consecutive space characters.
  648. %d
  649. call setline(1, ' one two')
  650. call MouseLeftClick(1, 2)
  651. call MouseLeftRelease(1, 2)
  652. call MouseLeftClick(1, 2)
  653. call MouseLeftRelease(1, 2)
  654. call assert_equal('v', mode(), msg)
  655. norm! r1
  656. call assert_equal(['1111one two'], getline(1, '$'), msg)
  657. " Double-click on a word with exclusive selection
  658. set selection=exclusive
  659. let @" = ''
  660. call MouseLeftClick(1, 10)
  661. call MouseLeftRelease(1, 10)
  662. call MouseLeftClick(1, 10)
  663. call MouseLeftRelease(1, 10)
  664. norm! y
  665. call assert_equal('two', @", msg)
  666. " Double click to select a block of text with exclusive selection
  667. %d
  668. call setline(1, 'one (two) three')
  669. call MouseLeftClick(1, 5)
  670. call MouseLeftRelease(1, 5)
  671. call MouseLeftClick(1, 5)
  672. call MouseLeftRelease(1, 5)
  673. norm! y
  674. call assert_equal(5, col("'<"), msg)
  675. call assert_equal(10, col("'>"), msg)
  676. call MouseLeftClick(1, 9)
  677. call MouseLeftRelease(1, 9)
  678. call MouseLeftClick(1, 9)
  679. call MouseLeftRelease(1, 9)
  680. norm! y
  681. call assert_equal(5, col("'<"), msg)
  682. call assert_equal(10, col("'>"), msg)
  683. set selection&
  684. " Click somewhere else so that the clicks above is not combined with the
  685. " clicks in the next iteration.
  686. call MouseRightClick(3, 10)
  687. call MouseRightRelease(3, 10)
  688. endfor
  689. let &mouse = save_mouse
  690. " let &term = save_term
  691. " let &ttymouse = save_ttymouse
  692. set mousetime&
  693. " call test_override('no_query_mouse', 0)
  694. bwipe!
  695. endfunc
  696. " Test for selecting text in visual blockwise mode using Alt-LeftClick
  697. func Test_mouse_alt_leftclick()
  698. let save_mouse = &mouse
  699. let save_term = &term
  700. " let save_ttymouse = &ttymouse
  701. " call test_override('no_query_mouse', 1)
  702. " set mouse=a term=xterm mousetime=200
  703. set mouse=a mousetime=200
  704. set mousemodel=popup
  705. new
  706. call setline(1, 'one (two) three')
  707. for ttymouse_val in g:Ttymouse_values
  708. let msg = 'ttymouse=' .. ttymouse_val
  709. " exe 'set ttymouse=' .. ttymouse_val
  710. " Left click with the Alt modifier key should extend the selection in
  711. " blockwise visual mode.
  712. let @" = ''
  713. call MouseLeftClick(1, 3)
  714. call MouseLeftRelease(1, 3)
  715. call MouseAltLeftClick(1, 11)
  716. call MouseLeftRelease(1, 11)
  717. call assert_equal("\<C-V>", mode(), msg)
  718. normal! y
  719. call assert_equal('e (two) t', @")
  720. endfor
  721. let &mouse = save_mouse
  722. " let &term = save_term
  723. " let &ttymouse = save_ttymouse
  724. set mousetime& mousemodel&
  725. " call test_override('no_query_mouse', 0)
  726. close!
  727. endfunc
  728. func Test_xterm_mouse_click_in_fold_columns()
  729. new
  730. let save_mouse = &mouse
  731. let save_term = &term
  732. " let save_ttymouse = &ttymouse
  733. let save_foldcolumn = &foldcolumn
  734. " set mouse=a term=xterm foldcolumn=3 ttymouse=xterm2
  735. set mouse=a foldcolumn=3
  736. " Create 2 nested folds.
  737. call setline(1, range(1, 7))
  738. 2,6fold
  739. norm! zR
  740. 4,5fold
  741. call assert_equal([-1, -1, -1, 4, 4, -1, -1],
  742. \ map(range(1, 7), 'foldclosed(v:val)'))
  743. " Click in "+" of inner fold in foldcolumn should open it.
  744. redraw
  745. let row = 4
  746. let col = 2
  747. call MouseLeftClick(row, col)
  748. call MouseLeftRelease(row, col)
  749. call assert_equal([-1, -1, -1, -1, -1, -1, -1],
  750. \ map(range(1, 7), 'foldclosed(v:val)'))
  751. " Click in "-" of outer fold in foldcolumn should close it.
  752. redraw
  753. let row = 2
  754. let col = 1
  755. call MouseLeftClick(row, col)
  756. call MouseLeftRelease(row, col)
  757. call assert_equal([-1, 2, 2, 2, 2, 2, -1],
  758. \ map(range(1, 7), 'foldclosed(v:val)'))
  759. norm! zR
  760. " Click in "|" of inner fold in foldcolumn should close it.
  761. redraw
  762. let row = 5
  763. let col = 2
  764. call MouseLeftClick(row, col)
  765. call MouseLeftRelease(row, col)
  766. call assert_equal([-1, -1, -1, 4, 4, -1, -1],
  767. \ map(range(1, 7), 'foldclosed(v:val)'))
  768. let &foldcolumn = save_foldcolumn
  769. " Redraw at the end of the test to avoid interfering with other tests.
  770. defer execute('redraw')
  771. " let &ttymouse = save_ttymouse
  772. " let &term = save_term
  773. let &mouse = save_mouse
  774. bwipe!
  775. endfunc
  776. " Test for the 'h' flag in the 'mouse' option. Using mouse in the help window.
  777. func Test_term_mouse_help_window()
  778. let save_mouse = &mouse
  779. let save_term = &term
  780. " let save_ttymouse = &ttymouse
  781. " call test_override('no_query_mouse', 1)
  782. " set mouse=h term=xterm mousetime=200
  783. set mouse=h mousetime=200
  784. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
  785. let msg = 'ttymouse=' .. ttymouse_val
  786. " exe 'set ttymouse=' .. ttymouse_val
  787. help
  788. let @" = ''
  789. call MouseLeftClick(2, 5)
  790. call MouseLeftRelease(2, 5)
  791. call MouseLeftClick(1, 1)
  792. call MouseLeftDrag(1, 10)
  793. call MouseLeftRelease(1, 10)
  794. norm! y
  795. call assert_equal('*help.txt*', @", msg)
  796. helpclose
  797. " Click somewhere else to make sure the left click above is not combined
  798. " with the next left click and treated as a double click
  799. call MouseRightClick(5, 10)
  800. call MouseRightRelease(5, 10)
  801. endfor
  802. let &mouse = save_mouse
  803. " let &term = save_term
  804. " let &ttymouse = save_ttymouse
  805. set mousetime&
  806. " call test_override('no_query_mouse', 0)
  807. %bw!
  808. endfunc
  809. " Test for the translation of various mouse terminal codes
  810. func Test_mouse_termcodes()
  811. let save_mouse = &mouse
  812. let save_term = &term
  813. " let save_ttymouse = &ttymouse
  814. " call test_override('no_query_mouse', 1)
  815. " set mouse=a term=xterm mousetime=200
  816. new
  817. for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
  818. let msg = 'ttymouse=' .. ttymouse_val
  819. " exe 'set ttymouse=' .. ttymouse_val
  820. let mouse_codes = [
  821. \ ["\<LeftMouse>", "<LeftMouse>"],
  822. \ ["\<MiddleMouse>", "<MiddleMouse>"],
  823. \ ["\<RightMouse>", "<RightMouse>"],
  824. \ ["\<S-LeftMouse>", "<S-LeftMouse>"],
  825. \ ["\<S-MiddleMouse>", "<S-MiddleMouse>"],
  826. \ ["\<S-RightMouse>", "<S-RightMouse>"],
  827. \ ["\<C-LeftMouse>", "<C-LeftMouse>"],
  828. \ ["\<C-MiddleMouse>", "<C-MiddleMouse>"],
  829. \ ["\<C-RightMouse>", "<C-RightMouse>"],
  830. \ ["\<M-LeftMouse>", "<M-LeftMouse>"],
  831. \ ["\<M-MiddleMouse>", "<M-MiddleMouse>"],
  832. \ ["\<M-RightMouse>", "<M-RightMouse>"],
  833. \ ["\<2-LeftMouse>", "<2-LeftMouse>"],
  834. \ ["\<2-MiddleMouse>", "<2-MiddleMouse>"],
  835. \ ["\<2-RightMouse>", "<2-RightMouse>"],
  836. \ ["\<3-LeftMouse>", "<3-LeftMouse>"],
  837. \ ["\<3-MiddleMouse>", "<3-MiddleMouse>"],
  838. \ ["\<3-RightMouse>", "<3-RightMouse>"],
  839. \ ["\<4-LeftMouse>", "<4-LeftMouse>"],
  840. \ ["\<4-MiddleMouse>", "<4-MiddleMouse>"],
  841. \ ["\<4-RightMouse>", "<4-RightMouse>"],
  842. \ ["\<LeftDrag>", "<LeftDrag>"],
  843. \ ["\<MiddleDrag>", "<MiddleDrag>"],
  844. \ ["\<RightDrag>", "<RightDrag>"],
  845. \ ["\<LeftRelease>", "<LeftRelease>"],
  846. \ ["\<MiddleRelease>", "<MiddleRelease>"],
  847. \ ["\<RightRelease>", "<RightRelease>"],
  848. \ ["\<ScrollWheelUp>", "<ScrollWheelUp>"],
  849. \ ["\<S-ScrollWheelUp>", "<S-ScrollWheelUp>"],
  850. \ ["\<C-ScrollWheelUp>", "<C-ScrollWheelUp>"],
  851. \ ["\<ScrollWheelDown>", "<ScrollWheelDown>"],
  852. \ ["\<S-ScrollWheelDown>", "<S-ScrollWheelDown>"],
  853. \ ["\<C-ScrollWheelDown>", "<C-ScrollWheelDown>"],
  854. \ ["\<ScrollWheelLeft>", "<ScrollWheelLeft>"],
  855. \ ["\<S-ScrollWheelLeft>", "<S-ScrollWheelLeft>"],
  856. \ ["\<C-ScrollWheelLeft>", "<C-ScrollWheelLeft>"],
  857. \ ["\<ScrollWheelRight>", "<ScrollWheelRight>"],
  858. \ ["\<S-ScrollWheelRight>", "<S-ScrollWheelRight>"],
  859. \ ["\<C-ScrollWheelRight>", "<C-ScrollWheelRight>"]
  860. \ ]
  861. for [code, outstr] in mouse_codes
  862. exe "normal ggC\<C-K>" . code
  863. call assert_equal(outstr, getline(1), msg)
  864. endfor
  865. endfor
  866. let &mouse = save_mouse
  867. " let &term = save_term
  868. " let &ttymouse = save_ttymouse
  869. set mousetime&
  870. " call test_override('no_query_mouse', 0)
  871. %bw!
  872. endfunc
  873. " Test for translation of special key codes (<xF1>, <xF2>, etc.)
  874. func Test_Keycode_Translation()
  875. let keycodes = [
  876. \ ["<xUp>", "<Up>"],
  877. \ ["<xDown>", "<Down>"],
  878. \ ["<xLeft>", "<Left>"],
  879. \ ["<xRight>", "<Right>"],
  880. \ ["<xHome>", "<Home>"],
  881. \ ["<xEnd>", "<End>"],
  882. \ ["<zHome>", "<Home>"],
  883. \ ["<zEnd>", "<End>"],
  884. \ ["<xF1>", "<F1>"],
  885. \ ["<xF2>", "<F2>"],
  886. \ ["<xF3>", "<F3>"],
  887. \ ["<xF4>", "<F4>"],
  888. \ ["<S-xF1>", "<S-F1>"],
  889. \ ["<S-xF2>", "<S-F2>"],
  890. \ ["<S-xF3>", "<S-F3>"],
  891. \ ["<S-xF4>", "<S-F4>"]]
  892. for [k1, k2] in keycodes
  893. exe "nnoremap " .. k1 .. " 2wx"
  894. call assert_true(maparg(k1, 'n', 0, 1).lhs == k2)
  895. exe "nunmap " .. k1
  896. endfor
  897. endfunc
  898. " Test for terminal keycodes that doesn't have termcap entries
  899. func Test_special_term_keycodes()
  900. new
  901. " Test for <xHome>, <S-xHome> and <C-xHome>
  902. " send <K_SPECIAL> <KS_EXTRA> keycode
  903. call feedkeys("i\<C-K>\x80\xfd\x3f\n", 'xt')
  904. " send <K_SPECIAL> <KS_MODIFIER> bitmap <K_SPECIAL> <KS_EXTRA> keycode
  905. call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3f\n", 'xt')
  906. call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3f\n", 'xt')
  907. " Test for <xEnd>, <S-xEnd> and <C-xEnd>
  908. call feedkeys("i\<C-K>\x80\xfd\x3d\n", 'xt')
  909. call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3d\n", 'xt')
  910. call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3d\n", 'xt')
  911. " Test for <zHome>, <S-zHome> and <C-zHome>
  912. call feedkeys("i\<C-K>\x80\xfd\x40\n", 'xt')
  913. call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x40\n", 'xt')
  914. call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x40\n", 'xt')
  915. " Test for <zEnd>, <S-zEnd> and <C-zEnd>
  916. call feedkeys("i\<C-K>\x80\xfd\x3e\n", 'xt')
  917. call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3e\n", 'xt')
  918. call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3e\n", 'xt')
  919. " Test for <xUp>, <xDown>, <xLeft> and <xRight>
  920. call feedkeys("i\<C-K>\x80\xfd\x41\n", 'xt')
  921. call feedkeys("i\<C-K>\x80\xfd\x42\n", 'xt')
  922. call feedkeys("i\<C-K>\x80\xfd\x43\n", 'xt')
  923. call feedkeys("i\<C-K>\x80\xfd\x44\n", 'xt')
  924. call assert_equal(['<Home>', '<S-Home>', '<C-Home>',
  925. \ '<End>', '<S-End>', '<C-End>',
  926. \ '<Home>', '<S-Home>', '<C-Home>',
  927. \ '<End>', '<S-End>', '<C-End>',
  928. \ '<Up>', '<Down>', '<Left>', '<Right>', ''], getline(1, '$'))
  929. bw!
  930. endfunc
  931. " vim: shiftwidth=2 sts=2 expandtab