blob: 8e8be02cb20ff6478f11c7a5bf30b9e6de81be3d [file] [log] [blame]
Bram Moolenaar905dd902019-04-07 14:21:47 +02001" Tests for decoding escape sequences sent by the terminal.
2
3" This only works for Unix in a terminal
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02004source check.vim
5CheckNotGui
6CheckUnix
Bram Moolenaar905dd902019-04-07 14:21:47 +02007
Bram Moolenaar564344a2019-04-28 13:00:12 +02008source shared.vim
Bram Moolenaar515545e2020-03-22 14:08:59 +01009source mouse.vim
Bram Moolenaarecd34bf2020-08-04 20:17:31 +020010source view_util.vim
Bram Moolenaare46a2ed2020-08-04 21:04:57 +020011source term_util.vim
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020012
Bram Moolenaar92fd5992019-05-02 23:00:22 +020013func Test_term_mouse_left_click()
Bram Moolenaar905dd902019-04-07 14:21:47 +020014 new
15 let save_mouse = &mouse
16 let save_term = &term
17 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +020018 call test_override('no_query_mouse', 1)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020019 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +000020 call WaitForResponses()
21
Bram Moolenaar905dd902019-04-07 14:21:47 +020022 call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer'])
Bram Moolenaar905dd902019-04-07 14:21:47 +020023
Bram Moolenaar515545e2020-03-22 14:08:59 +010024 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
Bram Moolenaar49452192019-04-17 16:27:02 +020025 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +020026 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020027 go
Bram Moolenaar49452192019-04-17 16:27:02 +020028 call assert_equal([0, 1, 1, 0], getpos('.'), msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020029 let row = 2
30 let col = 6
31 call MouseLeftClick(row, col)
32 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +020033 call assert_equal([0, 2, 6, 0], getpos('.'), msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020034 endfor
Bram Moolenaar905dd902019-04-07 14:21:47 +020035
36 let &mouse = save_mouse
37 let &term = save_term
38 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +020039 call test_override('no_query_mouse', 0)
Bram Moolenaar905dd902019-04-07 14:21:47 +020040 bwipe!
41endfunc
42
Bram Moolenaar6aa75232019-10-13 21:01:34 +020043func Test_xterm_mouse_right_click_extends_visual()
44 if has('mac')
45 throw "Skipped: test right click in visual mode does not work on macOs (why?)"
46 endif
47 let save_mouse = &mouse
48 let save_term = &term
49 let save_ttymouse = &ttymouse
50 call test_override('no_query_mouse', 1)
51 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +000052 call WaitForResponses()
Bram Moolenaar6aa75232019-10-13 21:01:34 +020053
54 for visual_mode in ["v", "V", "\<C-V>"]
Bram Moolenaar515545e2020-03-22 14:08:59 +010055 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar6aa75232019-10-13 21:01:34 +020056 let msg = 'visual=' .. visual_mode .. ' ttymouse=' .. ttymouse_val
57 exe 'set ttymouse=' .. ttymouse_val
58
59 call setline(1, repeat([repeat('-', 7)], 7))
60 call MouseLeftClick(4, 4)
61 call MouseLeftRelease(4, 4)
62 exe "norm! " .. visual_mode
63
64 " Right click extends top left of visual area.
65 call MouseRightClick(2, 2)
66 call MouseRightRelease(2, 2)
67
Bram Moolenaarf19f8d12019-12-18 19:36:23 +010068 " Right click extends bottom right of visual area.
Bram Moolenaar6aa75232019-10-13 21:01:34 +020069 call MouseRightClick(6, 6)
70 call MouseRightRelease(6, 6)
71 norm! r1gv
72
73 " Right click shrinks top left of visual area.
74 call MouseRightClick(3, 3)
75 call MouseRightRelease(3, 3)
76
77 " Right click shrinks bottom right of visual area.
78 call MouseRightClick(5, 5)
79 call MouseRightRelease(5, 5)
80 norm! r2
81
82 if visual_mode ==# 'v'
83 call assert_equal(['-------',
84 \ '-111111',
85 \ '1122222',
86 \ '2222222',
87 \ '2222211',
88 \ '111111-',
89 \ '-------'], getline(1, '$'), msg)
90 elseif visual_mode ==# 'V'
91 call assert_equal(['-------',
92 \ '1111111',
93 \ '2222222',
94 \ '2222222',
95 \ '2222222',
96 \ '1111111',
97 \ '-------'], getline(1, '$'), msg)
98 else
99 call assert_equal(['-------',
100 \ '-11111-',
101 \ '-12221-',
102 \ '-12221-',
103 \ '-12221-',
104 \ '-11111-',
105 \ '-------'], getline(1, '$'), msg)
106 endif
107 endfor
108 endfor
109
110 let &mouse = save_mouse
111 let &term = save_term
112 let &ttymouse = save_ttymouse
113 call test_override('no_query_mouse', 0)
114 bwipe!
115endfunc
116
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200117" Test that <C-LeftMouse> jumps to help tag and <C-RightMouse> jumps back.
Bram Moolenaar297bec02020-07-14 22:11:04 +0200118" Also test for g<LeftMouse> and g<RightMouse>.
119func Test_xterm_mouse_tagjump()
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200120 let save_mouse = &mouse
121 let save_term = &term
122 let save_ttymouse = &ttymouse
123 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +0000124 call WaitForResponses()
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200125
Bram Moolenaar515545e2020-03-22 14:08:59 +0100126 for ttymouse_val in g:Ttymouse_values
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200127 let msg = 'ttymouse=' .. ttymouse_val
128 exe 'set ttymouse=' .. ttymouse_val
129 help
130 /usr_02.txt
131 norm! zt
Bram Moolenaar297bec02020-07-14 22:11:04 +0200132
133 " CTRL-left click to jump to a tag
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200134 let row = 1
135 let col = 1
136 call MouseCtrlLeftClick(row, col)
137 call MouseLeftRelease(row, col)
138 call assert_match('usr_02.txt$', bufname('%'), msg)
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200139 call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg)
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200140
Bram Moolenaar297bec02020-07-14 22:11:04 +0200141 " CTRL-right click to pop a tag
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200142 call MouseCtrlRightClick(row, col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200143 call MouseRightRelease(row, col)
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200144 call assert_match('help.txt$', bufname('%'), msg)
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200145 call assert_equal('|usr_02.txt|', expand('<cWORD>'), msg)
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200146
Bram Moolenaar297bec02020-07-14 22:11:04 +0200147 " Jump to a tag
148 exe "normal \<C-]>"
149 call assert_match('usr_02.txt$', bufname('%'), msg)
150 call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg)
151
152 " Use CTRL-right click in insert mode to pop the tag
153 new
154 let str = 'iHello' .. MouseCtrlRightClickCode(row, col)
155 \ .. MouseRightReleaseCode(row, col) .. "\<C-C>"
Bram Moolenaar2764d062020-07-18 12:59:19 +0200156 call assert_fails('call feedkeys(str, "Lx!")', 'E37:', msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200157 close!
158
159 " CTRL-right click with a count
160 let str = "4" .. MouseCtrlRightClickCode(row, col)
161 \ .. MouseRightReleaseCode(row, col)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200162 call assert_fails('call feedkeys(str, "Lx!")', 'E555:', msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200163 call assert_match('help.txt$', bufname('%'), msg)
164 call assert_equal(1, line('.'), msg)
165
166 " g<LeftMouse> to jump to a tag
167 /usr_02.txt
168 norm! zt
169 call test_setmouse(row, col)
170 exe "normal g\<LeftMouse>"
171 call assert_match('usr_02.txt$', bufname('%'), msg)
172 call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg)
173
174 " g<RightMouse> to pop to a tag
175 call test_setmouse(row, col)
176 exe "normal g\<RightMouse>"
177 call assert_match('help.txt$', bufname('%'), msg)
178 call assert_equal('|usr_02.txt|', expand('<cWORD>'), msg)
179
180 %bw!
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200181 endfor
182
183 let &mouse = save_mouse
184 let &term = save_term
185 let &ttymouse = save_ttymouse
186endfunc
187
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200188func Test_term_mouse_middle_click()
Bram Moolenaar52992fe2019-08-12 14:20:33 +0200189 CheckFeature clipboard_working
Bram Moolenaar564344a2019-04-28 13:00:12 +0200190
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200191 new
192 let save_mouse = &mouse
193 let save_term = &term
194 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200195 call test_override('no_query_mouse', 1)
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200196 let save_quotestar = @*
Bram Moolenaar297bec02020-07-14 22:11:04 +0200197 let save_quoteplus = @+
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200198 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +0000199 call WaitForResponses()
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200200
Bram Moolenaar515545e2020-03-22 14:08:59 +0100201 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200202 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200203 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200204 call setline(1, ['123456789', '123456789'])
Bram Moolenaar297bec02020-07-14 22:11:04 +0200205 let @* = 'abc'
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200206
207 " Middle-click in the middle of the line pastes text where clicked.
208 let row = 1
209 let col = 6
210 call MouseMiddleClick(row, col)
211 call MouseMiddleRelease(row, col)
212 call assert_equal(['12345abc6789', '123456789'], getline(1, '$'), msg)
213
214 " Middle-click beyond end of the line pastes text at the end of the line.
215 let col = 20
216 call MouseMiddleClick(row, col)
217 call MouseMiddleRelease(row, col)
218 call assert_equal(['12345abc6789abc', '123456789'], getline(1, '$'), msg)
219
220 " Middle-click beyond the last line pastes in the last line.
221 let row = 5
222 let col = 3
223 call MouseMiddleClick(row, col)
224 call MouseMiddleRelease(row, col)
225 call assert_equal(['12345abc6789abc', '12abc3456789'], getline(1, '$'), msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200226
227 " Middle mouse click in operator pending mode beeps
228 call assert_beeps('exe "normal c\<MiddleMouse>"')
229
230 " Clicking middle mouse in visual mode, yanks the selection and pastes the
231 " clipboard contents
232 let save_clipboard = &clipboard
233 set clipboard=
234 let @" = ''
235 call cursor(1, 1)
236 call feedkeys("v3l" ..
237 \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7), 'Lx!')
238 call assert_equal(['12345abc6789abc', '12abc3abc456789'],
239 \ getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200240 call assert_equal('1234', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200241 let &clipboard = save_clipboard
242
243 " Clicking middle mouse in select mode, replaces the selected text with
244 " the clipboard contents
245 let @+ = 'xyz'
246 call cursor(1, 3)
247 exe "normal gh\<Right>\<Right>\<MiddleMouse>"
248 call assert_equal(['12xyzabc6789abc', '12abc3abc456789'],
249 \ getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200250
251 " Prefixing middle click with [ or ] fixes the indent after pasting.
252 %d
253 call setline(1, " one two")
254 call setreg('r', 'red blue', 'l')
255 call test_setmouse(1, 5)
256 exe "normal \"r[\<MiddleMouse>"
257 call assert_equal(' red blue', getline(1), msg)
258 call test_setmouse(2, 5)
259 exe "normal \"r]\<MiddleMouse>"
260 call assert_equal(' red blue', getline(3), msg)
261 %d
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200262 endfor
263
264 let &mouse = save_mouse
265 let &term = save_term
266 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200267 call test_override('no_query_mouse', 0)
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200268 let @* = save_quotestar
Bram Moolenaar297bec02020-07-14 22:11:04 +0200269 let @+ = save_quotestar
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200270 bwipe!
271endfunc
272
Bram Moolenaar297bec02020-07-14 22:11:04 +0200273" If clipboard is not working, then clicking the middle mouse button in visual
274" mode, will copy and paste the selected text.
275func Test_term_mouse_middle_click_no_clipboard()
276 if has('clipboard_working')
277 throw 'Skipped: clipboard support works'
Bram Moolenaar297bec02020-07-14 22:11:04 +0200278 endif
279 new
280 let save_mouse = &mouse
281 let save_term = &term
282 let save_ttymouse = &ttymouse
283 call test_override('no_query_mouse', 1)
284 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +0000285 call WaitForResponses()
Bram Moolenaar297bec02020-07-14 22:11:04 +0200286
287 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
288 let msg = 'ttymouse=' .. ttymouse_val
289 exe 'set ttymouse=' .. ttymouse_val
290 call setline(1, ['123456789', '123456789'])
291
292 " Clicking middle mouse in visual mode, yanks the selection and pastes it
293 call cursor(1, 1)
294 call feedkeys("v3l" ..
295 \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7), 'Lx!')
296 call assert_equal(['123456789', '1234561234789'],
297 \ getline(1, '$'), msg)
298 endfor
299
300 call test_override('no_query_mouse', 0)
301 let &ttymouse = save_ttymouse
302 let &term = save_term
303 let &mouse = save_mouse
304 close!
305endfunc
306
307func Test_term_mouse_middle_click_insert_mode()
308 CheckFeature clipboard_working
309
310 new
311 let save_mouse = &mouse
312 let save_term = &term
313 let save_ttymouse = &ttymouse
314 call test_override('no_query_mouse', 1)
315 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +0000316 call WaitForResponses()
Bram Moolenaar297bec02020-07-14 22:11:04 +0200317
318 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
319 let msg = 'ttymouse=' .. ttymouse_val
320 exe 'set ttymouse=' .. ttymouse_val
321 call setline(1, ['123456789', '123456789'])
322 let @* = 'abc'
323
Dominique Pelle923dce22021-11-21 11:36:04 +0000324 " Middle-click in insert mode doesn't move the cursor but inserts the
325 " contents of a register
Bram Moolenaar297bec02020-07-14 22:11:04 +0200326 call cursor(1, 4)
327 call feedkeys('i' ..
328 \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7) ..
329 \ "\<C-C>", 'Lx!')
330 call assert_equal(['123abc456789', '123456789'],
331 \ getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200332 call assert_equal([1, 6], [line('.'), col('.')], msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200333
334 " Middle-click in replace mode
335 call cursor(1, 1)
336 call feedkeys('$R' ..
337 \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7) ..
338 \ "\<C-C>", 'Lx!')
339 call assert_equal(['123abc45678abc', '123456789'],
340 \ getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200341 call assert_equal([1, 14], [line('.'), col('.')], msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200342 endfor
343
344 let &mouse = save_mouse
345 let &term = save_term
346 let &ttymouse = save_ttymouse
347 call test_override('no_query_mouse', 0)
348 close!
349endfunc
350
351" Test for switching window using mouse in insert mode
352func Test_term_mouse_switch_win_insert_mode()
353 5new
354 let save_mouse = &mouse
355 let save_term = &term
356 let save_ttymouse = &ttymouse
357 call test_override('no_query_mouse', 1)
358 set mouse=a term=xterm ttymouse=xterm2
Bram Moolenaarc255b782022-11-26 19:16:48 +0000359 call WaitForResponses()
Bram Moolenaar297bec02020-07-14 22:11:04 +0200360
361 call feedkeys('ivim' ..
362 \ MouseLeftClickCode(8, 6) .. MouseLeftReleaseCode(8, 6) ..
363 \ "\<C-C>", 'Lx!')
364 call assert_equal(2, winnr())
365 wincmd w
366 call assert_equal('n', mode())
367 call assert_equal(['vim'], getline(1, '$'))
368
369 let &mouse = save_mouse
370 let &term = save_term
371 let &ttymouse = save_ttymouse
372 call test_override('no_query_mouse', 0)
373 close!
374endfunc
375
Dominique Pelle923dce22021-11-21 11:36:04 +0000376" Test for using the mouse to increase the height of the cmdline window
Bram Moolenaar297bec02020-07-14 22:11:04 +0200377func Test_mouse_cmdwin_resize()
378 let save_mouse = &mouse
379 let save_term = &term
380 let save_ttymouse = &ttymouse
381 call test_override('no_query_mouse', 1)
382 set mouse=a term=xterm ttymouse=xterm2
Bram Moolenaarc255b782022-11-26 19:16:48 +0000383 call WaitForResponses()
384
Bram Moolenaar297bec02020-07-14 22:11:04 +0200385 5new
386 redraw!
387
388 let h = 0
389 let row = &lines - &cmdwinheight - 2
390 call feedkeys("q:" ..
391 \ MouseLeftClickCode(row, 1) ..
392 \ MouseLeftDragCode(row - 1, 1) ..
393 \ MouseLeftReleaseCode(row - 2, 1) ..
394 \ "alet h = \<C-R>=winheight(0)\<CR>\<CR>", 'Lx!')
395 call assert_equal(&cmdwinheight + 2, h)
396
397 let &mouse = save_mouse
398 let &term = save_term
399 let &ttymouse = save_ttymouse
400 call test_override('no_query_mouse', 0)
401 close!
402endfunc
403
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200404" TODO: for unclear reasons this test fails if it comes after
405" Test_xterm_mouse_ctrl_click()
406func Test_1xterm_mouse_wheel()
Bram Moolenaar049736f2019-04-07 21:55:07 +0200407 new
408 let save_mouse = &mouse
409 let save_term = &term
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200410 let save_wrap = &wrap
Bram Moolenaar049736f2019-04-07 21:55:07 +0200411 let save_ttymouse = &ttymouse
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200412 set mouse=a term=xterm nowrap
Bram Moolenaarc255b782022-11-26 19:16:48 +0000413 call WaitForResponses()
414
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200415 call setline(1, range(100000000000000, 100000000000100))
Bram Moolenaar049736f2019-04-07 21:55:07 +0200416
Bram Moolenaar515545e2020-03-22 14:08:59 +0100417 for ttymouse_val in g:Ttymouse_values
Bram Moolenaar49452192019-04-17 16:27:02 +0200418 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200419 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200420 go
Bram Moolenaar49452192019-04-17 16:27:02 +0200421 call assert_equal(1, line('w0'), msg)
422 call assert_equal([0, 1, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200423
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200424 call MouseWheelDown(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200425 call assert_equal(4, line('w0'), msg)
426 call assert_equal([0, 4, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200427
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200428 call MouseWheelDown(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200429 call assert_equal(7, line('w0'), msg)
430 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200431
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200432 call MouseWheelUp(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200433 call assert_equal(4, line('w0'), msg)
434 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200435
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200436 call MouseWheelUp(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200437 call assert_equal(1, line('w0'), msg)
438 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200439
Christopher Plewright20b795e2022-12-20 20:01:58 +0000440 call MouseWheelRight(1, 1)
441 call assert_equal(7, 1 + virtcol(".") - wincol(), msg)
442 call assert_equal([0, 7, 7, 0], getpos('.'), msg)
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200443
Christopher Plewright20b795e2022-12-20 20:01:58 +0000444 call MouseWheelRight(1, 1)
445 call assert_equal(13, 1 + virtcol(".") - wincol(), msg)
446 call assert_equal([0, 7, 13, 0], getpos('.'), msg)
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200447
Christopher Plewright20b795e2022-12-20 20:01:58 +0000448 call MouseWheelLeft(1, 1)
449 call assert_equal(7, 1 + virtcol(".") - wincol(), msg)
450 call assert_equal([0, 7, 13, 0], getpos('.'), msg)
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200451
Christopher Plewright20b795e2022-12-20 20:01:58 +0000452 call MouseWheelLeft(1, 1)
453 call assert_equal(1, 1 + virtcol(".") - wincol(), msg)
454 call assert_equal([0, 7, 13, 0], getpos('.'), msg)
455
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200456 endfor
Bram Moolenaar049736f2019-04-07 21:55:07 +0200457
458 let &mouse = save_mouse
459 let &term = save_term
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200460 let &wrap = save_wrap
Bram Moolenaar049736f2019-04-07 21:55:07 +0200461 let &ttymouse = save_ttymouse
462 bwipe!
463endfunc
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200464
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200465" Test that dragging beyond the window (at the bottom and at the top)
Bram Moolenaarf19f8d12019-12-18 19:36:23 +0100466" scrolls window content by the number of lines beyond the window.
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200467func Test_term_mouse_drag_beyond_window()
468 let save_mouse = &mouse
469 let save_term = &term
470 let save_ttymouse = &ttymouse
471 call test_override('no_query_mouse', 1)
472 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +0000473 call WaitForResponses()
474
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200475 let col = 1
476 call setline(1, range(1, 100))
477
478 " Split into 3 windows, and go into the middle window
479 " so we test dragging mouse below and above the window.
480 2split
481 wincmd j
482 2split
483
Bram Moolenaar515545e2020-03-22 14:08:59 +0100484 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200485 let msg = 'ttymouse=' .. ttymouse_val
486 exe 'set ttymouse=' .. ttymouse_val
487
488 " Line #10 at the top.
489 norm! 10zt
490 redraw
491 call assert_equal(10, winsaveview().topline, msg)
492 call assert_equal(2, winheight(0), msg)
493
494 let row = 4
495 call MouseLeftClick(row, col)
496 call assert_equal(10, winsaveview().topline, msg)
497
498 " Drag downwards. We're still in the window so topline should
499 " not change yet.
500 let row += 1
501 call MouseLeftDrag(row, col)
502 call assert_equal(10, winsaveview().topline, msg)
503
504 " We now leave the window at the bottom, so the window content should
505 " scroll by 1 line, then 2 lines (etc) as we drag further away.
506 let row += 1
507 call MouseLeftDrag(row, col)
508 call assert_equal(11, winsaveview().topline, msg)
509
510 let row += 1
511 call MouseLeftDrag(row, col)
512 call assert_equal(13, winsaveview().topline, msg)
513
514 " Now drag upwards.
515 let row -= 1
516 call MouseLeftDrag(row, col)
517 call assert_equal(14, winsaveview().topline, msg)
518
519 " We're now back in the window so the topline should not change.
520 let row -= 1
521 call MouseLeftDrag(row, col)
522 call assert_equal(14, winsaveview().topline, msg)
523
524 let row -= 1
525 call MouseLeftDrag(row, col)
526 call assert_equal(14, winsaveview().topline, msg)
527
528 " We now leave the window at the top so the window content should
529 " scroll by 1 line, then 2, then 3 (etc) in the opposite direction.
530 let row -= 1
531 call MouseLeftDrag(row, col)
532 call assert_equal(13, winsaveview().topline, msg)
533
534 let row -= 1
535 call MouseLeftDrag(row, col)
536 call assert_equal(11, winsaveview().topline, msg)
537
538 let row -= 1
539 call MouseLeftDrag(row, col)
540 call assert_equal(8, winsaveview().topline, msg)
541
542 call MouseLeftRelease(row, col)
543 call assert_equal(8, winsaveview().topline, msg)
544 call assert_equal(2, winheight(0), msg)
545 endfor
546
547 let &mouse = save_mouse
548 let &term = save_term
549 let &ttymouse = save_ttymouse
550 call test_override('no_query_mouse', 0)
551 bwipe!
552endfunc
553
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200554func Test_term_mouse_drag_window_separator()
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200555 let save_mouse = &mouse
556 let save_term = &term
557 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200558 call test_override('no_query_mouse', 1)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200559 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +0000560 call WaitForResponses()
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200561
Bram Moolenaar515545e2020-03-22 14:08:59 +0100562 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200563 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200564 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200565
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200566 " Split horizontally and test dragging the horizontal window separator.
567 split
568 let rowseparator = winheight(0) + 1
569 let row = rowseparator
570 let col = 1
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200571
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200572 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
573 if ttymouse_val !=# 'xterm2' || row <= 223
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200574 call MouseLeftClick(row, col)
575 let row -= 1
576 call MouseLeftDrag(row, col)
zeertzjq8e0ccb62022-11-01 18:35:27 +0000577 call assert_equal(rowseparator - 1, winheight(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200578 let row += 1
579 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200580 call assert_equal(rowseparator, winheight(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200581 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200582 call assert_equal(rowseparator, winheight(0) + 1, msg)
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200583 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200584 bwipe!
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200585
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200586 " Split vertically and test dragging the vertical window separator.
587 vsplit
588 let colseparator = winwidth(0) + 1
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200589 let row = 1
590 let col = colseparator
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200591
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200592 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
593 if ttymouse_val !=# 'xterm2' || col <= 223
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200594 call MouseLeftClick(row, col)
595 let col -= 1
596 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200597 call assert_equal(colseparator - 1, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200598 let col += 1
599 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200600 call assert_equal(colseparator, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200601 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200602 call assert_equal(colseparator, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200603 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200604 bwipe!
605 endfor
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200606
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200607 let &mouse = save_mouse
608 let &term = save_term
609 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200610 call test_override('no_query_mouse', 0)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200611endfunc
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200612
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200613func Test_term_mouse_drag_statusline()
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200614 let save_mouse = &mouse
615 let save_term = &term
616 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200617 call test_override('no_query_mouse', 1)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200618 let save_laststatus = &laststatus
619 set mouse=a term=xterm laststatus=2
Bram Moolenaarc255b782022-11-26 19:16:48 +0000620 call WaitForResponses()
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200621
Bram Moolenaar515545e2020-03-22 14:08:59 +0100622 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200623 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200624 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200625
Bram Moolenaar49452192019-04-17 16:27:02 +0200626 call assert_equal(1, &cmdheight, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200627 let rowstatusline = winheight(0) + 1
628 let row = rowstatusline
629 let col = 1
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200630
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200631 if ttymouse_val ==# 'xterm2' && row > 223
632 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200633 continue
634 endif
635
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200636 call MouseLeftClick(row, col)
637 let row -= 1
638 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200639 call assert_equal(2, &cmdheight, msg)
640 call assert_equal(rowstatusline - 1, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200641 let row += 1
642 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200643 call assert_equal(1, &cmdheight, msg)
644 call assert_equal(rowstatusline, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200645 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200646 call assert_equal(1, &cmdheight, msg)
647 call assert_equal(rowstatusline, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200648 endfor
649
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200650 let &mouse = save_mouse
651 let &term = save_term
652 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200653 call test_override('no_query_mouse', 0)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200654 let &laststatus = save_laststatus
655endfunc
656
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200657func Test_term_mouse_click_tab()
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200658 let save_mouse = &mouse
659 let save_term = &term
660 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200661 call test_override('no_query_mouse', 1)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200662 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +0000663 call WaitForResponses()
664
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200665 let row = 1
666
Bram Moolenaar515545e2020-03-22 14:08:59 +0100667 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
Bram Moolenaar49452192019-04-17 16:27:02 +0200668 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200669 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200670 e Xfoo
671 tabnew Xbar
672
673 let a = split(execute(':tabs'), "\n")
674 call assert_equal(['Tab page 1',
675 \ ' Xfoo',
676 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200677 \ '> Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200678
679 " Test clicking on tab names in the tabline at the top.
680 let col = 2
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200681 redraw
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200682 call MouseLeftClick(row, col)
683 call MouseLeftRelease(row, col)
684 let a = split(execute(':tabs'), "\n")
685 call assert_equal(['Tab page 1',
686 \ '> Xfoo',
687 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200688 \ ' Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200689
690 let col = 9
691 call MouseLeftClick(row, col)
692 call MouseLeftRelease(row, col)
693 let a = split(execute(':tabs'), "\n")
694 call assert_equal(['Tab page 1',
695 \ ' Xfoo',
696 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200697 \ '> Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200698
699 %bwipe!
700 endfor
701
702 let &mouse = save_mouse
703 let &term = save_term
704 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200705 call test_override('no_query_mouse', 0)
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200706endfunc
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200707
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200708func Test_term_mouse_click_X_to_close_tab()
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200709 let save_mouse = &mouse
710 let save_term = &term
711 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200712 call test_override('no_query_mouse', 1)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200713 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +0000714 call WaitForResponses()
715
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200716 let row = 1
717 let col = &columns
718
Bram Moolenaar515545e2020-03-22 14:08:59 +0100719 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200720 if ttymouse_val ==# 'xterm2' && col > 223
721 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200722 continue
723 endif
Bram Moolenaar49452192019-04-17 16:27:02 +0200724 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200725 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200726 e Xtab1
727 tabnew Xtab2
728 tabnew Xtab3
729 tabn 2
730
731 let a = split(execute(':tabs'), "\n")
732 call assert_equal(['Tab page 1',
733 \ ' Xtab1',
734 \ 'Tab page 2',
735 \ '> Xtab2',
736 \ 'Tab page 3',
Bram Moolenaar49452192019-04-17 16:27:02 +0200737 \ ' Xtab3'], a, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200738
739 " Click on "X" in tabline to close current tab i.e. Xtab2.
740 redraw
741 call MouseLeftClick(row, col)
742 call MouseLeftRelease(row, col)
743 let a = split(execute(':tabs'), "\n")
744 call assert_equal(['Tab page 1',
745 \ ' Xtab1',
746 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200747 \ '> Xtab3'], a, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200748
749 %bwipe!
750 endfor
751
752 let &mouse = save_mouse
753 let &term = save_term
754 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200755 call test_override('no_query_mouse', 0)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200756endfunc
Bram Moolenaare3e38282019-04-15 20:55:31 +0200757
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200758func Test_term_mouse_drag_to_move_tab()
Bram Moolenaare3e38282019-04-15 20:55:31 +0200759 let save_mouse = &mouse
760 let save_term = &term
761 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200762 call test_override('no_query_mouse', 1)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200763 " Set 'mousetime' to 1 to avoid recognizing a double-click in the loop
764 set mouse=a term=xterm mousetime=1
Bram Moolenaarc255b782022-11-26 19:16:48 +0000765 call WaitForResponses()
766
Bram Moolenaare3e38282019-04-15 20:55:31 +0200767 let row = 1
768
Bram Moolenaar515545e2020-03-22 14:08:59 +0100769 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200770 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200771 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaare3e38282019-04-15 20:55:31 +0200772 e Xtab1
773 tabnew Xtab2
774
775 let a = split(execute(':tabs'), "\n")
776 call assert_equal(['Tab page 1',
777 \ ' Xtab1',
778 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200779 \ '> Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200780 redraw
781
782 " Click in tab2 and drag it to tab1.
783 " Check getcharmod() to verify that click is not
784 " interpreted as a spurious double-click.
785 call MouseLeftClick(row, 10)
Bram Moolenaar49452192019-04-17 16:27:02 +0200786 call assert_equal(0, getcharmod(), msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200787 for col in [9, 8, 7, 6]
788 call MouseLeftDrag(row, col)
789 endfor
790 call MouseLeftRelease(row, col)
791 let a = split(execute(':tabs'), "\n")
792 call assert_equal(['Tab page 1',
793 \ '> Xtab2',
794 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200795 \ ' Xtab1'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200796
zeertzjq8e0ccb62022-11-01 18:35:27 +0000797 " Switch to tab1
798 tabnext
799 let a = split(execute(':tabs'), "\n")
800 call assert_equal(['Tab page 1',
801 \ ' Xtab2',
802 \ 'Tab page 2',
803 \ '> Xtab1'], a, msg)
804
805 " Click in tab2 and drag it to tab1.
806 " This time it is non-current tab.
807 call MouseLeftClick(row, 6)
808 call assert_equal(0, getcharmod(), msg)
809 for col in [7, 8, 9, 10]
810 call MouseLeftDrag(row, col)
811 endfor
812 call MouseLeftRelease(row, col)
813 let a = split(execute(':tabs'), "\n")
814 call assert_equal(['Tab page 1',
815 \ ' Xtab1',
816 \ 'Tab page 2',
817 \ '> Xtab2'], a, msg)
818
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100819 " Click elsewhere so that click in next iteration is not
820 " interpreted as unwanted double-click.
821 call MouseLeftClick(row, 11)
822 call MouseLeftRelease(row, 11)
823
Bram Moolenaare3e38282019-04-15 20:55:31 +0200824 %bwipe!
825 endfor
826
827 let &mouse = save_mouse
828 let &term = save_term
829 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200830 call test_override('no_query_mouse', 0)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200831 set mousetime&
832endfunc
833
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200834func Test_term_mouse_double_click_to_create_tab()
Bram Moolenaare3e38282019-04-15 20:55:31 +0200835 let save_mouse = &mouse
836 let save_term = &term
837 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200838 call test_override('no_query_mouse', 1)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200839 " Set 'mousetime' to a small value, so that double-click works but we don't
840 " have to wait long to avoid a triple-click.
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100841 set mouse=a term=xterm mousetime=200
Bram Moolenaarc255b782022-11-26 19:16:48 +0000842 call WaitForResponses()
843
Bram Moolenaare3e38282019-04-15 20:55:31 +0200844 let row = 1
845 let col = 10
846
Bram Moolenaar515545e2020-03-22 14:08:59 +0100847 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200848 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200849 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaare3e38282019-04-15 20:55:31 +0200850 e Xtab1
851 tabnew Xtab2
852
853 let a = split(execute(':tabs'), "\n")
854 call assert_equal(['Tab page 1',
855 \ ' Xtab1',
856 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200857 \ '> Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200858
859 redraw
860 call MouseLeftClick(row, col)
861 " Check getcharmod() to verify that first click is not
862 " interpreted as a spurious double-click.
Bram Moolenaar49452192019-04-17 16:27:02 +0200863 call assert_equal(0, getcharmod(), msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200864 call MouseLeftRelease(row, col)
865 call MouseLeftClick(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200866 call assert_equal(32, getcharmod(), msg) " double-click
Bram Moolenaare3e38282019-04-15 20:55:31 +0200867 call MouseLeftRelease(row, col)
868 let a = split(execute(':tabs'), "\n")
869 call assert_equal(['Tab page 1',
870 \ ' Xtab1',
871 \ 'Tab page 2',
872 \ '> [No Name]',
873 \ 'Tab page 3',
Bram Moolenaar49452192019-04-17 16:27:02 +0200874 \ ' Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200875
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100876 " Click elsewhere so that click in next iteration is not
877 " interpreted as unwanted double click.
878 call MouseLeftClick(row, col + 1)
879 call MouseLeftRelease(row, col + 1)
880
Bram Moolenaare3e38282019-04-15 20:55:31 +0200881 %bwipe!
882 endfor
883
884 let &mouse = save_mouse
885 let &term = save_term
886 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200887 call test_override('no_query_mouse', 0)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200888 set mousetime&
889endfunc
Bram Moolenaar696d6372019-04-17 16:33:46 +0200890
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100891" Test double/triple/quadruple click in normal mode to visually select.
892func Test_term_mouse_multiple_clicks_to_visually_select()
893 let save_mouse = &mouse
894 let save_term = &term
895 let save_ttymouse = &ttymouse
896 call test_override('no_query_mouse', 1)
Bram Moolenaar94722c52023-01-28 19:19:03 +0000897
Bram Moolenaar2a5c61a2020-12-30 14:59:23 +0100898 " 'mousetime' must be sufficiently large, or else the test is flaky when
899 " using a ssh connection with X forwarding; i.e. ssh -X (issue #7563).
900 set mouse=a term=xterm mousetime=600
Bram Moolenaarc255b782022-11-26 19:16:48 +0000901 call WaitForResponses()
902
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100903 new
904
Bram Moolenaar515545e2020-03-22 14:08:59 +0100905 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100906 let msg = 'ttymouse=' .. ttymouse_val
907 exe 'set ttymouse=' .. ttymouse_val
908 call setline(1, ['foo [foo bar] foo', 'foo'])
909
910 " Double-click on word should visually select the word.
911 call MouseLeftClick(1, 2)
912 call assert_equal(0, getcharmod(), msg)
913 call MouseLeftRelease(1, 2)
914 call MouseLeftClick(1, 2)
915 call assert_equal(32, getcharmod(), msg) " double-click
916 call MouseLeftRelease(1, 2)
917 call assert_equal('v', mode(), msg)
918 norm! r1
919 call assert_equal(['111 [foo bar] foo', 'foo'], getline(1, '$'), msg)
920
921 " Double-click on opening square bracket should visually
922 " select the whole [foo bar].
923 call MouseLeftClick(1, 5)
924 call assert_equal(0, getcharmod(), msg)
925 call MouseLeftRelease(1, 5)
926 call MouseLeftClick(1, 5)
927 call assert_equal(32, getcharmod(), msg) " double-click
928 call MouseLeftRelease(1, 5)
929 call assert_equal('v', mode(), msg)
930 norm! r2
931 call assert_equal(['111 222222222 foo', 'foo'], getline(1, '$'), msg)
932
933 " Triple-click should visually select the whole line.
934 call MouseLeftClick(1, 3)
935 call assert_equal(0, getcharmod(), msg)
936 call MouseLeftRelease(1, 3)
937 call MouseLeftClick(1, 3)
938 call assert_equal(32, getcharmod(), msg) " double-click
939 call MouseLeftRelease(1, 3)
940 call MouseLeftClick(1, 3)
941 call assert_equal(64, getcharmod(), msg) " triple-click
942 call MouseLeftRelease(1, 3)
943 call assert_equal('V', mode(), msg)
944 norm! r3
945 call assert_equal(['33333333333333333', 'foo'], getline(1, '$'), msg)
946
947 " Quadruple-click should start visual block select.
948 call MouseLeftClick(1, 2)
949 call assert_equal(0, getcharmod(), msg)
950 call MouseLeftRelease(1, 2)
951 call MouseLeftClick(1, 2)
952 call assert_equal(32, getcharmod(), msg) " double-click
953 call MouseLeftRelease(1, 2)
954 call MouseLeftClick(1, 2)
955 call assert_equal(64, getcharmod(), msg) " triple-click
956 call MouseLeftRelease(1, 2)
957 call MouseLeftClick(1, 2)
958 call assert_equal(96, getcharmod(), msg) " quadruple-click
959 call MouseLeftRelease(1, 2)
960 call assert_equal("\<c-v>", mode(), msg)
961 norm! r4
962 call assert_equal(['34333333333333333', 'foo'], getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200963
964 " Double-click on a space character should visually select all the
965 " consecutive space characters.
966 %d
967 call setline(1, ' one two')
968 call MouseLeftClick(1, 2)
969 call MouseLeftRelease(1, 2)
970 call MouseLeftClick(1, 2)
971 call MouseLeftRelease(1, 2)
972 call assert_equal('v', mode(), msg)
973 norm! r1
974 call assert_equal(['1111one two'], getline(1, '$'), msg)
975
976 " Double-click on a word with exclusive selection
977 set selection=exclusive
978 let @" = ''
979 call MouseLeftClick(1, 10)
980 call MouseLeftRelease(1, 10)
981 call MouseLeftClick(1, 10)
982 call MouseLeftRelease(1, 10)
983 norm! y
984 call assert_equal('two', @", msg)
985
986 " Double click to select a block of text with exclusive selection
987 %d
988 call setline(1, 'one (two) three')
989 call MouseLeftClick(1, 5)
990 call MouseLeftRelease(1, 5)
991 call MouseLeftClick(1, 5)
992 call MouseLeftRelease(1, 5)
993 norm! y
994 call assert_equal(5, col("'<"), msg)
995 call assert_equal(10, col("'>"), msg)
996
997 call MouseLeftClick(1, 9)
998 call MouseLeftRelease(1, 9)
999 call MouseLeftClick(1, 9)
1000 call MouseLeftRelease(1, 9)
1001 norm! y
1002 call assert_equal(5, col("'<"), msg)
1003 call assert_equal(10, col("'>"), msg)
1004 set selection&
1005
1006 " Click somewhere else so that the clicks above is not combined with the
1007 " clicks in the next iteration.
1008 call MouseRightClick(3, 10)
1009 call MouseRightRelease(3, 10)
Bram Moolenaarf36a2c72019-11-16 18:57:16 +01001010 endfor
1011
1012 let &mouse = save_mouse
1013 let &term = save_term
1014 let &ttymouse = save_ttymouse
1015 set mousetime&
1016 call test_override('no_query_mouse', 0)
1017 bwipe!
1018endfunc
1019
Bram Moolenaar2764d062020-07-18 12:59:19 +02001020" Test for selecting text in visual blockwise mode using Alt-LeftClick
1021func Test_mouse_alt_leftclick()
1022 let save_mouse = &mouse
1023 let save_term = &term
1024 let save_ttymouse = &ttymouse
1025 call test_override('no_query_mouse', 1)
1026 set mouse=a term=xterm mousetime=200
1027 set mousemodel=popup
Bram Moolenaarc255b782022-11-26 19:16:48 +00001028 call WaitForResponses()
1029
Bram Moolenaar2764d062020-07-18 12:59:19 +02001030 new
1031 call setline(1, 'one (two) three')
1032
1033 for ttymouse_val in g:Ttymouse_values
1034 let msg = 'ttymouse=' .. ttymouse_val
1035 exe 'set ttymouse=' .. ttymouse_val
1036
1037 " Left click with the Alt modifier key should extend the selection in
1038 " blockwise visual mode.
1039 let @" = ''
1040 call MouseLeftClick(1, 3)
1041 call MouseLeftRelease(1, 3)
1042 call MouseAltLeftClick(1, 11)
1043 call MouseLeftRelease(1, 11)
1044 call assert_equal("\<C-V>", mode(), msg)
1045 normal! y
1046 call assert_equal('e (two) t', @")
1047 endfor
1048
1049 let &mouse = save_mouse
1050 let &term = save_term
1051 let &ttymouse = save_ttymouse
1052 set mousetime& mousemodel&
1053 call test_override('no_query_mouse', 0)
1054 close!
1055endfunc
1056
Bram Moolenaar696d6372019-04-17 16:33:46 +02001057func Test_xterm_mouse_click_in_fold_columns()
1058 new
1059 let save_mouse = &mouse
1060 let save_term = &term
1061 let save_ttymouse = &ttymouse
1062 let save_foldcolumn = &foldcolumn
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +02001063 set mouse=a term=xterm foldcolumn=3 ttymouse=xterm2
Bram Moolenaarc255b782022-11-26 19:16:48 +00001064 call WaitForResponses()
Bram Moolenaar696d6372019-04-17 16:33:46 +02001065
1066 " Create 2 nested folds.
1067 call setline(1, range(1, 7))
1068 2,6fold
1069 norm! zR
1070 4,5fold
1071 call assert_equal([-1, -1, -1, 4, 4, -1, -1],
1072 \ map(range(1, 7), 'foldclosed(v:val)'))
1073
1074 " Click in "+" of inner fold in foldcolumn should open it.
1075 redraw
1076 let row = 4
1077 let col = 2
1078 call MouseLeftClick(row, col)
1079 call MouseLeftRelease(row, col)
1080 call assert_equal([-1, -1, -1, -1, -1, -1, -1],
1081 \ map(range(1, 7), 'foldclosed(v:val)'))
1082
1083 " Click in "-" of outer fold in foldcolumn should close it.
1084 redraw
1085 let row = 2
1086 let col = 1
1087 call MouseLeftClick(row, col)
1088 call MouseLeftRelease(row, col)
1089 call assert_equal([-1, 2, 2, 2, 2, 2, -1],
1090 \ map(range(1, 7), 'foldclosed(v:val)'))
1091 norm! zR
1092
1093 " Click in "|" of inner fold in foldcolumn should close it.
1094 redraw
1095 let row = 5
1096 let col = 2
1097 call MouseLeftClick(row, col)
1098 call MouseLeftRelease(row, col)
1099 call assert_equal([-1, -1, -1, 4, 4, -1, -1],
1100 \ map(range(1, 7), 'foldclosed(v:val)'))
1101
1102 let &foldcolumn = save_foldcolumn
1103 let &ttymouse = save_ttymouse
1104 let &term = save_term
1105 let &mouse = save_mouse
1106 bwipe!
1107endfunc
Bram Moolenaar66761db2019-06-05 22:07:51 +02001108
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001109" Left or right click in Ex command line sets position of the cursor.
1110func Test_term_mouse_click_in_cmdline_to_set_pos()
1111 let save_mouse = &mouse
1112 let save_term = &term
1113 let save_ttymouse = &ttymouse
1114 call test_override('no_query_mouse', 1)
1115 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +00001116 call WaitForResponses()
1117
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001118 let row = &lines
1119
Bram Moolenaar515545e2020-03-22 14:08:59 +01001120 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarab505b12020-03-23 19:28:44 +01001121 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
1122 if ttymouse_val !=# 'xterm2' || row <= 223
1123 let msg = 'ttymouse=' .. ttymouse_val
1124 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001125
Bram Moolenaarab505b12020-03-23 19:28:44 +01001126
1127 call feedkeys(':"3456789'
1128 \ .. MouseLeftClickCode(row, 7)
1129 \ .. MouseLeftReleaseCode(row, 7) .. 'L'
1130 \ .. MouseRightClickCode(row, 4)
1131 \ .. MouseRightReleaseCode(row, 4) .. 'R'
1132 \ .. "\<CR>", 'Lx!')
1133 call assert_equal('"3R456L789', @:, msg)
1134 endif
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001135 endfor
1136
1137 let &mouse = save_mouse
1138 let &term = save_term
1139 let &ttymouse = save_ttymouse
1140 set mousetime&
1141 call test_override('no_query_mouse', 0)
1142endfunc
1143
1144" Middle click in command line pastes at position of cursor.
1145func Test_term_mouse_middle_click_in_cmdline_to_paste()
1146 CheckFeature clipboard_working
1147 let save_mouse = &mouse
1148 let save_term = &term
1149 let save_ttymouse = &ttymouse
1150 call test_override('no_query_mouse', 1)
1151 set mouse=a term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +00001152 call WaitForResponses()
1153
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001154 let row = &lines
1155 " Column values does not matter, paste is done at position of cursor.
1156 let col = 1
1157 let @* = 'paste'
1158
Bram Moolenaar515545e2020-03-22 14:08:59 +01001159 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001160 let msg = 'ttymouse=' .. ttymouse_val
1161 exe 'set ttymouse=' .. ttymouse_val
1162
1163 call feedkeys(":\"->"
1164 \ .. MouseMiddleReleaseCode(row, col)
1165 \ .. MouseMiddleClickCode(row, col)
1166 \ .. "<-"
1167 \ .. MouseMiddleReleaseCode(row, col)
1168 \ .. MouseMiddleClickCode(row, col)
1169 \ .. "\<CR>", 'Lx!')
1170 call assert_equal('"->paste<-paste', @:, msg)
1171 endfor
1172
1173 let &mouse = save_mouse
1174 let &term = save_term
1175 let &ttymouse = save_ttymouse
1176 let @* = ''
1177 call test_override('no_query_mouse', 0)
1178endfunc
1179
Bram Moolenaar297bec02020-07-14 22:11:04 +02001180" Test for making sure S-Middlemouse doesn't do anything
1181func Test_term_mouse_shift_middle_click()
1182 new
1183 let save_mouse = &mouse
1184 let save_term = &term
1185 let save_ttymouse = &ttymouse
1186 call test_override('no_query_mouse', 1)
1187 set mouse=a term=xterm ttymouse=xterm2 mousemodel=
Bram Moolenaarc255b782022-11-26 19:16:48 +00001188 call WaitForResponses()
Bram Moolenaar297bec02020-07-14 22:11:04 +02001189
1190 call test_setmouse(1, 1)
1191 exe "normal \<S-MiddleMouse>"
1192 call assert_equal([''], getline(1, '$'))
1193 call assert_equal(1, winnr())
1194
1195 let &mouse = save_mouse
1196 let &term = save_term
1197 let &ttymouse = save_ttymouse
1198 set mousemodel&
1199 call test_override('no_query_mouse', 0)
1200 close!
1201endfunc
1202
1203" Test for using mouse in visual mode
1204func Test_term_mouse_visual_mode()
1205 new
1206 let save_mouse = &mouse
1207 let save_term = &term
1208 let save_ttymouse = &ttymouse
1209 call test_override('no_query_mouse', 1)
1210 set term=xterm ttymouse=xterm2
Bram Moolenaarc255b782022-11-26 19:16:48 +00001211 call WaitForResponses()
Bram Moolenaar297bec02020-07-14 22:11:04 +02001212
1213 " If visual mode is not present in 'mouse', then left click should not
1214 " do anything in visal mode.
1215 call setline(1, ['one two three four'])
1216 set mouse=nci
1217 call cursor(1, 5)
1218 let @" = ''
1219 call feedkeys("ve"
1220 \ .. MouseLeftClickCode(1, 15) .. MouseLeftReleaseCode(1, 15)
1221 \ .. 'y', 'Lx!')
1222 call assert_equal(5, col('.'))
1223 call assert_equal('two', @")
1224
1225 " Pressing right click in visual mode should change the visual selection
1226 " if 'mousemodel' doesn't contain popup.
1227 " Right click after the visual selection
1228 set mousemodel=
1229 set mouse=a
1230 call test_setmouse(1, 13)
1231 exe "normal 5|ve\<RightMouse>y"
1232 call assert_equal('two three', @")
1233 call assert_equal(5, col('.'))
1234
1235 " Right click before the visual selection
1236 call test_setmouse(1, 9)
1237 exe "normal 15|ve\<RightMouse>y"
1238 call assert_equal('three four', @")
1239 call assert_equal(9, col('.'))
1240
Bram Moolenaar2764d062020-07-18 12:59:19 +02001241 " Right click inside the selection closer to the start of the selection
1242 call test_setmouse(1, 7)
1243 exe "normal 5|vee\<RightMouse>lly"
1244 call assert_equal('three', @")
1245 call assert_equal(9, col('.'))
1246 call assert_equal(9, col("'<"))
1247 call assert_equal(13, col("'>"))
1248
1249 " Right click inside the selection closer to the end of the selection
1250 call test_setmouse(1, 11)
1251 exe "normal 5|vee\<RightMouse>ly"
1252 call assert_equal('two thre', @")
1253 call assert_equal(5, col('.'))
1254 call assert_equal(5, col("'<"))
1255 call assert_equal(12, col("'>"))
1256
dundargocc57b5bc2022-11-02 13:30:51 +00001257 " Multi-line selection. Right click inside the selection.
Bram Moolenaar2764d062020-07-18 12:59:19 +02001258 call setline(1, repeat(['aaaaaa'], 7))
Bram Moolenaar297bec02020-07-14 22:11:04 +02001259 call test_setmouse(3, 1)
1260 exe "normal ggVG\<RightMouse>y"
1261 call assert_equal(3, line("'<"))
Bram Moolenaar2764d062020-07-18 12:59:19 +02001262 call test_setmouse(5, 1)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001263 exe "normal ggVG\<RightMouse>y"
Bram Moolenaar2764d062020-07-18 12:59:19 +02001264 call assert_equal(5, line("'>"))
1265
1266 " Click right in the middle line of the selection
1267 call test_setmouse(4, 3)
1268 exe "normal ggVG$\<RightMouse>y"
1269 call assert_equal(4, line("'<"))
1270 call test_setmouse(4, 4)
1271 exe "normal ggVG$\<RightMouse>y"
Bram Moolenaar297bec02020-07-14 22:11:04 +02001272 call assert_equal(4, line("'>"))
1273
1274 set mousemodel&
1275 let &mouse = save_mouse
1276 let &term = save_term
1277 let &ttymouse = save_ttymouse
1278 call test_override('no_query_mouse', 0)
1279 close!
1280endfunc
1281
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001282" Test for displaying the popup menu using the right mouse click
Bram Moolenaar297bec02020-07-14 22:11:04 +02001283func Test_term_mouse_popup_menu()
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001284 CheckFeature menu
1285 new
1286 call setline(1, 'popup menu test')
1287 let save_mouse = &mouse
1288 let save_term = &term
1289 let save_ttymouse = &ttymouse
1290 let save_mousemodel = &mousemodel
1291 call test_override('no_query_mouse', 1)
1292 set mouse=a term=xterm mousemodel=popup
Bram Moolenaarc255b782022-11-26 19:16:48 +00001293 call WaitForResponses()
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001294
1295 menu PopUp.foo :let g:menustr = 'foo'<CR>
1296 menu PopUp.bar :let g:menustr = 'bar'<CR>
1297 menu PopUp.baz :let g:menustr = 'baz'<CR>
1298
Bram Moolenaar515545e2020-03-22 14:08:59 +01001299 for ttymouse_val in g:Ttymouse_values
Bram Moolenaar2764d062020-07-18 12:59:19 +02001300 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001301 exe 'set ttymouse=' .. ttymouse_val
1302 let g:menustr = ''
1303 call feedkeys(MouseRightClickCode(1, 4)
1304 \ .. MouseRightReleaseCode(1, 4) .. "\<Down>\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001305 call assert_equal('bar', g:menustr, msg)
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001306 endfor
1307
1308 unmenu PopUp
1309 let &mouse = save_mouse
1310 let &term = save_term
1311 let &ttymouse = save_ttymouse
1312 let &mousemodel = save_mousemodel
1313 call test_override('no_query_mouse', 0)
1314 close!
1315endfunc
1316
Bram Moolenaar297bec02020-07-14 22:11:04 +02001317" Test for 'mousemodel' set to popup_setpos to move the cursor where the popup
1318" menu is displayed.
1319func Test_term_mouse_popup_menu_setpos()
1320 CheckFeature menu
1321 5new
1322 call setline(1, ['the dish ran away with the spoon',
1323 \ 'the cow jumped over the moon' ])
1324 let save_mouse = &mouse
1325 let save_term = &term
1326 let save_ttymouse = &ttymouse
1327 let save_mousemodel = &mousemodel
1328 call test_override('no_query_mouse', 1)
1329 set mouse=a term=xterm mousemodel=popup_setpos
Bram Moolenaarc255b782022-11-26 19:16:48 +00001330 call WaitForResponses()
Bram Moolenaar297bec02020-07-14 22:11:04 +02001331
1332 nmenu PopUp.foo :let g:menustr = 'foo'<CR>
1333 nmenu PopUp.bar :let g:menustr = 'bar'<CR>
1334 nmenu PopUp.baz :let g:menustr = 'baz'<CR>
1335 vmenu PopUp.foo y:<C-U>let g:menustr = 'foo'<CR>
1336 vmenu PopUp.bar y:<C-U>let g:menustr = 'bar'<CR>
1337 vmenu PopUp.baz y:<C-U>let g:menustr = 'baz'<CR>
1338
1339 for ttymouse_val in g:Ttymouse_values
Bram Moolenaar2764d062020-07-18 12:59:19 +02001340 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar297bec02020-07-14 22:11:04 +02001341 exe 'set ttymouse=' .. ttymouse_val
1342 let g:menustr = ''
1343 call cursor(1, 1)
1344 call feedkeys(MouseRightClickCode(1, 5)
1345 \ .. MouseRightReleaseCode(1, 5) .. "\<Down>\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001346 call assert_equal('bar', g:menustr, msg)
1347 call assert_equal([1, 5], [line('.'), col('.')], msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001348
1349 " Test for right click in visual mode inside the selection
1350 let @" = ''
1351 call cursor(1, 10)
1352 call feedkeys('vee' .. MouseRightClickCode(1, 12)
1353 \ .. MouseRightReleaseCode(1, 12) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001354 call assert_equal([1, 10], [line('.'), col('.')], msg)
1355 call assert_equal('ran away', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001356
Yee Cheng Chin17822c52022-10-13 13:17:40 +01001357 " Test for right click in visual mode right before the selection
Bram Moolenaar297bec02020-07-14 22:11:04 +02001358 let @" = ''
1359 call cursor(1, 10)
Yee Cheng Chin17822c52022-10-13 13:17:40 +01001360 call feedkeys('vee' .. MouseRightClickCode(1, 9)
1361 \ .. MouseRightReleaseCode(1, 9) .. "\<Down>\<CR>", "x")
1362 call assert_equal([1, 9], [line('.'), col('.')], msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +02001363 call assert_equal('', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001364
Yee Cheng Chin17822c52022-10-13 13:17:40 +01001365 " Test for right click in visual mode right after the selection
Bram Moolenaar297bec02020-07-14 22:11:04 +02001366 let @" = ''
1367 call cursor(1, 10)
Yee Cheng Chin17822c52022-10-13 13:17:40 +01001368 call feedkeys('vee' .. MouseRightClickCode(1, 18)
1369 \ .. MouseRightReleaseCode(1, 18) .. "\<Down>\<CR>", "x")
1370 call assert_equal([1, 18], [line('.'), col('.')], msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +02001371 call assert_equal('', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001372
1373 " Test for right click in block-wise visual mode inside the selection
1374 let @" = ''
1375 call cursor(1, 16)
1376 call feedkeys("\<C-V>j3l" .. MouseRightClickCode(2, 17)
1377 \ .. MouseRightReleaseCode(2, 17) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001378 call assert_equal([1, 16], [line('.'), col('.')], msg)
1379 call assert_equal("\<C-V>4", getregtype('"'), msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001380
1381 " Test for right click in block-wise visual mode outside the selection
1382 let @" = ''
1383 call cursor(1, 16)
1384 call feedkeys("\<C-V>j3l" .. MouseRightClickCode(2, 2)
1385 \ .. MouseRightReleaseCode(2, 2) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001386 call assert_equal([2, 2], [line('.'), col('.')], msg)
1387 call assert_equal('v', getregtype('"'), msg)
1388 call assert_equal('', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001389
Yee Cheng Chin17822c52022-10-13 13:17:40 +01001390 " Test for right click in line-wise visual mode inside the selection
1391 let @" = ''
1392 call cursor(1, 16)
1393 call feedkeys("V" .. MouseRightClickCode(1, 10)
1394 \ .. MouseRightReleaseCode(1, 10) .. "\<Down>\<CR>", "x")
1395 call assert_equal([1, 1], [line('.'), col('.')], msg) " After yanking, the cursor goes to 1,1
1396 call assert_equal("V", getregtype('"'), msg)
zeertzjqdf63f052022-10-19 15:12:54 +01001397 call assert_equal(1, len(getreg('"', 1, v:true)), msg)
Yee Cheng Chin17822c52022-10-13 13:17:40 +01001398
1399 " Test for right click in multi-line line-wise visual mode inside the selection
1400 let @" = ''
1401 call cursor(1, 16)
1402 call feedkeys("Vj" .. MouseRightClickCode(2, 20)
1403 \ .. MouseRightReleaseCode(2, 20) .. "\<Down>\<CR>", "x")
1404 call assert_equal([1, 1], [line('.'), col('.')], msg) " After yanking, the cursor goes to 1,1
1405 call assert_equal("V", getregtype('"'), msg)
zeertzjqdf63f052022-10-19 15:12:54 +01001406 call assert_equal(2, len(getreg('"', 1, v:true)), msg)
Yee Cheng Chin17822c52022-10-13 13:17:40 +01001407
1408 " Test for right click in line-wise visual mode outside the selection
1409 let @" = ''
1410 call cursor(1, 16)
1411 call feedkeys("V" .. MouseRightClickCode(2, 10)
1412 \ .. MouseRightReleaseCode(2, 10) .. "\<Down>\<CR>", "x")
1413 call assert_equal([2, 10], [line('.'), col('.')], msg)
1414 call assert_equal("", @", msg)
1415
Bram Moolenaar297bec02020-07-14 22:11:04 +02001416 " Try clicking on the status line
1417 let @" = ''
1418 call cursor(1, 10)
1419 call feedkeys('vee' .. MouseRightClickCode(6, 2)
1420 \ .. MouseRightReleaseCode(6, 2) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001421 call assert_equal([1, 10], [line('.'), col('.')], msg)
1422 call assert_equal('ran away', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001423
1424 " Try clicking outside the window
1425 let @" = ''
zeertzjqdf63f052022-10-19 15:12:54 +01001426 call cursor(2, 2)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001427 call feedkeys('vee' .. MouseRightClickCode(7, 2)
1428 \ .. MouseRightReleaseCode(7, 2) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001429 call assert_equal(2, winnr(), msg)
1430 call assert_equal('', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001431 wincmd w
1432 endfor
1433
1434 unmenu PopUp
1435 let &mouse = save_mouse
1436 let &term = save_term
1437 let &ttymouse = save_ttymouse
1438 let &mousemodel = save_mousemodel
1439 call test_override('no_query_mouse', 0)
1440 close!
1441endfunc
1442
1443" Test for searching for the word under the cursor using Shift-Right or
1444" Shift-Left click.
1445func Test_term_mouse_search()
1446 new
1447 let save_mouse = &mouse
1448 let save_term = &term
1449 let save_ttymouse = &ttymouse
1450 call test_override('no_query_mouse', 1)
1451 set mouse=a term=xterm ttymouse=xterm2
1452 set mousemodel=
Bram Moolenaarc255b782022-11-26 19:16:48 +00001453 call WaitForResponses()
Bram Moolenaar297bec02020-07-14 22:11:04 +02001454
1455 " In normal mode, Shift-Left or Shift-Right click should search for the word
1456 " under the cursor.
1457 call setline(1, ['one two three four', 'four three two one'])
1458 call test_setmouse(1, 4)
1459 exe "normal \<S-LeftMouse>"
1460 call assert_equal([2, 12], [line('.'), col('.')])
1461 call test_setmouse(2, 16)
1462 exe "normal \<S-RightMouse>"
1463 call assert_equal([1, 1], [line('.'), col('.')])
1464
1465 " In visual mode, Shift-Left or Shift-Right click should search for the word
1466 " under the cursor and extend the selection.
1467 call test_setmouse(1, 4)
1468 exe "normal 4|ve\<S-LeftMouse>y"
1469 call assert_equal([2, 12], [line("'>"), col("'>")])
1470 call test_setmouse(2, 16)
1471 exe "normal 2G16|ve\<S-RightMouse>y"
1472 call assert_equal([1, 1], [line("'<"), col("'<")])
1473
1474 set mousemodel&
1475 let &mouse = save_mouse
1476 let &term = save_term
1477 let &ttymouse = save_ttymouse
1478 call test_override('no_query_mouse', 0)
1479 close!
1480endfunc
1481
1482" Test for selecting an entry in the quickfix/location list window using the
1483" mouse.
1484func Test_term_mouse_quickfix_window()
1485 let save_mouse = &mouse
1486 let save_term = &term
1487 let save_ttymouse = &ttymouse
1488 call test_override('no_query_mouse', 1)
1489 set mouse=a term=xterm ttymouse=xterm2
1490 set mousemodel=
Bram Moolenaarc255b782022-11-26 19:16:48 +00001491 call WaitForResponses()
Bram Moolenaar297bec02020-07-14 22:11:04 +02001492
1493 cgetexpr "Xfile1:1:L1"
1494 copen 5
1495 call test_setmouse(&lines - 7, 1)
1496 exe "normal \<2-LeftMouse>"
1497 call assert_equal('Xfile1', @%)
1498 %bw!
1499
1500 lgetexpr "Xfile2:1:L1"
1501 lopen 5
1502 call test_setmouse(&lines - 7, 1)
1503 exe "normal \<2-LeftMouse>"
1504 call assert_equal('Xfile2', @%)
1505 %bw!
1506
1507 set mousemodel&
1508 let &mouse = save_mouse
1509 let &term = save_term
1510 let &ttymouse = save_ttymouse
1511 call test_override('no_query_mouse', 0)
1512endfunc
1513
Bram Moolenaar2764d062020-07-18 12:59:19 +02001514" Test for the 'h' flag in the 'mouse' option. Using mouse in the help window.
1515func Test_term_mouse_help_window()
1516 let save_mouse = &mouse
1517 let save_term = &term
1518 let save_ttymouse = &ttymouse
1519 call test_override('no_query_mouse', 1)
1520 set mouse=h term=xterm mousetime=200
Bram Moolenaarc255b782022-11-26 19:16:48 +00001521 call WaitForResponses()
Bram Moolenaar2764d062020-07-18 12:59:19 +02001522
1523 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
1524 let msg = 'ttymouse=' .. ttymouse_val
1525 exe 'set ttymouse=' .. ttymouse_val
1526 help
1527 let @" = ''
1528 call MouseLeftClick(2, 5)
1529 call MouseLeftRelease(2, 5)
1530 call MouseLeftClick(1, 1)
1531 call MouseLeftDrag(1, 10)
1532 call MouseLeftRelease(1, 10)
1533 norm! y
1534 call assert_equal('*help.txt*', @", msg)
1535 helpclose
1536
1537 " Click somewhere else to make sure the left click above is not combined
1538 " with the next left click and treated as a double click
1539 call MouseRightClick(5, 10)
1540 call MouseRightRelease(5, 10)
1541 endfor
1542
1543 let &mouse = save_mouse
1544 let &term = save_term
1545 let &ttymouse = save_ttymouse
1546 set mousetime&
1547 call test_override('no_query_mouse', 0)
1548 %bw!
1549endfunc
1550
1551" Test for the translation of various mouse terminal codes
1552func Test_mouse_termcodes()
1553 let save_mouse = &mouse
1554 let save_term = &term
1555 let save_ttymouse = &ttymouse
1556 call test_override('no_query_mouse', 1)
1557 set mouse=a term=xterm mousetime=200
Bram Moolenaarc255b782022-11-26 19:16:48 +00001558 call WaitForResponses()
Bram Moolenaar2764d062020-07-18 12:59:19 +02001559
1560 new
1561 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
1562 let msg = 'ttymouse=' .. ttymouse_val
1563 exe 'set ttymouse=' .. ttymouse_val
1564
1565 let mouse_codes = [
1566 \ ["\<LeftMouse>", "<LeftMouse>"],
1567 \ ["\<MiddleMouse>", "<MiddleMouse>"],
1568 \ ["\<RightMouse>", "<RightMouse>"],
1569 \ ["\<S-LeftMouse>", "<S-LeftMouse>"],
1570 \ ["\<S-MiddleMouse>", "<S-MiddleMouse>"],
1571 \ ["\<S-RightMouse>", "<S-RightMouse>"],
1572 \ ["\<C-LeftMouse>", "<C-LeftMouse>"],
1573 \ ["\<C-MiddleMouse>", "<C-MiddleMouse>"],
1574 \ ["\<C-RightMouse>", "<C-RightMouse>"],
1575 \ ["\<M-LeftMouse>", "<M-LeftMouse>"],
1576 \ ["\<M-MiddleMouse>", "<M-MiddleMouse>"],
1577 \ ["\<M-RightMouse>", "<M-RightMouse>"],
1578 \ ["\<2-LeftMouse>", "<2-LeftMouse>"],
1579 \ ["\<2-MiddleMouse>", "<2-MiddleMouse>"],
1580 \ ["\<2-RightMouse>", "<2-RightMouse>"],
1581 \ ["\<3-LeftMouse>", "<3-LeftMouse>"],
1582 \ ["\<3-MiddleMouse>", "<3-MiddleMouse>"],
1583 \ ["\<3-RightMouse>", "<3-RightMouse>"],
1584 \ ["\<4-LeftMouse>", "<4-LeftMouse>"],
1585 \ ["\<4-MiddleMouse>", "<4-MiddleMouse>"],
1586 \ ["\<4-RightMouse>", "<4-RightMouse>"],
1587 \ ["\<LeftDrag>", "<LeftDrag>"],
1588 \ ["\<MiddleDrag>", "<MiddleDrag>"],
1589 \ ["\<RightDrag>", "<RightDrag>"],
1590 \ ["\<LeftRelease>", "<LeftRelease>"],
1591 \ ["\<MiddleRelease>", "<MiddleRelease>"],
1592 \ ["\<RightRelease>", "<RightRelease>"],
1593 \ ["\<ScrollWheelUp>", "<ScrollWheelUp>"],
1594 \ ["\<S-ScrollWheelUp>", "<S-ScrollWheelUp>"],
1595 \ ["\<C-ScrollWheelUp>", "<C-ScrollWheelUp>"],
1596 \ ["\<ScrollWheelDown>", "<ScrollWheelDown>"],
1597 \ ["\<S-ScrollWheelDown>", "<S-ScrollWheelDown>"],
1598 \ ["\<C-ScrollWheelDown>", "<C-ScrollWheelDown>"],
1599 \ ["\<ScrollWheelLeft>", "<ScrollWheelLeft>"],
1600 \ ["\<S-ScrollWheelLeft>", "<S-ScrollWheelLeft>"],
1601 \ ["\<C-ScrollWheelLeft>", "<C-ScrollWheelLeft>"],
1602 \ ["\<ScrollWheelRight>", "<ScrollWheelRight>"],
1603 \ ["\<S-ScrollWheelRight>", "<S-ScrollWheelRight>"],
1604 \ ["\<C-ScrollWheelRight>", "<C-ScrollWheelRight>"]
1605 \ ]
1606
1607 for [code, outstr] in mouse_codes
1608 exe "normal ggC\<C-K>" . code
1609 call assert_equal(outstr, getline(1), msg)
1610 endfor
1611 endfor
1612
1613 let &mouse = save_mouse
1614 let &term = save_term
1615 let &ttymouse = save_ttymouse
1616 set mousetime&
1617 call test_override('no_query_mouse', 0)
1618 %bw!
1619endfunc
1620
Bram Moolenaar66761db2019-06-05 22:07:51 +02001621" This only checks if the sequence is recognized.
Bram Moolenaar66761db2019-06-05 22:07:51 +02001622func Test_term_rgb_response()
1623 set t_RF=x
1624 set t_RB=y
1625
1626 " response to t_RF, 4 digits
1627 let red = 0x12
1628 let green = 0x34
1629 let blue = 0x56
1630 let seq = printf("\<Esc>]10;rgb:%02x00/%02x00/%02x00\x07", red, green, blue)
1631 call feedkeys(seq, 'Lx!')
1632 call assert_equal(seq, v:termrfgresp)
1633
1634 " response to t_RF, 2 digits
1635 let red = 0x78
1636 let green = 0x9a
1637 let blue = 0xbc
1638 let seq = printf("\<Esc>]10;rgb:%02x/%02x/%02x\x07", red, green, blue)
1639 call feedkeys(seq, 'Lx!')
1640 call assert_equal(seq, v:termrfgresp)
1641
Bram Moolenaar32e19772019-06-05 22:57:04 +02001642 " response to t_RB, 4 digits, dark
1643 set background=light
Bram Moolenaarce90e362019-09-08 18:58:44 +02001644 eval 'background'->test_option_not_set()
Bram Moolenaar32e19772019-06-05 22:57:04 +02001645 let red = 0x29
1646 let green = 0x4a
1647 let blue = 0x6b
1648 let seq = printf("\<Esc>]11;rgb:%02x00/%02x00/%02x00\x07", red, green, blue)
1649 call feedkeys(seq, 'Lx!')
1650 call assert_equal(seq, v:termrbgresp)
1651 call assert_equal('dark', &background)
1652
1653 " response to t_RB, 4 digits, light
1654 set background=dark
1655 call test_option_not_set('background')
1656 let red = 0x81
1657 let green = 0x63
Bram Moolenaar66761db2019-06-05 22:07:51 +02001658 let blue = 0x65
1659 let seq = printf("\<Esc>]11;rgb:%02x00/%02x00/%02x00\x07", red, green, blue)
1660 call feedkeys(seq, 'Lx!')
1661 call assert_equal(seq, v:termrbgresp)
Bram Moolenaar32e19772019-06-05 22:57:04 +02001662 call assert_equal('light', &background)
Bram Moolenaar66761db2019-06-05 22:07:51 +02001663
Bram Moolenaar32e19772019-06-05 22:57:04 +02001664 " response to t_RB, 2 digits, dark
1665 set background=light
1666 call test_option_not_set('background')
1667 let red = 0x47
1668 let green = 0x59
1669 let blue = 0x5b
Bram Moolenaar66761db2019-06-05 22:07:51 +02001670 let seq = printf("\<Esc>]11;rgb:%02x/%02x/%02x\x07", red, green, blue)
1671 call feedkeys(seq, 'Lx!')
1672 call assert_equal(seq, v:termrbgresp)
Bram Moolenaar32e19772019-06-05 22:57:04 +02001673 call assert_equal('dark', &background)
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001674
Bram Moolenaar32e19772019-06-05 22:57:04 +02001675 " response to t_RB, 2 digits, light
1676 set background=dark
1677 call test_option_not_set('background')
1678 let red = 0x83
1679 let green = 0xa4
1680 let blue = 0xc2
1681 let seq = printf("\<Esc>]11;rgb:%02x/%02x/%02x\x07", red, green, blue)
1682 call feedkeys(seq, 'Lx!')
1683 call assert_equal(seq, v:termrbgresp)
1684 call assert_equal('light', &background)
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001685
Bram Moolenaar66761db2019-06-05 22:07:51 +02001686 set t_RF= t_RB=
1687endfunc
1688
1689" This only checks if the sequence is recognized.
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001690" This must be after other tests, because it has side effects to xterm
1691" properties.
1692func Test_xx01_term_style_response()
Bram Moolenaar66761db2019-06-05 22:07:51 +02001693 " Termresponse is only parsed when t_RV is not empty.
1694 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001695 call test_override('term_props', 1)
Bram Moolenaar66761db2019-06-05 22:07:51 +02001696
1697 " send the termresponse to trigger requesting the XT codes
1698 let seq = "\<Esc>[>41;337;0c"
1699 call feedkeys(seq, 'Lx!')
1700 call assert_equal(seq, v:termresponse)
1701
1702 let seq = "\<Esc>P1$r2 q\<Esc>\\"
1703 call feedkeys(seq, 'Lx!')
1704 call assert_equal(seq, v:termstyleresp)
1705
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001706 call assert_equal(#{
1707 \ cursor_style: 'u',
1708 \ cursor_blink_mode: 'u',
1709 \ underline_rgb: 'u',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001710 \ mouse: 's',
1711 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001712 \ }, terminalprops())
1713
Bram Moolenaar66761db2019-06-05 22:07:51 +02001714 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001715 call test_override('term_props', 0)
Bram Moolenaar66761db2019-06-05 22:07:51 +02001716endfunc
Bram Moolenaarde6dbb42019-06-06 11:59:18 +02001717
Bram Moolenaar89577b32019-10-18 21:26:05 +02001718" This checks the iTerm2 version response.
1719" This must be after other tests, because it has side effects to xterm
1720" properties.
1721func Test_xx02_iTerm2_response()
1722 " Termresponse is only parsed when t_RV is not empty.
1723 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001724 call test_override('term_props', 1)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001725
1726 " Old versions of iTerm2 used a different style term response.
1727 set ttymouse=xterm
1728 call test_option_not_set('ttymouse')
1729 let seq = "\<Esc>[>0;95;c"
1730 call feedkeys(seq, 'Lx!')
1731 call assert_equal(seq, v:termresponse)
1732 call assert_equal('xterm', &ttymouse)
1733
1734 set ttymouse=xterm
1735 call test_option_not_set('ttymouse')
1736 let seq = "\<Esc>[>0;95;0c"
1737 call feedkeys(seq, 'Lx!')
1738 call assert_equal(seq, v:termresponse)
1739 call assert_equal('sgr', &ttymouse)
1740
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001741 call assert_equal(#{
1742 \ cursor_style: 'n',
1743 \ cursor_blink_mode: 'u',
1744 \ underline_rgb: 'u',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001745 \ mouse: 's',
1746 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001747 \ }, terminalprops())
1748
Bram Moolenaar89577b32019-10-18 21:26:05 +02001749 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001750 call test_override('term_props', 0)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001751endfunc
1752
Bram Moolenaard55f9ef2022-08-26 12:26:07 +01001753func Run_libvterm_konsole_response(code)
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001754 set ttymouse=xterm
1755 call test_option_not_set('ttymouse')
Bram Moolenaard55f9ef2022-08-26 12:26:07 +01001756 let seq = "\<Esc>[>0;" .. a:code .. ";0c"
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001757 call feedkeys(seq, 'Lx!')
1758 call assert_equal(seq, v:termresponse)
1759 call assert_equal('sgr', &ttymouse)
1760
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001761 call assert_equal(#{
1762 \ cursor_style: 'n',
1763 \ cursor_blink_mode: 'u',
1764 \ underline_rgb: 'u',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001765 \ mouse: 's',
1766 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001767 \ }, terminalprops())
Bram Moolenaard55f9ef2022-08-26 12:26:07 +01001768endfunc
1769
1770" This checks the libvterm version response.
1771" This must be after other tests, because it has side effects to xterm
1772" properties.
1773func Test_xx03_libvterm_konsole_response()
1774 " Termresponse is only parsed when t_RV is not empty.
1775 set t_RV=x
1776 call test_override('term_props', 1)
1777
1778 " libvterm
1779 call Run_libvterm_konsole_response(100)
1780 " Konsole
1781 call Run_libvterm_konsole_response(115)
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001782
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001783 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001784 call test_override('term_props', 0)
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001785endfunc
1786
Bram Moolenaar89577b32019-10-18 21:26:05 +02001787" This checks the Mac Terminal.app version response.
1788" This must be after other tests, because it has side effects to xterm
1789" properties.
1790func Test_xx04_Mac_Terminal_response()
1791 " Termresponse is only parsed when t_RV is not empty.
1792 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001793 call test_override('term_props', 1)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001794
1795 set ttymouse=xterm
Bram Moolenaar8dff4cb2020-06-14 14:34:16 +02001796 " t_8u is not reset
1797 let &t_8u = "\<Esc>[58;2;%lu;%lu;%lum"
Bram Moolenaar89577b32019-10-18 21:26:05 +02001798 call test_option_not_set('ttymouse')
1799 let seq = "\<Esc>[>1;95;0c"
1800 call feedkeys(seq, 'Lx!')
1801 call assert_equal(seq, v:termresponse)
1802 call assert_equal('sgr', &ttymouse)
1803
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001804 call assert_equal(#{
1805 \ cursor_style: 'n',
1806 \ cursor_blink_mode: 'u',
1807 \ underline_rgb: 'y',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001808 \ mouse: 's',
1809 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001810 \ }, terminalprops())
Bram Moolenaar8dff4cb2020-06-14 14:34:16 +02001811 call assert_equal("\<Esc>[58;2;%lu;%lu;%lum", &t_8u)
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001812
Bram Moolenaar89577b32019-10-18 21:26:05 +02001813 " Reset is_not_xterm and is_mac_terminal.
1814 set t_RV=
1815 set term=xterm
1816 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001817 call test_override('term_props', 0)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001818endfunc
1819
1820" This checks the mintty version response.
1821" This must be after other tests, because it has side effects to xterm
1822" properties.
1823func Test_xx05_mintty_response()
1824 " Termresponse is only parsed when t_RV is not empty.
1825 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001826 call test_override('term_props', 1)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001827
1828 set ttymouse=xterm
1829 call test_option_not_set('ttymouse')
1830 let seq = "\<Esc>[>77;20905;0c"
1831 call feedkeys(seq, 'Lx!')
1832 call assert_equal(seq, v:termresponse)
1833 call assert_equal('sgr', &ttymouse)
1834
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001835 call assert_equal(#{
1836 \ cursor_style: 'n',
1837 \ cursor_blink_mode: 'u',
1838 \ underline_rgb: 'y',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001839 \ mouse: 's',
1840 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001841 \ }, terminalprops())
1842
Bram Moolenaar89577b32019-10-18 21:26:05 +02001843 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001844 call test_override('term_props', 0)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001845endfunc
1846
1847" This checks the screen version response.
1848" This must be after other tests, because it has side effects to xterm
1849" properties.
1850func Test_xx06_screen_response()
1851 " Termresponse is only parsed when t_RV is not empty.
1852 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001853 call test_override('term_props', 1)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001854
1855 " Old versions of screen don't support SGR mouse mode.
1856 set ttymouse=xterm
1857 call test_option_not_set('ttymouse')
1858 let seq = "\<Esc>[>83;40500;0c"
1859 call feedkeys(seq, 'Lx!')
1860 call assert_equal(seq, v:termresponse)
1861 call assert_equal('xterm', &ttymouse)
1862
1863 " screen supports SGR mouse mode starting in version 4.7.
1864 set ttymouse=xterm
1865 call test_option_not_set('ttymouse')
1866 let seq = "\<Esc>[>83;40700;0c"
1867 call feedkeys(seq, 'Lx!')
1868 call assert_equal(seq, v:termresponse)
1869 call assert_equal('sgr', &ttymouse)
1870
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001871 call assert_equal(#{
1872 \ cursor_style: 'n',
1873 \ cursor_blink_mode: 'n',
1874 \ underline_rgb: 'y',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001875 \ mouse: 's',
1876 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001877 \ }, terminalprops())
1878
Bram Moolenaar89577b32019-10-18 21:26:05 +02001879 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001880 call test_override('term_props', 0)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001881endfunc
1882
Bram Moolenaard0eaf672022-04-20 19:55:37 +01001883func Do_check_t_8u_set_reset(set_by_user)
1884 set ttymouse=xterm
1885 call test_option_not_set('ttymouse')
1886 let default_value = "\<Esc>[58;2;%lu;%lu;%lum"
1887 let &t_8u = default_value
1888 if !a:set_by_user
1889 call test_option_not_set('t_8u')
1890 endif
1891 let seq = "\<Esc>[>0;279;0c"
1892 call feedkeys(seq, 'Lx!')
1893 call assert_equal(seq, v:termresponse)
1894 call assert_equal('sgr', &ttymouse)
1895
1896 call assert_equal(#{
1897 \ cursor_style: 'u',
1898 \ cursor_blink_mode: 'u',
1899 \ underline_rgb: 'u',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001900 \ mouse: 's',
1901 \ kitty: 'u',
Bram Moolenaard0eaf672022-04-20 19:55:37 +01001902 \ }, terminalprops())
1903 call assert_equal(a:set_by_user ? default_value : '', &t_8u)
1904endfunc
1905
Bram Moolenaar03b00472019-10-14 22:22:03 +02001906" This checks the xterm version response.
1907" This must be after other tests, because it has side effects to xterm
1908" properties.
Bram Moolenaar89577b32019-10-18 21:26:05 +02001909func Test_xx07_xterm_response()
Bram Moolenaar03b00472019-10-14 22:22:03 +02001910 " Termresponse is only parsed when t_RV is not empty.
1911 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001912 call test_override('term_props', 1)
Bram Moolenaar03b00472019-10-14 22:22:03 +02001913
Bram Moolenaar3cea8a92019-10-17 21:55:24 +02001914 " Do Terminal.app first to check that is_mac_terminal is reset.
1915 set ttymouse=xterm
1916 call test_option_not_set('ttymouse')
1917 let seq = "\<Esc>[>1;95;0c"
1918 call feedkeys(seq, 'Lx!')
1919 call assert_equal(seq, v:termresponse)
1920 call assert_equal('sgr', &ttymouse)
1921
Bram Moolenaar03b00472019-10-14 22:22:03 +02001922 " xterm < 95: "xterm" (actually unmodified)
Bram Moolenaar3cea8a92019-10-17 21:55:24 +02001923 set t_RV=
1924 set term=xterm
Bram Moolenaarc255b782022-11-26 19:16:48 +00001925 call WaitForResponses()
1926
Bram Moolenaar3cea8a92019-10-17 21:55:24 +02001927 set t_RV=x
Bram Moolenaar03b00472019-10-14 22:22:03 +02001928 set ttymouse=xterm
1929 call test_option_not_set('ttymouse')
1930 let seq = "\<Esc>[>0;94;0c"
1931 call feedkeys(seq, 'Lx!')
1932 call assert_equal(seq, v:termresponse)
1933 call assert_equal('xterm', &ttymouse)
1934
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001935 call assert_equal(#{
1936 \ cursor_style: 'n',
1937 \ cursor_blink_mode: 'u',
1938 \ underline_rgb: 'y',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001939 \ mouse: 'u',
1940 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001941 \ }, terminalprops())
1942
Bram Moolenaar03b00472019-10-14 22:22:03 +02001943 " xterm >= 95 < 277 "xterm2"
1944 set ttymouse=xterm
1945 call test_option_not_set('ttymouse')
1946 let seq = "\<Esc>[>0;267;0c"
1947 call feedkeys(seq, 'Lx!')
1948 call assert_equal(seq, v:termresponse)
1949 call assert_equal('xterm2', &ttymouse)
1950
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001951 call assert_equal(#{
1952 \ cursor_style: 'n',
1953 \ cursor_blink_mode: 'u',
1954 \ underline_rgb: 'u',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001955 \ mouse: '2',
1956 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001957 \ }, terminalprops())
1958
Bram Moolenaar03b00472019-10-14 22:22:03 +02001959 " xterm >= 277: "sgr"
1960 set ttymouse=xterm
1961 call test_option_not_set('ttymouse')
1962 let seq = "\<Esc>[>0;277;0c"
1963 call feedkeys(seq, 'Lx!')
1964 call assert_equal(seq, v:termresponse)
1965 call assert_equal('sgr', &ttymouse)
1966
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001967 call assert_equal(#{
1968 \ cursor_style: 'n',
1969 \ cursor_blink_mode: 'u',
1970 \ underline_rgb: 'u',
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001971 \ mouse: 's',
1972 \ kitty: 'u',
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001973 \ }, terminalprops())
1974
Bram Moolenaard0eaf672022-04-20 19:55:37 +01001975 " xterm >= 279: "sgr" and cursor_style not reset; also check t_8u reset,
1976 " except when it was set by the user
1977 call Do_check_t_8u_set_reset(0)
1978 call Do_check_t_8u_set_reset(1)
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001979
Bram Moolenaar03b00472019-10-14 22:22:03 +02001980 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001981 call test_override('term_props', 0)
Bram Moolenaar03b00472019-10-14 22:22:03 +02001982endfunc
1983
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01001984func Test_xx08_kitty_response()
1985 " Termresponse is only parsed when t_RV is not empty.
1986 set t_RV=x
1987 call test_override('term_props', 1)
1988
1989 set ttymouse=xterm
1990 call test_option_not_set('ttymouse')
1991 let seq = "\<Esc>[>1;4001;12c"
1992 call feedkeys(seq, 'Lx!')
1993 call assert_equal(seq, v:termresponse)
1994 call assert_equal('sgr', &ttymouse)
1995
1996 call assert_equal(#{
1997 \ cursor_style: 'u',
1998 \ cursor_blink_mode: 'u',
1999 \ underline_rgb: 'y',
2000 \ mouse: 's',
2001 \ kitty: 'y',
2002 \ }, terminalprops())
2003
2004 set t_RV=
2005 call test_override('term_props', 0)
2006endfunc
2007
Bram Moolenaar92e5df82021-01-30 15:39:47 +01002008func Test_focus_events()
2009 let save_term = &term
2010 let save_ttymouse = &ttymouse
2011 set term=xterm ttymouse=xterm2
Bram Moolenaarc255b782022-11-26 19:16:48 +00002012 call WaitForResponses()
Bram Moolenaar92e5df82021-01-30 15:39:47 +01002013
2014 au FocusGained * let g:focus_gained += 1
2015 au FocusLost * let g:focus_lost += 1
2016 let g:focus_gained = 0
2017 let g:focus_lost = 0
2018
2019 call feedkeys("\<Esc>[O", "Lx!")
2020 call assert_equal(1, g:focus_lost)
2021 call feedkeys("\<Esc>[I", "Lx!")
2022 call assert_equal(1, g:focus_gained)
2023
2024 " still works when 'ttymouse' is empty
2025 set ttymouse=
2026 call feedkeys("\<Esc>[O", "Lx!")
2027 call assert_equal(2, g:focus_lost)
2028 call feedkeys("\<Esc>[I", "Lx!")
2029 call assert_equal(2, g:focus_gained)
2030
2031 au! FocusGained
2032 au! FocusLost
2033 let &term = save_term
2034 let &ttymouse = save_ttymouse
2035endfunc
2036
Bram Moolenaarde6dbb42019-06-06 11:59:18 +02002037func Test_get_termcode()
Bram Moolenaareb663282019-10-06 12:02:15 +02002038 try
2039 let k1 = &t_k1
2040 catch /E113/
2041 throw 'Skipped: Unable to query termcodes'
2042 endtry
Bram Moolenaarde6dbb42019-06-06 11:59:18 +02002043 set t_k1=
2044 set t_k1&
2045 call assert_equal(k1, &t_k1)
Bram Moolenaar9aeb3362019-06-06 12:36:15 +02002046
2047 " use external termcap first
2048 set nottybuiltin
2049 set t_k1=
2050 set t_k1&
2051 " when using external termcap may get something else, but it must not be
2052 " empty, since we would fallback to the builtin one.
2053 call assert_notequal('', &t_k1)
2054
2055 if &term =~ 'xterm'
2056 " use internal termcap first
2057 let term_save = &term
2058 let &term = 'builtin_' .. &term
2059 set t_k1=
2060 set t_k1&
2061 call assert_equal(k1, &t_k1)
2062 let &term = term_save
2063 endif
2064
2065 set ttybuiltin
Bram Moolenaarde6dbb42019-06-06 11:59:18 +02002066endfunc
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002067
Bram Moolenaarecd34bf2020-08-04 20:17:31 +02002068func Test_list_builtin_terminals()
Bram Moolenaare46a2ed2020-08-04 21:04:57 +02002069 CheckRunVimInTerminal
Bram Moolenaar4654d632022-11-17 22:05:12 +00002070
Bram Moolenaar4d05af02020-11-27 20:55:00 +01002071 call RunVimInTerminal('', #{rows: 14})
2072 call term_sendkeys('', ":set cmdheight=3\<CR>")
2073 call TermWait('', 100)
2074 call term_sendkeys('', ":set term=xxx\<CR>")
2075 call TermWait('', 100)
Bram Moolenaar4654d632022-11-17 22:05:12 +00002076
2077 " Check that the list ends in "builtin_dumb" and "builtin_debug".
2078 let dumb_idx = 0
2079 for n in range(8, 12)
2080 if term_getline('', n) =~ 'builtin_dumb'
2081 let dumb_idx = n
2082 break
2083 endif
2084 endfor
2085 call assert_notequal(0, dumb_idx, 'builtin_dumb not found')
2086
2087 call assert_match('builtin_dumb', term_getline('', dumb_idx))
2088 call assert_match('builtin_debug', term_getline('', dumb_idx + 1))
2089 call assert_match('Not found in termcap', term_getline('', dumb_idx + 2))
2090
Bram Moolenaar4d05af02020-11-27 20:55:00 +01002091 call StopVimInTerminal('')
Bram Moolenaarecd34bf2020-08-04 20:17:31 +02002092endfunc
2093
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002094" This checks the CSI sequences when in modifyOtherKeys mode.
2095" The mode doesn't need to be enabled, the codes are always detected.
2096func RunTest_modifyOtherKeys(func)
2097 new
Bram Moolenaar459fd782019-10-13 16:43:39 +02002098 set timeoutlen=10
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002099
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002100 " Shift-X is sent as 'X' with the shift modifier
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002101 call feedkeys('a' .. a:func('X', 2) .. "\<Esc>", 'Lx!')
2102 call assert_equal('X', getline(1))
2103
2104 " Ctrl-i is Tab
2105 call setline(1, '')
2106 call feedkeys('a' .. a:func('i', 5) .. "\<Esc>", 'Lx!')
2107 call assert_equal("\t", getline(1))
2108
2109 " Ctrl-I is also Tab
2110 call setline(1, '')
2111 call feedkeys('a' .. a:func('I', 5) .. "\<Esc>", 'Lx!')
2112 call assert_equal("\t", getline(1))
2113
2114 " Alt-x is ø
2115 call setline(1, '')
2116 call feedkeys('a' .. a:func('x', 3) .. "\<Esc>", 'Lx!')
2117 call assert_equal("ø", getline(1))
2118
2119 " Meta-x is also ø
2120 call setline(1, '')
2121 call feedkeys('a' .. a:func('x', 9) .. "\<Esc>", 'Lx!')
2122 call assert_equal("ø", getline(1))
2123
2124 " Alt-X is Ø
2125 call setline(1, '')
2126 call feedkeys('a' .. a:func('X', 3) .. "\<Esc>", 'Lx!')
2127 call assert_equal("Ø", getline(1))
2128
2129 " Meta-X is ø
2130 call setline(1, '')
2131 call feedkeys('a' .. a:func('X', 9) .. "\<Esc>", 'Lx!')
2132 call assert_equal("Ø", getline(1))
2133
Bram Moolenaar828ffd52019-11-21 23:24:00 +01002134 " Ctrl-6 is Ctrl-^
2135 split aaa
2136 edit bbb
2137 call feedkeys(a:func('6', 5), 'Lx!')
2138 call assert_equal("aaa", bufname())
2139 bwipe aaa
2140 bwipe bbb
2141
Bram Moolenaar0684e362020-12-03 19:54:42 +01002142 " Ctrl-V X 33 is 3
2143 call setline(1, '')
2144 call feedkeys("a\<C-V>" .. a:func('X', 2) .. "33\<Esc>", 'Lx!')
2145 call assert_equal("3", getline(1))
2146
2147 " Ctrl-V U 12345 is Unicode 12345
2148 call setline(1, '')
2149 call feedkeys("a\<C-V>" .. a:func('U', 2) .. "12345\<Esc>", 'Lx!')
2150 call assert_equal("\U12345", getline(1))
2151
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002152 bwipe!
2153 set timeoutlen&
2154endfunc
2155
Bram Moolenaar459fd782019-10-13 16:43:39 +02002156func Test_modifyOtherKeys_basic()
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002157 call RunTest_modifyOtherKeys(function('GetEscCodeCSI27'))
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002158 call RunTest_modifyOtherKeys(function('GetEscCodeCSIu'))
2159endfunc
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002160
Bram Moolenaar38571a02019-11-26 14:28:15 +01002161func Test_modifyOtherKeys_no_mapping()
2162 set timeoutlen=10
2163
2164 let @a = 'aaa'
2165 call feedkeys(":let x = '" .. GetEscCodeCSI27('R', 5) .. GetEscCodeCSI27('R', 5) .. "a'\<CR>", 'Lx!')
2166 call assert_equal("let x = 'aaa'", @:)
2167
2168 new
2169 call feedkeys("a" .. GetEscCodeCSI27('R', 5) .. GetEscCodeCSI27('R', 5) .. "a\<Esc>", 'Lx!')
2170 call assert_equal("aaa", getline(1))
2171 bwipe!
2172
2173 new
2174 call feedkeys("axx\<CR>yy" .. GetEscCodeCSI27('G', 5) .. GetEscCodeCSI27('K', 5) .. "a\<Esc>", 'Lx!')
2175 call assert_equal("axx", getline(1))
2176 call assert_equal("yy", getline(2))
2177 bwipe!
2178
2179 set timeoutlen&
2180endfunc
2181
Trygve Aabergeb9c09c12022-10-14 12:08:24 +01002182func Test_CSIu_keys_without_modifiers()
Bram Moolenaarebed1b02022-11-24 14:05:19 +00002183 " make this execute faster
2184 set timeoutlen=10
2185
Bram Moolenaarc255b782022-11-26 19:16:48 +00002186 call WaitForResponses()
2187
Trygve Aabergeb9c09c12022-10-14 12:08:24 +01002188 " Escape sent as `CSI 27 u` should act as normal escape and not undo
2189 call setline(1, 'a')
2190 call feedkeys('a' .. GetEscCodeCSIuWithoutModifier("\e"), 'Lx!')
2191 call assert_equal('n', mode())
2192 call assert_equal('a', getline(1))
2193
2194 " Tab sent as `CSI 9 u` should work
2195 call setline(1, '')
2196 call feedkeys('a' .. GetEscCodeCSIuWithoutModifier("\t") .. "\<Esc>", 'Lx!')
2197 call assert_equal("\t", getline(1))
Bram Moolenaarebed1b02022-11-24 14:05:19 +00002198
2199 set timeoutlen&
Trygve Aabergeb9c09c12022-10-14 12:08:24 +01002200endfunc
2201
Bram Moolenaarc14b57c2021-12-03 13:20:29 +00002202" Check that when DEC mouse codes are recognized a special key is handled.
2203func Test_ignore_dec_mouse()
Dominique Pellef589fd32021-12-05 12:39:21 +00002204 silent !infocmp gnome >/dev/null 2>&1
2205 if v:shell_error != 0
2206 throw 'Skipped: gnome entry missing in the terminfo db'
2207 endif
Bram Moolenaarc14b57c2021-12-03 13:20:29 +00002208
2209 new
2210 let save_mouse = &mouse
2211 let save_term = &term
2212 let save_ttymouse = &ttymouse
2213 call test_override('no_query_mouse', 1)
2214 set mouse=a term=gnome ttymouse=
Bram Moolenaarc255b782022-11-26 19:16:48 +00002215 call WaitForResponses()
Bram Moolenaarc14b57c2021-12-03 13:20:29 +00002216
2217 execute "set <xF1>=\<Esc>[1;*P"
2218 nnoremap <S-F1> agot it<Esc>
2219 call feedkeys("\<Esc>[1;2P", 'Lx!')
2220 call assert_equal('got it', getline(1))
2221
2222 let &mouse = save_mouse
2223 let &term = save_term
2224 let &ttymouse = save_ttymouse
2225 call test_override('no_query_mouse', 0)
2226 bwipe!
2227endfunc
2228
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002229func RunTest_mapping_shift(key, func)
2230 call setline(1, '')
2231 if a:key == '|'
2232 exe 'inoremap \| xyz'
2233 else
2234 exe 'inoremap ' .. a:key .. ' xyz'
2235 endif
2236 call feedkeys('a' .. a:func(a:key, 2) .. "\<Esc>", 'Lx!')
2237 call assert_equal("xyz", getline(1))
2238 if a:key == '|'
2239 exe 'iunmap \|'
2240 else
2241 exe 'iunmap ' .. a:key
2242 endif
2243endfunc
2244
Bram Moolenaar975a8802020-06-06 22:36:24 +02002245func Test_modifyOtherKeys_mapped()
2246 set timeoutlen=10
2247 imap ' <C-W>
2248 imap <C-W><C-A> c-a
2249 call setline(1, '')
2250
2251 " single quote is turned into single byte CTRL-W
2252 " CTRL-A is added with a separate modifier, and needs to be simplified before
2253 " the mapping can match.
2254 call feedkeys("a'" .. GetEscCodeCSI27('A', 5) .. "\<Esc>", 'Lx!')
2255 call assert_equal('c-a', getline(1))
2256
2257 iunmap '
2258 iunmap <C-W><C-A>
2259 set timeoutlen&
2260endfunc
2261
Bram Moolenaar196c3852022-03-04 19:22:36 +00002262func Test_modifyOtherKeys_ambiguous_mapping()
2263 new
2264 set timeoutlen=10
2265 map <C-J> a
2266 map <C-J>x <Nop>
2267 call setline(1, 'x')
2268
2269 " CTRL-J b should have trigger the <C-J> mapping and then insert "b"
2270 call feedkeys(GetEscCodeCSI27('J', 5) .. "b\<Esc>", 'Lx!')
2271 call assert_equal('xb', getline(1))
2272
2273 unmap <C-J>
2274 unmap <C-J>x
Bram Moolenaarf35fd8e2022-03-18 15:41:17 +00002275
2276 " if a special character is following there should be a check for a termcode
2277 nnoremap s aX<Esc>
2278 nnoremap s<BS> aY<Esc>
2279 set t_kb=
2280 call setline(1, 'x')
2281 call feedkeys("s\x08", 'Lx!')
2282 call assert_equal('xY', getline(1))
2283
Bram Moolenaar196c3852022-03-04 19:22:36 +00002284 set timeoutlen&
2285 bwipe!
2286endfunc
2287
Bram Moolenaar749bc952020-10-31 16:33:47 +01002288" Whether Shift-Tab sends "ESC [ Z" or "ESC [ 27 ; 2 ; 9 ~" is unpredictable,
2289" both should work.
2290func Test_modifyOtherKeys_shift_tab()
2291 set timeoutlen=10
2292
2293 call setline(1, '')
2294 call feedkeys("a\<C-K>" .. GetEscCodeCSI27("\t", '2') .. "\<Esc>", 'Lx!')
2295 eval getline(1)->assert_equal('<S-Tab>')
2296
2297 call setline(1, '')
2298 call feedkeys("a\<C-K>\<Esc>[Z\<Esc>", 'Lx!')
2299 eval getline(1)->assert_equal('<S-Tab>')
2300
2301 set timeoutlen&
2302 bwipe!
2303endfunc
2304
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002305func RunTest_mapping_works_with_shift(func)
2306 new
Bram Moolenaar459fd782019-10-13 16:43:39 +02002307 set timeoutlen=10
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002308
2309 call RunTest_mapping_shift('@', a:func)
2310 call RunTest_mapping_shift('A', a:func)
2311 call RunTest_mapping_shift('Z', a:func)
2312 call RunTest_mapping_shift('^', a:func)
2313 call RunTest_mapping_shift('_', a:func)
2314 call RunTest_mapping_shift('{', a:func)
2315 call RunTest_mapping_shift('|', a:func)
2316 call RunTest_mapping_shift('}', a:func)
2317 call RunTest_mapping_shift('~', a:func)
2318
2319 bwipe!
2320 set timeoutlen&
2321endfunc
2322
Bram Moolenaar459fd782019-10-13 16:43:39 +02002323func Test_mapping_works_with_shift_plain()
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002324 call RunTest_mapping_works_with_shift(function('GetEscCodeCSI27'))
2325 call RunTest_mapping_works_with_shift(function('GetEscCodeCSIu'))
2326endfunc
Bram Moolenaar459fd782019-10-13 16:43:39 +02002327
2328func RunTest_mapping_mods(map, key, func, code)
2329 call setline(1, '')
2330 exe 'inoremap ' .. a:map .. ' xyz'
2331 call feedkeys('a' .. a:func(a:key, a:code) .. "\<Esc>", 'Lx!')
2332 call assert_equal("xyz", getline(1))
2333 exe 'iunmap ' .. a:map
2334endfunc
2335
2336func RunTest_mapping_works_with_mods(func, mods, code)
2337 new
2338 set timeoutlen=10
2339
2340 if a:mods !~ 'S'
2341 " Shift by itself has no effect
2342 call RunTest_mapping_mods('<' .. a:mods .. '-@>', '@', a:func, a:code)
2343 endif
2344 call RunTest_mapping_mods('<' .. a:mods .. '-A>', 'A', a:func, a:code)
2345 call RunTest_mapping_mods('<' .. a:mods .. '-Z>', 'Z', a:func, a:code)
2346 if a:mods !~ 'S'
2347 " with Shift code is always upper case
2348 call RunTest_mapping_mods('<' .. a:mods .. '-a>', 'a', a:func, a:code)
2349 call RunTest_mapping_mods('<' .. a:mods .. '-z>', 'z', a:func, a:code)
2350 endif
2351 if a:mods != 'A'
2352 " with Alt code is not in upper case
2353 call RunTest_mapping_mods('<' .. a:mods .. '-a>', 'A', a:func, a:code)
2354 call RunTest_mapping_mods('<' .. a:mods .. '-z>', 'Z', a:func, a:code)
2355 endif
2356 call RunTest_mapping_mods('<' .. a:mods .. '-á>', 'á', a:func, a:code)
2357 if a:mods !~ 'S'
2358 " Shift by itself has no effect
2359 call RunTest_mapping_mods('<' .. a:mods .. '-^>', '^', a:func, a:code)
2360 call RunTest_mapping_mods('<' .. a:mods .. '-_>', '_', a:func, a:code)
2361 call RunTest_mapping_mods('<' .. a:mods .. '-{>', '{', a:func, a:code)
2362 call RunTest_mapping_mods('<' .. a:mods .. '-\|>', '|', a:func, a:code)
2363 call RunTest_mapping_mods('<' .. a:mods .. '-}>', '}', a:func, a:code)
2364 call RunTest_mapping_mods('<' .. a:mods .. '-~>', '~', a:func, a:code)
2365 endif
2366
2367 bwipe!
2368 set timeoutlen&
2369endfunc
2370
2371func Test_mapping_works_with_shift()
2372 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'S', 2)
2373 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'S', 2)
2374endfunc
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002375
Bram Moolenaar459fd782019-10-13 16:43:39 +02002376func Test_mapping_works_with_ctrl()
2377 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C', 5)
2378 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C', 5)
Bram Moolenaar4e2114e2020-10-07 16:12:37 +02002379
2380 new
2381 set timeoutlen=10
2382
2383 " CTRL-@ actually produces the code for CTRL-2, which is converted
2384 call RunTest_mapping_mods('<C-@>', '2', function('GetEscCodeCSI27'), 5)
2385 call RunTest_mapping_mods('<C-@>', '2', function('GetEscCodeCSIu'), 5)
2386
2387 " CTRL-^ actually produces the code for CTRL-6, which is converted
2388 call RunTest_mapping_mods('<C-^>', '6', function('GetEscCodeCSI27'), 5)
2389 call RunTest_mapping_mods('<C-^>', '6', function('GetEscCodeCSIu'), 5)
2390
2391 " CTRL-_ actually produces the code for CTRL--, which is converted
2392 call RunTest_mapping_mods('<C-_>', '-', function('GetEscCodeCSI27'), 5)
2393 call RunTest_mapping_mods('<C-_>', '-', function('GetEscCodeCSIu'), 5)
2394
2395 bwipe!
2396 set timeoutlen&
Bram Moolenaar459fd782019-10-13 16:43:39 +02002397endfunc
2398
2399func Test_mapping_works_with_shift_ctrl()
2400 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-S', 6)
2401 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-S', 6)
Bram Moolenaar9a033d72020-10-07 17:29:48 +02002402
2403 new
2404 set timeoutlen=10
2405
2406 " Ctrl-Shift-[ actually produces CTRL-Shift-{ which is mapped as <C-{>
2407 call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSI27'), 6)
2408 call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSIu'), 6)
2409
2410 " Ctrl-Shift-] actually produces CTRL-Shift-} which is mapped as <C-}>
2411 call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSI27'), 6)
2412 call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSIu'), 6)
2413
2414 " Ctrl-Shift-\ actually produces CTRL-Shift-| which is mapped as <C-|>
2415 call RunTest_mapping_mods('<C-\|>', '|', function('GetEscCodeCSI27'), 6)
2416 call RunTest_mapping_mods('<C-\|>', '|', function('GetEscCodeCSIu'), 6)
2417
2418 bwipe!
2419 set timeoutlen&
Bram Moolenaar459fd782019-10-13 16:43:39 +02002420endfunc
2421
2422" Below we also test the "u" code with Alt, This works, but libvterm would not
2423" send the Alt key like this but by prefixing an Esc.
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002424
Bram Moolenaar459fd782019-10-13 16:43:39 +02002425func Test_mapping_works_with_alt()
2426 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'A', 3)
2427 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'A', 3)
2428endfunc
2429
2430func Test_mapping_works_with_shift_alt()
2431 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'S-A', 4)
2432 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'S-A', 4)
2433endfunc
2434
Bram Moolenaardaff0fb2020-09-27 13:16:46 +02002435func Test_mapping_works_with_alt_and_shift()
2436 new
2437 set timeoutlen=10
2438
2439 " mapping <A-?> works even though the code is A-S-?
2440 for c in ['!', '$', '+', ':', '?', '^', '~']
2441 call RunTest_mapping_mods('<A-' .. c .. '>', c, function('GetEscCodeCSI27'), 4)
2442 call RunTest_mapping_mods('<A-' .. c .. '>', c, function('GetEscCodeCSIu'), 4)
2443 endfor
2444
2445 bwipe!
2446 set timeoutlen&
2447endfunc
2448
Bram Moolenaar459fd782019-10-13 16:43:39 +02002449func Test_mapping_works_with_ctrl_alt()
2450 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-A', 7)
2451 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-A', 7)
2452endfunc
2453
2454func Test_mapping_works_with_shift_ctrl_alt()
2455 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-S-A', 8)
2456 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-S-A', 8)
2457endfunc
Bram Moolenaarfc4ea2a2019-11-26 19:33:22 +01002458
Bram Moolenaar064fd672022-11-29 18:32:32 +00002459func Test_mapping_works_with_unknown_modifiers()
2460 new
2461 set timeoutlen=10
2462
2463 for Func in [function('GetEscCodeCSI27'), function('GetEscCodeCSIu')]
2464 call RunTest_mapping_mods('<C-z>', 'z', Func, 5)
2465 " Add 16, 32, 64 or 128 for modifiers we currently don't support.
2466 call RunTest_mapping_mods('<C-z>', 'z', Func, 5 + 16)
2467 call RunTest_mapping_mods('<C-z>', 'z', Func, 5 + 32)
2468 call RunTest_mapping_mods('<C-z>', 'z', Func, 5 + 64)
2469 call RunTest_mapping_mods('<C-z>', 'z', Func, 5 + 128)
2470
2471 call RunTest_mapping_mods('<S-X>', 'X', Func, 2)
2472 " Add 16, 32, 64 or 128 for modifiers we currently don't support.
2473 call RunTest_mapping_mods('<S-X>', 'X', Func, 2 + 16)
2474 call RunTest_mapping_mods('<S-X>', 'X', Func, 2 + 32)
2475 call RunTest_mapping_mods('<S-X>', 'X', Func, 2 + 64)
2476 call RunTest_mapping_mods('<S-X>', 'X', Func, 2 + 128)
2477 endfor
2478
2479 bwipe!
2480 set timeoutlen&
2481endfunc
2482
Bram Moolenaar1a173402022-12-02 12:28:47 +00002483func RunTest_mapping_funckey(map, func, key, code)
2484 call setline(1, '')
2485 exe 'inoremap ' .. a:map .. ' xyz'
2486 call feedkeys('a' .. a:func(a:key, a:code) .. "\<Esc>", 'Lx!')
2487 call assert_equal("xyz", getline(1), 'mapping ' .. a:map)
2488 exe 'iunmap ' .. a:map
2489endfunc
2490
2491func Test_mapping_kitty_function_keys()
2492 new
2493 set timeoutlen=10
2494
2495 " Function keys made with CSI and ending in [ABCDEFHPQRS].
2496 " 'E' is keypad BEGIN, not supported
2497 let maps = [
2498 \ ['<Up>', 'A', 0],
2499 \ ['<S-Up>', 'A', 2],
2500 \ ['<C-Up>', 'A', 5],
2501 \ ['<C-S-Up>', 'A', 6],
2502 \
2503 \ ['<Down>', 'B', 0],
2504 \ ['<S-Down>', 'B', 2],
2505 \ ['<C-Down>', 'B', 5],
2506 \ ['<C-S-Down>', 'B', 6],
2507 \
2508 \ ['<Right>', 'C', 0],
2509 \ ['<S-Right>', 'C', 2],
2510 \ ['<C-Right>', 'C', 5],
2511 \ ['<C-S-Right>', 'C', 6],
2512 \
2513 \ ['<Left>', 'D', 0],
2514 \ ['<S-Left>', 'D', 2],
2515 \ ['<C-Left>', 'D', 5],
2516 \ ['<C-S-Left>', 'D', 6],
2517 \
2518 \ ['<End>', 'F', 0],
2519 \ ['<S-End>', 'F', 2],
2520 \ ['<C-End>', 'F', 5],
2521 \ ['<C-S-End>', 'F', 6],
2522 \
2523 \ ['<Home>', 'H', 0],
2524 \ ['<S-Home>', 'H', 2],
2525 \ ['<C-Home>', 'H', 5],
2526 \ ['<C-S-Home>', 'H', 6],
2527 \
2528 \ ['<F1>', 'P', 0],
2529 \ ['<S-F1>', 'P', 2],
2530 \ ['<C-F1>', 'P', 5],
2531 \ ['<C-S-F1>', 'P', 6],
2532 \
2533 \ ['<F2>', 'Q', 0],
2534 \ ['<S-F2>', 'Q', 2],
2535 \ ['<C-F2>', 'Q', 5],
2536 \ ['<C-S-F2>', 'Q', 6],
2537 \
2538 \ ['<F3>', 'R', 0],
2539 \ ['<S-F3>', 'R', 2],
2540 \ ['<C-F3>', 'R', 5],
2541 \ ['<C-S-F3>', 'R', 6],
2542 \
2543 \ ['<F4>', 'S', 0],
2544 \ ['<S-F4>', 'S', 2],
2545 \ ['<C-F4>', 'S', 5],
2546 \ ['<C-S-F4>', 'S', 6],
2547 \ ]
2548
2549 for map in maps
2550 call RunTest_mapping_funckey(map[0], function('GetEscCodeFunckey'), map[1], map[2])
2551 endfor
2552
2553 bwipe!
2554 set timeoutlen&
2555endfunc
2556
Bram Moolenaarfc4ea2a2019-11-26 19:33:22 +01002557func Test_insert_literal()
2558 set timeoutlen=10
Bram Moolenaarc255b782022-11-26 19:16:48 +00002559
2560 call WaitForResponses()
2561
Bram Moolenaarfc4ea2a2019-11-26 19:33:22 +01002562 new
2563 " CTRL-V CTRL-X inserts a ^X
2564 call feedkeys('a' .. GetEscCodeCSIu('V', '5') .. GetEscCodeCSIu('X', '5') .. "\<Esc>", 'Lx!')
2565 call assert_equal("\<C-X>", getline(1))
2566
2567 call setline(1, '')
2568 call feedkeys('a' .. GetEscCodeCSI27('V', '5') .. GetEscCodeCSI27('X', '5') .. "\<Esc>", 'Lx!')
2569 call assert_equal("\<C-X>", getline(1))
2570
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002571 " CTRL-SHIFT-V CTRL-X inserts escape sequence
Bram Moolenaarfc4ea2a2019-11-26 19:33:22 +01002572 call setline(1, '')
2573 call feedkeys('a' .. GetEscCodeCSIu('V', '6') .. GetEscCodeCSIu('X', '5') .. "\<Esc>", 'Lx!')
2574 call assert_equal("\<Esc>[88;5u", getline(1))
2575
2576 call setline(1, '')
2577 call feedkeys('a' .. GetEscCodeCSI27('V', '6') .. GetEscCodeCSI27('X', '5') .. "\<Esc>", 'Lx!')
2578 call assert_equal("\<Esc>[27;5;88~", getline(1))
2579
2580 bwipe!
2581 set timeoutlen&
2582endfunc
2583
2584func Test_cmdline_literal()
2585 set timeoutlen=10
2586
2587 " CTRL-V CTRL-Y inserts a ^Y
2588 call feedkeys(':' .. GetEscCodeCSIu('V', '5') .. GetEscCodeCSIu('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!')
2589 call assert_equal("\"\<C-Y>", @:)
2590
2591 call feedkeys(':' .. GetEscCodeCSI27('V', '5') .. GetEscCodeCSI27('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!')
2592 call assert_equal("\"\<C-Y>", @:)
2593
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002594 " CTRL-SHIFT-V CTRL-Y inserts escape sequence
Bram Moolenaarfc4ea2a2019-11-26 19:33:22 +01002595 call feedkeys(':' .. GetEscCodeCSIu('V', '6') .. GetEscCodeCSIu('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!')
2596 call assert_equal("\"\<Esc>[89;5u", @:)
2597
2598 call setline(1, '')
2599 call feedkeys(':' .. GetEscCodeCSI27('V', '6') .. GetEscCodeCSI27('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!')
2600 call assert_equal("\"\<Esc>[27;5;89~", @:)
2601
2602 set timeoutlen&
2603endfunc
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01002604
Bram Moolenaarbbf84e22022-03-12 13:48:39 +00002605func Test_mapping_esc()
2606 set timeoutlen=10
2607
2608 new
2609 nnoremap <Up> iHello<Esc>
2610 nnoremap <Esc> <Nop>
2611
2612 call feedkeys(substitute(&t_ku, '\*', '', 'g'), 'Lx!')
2613 call assert_equal("Hello", getline(1))
2614
2615 bwipe!
2616 nunmap <Up>
2617 nunmap <Esc>
2618 set timeoutlen&
2619endfunc
2620
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +02002621" Test for translation of special key codes (<xF1>, <xF2>, etc.)
Bram Moolenaar92e5df82021-01-30 15:39:47 +01002622func Test_Keycode_Translation()
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +02002623 let keycodes = [
2624 \ ["<xUp>", "<Up>"],
2625 \ ["<xDown>", "<Down>"],
2626 \ ["<xLeft>", "<Left>"],
2627 \ ["<xRight>", "<Right>"],
2628 \ ["<xHome>", "<Home>"],
2629 \ ["<xEnd>", "<End>"],
2630 \ ["<zHome>", "<Home>"],
2631 \ ["<zEnd>", "<End>"],
2632 \ ["<xF1>", "<F1>"],
2633 \ ["<xF2>", "<F2>"],
2634 \ ["<xF3>", "<F3>"],
2635 \ ["<xF4>", "<F4>"],
2636 \ ["<S-xF1>", "<S-F1>"],
2637 \ ["<S-xF2>", "<S-F2>"],
2638 \ ["<S-xF3>", "<S-F3>"],
2639 \ ["<S-xF4>", "<S-F4>"]]
2640 for [k1, k2] in keycodes
2641 exe "nnoremap " .. k1 .. " 2wx"
2642 call assert_true(maparg(k1, 'n', 0, 1).lhs == k2)
2643 exe "nunmap " .. k1
2644 endfor
2645endfunc
2646
Bram Moolenaar1f448d92021-03-22 19:37:06 +01002647" Test for terminal keycodes that doesn't have termcap entries
2648func Test_special_term_keycodes()
2649 new
2650 " Test for <xHome>, <S-xHome> and <C-xHome>
2651 " send <K_SPECIAL> <KS_EXTRA> keycode
2652 call feedkeys("i\<C-K>\x80\xfd\x3f\n", 'xt')
2653 " send <K_SPECIAL> <KS_MODIFIER> bitmap <K_SPECIAL> <KS_EXTRA> keycode
2654 call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3f\n", 'xt')
2655 call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3f\n", 'xt')
2656 " Test for <xEnd>, <S-xEnd> and <C-xEnd>
2657 call feedkeys("i\<C-K>\x80\xfd\x3d\n", 'xt')
2658 call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3d\n", 'xt')
2659 call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3d\n", 'xt')
2660 " Test for <zHome>, <S-zHome> and <C-zHome>
2661 call feedkeys("i\<C-K>\x80\xfd\x40\n", 'xt')
2662 call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x40\n", 'xt')
2663 call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x40\n", 'xt')
2664 " Test for <zEnd>, <S-zEnd> and <C-zEnd>
2665 call feedkeys("i\<C-K>\x80\xfd\x3e\n", 'xt')
2666 call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3e\n", 'xt')
2667 call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3e\n", 'xt')
2668 " Test for <xUp>, <xDown>, <xLeft> and <xRight>
2669 call feedkeys("i\<C-K>\x80\xfd\x41\n", 'xt')
2670 call feedkeys("i\<C-K>\x80\xfd\x42\n", 'xt')
2671 call feedkeys("i\<C-K>\x80\xfd\x43\n", 'xt')
2672 call feedkeys("i\<C-K>\x80\xfd\x44\n", 'xt')
2673 call assert_equal(['<Home>', '<S-Home>', '<C-Home>',
2674 \ '<End>', '<S-End>', '<C-End>',
2675 \ '<Home>', '<S-Home>', '<C-Home>',
2676 \ '<End>', '<S-End>', '<C-End>',
2677 \ '<Up>', '<Down>', '<Left>', '<Right>', ''], getline(1, '$'))
2678 bw!
2679endfunc
2680
Bram Moolenaar1573e732022-11-16 20:33:21 +00002681func Test_home_key_works()
2682 " The '@' character in K_HOME must only match "1" when followed by ";",
2683 " otherwise this code for Home is not recognized: "<Esc>[1~"
Bram Moolenaar1d8765d2022-11-17 16:43:35 +00002684 " Set termcap values like "xterm" uses them. Except using F2 for xHome,
2685 " because that termcap entry can't be set here.
2686 let save_K1 = exists('&t_K1') ? &t_K1 : ''
2687 let save_kh = exists('&t_kh') ? &t_kh : ''
2688 let save_k2 = exists('&t_k2') ? &t_k2 : ''
2689 let save_k3 = exists('&t_k3') ? &t_k3 : ''
2690 let save_end = exists('&t_@7') ? &t_@7 : ''
2691
Bram Moolenaar1573e732022-11-16 20:33:21 +00002692 let &t_K1 = "\<Esc>[1;*~" " <kHome>
2693 let &t_kh = "\<Esc>[@;*H" " <Home>
Bram Moolenaar1d8765d2022-11-17 16:43:35 +00002694 let &t_k2 = "\<Esc>O*H" " use <F2> for <xHome>
Bram Moolenaar1573e732022-11-16 20:33:21 +00002695 let &t_k3 = "\<Esc>[7;*~" " use <F3> for <zHome>
2696 let &t_@7 = "\<Esc>[@;*F" " <End>
2697
2698 new
2699 call feedkeys("i\<C-K>\<Esc>OH\n\<Esc>", 'tx')
2700 call feedkeys("i\<C-K>\<Esc>[1~\n\<Esc>", 'tx')
2701 call assert_equal([
Bram Moolenaar1d8765d2022-11-17 16:43:35 +00002702 \ '<F2>',
Bram Moolenaar1573e732022-11-16 20:33:21 +00002703 \ '<kHome>',
2704 \ ''], getline(1, '$'))
2705
2706 bwipe!
Bram Moolenaar1573e732022-11-16 20:33:21 +00002707 let &t_K1 = save_K1
Bram Moolenaar1d8765d2022-11-17 16:43:35 +00002708 let &t_kh = save_kh
Bram Moolenaar1573e732022-11-16 20:33:21 +00002709 let &t_k2 = save_k2
2710 let &t_k3 = save_k3
2711 let &t_@7 = save_end
2712endfunc
2713
Bram Moolenaar0f5575d2021-07-30 21:18:03 +02002714func Test_terminal_builtin_without_gui()
2715 CheckNotMSWindows
2716
2717 " builtin_gui should not be output by :set term=xxx
2718 let output = systemlist("TERM=dumb " .. v:progpath .. " --clean -c ':set t_ti= t_te=' -c 'set term=xxx' -c ':q!'")
2719 redraw!
2720 call map(output, {_, val -> trim(val)})
2721 call assert_equal(-1, index(output, 'builtin_gui'))
2722 call assert_notequal(-1, index(output, 'builtin_dumb'))
2723endfunc
2724
2725
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01002726" vim: shiftwidth=2 sts=2 expandtab