blob: 578c97018aab96655d21d81c472870f382da97c9 [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 Moolenaar905dd902019-04-07 14:21:47 +020020 call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer'])
Bram Moolenaar905dd902019-04-07 14:21:47 +020021
Bram Moolenaar515545e2020-03-22 14:08:59 +010022 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
Bram Moolenaar49452192019-04-17 16:27:02 +020023 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +020024 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020025 go
Bram Moolenaar49452192019-04-17 16:27:02 +020026 call assert_equal([0, 1, 1, 0], getpos('.'), msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020027 let row = 2
28 let col = 6
29 call MouseLeftClick(row, col)
30 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +020031 call assert_equal([0, 2, 6, 0], getpos('.'), msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +020032 endfor
Bram Moolenaar905dd902019-04-07 14:21:47 +020033
34 let &mouse = save_mouse
35 let &term = save_term
36 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +020037 call test_override('no_query_mouse', 0)
Bram Moolenaar905dd902019-04-07 14:21:47 +020038 bwipe!
39endfunc
40
Bram Moolenaar6aa75232019-10-13 21:01:34 +020041func Test_xterm_mouse_right_click_extends_visual()
42 if has('mac')
43 throw "Skipped: test right click in visual mode does not work on macOs (why?)"
44 endif
45 let save_mouse = &mouse
46 let save_term = &term
47 let save_ttymouse = &ttymouse
48 call test_override('no_query_mouse', 1)
49 set mouse=a term=xterm
50
51 for visual_mode in ["v", "V", "\<C-V>"]
Bram Moolenaar515545e2020-03-22 14:08:59 +010052 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar6aa75232019-10-13 21:01:34 +020053 let msg = 'visual=' .. visual_mode .. ' ttymouse=' .. ttymouse_val
54 exe 'set ttymouse=' .. ttymouse_val
55
56 call setline(1, repeat([repeat('-', 7)], 7))
57 call MouseLeftClick(4, 4)
58 call MouseLeftRelease(4, 4)
59 exe "norm! " .. visual_mode
60
61 " Right click extends top left of visual area.
62 call MouseRightClick(2, 2)
63 call MouseRightRelease(2, 2)
64
Bram Moolenaarf19f8d12019-12-18 19:36:23 +010065 " Right click extends bottom right of visual area.
Bram Moolenaar6aa75232019-10-13 21:01:34 +020066 call MouseRightClick(6, 6)
67 call MouseRightRelease(6, 6)
68 norm! r1gv
69
70 " Right click shrinks top left of visual area.
71 call MouseRightClick(3, 3)
72 call MouseRightRelease(3, 3)
73
74 " Right click shrinks bottom right of visual area.
75 call MouseRightClick(5, 5)
76 call MouseRightRelease(5, 5)
77 norm! r2
78
79 if visual_mode ==# 'v'
80 call assert_equal(['-------',
81 \ '-111111',
82 \ '1122222',
83 \ '2222222',
84 \ '2222211',
85 \ '111111-',
86 \ '-------'], getline(1, '$'), msg)
87 elseif visual_mode ==# 'V'
88 call assert_equal(['-------',
89 \ '1111111',
90 \ '2222222',
91 \ '2222222',
92 \ '2222222',
93 \ '1111111',
94 \ '-------'], getline(1, '$'), msg)
95 else
96 call assert_equal(['-------',
97 \ '-11111-',
98 \ '-12221-',
99 \ '-12221-',
100 \ '-12221-',
101 \ '-11111-',
102 \ '-------'], getline(1, '$'), msg)
103 endif
104 endfor
105 endfor
106
107 let &mouse = save_mouse
108 let &term = save_term
109 let &ttymouse = save_ttymouse
110 call test_override('no_query_mouse', 0)
111 bwipe!
112endfunc
113
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200114" Test that <C-LeftMouse> jumps to help tag and <C-RightMouse> jumps back.
Bram Moolenaar297bec02020-07-14 22:11:04 +0200115" Also test for g<LeftMouse> and g<RightMouse>.
116func Test_xterm_mouse_tagjump()
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200117 let save_mouse = &mouse
118 let save_term = &term
119 let save_ttymouse = &ttymouse
120 set mouse=a term=xterm
121
Bram Moolenaar515545e2020-03-22 14:08:59 +0100122 for ttymouse_val in g:Ttymouse_values
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200123 let msg = 'ttymouse=' .. ttymouse_val
124 exe 'set ttymouse=' .. ttymouse_val
125 help
126 /usr_02.txt
127 norm! zt
Bram Moolenaar297bec02020-07-14 22:11:04 +0200128
129 " CTRL-left click to jump to a tag
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200130 let row = 1
131 let col = 1
132 call MouseCtrlLeftClick(row, col)
133 call MouseLeftRelease(row, col)
134 call assert_match('usr_02.txt$', bufname('%'), msg)
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200135 call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg)
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200136
Bram Moolenaar297bec02020-07-14 22:11:04 +0200137 " CTRL-right click to pop a tag
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200138 call MouseCtrlRightClick(row, col)
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200139 call MouseRightRelease(row, col)
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200140 call assert_match('help.txt$', bufname('%'), msg)
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200141 call assert_equal('|usr_02.txt|', expand('<cWORD>'), msg)
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200142
Bram Moolenaar297bec02020-07-14 22:11:04 +0200143 " Jump to a tag
144 exe "normal \<C-]>"
145 call assert_match('usr_02.txt$', bufname('%'), msg)
146 call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg)
147
148 " Use CTRL-right click in insert mode to pop the tag
149 new
150 let str = 'iHello' .. MouseCtrlRightClickCode(row, col)
151 \ .. MouseRightReleaseCode(row, col) .. "\<C-C>"
Bram Moolenaar2764d062020-07-18 12:59:19 +0200152 call assert_fails('call feedkeys(str, "Lx!")', 'E37:', msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200153 close!
154
155 " CTRL-right click with a count
156 let str = "4" .. MouseCtrlRightClickCode(row, col)
157 \ .. MouseRightReleaseCode(row, col)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200158 call assert_fails('call feedkeys(str, "Lx!")', 'E555:', msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200159 call assert_match('help.txt$', bufname('%'), msg)
160 call assert_equal(1, line('.'), msg)
161
162 " g<LeftMouse> to jump to a tag
163 /usr_02.txt
164 norm! zt
165 call test_setmouse(row, col)
166 exe "normal g\<LeftMouse>"
167 call assert_match('usr_02.txt$', bufname('%'), msg)
168 call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg)
169
170 " g<RightMouse> to pop to a tag
171 call test_setmouse(row, col)
172 exe "normal g\<RightMouse>"
173 call assert_match('help.txt$', bufname('%'), msg)
174 call assert_equal('|usr_02.txt|', expand('<cWORD>'), msg)
175
176 %bw!
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200177 endfor
178
179 let &mouse = save_mouse
180 let &term = save_term
181 let &ttymouse = save_ttymouse
182endfunc
183
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200184func Test_term_mouse_middle_click()
Bram Moolenaar52992fe2019-08-12 14:20:33 +0200185 CheckFeature clipboard_working
Bram Moolenaar564344a2019-04-28 13:00:12 +0200186
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200187 new
188 let save_mouse = &mouse
189 let save_term = &term
190 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200191 call test_override('no_query_mouse', 1)
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200192 let save_quotestar = @*
Bram Moolenaar297bec02020-07-14 22:11:04 +0200193 let save_quoteplus = @+
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200194 set mouse=a term=xterm
195
Bram Moolenaar515545e2020-03-22 14:08:59 +0100196 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200197 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200198 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200199 call setline(1, ['123456789', '123456789'])
Bram Moolenaar297bec02020-07-14 22:11:04 +0200200 let @* = 'abc'
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200201
202 " Middle-click in the middle of the line pastes text where clicked.
203 let row = 1
204 let col = 6
205 call MouseMiddleClick(row, col)
206 call MouseMiddleRelease(row, col)
207 call assert_equal(['12345abc6789', '123456789'], getline(1, '$'), msg)
208
209 " Middle-click beyond end of the line pastes text at the end of the line.
210 let col = 20
211 call MouseMiddleClick(row, col)
212 call MouseMiddleRelease(row, col)
213 call assert_equal(['12345abc6789abc', '123456789'], getline(1, '$'), msg)
214
215 " Middle-click beyond the last line pastes in the last line.
216 let row = 5
217 let col = 3
218 call MouseMiddleClick(row, col)
219 call MouseMiddleRelease(row, col)
220 call assert_equal(['12345abc6789abc', '12abc3456789'], getline(1, '$'), msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200221
222 " Middle mouse click in operator pending mode beeps
223 call assert_beeps('exe "normal c\<MiddleMouse>"')
224
225 " Clicking middle mouse in visual mode, yanks the selection and pastes the
226 " clipboard contents
227 let save_clipboard = &clipboard
228 set clipboard=
229 let @" = ''
230 call cursor(1, 1)
231 call feedkeys("v3l" ..
232 \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7), 'Lx!')
233 call assert_equal(['12345abc6789abc', '12abc3abc456789'],
234 \ getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200235 call assert_equal('1234', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200236 let &clipboard = save_clipboard
237
238 " Clicking middle mouse in select mode, replaces the selected text with
239 " the clipboard contents
240 let @+ = 'xyz'
241 call cursor(1, 3)
242 exe "normal gh\<Right>\<Right>\<MiddleMouse>"
243 call assert_equal(['12xyzabc6789abc', '12abc3abc456789'],
244 \ getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200245
246 " Prefixing middle click with [ or ] fixes the indent after pasting.
247 %d
248 call setline(1, " one two")
249 call setreg('r', 'red blue', 'l')
250 call test_setmouse(1, 5)
251 exe "normal \"r[\<MiddleMouse>"
252 call assert_equal(' red blue', getline(1), msg)
253 call test_setmouse(2, 5)
254 exe "normal \"r]\<MiddleMouse>"
255 call assert_equal(' red blue', getline(3), msg)
256 %d
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200257 endfor
258
259 let &mouse = save_mouse
260 let &term = save_term
261 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200262 call test_override('no_query_mouse', 0)
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200263 let @* = save_quotestar
Bram Moolenaar297bec02020-07-14 22:11:04 +0200264 let @+ = save_quotestar
Bram Moolenaarc1b81602019-04-27 19:11:35 +0200265 bwipe!
266endfunc
267
Bram Moolenaar297bec02020-07-14 22:11:04 +0200268" If clipboard is not working, then clicking the middle mouse button in visual
269" mode, will copy and paste the selected text.
270func Test_term_mouse_middle_click_no_clipboard()
271 if has('clipboard_working')
272 throw 'Skipped: clipboard support works'
Bram Moolenaar297bec02020-07-14 22:11:04 +0200273 endif
274 new
275 let save_mouse = &mouse
276 let save_term = &term
277 let save_ttymouse = &ttymouse
278 call test_override('no_query_mouse', 1)
279 set mouse=a term=xterm
280
281 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
282 let msg = 'ttymouse=' .. ttymouse_val
283 exe 'set ttymouse=' .. ttymouse_val
284 call setline(1, ['123456789', '123456789'])
285
286 " Clicking middle mouse in visual mode, yanks the selection and pastes it
287 call cursor(1, 1)
288 call feedkeys("v3l" ..
289 \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7), 'Lx!')
290 call assert_equal(['123456789', '1234561234789'],
291 \ getline(1, '$'), msg)
292 endfor
293
294 call test_override('no_query_mouse', 0)
295 let &ttymouse = save_ttymouse
296 let &term = save_term
297 let &mouse = save_mouse
298 close!
299endfunc
300
301func Test_term_mouse_middle_click_insert_mode()
302 CheckFeature clipboard_working
303
304 new
305 let save_mouse = &mouse
306 let save_term = &term
307 let save_ttymouse = &ttymouse
308 call test_override('no_query_mouse', 1)
309 set mouse=a term=xterm
310
311 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
312 let msg = 'ttymouse=' .. ttymouse_val
313 exe 'set ttymouse=' .. ttymouse_val
314 call setline(1, ['123456789', '123456789'])
315 let @* = 'abc'
316
Dominique Pelle923dce22021-11-21 11:36:04 +0000317 " Middle-click in insert mode doesn't move the cursor but inserts the
318 " contents of a register
Bram Moolenaar297bec02020-07-14 22:11:04 +0200319 call cursor(1, 4)
320 call feedkeys('i' ..
321 \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7) ..
322 \ "\<C-C>", 'Lx!')
323 call assert_equal(['123abc456789', '123456789'],
324 \ getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200325 call assert_equal([1, 6], [line('.'), col('.')], msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200326
327 " Middle-click in replace mode
328 call cursor(1, 1)
329 call feedkeys('$R' ..
330 \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7) ..
331 \ "\<C-C>", 'Lx!')
332 call assert_equal(['123abc45678abc', '123456789'],
333 \ getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200334 call assert_equal([1, 14], [line('.'), col('.')], msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +0200335 endfor
336
337 let &mouse = save_mouse
338 let &term = save_term
339 let &ttymouse = save_ttymouse
340 call test_override('no_query_mouse', 0)
341 close!
342endfunc
343
344" Test for switching window using mouse in insert mode
345func Test_term_mouse_switch_win_insert_mode()
346 5new
347 let save_mouse = &mouse
348 let save_term = &term
349 let save_ttymouse = &ttymouse
350 call test_override('no_query_mouse', 1)
351 set mouse=a term=xterm ttymouse=xterm2
352
353 call feedkeys('ivim' ..
354 \ MouseLeftClickCode(8, 6) .. MouseLeftReleaseCode(8, 6) ..
355 \ "\<C-C>", 'Lx!')
356 call assert_equal(2, winnr())
357 wincmd w
358 call assert_equal('n', mode())
359 call assert_equal(['vim'], getline(1, '$'))
360
361 let &mouse = save_mouse
362 let &term = save_term
363 let &ttymouse = save_ttymouse
364 call test_override('no_query_mouse', 0)
365 close!
366endfunc
367
Dominique Pelle923dce22021-11-21 11:36:04 +0000368" Test for using the mouse to increase the height of the cmdline window
Bram Moolenaar297bec02020-07-14 22:11:04 +0200369func Test_mouse_cmdwin_resize()
Bram Moolenaar21829c52021-01-26 22:42:21 +0100370 CheckFeature cmdwin
371
Bram Moolenaar297bec02020-07-14 22:11:04 +0200372 let save_mouse = &mouse
373 let save_term = &term
374 let save_ttymouse = &ttymouse
375 call test_override('no_query_mouse', 1)
376 set mouse=a term=xterm ttymouse=xterm2
377 5new
378 redraw!
379
380 let h = 0
381 let row = &lines - &cmdwinheight - 2
382 call feedkeys("q:" ..
383 \ MouseLeftClickCode(row, 1) ..
384 \ MouseLeftDragCode(row - 1, 1) ..
385 \ MouseLeftReleaseCode(row - 2, 1) ..
386 \ "alet h = \<C-R>=winheight(0)\<CR>\<CR>", 'Lx!')
387 call assert_equal(&cmdwinheight + 2, h)
388
389 let &mouse = save_mouse
390 let &term = save_term
391 let &ttymouse = save_ttymouse
392 call test_override('no_query_mouse', 0)
393 close!
394endfunc
395
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200396" TODO: for unclear reasons this test fails if it comes after
397" Test_xterm_mouse_ctrl_click()
398func Test_1xterm_mouse_wheel()
Bram Moolenaar049736f2019-04-07 21:55:07 +0200399 new
400 let save_mouse = &mouse
401 let save_term = &term
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200402 let save_wrap = &wrap
Bram Moolenaar049736f2019-04-07 21:55:07 +0200403 let save_ttymouse = &ttymouse
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200404 set mouse=a term=xterm nowrap
405 call setline(1, range(100000000000000, 100000000000100))
Bram Moolenaar049736f2019-04-07 21:55:07 +0200406
Bram Moolenaar515545e2020-03-22 14:08:59 +0100407 for ttymouse_val in g:Ttymouse_values
Bram Moolenaar49452192019-04-17 16:27:02 +0200408 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200409 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200410 go
Bram Moolenaar49452192019-04-17 16:27:02 +0200411 call assert_equal(1, line('w0'), msg)
412 call assert_equal([0, 1, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200413
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200414 call MouseWheelDown(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200415 call assert_equal(4, line('w0'), msg)
416 call assert_equal([0, 4, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200417
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200418 call MouseWheelDown(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200419 call assert_equal(7, line('w0'), msg)
420 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200421
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200422 call MouseWheelUp(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200423 call assert_equal(4, line('w0'), msg)
424 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaar049736f2019-04-07 21:55:07 +0200425
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200426 call MouseWheelUp(1, 1)
Bram Moolenaar49452192019-04-17 16:27:02 +0200427 call assert_equal(1, line('w0'), msg)
428 call assert_equal([0, 7, 1, 0], getpos('.'), msg)
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200429
430 if has('gui')
431 " Horizontal wheel scrolling currently only works when vim is
432 " compiled with gui enabled.
433 call MouseWheelRight(1, 1)
434 call assert_equal(7, 1 + virtcol(".") - wincol(), msg)
435 call assert_equal([0, 7, 7, 0], getpos('.'), msg)
436
437 call MouseWheelRight(1, 1)
438 call assert_equal(13, 1 + virtcol(".") - wincol(), msg)
439 call assert_equal([0, 7, 13, 0], getpos('.'), msg)
440
441 call MouseWheelLeft(1, 1)
442 call assert_equal(7, 1 + virtcol(".") - wincol(), msg)
443 call assert_equal([0, 7, 13, 0], getpos('.'), msg)
444
445 call MouseWheelLeft(1, 1)
446 call assert_equal(1, 1 + virtcol(".") - wincol(), msg)
447 call assert_equal([0, 7, 13, 0], getpos('.'), msg)
448 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200449 endfor
Bram Moolenaar049736f2019-04-07 21:55:07 +0200450
451 let &mouse = save_mouse
452 let &term = save_term
Bram Moolenaard58d4f92020-07-01 15:49:29 +0200453 let &wrap = save_wrap
Bram Moolenaar049736f2019-04-07 21:55:07 +0200454 let &ttymouse = save_ttymouse
455 bwipe!
456endfunc
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200457
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200458" Test that dragging beyond the window (at the bottom and at the top)
Bram Moolenaarf19f8d12019-12-18 19:36:23 +0100459" scrolls window content by the number of lines beyond the window.
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200460func Test_term_mouse_drag_beyond_window()
461 let save_mouse = &mouse
462 let save_term = &term
463 let save_ttymouse = &ttymouse
464 call test_override('no_query_mouse', 1)
465 set mouse=a term=xterm
466 let col = 1
467 call setline(1, range(1, 100))
468
469 " Split into 3 windows, and go into the middle window
470 " so we test dragging mouse below and above the window.
471 2split
472 wincmd j
473 2split
474
Bram Moolenaar515545e2020-03-22 14:08:59 +0100475 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarb4367b72019-10-01 14:19:07 +0200476 let msg = 'ttymouse=' .. ttymouse_val
477 exe 'set ttymouse=' .. ttymouse_val
478
479 " Line #10 at the top.
480 norm! 10zt
481 redraw
482 call assert_equal(10, winsaveview().topline, msg)
483 call assert_equal(2, winheight(0), msg)
484
485 let row = 4
486 call MouseLeftClick(row, col)
487 call assert_equal(10, winsaveview().topline, msg)
488
489 " Drag downwards. We're still in the window so topline should
490 " not change yet.
491 let row += 1
492 call MouseLeftDrag(row, col)
493 call assert_equal(10, winsaveview().topline, msg)
494
495 " We now leave the window at the bottom, so the window content should
496 " scroll by 1 line, then 2 lines (etc) as we drag further away.
497 let row += 1
498 call MouseLeftDrag(row, col)
499 call assert_equal(11, winsaveview().topline, msg)
500
501 let row += 1
502 call MouseLeftDrag(row, col)
503 call assert_equal(13, winsaveview().topline, msg)
504
505 " Now drag upwards.
506 let row -= 1
507 call MouseLeftDrag(row, col)
508 call assert_equal(14, winsaveview().topline, msg)
509
510 " We're now back in the window so the topline should not change.
511 let row -= 1
512 call MouseLeftDrag(row, col)
513 call assert_equal(14, winsaveview().topline, msg)
514
515 let row -= 1
516 call MouseLeftDrag(row, col)
517 call assert_equal(14, winsaveview().topline, msg)
518
519 " We now leave the window at the top so the window content should
520 " scroll by 1 line, then 2, then 3 (etc) in the opposite direction.
521 let row -= 1
522 call MouseLeftDrag(row, col)
523 call assert_equal(13, winsaveview().topline, msg)
524
525 let row -= 1
526 call MouseLeftDrag(row, col)
527 call assert_equal(11, winsaveview().topline, msg)
528
529 let row -= 1
530 call MouseLeftDrag(row, col)
531 call assert_equal(8, winsaveview().topline, msg)
532
533 call MouseLeftRelease(row, col)
534 call assert_equal(8, winsaveview().topline, msg)
535 call assert_equal(2, winheight(0), msg)
536 endfor
537
538 let &mouse = save_mouse
539 let &term = save_term
540 let &ttymouse = save_ttymouse
541 call test_override('no_query_mouse', 0)
542 bwipe!
543endfunc
544
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200545func Test_term_mouse_drag_window_separator()
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200546 let save_mouse = &mouse
547 let save_term = &term
548 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200549 call test_override('no_query_mouse', 1)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200550 set mouse=a term=xterm
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200551
Bram Moolenaar515545e2020-03-22 14:08:59 +0100552 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200553 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200554 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200555
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200556 " Split horizontally and test dragging the horizontal window separator.
557 split
558 let rowseparator = winheight(0) + 1
559 let row = rowseparator
560 let col = 1
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200561
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200562 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
563 if ttymouse_val !=# 'xterm2' || row <= 223
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200564 call MouseLeftClick(row, col)
565 let row -= 1
566 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200567 call assert_equal(rowseparator - 1, winheight(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200568 let row += 1
569 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200570 call assert_equal(rowseparator, winheight(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200571 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200572 call assert_equal(rowseparator, winheight(0) + 1, msg)
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200573 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200574 bwipe!
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200575
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200576 " Split vertically and test dragging the vertical window separator.
577 vsplit
578 let colseparator = winwidth(0) + 1
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200579 let row = 1
580 let col = colseparator
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200581
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200582 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
583 if ttymouse_val !=# 'xterm2' || col <= 223
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200584 call MouseLeftClick(row, col)
585 let col -= 1
586 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200587 call assert_equal(colseparator - 1, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200588 let col += 1
589 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200590 call assert_equal(colseparator, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200591 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200592 call assert_equal(colseparator, winwidth(0) + 1, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200593 endif
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200594 bwipe!
595 endfor
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200596
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200597 let &mouse = save_mouse
598 let &term = save_term
599 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200600 call test_override('no_query_mouse', 0)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200601endfunc
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200602
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200603func Test_term_mouse_drag_statusline()
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200604 let save_mouse = &mouse
605 let save_term = &term
606 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200607 call test_override('no_query_mouse', 1)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200608 let save_laststatus = &laststatus
609 set mouse=a term=xterm laststatus=2
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200610
Bram Moolenaar515545e2020-03-22 14:08:59 +0100611 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200612 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200613 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200614
Bram Moolenaar49452192019-04-17 16:27:02 +0200615 call assert_equal(1, &cmdheight, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200616 let rowstatusline = winheight(0) + 1
617 let row = rowstatusline
618 let col = 1
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200619
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200620 if ttymouse_val ==# 'xterm2' && row > 223
621 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
Bram Moolenaarc8b3dda2019-04-12 21:42:52 +0200622 continue
623 endif
624
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200625 call MouseLeftClick(row, col)
626 let row -= 1
627 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200628 call assert_equal(2, &cmdheight, msg)
629 call assert_equal(rowstatusline - 1, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200630 let row += 1
631 call MouseLeftDrag(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200632 call assert_equal(1, &cmdheight, msg)
633 call assert_equal(rowstatusline, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200634 call MouseLeftRelease(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200635 call assert_equal(1, &cmdheight, msg)
636 call assert_equal(rowstatusline, winheight(0) + 1, msg)
Bram Moolenaar3fbd2d72019-04-11 23:56:16 +0200637 endfor
638
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200639 let &mouse = save_mouse
640 let &term = save_term
641 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200642 call test_override('no_query_mouse', 0)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200643 let &laststatus = save_laststatus
644endfunc
645
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200646func Test_term_mouse_click_tab()
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200647 let save_mouse = &mouse
648 let save_term = &term
649 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200650 call test_override('no_query_mouse', 1)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200651 set mouse=a term=xterm
652 let row = 1
653
Bram Moolenaar515545e2020-03-22 14:08:59 +0100654 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
Bram Moolenaar49452192019-04-17 16:27:02 +0200655 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200656 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200657 e Xfoo
658 tabnew Xbar
659
660 let a = split(execute(':tabs'), "\n")
661 call assert_equal(['Tab page 1',
662 \ ' Xfoo',
663 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200664 \ '> Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200665
666 " Test clicking on tab names in the tabline at the top.
667 let col = 2
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200668 redraw
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200669 call MouseLeftClick(row, col)
670 call MouseLeftRelease(row, col)
671 let a = split(execute(':tabs'), "\n")
672 call assert_equal(['Tab page 1',
673 \ '> Xfoo',
674 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200675 \ ' Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200676
677 let col = 9
678 call MouseLeftClick(row, col)
679 call MouseLeftRelease(row, col)
680 let a = split(execute(':tabs'), "\n")
681 call assert_equal(['Tab page 1',
682 \ ' Xfoo',
683 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200684 \ '> Xbar'], a, msg)
Bram Moolenaarca57ab52019-04-13 14:53:16 +0200685
686 %bwipe!
687 endfor
688
689 let &mouse = save_mouse
690 let &term = save_term
691 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200692 call test_override('no_query_mouse', 0)
Bram Moolenaar3fb01a52019-04-09 21:52:02 +0200693endfunc
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200694
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200695func Test_term_mouse_click_X_to_close_tab()
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200696 let save_mouse = &mouse
697 let save_term = &term
698 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200699 call test_override('no_query_mouse', 1)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200700 set mouse=a term=xterm
701 let row = 1
702 let col = &columns
703
Bram Moolenaar515545e2020-03-22 14:08:59 +0100704 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +0200705 if ttymouse_val ==# 'xterm2' && col > 223
706 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200707 continue
708 endif
Bram Moolenaar49452192019-04-17 16:27:02 +0200709 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200710 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200711 e Xtab1
712 tabnew Xtab2
713 tabnew Xtab3
714 tabn 2
715
716 let a = split(execute(':tabs'), "\n")
717 call assert_equal(['Tab page 1',
718 \ ' Xtab1',
719 \ 'Tab page 2',
720 \ '> Xtab2',
721 \ 'Tab page 3',
Bram Moolenaar49452192019-04-17 16:27:02 +0200722 \ ' Xtab3'], a, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200723
724 " Click on "X" in tabline to close current tab i.e. Xtab2.
725 redraw
726 call MouseLeftClick(row, col)
727 call MouseLeftRelease(row, col)
728 let a = split(execute(':tabs'), "\n")
729 call assert_equal(['Tab page 1',
730 \ ' Xtab1',
731 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200732 \ '> Xtab3'], a, msg)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200733
734 %bwipe!
735 endfor
736
737 let &mouse = save_mouse
738 let &term = save_term
739 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200740 call test_override('no_query_mouse', 0)
Bram Moolenaar39f76c62019-04-13 22:13:23 +0200741endfunc
Bram Moolenaare3e38282019-04-15 20:55:31 +0200742
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200743func Test_term_mouse_drag_to_move_tab()
Bram Moolenaare3e38282019-04-15 20:55:31 +0200744 let save_mouse = &mouse
745 let save_term = &term
746 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200747 call test_override('no_query_mouse', 1)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200748 " Set 'mousetime' to 1 to avoid recognizing a double-click in the loop
749 set mouse=a term=xterm mousetime=1
750 let row = 1
751
Bram Moolenaar515545e2020-03-22 14:08:59 +0100752 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200753 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200754 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaare3e38282019-04-15 20:55:31 +0200755 e Xtab1
756 tabnew Xtab2
757
758 let a = split(execute(':tabs'), "\n")
759 call assert_equal(['Tab page 1',
760 \ ' Xtab1',
761 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200762 \ '> Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200763 redraw
764
765 " Click in tab2 and drag it to tab1.
766 " Check getcharmod() to verify that click is not
767 " interpreted as a spurious double-click.
768 call MouseLeftClick(row, 10)
Bram Moolenaar49452192019-04-17 16:27:02 +0200769 call assert_equal(0, getcharmod(), msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200770 for col in [9, 8, 7, 6]
771 call MouseLeftDrag(row, col)
772 endfor
773 call MouseLeftRelease(row, col)
774 let a = split(execute(':tabs'), "\n")
775 call assert_equal(['Tab page 1',
776 \ '> Xtab2',
777 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200778 \ ' Xtab1'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200779
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100780 " Click elsewhere so that click in next iteration is not
781 " interpreted as unwanted double-click.
782 call MouseLeftClick(row, 11)
783 call MouseLeftRelease(row, 11)
784
Bram Moolenaare3e38282019-04-15 20:55:31 +0200785 %bwipe!
786 endfor
787
788 let &mouse = save_mouse
789 let &term = save_term
790 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200791 call test_override('no_query_mouse', 0)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200792 set mousetime&
793endfunc
794
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200795func Test_term_mouse_double_click_to_create_tab()
Bram Moolenaare3e38282019-04-15 20:55:31 +0200796 let save_mouse = &mouse
797 let save_term = &term
798 let save_ttymouse = &ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200799 call test_override('no_query_mouse', 1)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200800 " Set 'mousetime' to a small value, so that double-click works but we don't
801 " have to wait long to avoid a triple-click.
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100802 set mouse=a term=xterm mousetime=200
Bram Moolenaare3e38282019-04-15 20:55:31 +0200803 let row = 1
804 let col = 10
805
Bram Moolenaar515545e2020-03-22 14:08:59 +0100806 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaar49452192019-04-17 16:27:02 +0200807 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar1ee36d62019-05-01 23:13:56 +0200808 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaare3e38282019-04-15 20:55:31 +0200809 e Xtab1
810 tabnew Xtab2
811
812 let a = split(execute(':tabs'), "\n")
813 call assert_equal(['Tab page 1',
814 \ ' Xtab1',
815 \ 'Tab page 2',
Bram Moolenaar49452192019-04-17 16:27:02 +0200816 \ '> Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200817
818 redraw
819 call MouseLeftClick(row, col)
820 " Check getcharmod() to verify that first click is not
821 " interpreted as a spurious double-click.
Bram Moolenaar49452192019-04-17 16:27:02 +0200822 call assert_equal(0, getcharmod(), msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200823 call MouseLeftRelease(row, col)
824 call MouseLeftClick(row, col)
Bram Moolenaar49452192019-04-17 16:27:02 +0200825 call assert_equal(32, getcharmod(), msg) " double-click
Bram Moolenaare3e38282019-04-15 20:55:31 +0200826 call MouseLeftRelease(row, col)
827 let a = split(execute(':tabs'), "\n")
828 call assert_equal(['Tab page 1',
829 \ ' Xtab1',
830 \ 'Tab page 2',
831 \ '> [No Name]',
832 \ 'Tab page 3',
Bram Moolenaar49452192019-04-17 16:27:02 +0200833 \ ' Xtab2'], a, msg)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200834
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100835 " Click elsewhere so that click in next iteration is not
836 " interpreted as unwanted double click.
837 call MouseLeftClick(row, col + 1)
838 call MouseLeftRelease(row, col + 1)
839
Bram Moolenaare3e38282019-04-15 20:55:31 +0200840 %bwipe!
841 endfor
842
843 let &mouse = save_mouse
844 let &term = save_term
845 let &ttymouse = save_ttymouse
Bram Moolenaar92fd5992019-05-02 23:00:22 +0200846 call test_override('no_query_mouse', 0)
Bram Moolenaare3e38282019-04-15 20:55:31 +0200847 set mousetime&
848endfunc
Bram Moolenaar696d6372019-04-17 16:33:46 +0200849
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100850" Test double/triple/quadruple click in normal mode to visually select.
851func Test_term_mouse_multiple_clicks_to_visually_select()
852 let save_mouse = &mouse
853 let save_term = &term
854 let save_ttymouse = &ttymouse
855 call test_override('no_query_mouse', 1)
Bram Moolenaar2a5c61a2020-12-30 14:59:23 +0100856
857 " 'mousetime' must be sufficiently large, or else the test is flaky when
858 " using a ssh connection with X forwarding; i.e. ssh -X (issue #7563).
859 set mouse=a term=xterm mousetime=600
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100860 new
861
Bram Moolenaar515545e2020-03-22 14:08:59 +0100862 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100863 let msg = 'ttymouse=' .. ttymouse_val
864 exe 'set ttymouse=' .. ttymouse_val
865 call setline(1, ['foo [foo bar] foo', 'foo'])
866
867 " Double-click on word should visually select the word.
868 call MouseLeftClick(1, 2)
869 call assert_equal(0, getcharmod(), msg)
870 call MouseLeftRelease(1, 2)
871 call MouseLeftClick(1, 2)
872 call assert_equal(32, getcharmod(), msg) " double-click
873 call MouseLeftRelease(1, 2)
874 call assert_equal('v', mode(), msg)
875 norm! r1
876 call assert_equal(['111 [foo bar] foo', 'foo'], getline(1, '$'), msg)
877
878 " Double-click on opening square bracket should visually
879 " select the whole [foo bar].
880 call MouseLeftClick(1, 5)
881 call assert_equal(0, getcharmod(), msg)
882 call MouseLeftRelease(1, 5)
883 call MouseLeftClick(1, 5)
884 call assert_equal(32, getcharmod(), msg) " double-click
885 call MouseLeftRelease(1, 5)
886 call assert_equal('v', mode(), msg)
887 norm! r2
888 call assert_equal(['111 222222222 foo', 'foo'], getline(1, '$'), msg)
889
890 " Triple-click should visually select the whole line.
891 call MouseLeftClick(1, 3)
892 call assert_equal(0, getcharmod(), msg)
893 call MouseLeftRelease(1, 3)
894 call MouseLeftClick(1, 3)
895 call assert_equal(32, getcharmod(), msg) " double-click
896 call MouseLeftRelease(1, 3)
897 call MouseLeftClick(1, 3)
898 call assert_equal(64, getcharmod(), msg) " triple-click
899 call MouseLeftRelease(1, 3)
900 call assert_equal('V', mode(), msg)
901 norm! r3
902 call assert_equal(['33333333333333333', 'foo'], getline(1, '$'), msg)
903
904 " Quadruple-click should start visual block select.
905 call MouseLeftClick(1, 2)
906 call assert_equal(0, getcharmod(), msg)
907 call MouseLeftRelease(1, 2)
908 call MouseLeftClick(1, 2)
909 call assert_equal(32, getcharmod(), msg) " double-click
910 call MouseLeftRelease(1, 2)
911 call MouseLeftClick(1, 2)
912 call assert_equal(64, getcharmod(), msg) " triple-click
913 call MouseLeftRelease(1, 2)
914 call MouseLeftClick(1, 2)
915 call assert_equal(96, getcharmod(), msg) " quadruple-click
916 call MouseLeftRelease(1, 2)
917 call assert_equal("\<c-v>", mode(), msg)
918 norm! r4
919 call assert_equal(['34333333333333333', 'foo'], getline(1, '$'), msg)
Bram Moolenaar2764d062020-07-18 12:59:19 +0200920
921 " Double-click on a space character should visually select all the
922 " consecutive space characters.
923 %d
924 call setline(1, ' one two')
925 call MouseLeftClick(1, 2)
926 call MouseLeftRelease(1, 2)
927 call MouseLeftClick(1, 2)
928 call MouseLeftRelease(1, 2)
929 call assert_equal('v', mode(), msg)
930 norm! r1
931 call assert_equal(['1111one two'], getline(1, '$'), msg)
932
933 " Double-click on a word with exclusive selection
934 set selection=exclusive
935 let @" = ''
936 call MouseLeftClick(1, 10)
937 call MouseLeftRelease(1, 10)
938 call MouseLeftClick(1, 10)
939 call MouseLeftRelease(1, 10)
940 norm! y
941 call assert_equal('two', @", msg)
942
943 " Double click to select a block of text with exclusive selection
944 %d
945 call setline(1, 'one (two) three')
946 call MouseLeftClick(1, 5)
947 call MouseLeftRelease(1, 5)
948 call MouseLeftClick(1, 5)
949 call MouseLeftRelease(1, 5)
950 norm! y
951 call assert_equal(5, col("'<"), msg)
952 call assert_equal(10, col("'>"), msg)
953
954 call MouseLeftClick(1, 9)
955 call MouseLeftRelease(1, 9)
956 call MouseLeftClick(1, 9)
957 call MouseLeftRelease(1, 9)
958 norm! y
959 call assert_equal(5, col("'<"), msg)
960 call assert_equal(10, col("'>"), msg)
961 set selection&
962
963 " Click somewhere else so that the clicks above is not combined with the
964 " clicks in the next iteration.
965 call MouseRightClick(3, 10)
966 call MouseRightRelease(3, 10)
Bram Moolenaarf36a2c72019-11-16 18:57:16 +0100967 endfor
968
969 let &mouse = save_mouse
970 let &term = save_term
971 let &ttymouse = save_ttymouse
972 set mousetime&
973 call test_override('no_query_mouse', 0)
974 bwipe!
975endfunc
976
Bram Moolenaar2764d062020-07-18 12:59:19 +0200977" Test for selecting text in visual blockwise mode using Alt-LeftClick
978func Test_mouse_alt_leftclick()
979 let save_mouse = &mouse
980 let save_term = &term
981 let save_ttymouse = &ttymouse
982 call test_override('no_query_mouse', 1)
983 set mouse=a term=xterm mousetime=200
984 set mousemodel=popup
985 new
986 call setline(1, 'one (two) three')
987
988 for ttymouse_val in g:Ttymouse_values
989 let msg = 'ttymouse=' .. ttymouse_val
990 exe 'set ttymouse=' .. ttymouse_val
991
992 " Left click with the Alt modifier key should extend the selection in
993 " blockwise visual mode.
994 let @" = ''
995 call MouseLeftClick(1, 3)
996 call MouseLeftRelease(1, 3)
997 call MouseAltLeftClick(1, 11)
998 call MouseLeftRelease(1, 11)
999 call assert_equal("\<C-V>", mode(), msg)
1000 normal! y
1001 call assert_equal('e (two) t', @")
1002 endfor
1003
1004 let &mouse = save_mouse
1005 let &term = save_term
1006 let &ttymouse = save_ttymouse
1007 set mousetime& mousemodel&
1008 call test_override('no_query_mouse', 0)
1009 close!
1010endfunc
1011
Bram Moolenaar696d6372019-04-17 16:33:46 +02001012func Test_xterm_mouse_click_in_fold_columns()
1013 new
1014 let save_mouse = &mouse
1015 let save_term = &term
1016 let save_ttymouse = &ttymouse
1017 let save_foldcolumn = &foldcolumn
Bram Moolenaar2b00b9b2019-04-17 17:08:27 +02001018 set mouse=a term=xterm foldcolumn=3 ttymouse=xterm2
Bram Moolenaar696d6372019-04-17 16:33:46 +02001019
1020 " Create 2 nested folds.
1021 call setline(1, range(1, 7))
1022 2,6fold
1023 norm! zR
1024 4,5fold
1025 call assert_equal([-1, -1, -1, 4, 4, -1, -1],
1026 \ map(range(1, 7), 'foldclosed(v:val)'))
1027
1028 " Click in "+" of inner fold in foldcolumn should open it.
1029 redraw
1030 let row = 4
1031 let col = 2
1032 call MouseLeftClick(row, col)
1033 call MouseLeftRelease(row, col)
1034 call assert_equal([-1, -1, -1, -1, -1, -1, -1],
1035 \ map(range(1, 7), 'foldclosed(v:val)'))
1036
1037 " Click in "-" of outer fold in foldcolumn should close it.
1038 redraw
1039 let row = 2
1040 let col = 1
1041 call MouseLeftClick(row, col)
1042 call MouseLeftRelease(row, col)
1043 call assert_equal([-1, 2, 2, 2, 2, 2, -1],
1044 \ map(range(1, 7), 'foldclosed(v:val)'))
1045 norm! zR
1046
1047 " Click in "|" of inner fold in foldcolumn should close it.
1048 redraw
1049 let row = 5
1050 let col = 2
1051 call MouseLeftClick(row, col)
1052 call MouseLeftRelease(row, col)
1053 call assert_equal([-1, -1, -1, 4, 4, -1, -1],
1054 \ map(range(1, 7), 'foldclosed(v:val)'))
1055
1056 let &foldcolumn = save_foldcolumn
1057 let &ttymouse = save_ttymouse
1058 let &term = save_term
1059 let &mouse = save_mouse
1060 bwipe!
1061endfunc
Bram Moolenaar66761db2019-06-05 22:07:51 +02001062
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001063" Left or right click in Ex command line sets position of the cursor.
1064func Test_term_mouse_click_in_cmdline_to_set_pos()
1065 let save_mouse = &mouse
1066 let save_term = &term
1067 let save_ttymouse = &ttymouse
1068 call test_override('no_query_mouse', 1)
1069 set mouse=a term=xterm
1070 let row = &lines
1071
Bram Moolenaar515545e2020-03-22 14:08:59 +01001072 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarab505b12020-03-23 19:28:44 +01001073 " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported.
1074 if ttymouse_val !=# 'xterm2' || row <= 223
1075 let msg = 'ttymouse=' .. ttymouse_val
1076 exe 'set ttymouse=' .. ttymouse_val
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001077
Bram Moolenaarab505b12020-03-23 19:28:44 +01001078
1079 call feedkeys(':"3456789'
1080 \ .. MouseLeftClickCode(row, 7)
1081 \ .. MouseLeftReleaseCode(row, 7) .. 'L'
1082 \ .. MouseRightClickCode(row, 4)
1083 \ .. MouseRightReleaseCode(row, 4) .. 'R'
1084 \ .. "\<CR>", 'Lx!')
1085 call assert_equal('"3R456L789', @:, msg)
1086 endif
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001087 endfor
1088
1089 let &mouse = save_mouse
1090 let &term = save_term
1091 let &ttymouse = save_ttymouse
1092 set mousetime&
1093 call test_override('no_query_mouse', 0)
1094endfunc
1095
1096" Middle click in command line pastes at position of cursor.
1097func Test_term_mouse_middle_click_in_cmdline_to_paste()
1098 CheckFeature clipboard_working
1099 let save_mouse = &mouse
1100 let save_term = &term
1101 let save_ttymouse = &ttymouse
1102 call test_override('no_query_mouse', 1)
1103 set mouse=a term=xterm
1104 let row = &lines
1105 " Column values does not matter, paste is done at position of cursor.
1106 let col = 1
1107 let @* = 'paste'
1108
Bram Moolenaar515545e2020-03-22 14:08:59 +01001109 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001110 let msg = 'ttymouse=' .. ttymouse_val
1111 exe 'set ttymouse=' .. ttymouse_val
1112
1113 call feedkeys(":\"->"
1114 \ .. MouseMiddleReleaseCode(row, col)
1115 \ .. MouseMiddleClickCode(row, col)
1116 \ .. "<-"
1117 \ .. MouseMiddleReleaseCode(row, col)
1118 \ .. MouseMiddleClickCode(row, col)
1119 \ .. "\<CR>", 'Lx!')
1120 call assert_equal('"->paste<-paste', @:, msg)
1121 endfor
1122
1123 let &mouse = save_mouse
1124 let &term = save_term
1125 let &ttymouse = save_ttymouse
1126 let @* = ''
1127 call test_override('no_query_mouse', 0)
1128endfunc
1129
Bram Moolenaar297bec02020-07-14 22:11:04 +02001130" Test for making sure S-Middlemouse doesn't do anything
1131func Test_term_mouse_shift_middle_click()
1132 new
1133 let save_mouse = &mouse
1134 let save_term = &term
1135 let save_ttymouse = &ttymouse
1136 call test_override('no_query_mouse', 1)
1137 set mouse=a term=xterm ttymouse=xterm2 mousemodel=
1138
1139 call test_setmouse(1, 1)
1140 exe "normal \<S-MiddleMouse>"
1141 call assert_equal([''], getline(1, '$'))
1142 call assert_equal(1, winnr())
1143
1144 let &mouse = save_mouse
1145 let &term = save_term
1146 let &ttymouse = save_ttymouse
1147 set mousemodel&
1148 call test_override('no_query_mouse', 0)
1149 close!
1150endfunc
1151
1152" Test for using mouse in visual mode
1153func Test_term_mouse_visual_mode()
1154 new
1155 let save_mouse = &mouse
1156 let save_term = &term
1157 let save_ttymouse = &ttymouse
1158 call test_override('no_query_mouse', 1)
1159 set term=xterm ttymouse=xterm2
1160
1161 " If visual mode is not present in 'mouse', then left click should not
1162 " do anything in visal mode.
1163 call setline(1, ['one two three four'])
1164 set mouse=nci
1165 call cursor(1, 5)
1166 let @" = ''
1167 call feedkeys("ve"
1168 \ .. MouseLeftClickCode(1, 15) .. MouseLeftReleaseCode(1, 15)
1169 \ .. 'y', 'Lx!')
1170 call assert_equal(5, col('.'))
1171 call assert_equal('two', @")
1172
1173 " Pressing right click in visual mode should change the visual selection
1174 " if 'mousemodel' doesn't contain popup.
1175 " Right click after the visual selection
1176 set mousemodel=
1177 set mouse=a
1178 call test_setmouse(1, 13)
1179 exe "normal 5|ve\<RightMouse>y"
1180 call assert_equal('two three', @")
1181 call assert_equal(5, col('.'))
1182
1183 " Right click before the visual selection
1184 call test_setmouse(1, 9)
1185 exe "normal 15|ve\<RightMouse>y"
1186 call assert_equal('three four', @")
1187 call assert_equal(9, col('.'))
1188
Bram Moolenaar2764d062020-07-18 12:59:19 +02001189 " Right click inside the selection closer to the start of the selection
1190 call test_setmouse(1, 7)
1191 exe "normal 5|vee\<RightMouse>lly"
1192 call assert_equal('three', @")
1193 call assert_equal(9, col('.'))
1194 call assert_equal(9, col("'<"))
1195 call assert_equal(13, col("'>"))
1196
1197 " Right click inside the selection closer to the end of the selection
1198 call test_setmouse(1, 11)
1199 exe "normal 5|vee\<RightMouse>ly"
1200 call assert_equal('two thre', @")
1201 call assert_equal(5, col('.'))
1202 call assert_equal(5, col("'<"))
1203 call assert_equal(12, col("'>"))
1204
1205 " Multi-line selection. Right click inside thse selection.
1206 call setline(1, repeat(['aaaaaa'], 7))
Bram Moolenaar297bec02020-07-14 22:11:04 +02001207 call test_setmouse(3, 1)
1208 exe "normal ggVG\<RightMouse>y"
1209 call assert_equal(3, line("'<"))
Bram Moolenaar2764d062020-07-18 12:59:19 +02001210 call test_setmouse(5, 1)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001211 exe "normal ggVG\<RightMouse>y"
Bram Moolenaar2764d062020-07-18 12:59:19 +02001212 call assert_equal(5, line("'>"))
1213
1214 " Click right in the middle line of the selection
1215 call test_setmouse(4, 3)
1216 exe "normal ggVG$\<RightMouse>y"
1217 call assert_equal(4, line("'<"))
1218 call test_setmouse(4, 4)
1219 exe "normal ggVG$\<RightMouse>y"
Bram Moolenaar297bec02020-07-14 22:11:04 +02001220 call assert_equal(4, line("'>"))
1221
1222 set mousemodel&
1223 let &mouse = save_mouse
1224 let &term = save_term
1225 let &ttymouse = save_ttymouse
1226 call test_override('no_query_mouse', 0)
1227 close!
1228endfunc
1229
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001230" Test for displaying the popup menu using the right mouse click
Bram Moolenaar297bec02020-07-14 22:11:04 +02001231func Test_term_mouse_popup_menu()
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001232 CheckFeature menu
1233 new
1234 call setline(1, 'popup menu test')
1235 let save_mouse = &mouse
1236 let save_term = &term
1237 let save_ttymouse = &ttymouse
1238 let save_mousemodel = &mousemodel
1239 call test_override('no_query_mouse', 1)
1240 set mouse=a term=xterm mousemodel=popup
1241
1242 menu PopUp.foo :let g:menustr = 'foo'<CR>
1243 menu PopUp.bar :let g:menustr = 'bar'<CR>
1244 menu PopUp.baz :let g:menustr = 'baz'<CR>
1245
Bram Moolenaar515545e2020-03-22 14:08:59 +01001246 for ttymouse_val in g:Ttymouse_values
Bram Moolenaar2764d062020-07-18 12:59:19 +02001247 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001248 exe 'set ttymouse=' .. ttymouse_val
1249 let g:menustr = ''
1250 call feedkeys(MouseRightClickCode(1, 4)
1251 \ .. MouseRightReleaseCode(1, 4) .. "\<Down>\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001252 call assert_equal('bar', g:menustr, msg)
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01001253 endfor
1254
1255 unmenu PopUp
1256 let &mouse = save_mouse
1257 let &term = save_term
1258 let &ttymouse = save_ttymouse
1259 let &mousemodel = save_mousemodel
1260 call test_override('no_query_mouse', 0)
1261 close!
1262endfunc
1263
Bram Moolenaar297bec02020-07-14 22:11:04 +02001264" Test for 'mousemodel' set to popup_setpos to move the cursor where the popup
1265" menu is displayed.
1266func Test_term_mouse_popup_menu_setpos()
1267 CheckFeature menu
1268 5new
1269 call setline(1, ['the dish ran away with the spoon',
1270 \ 'the cow jumped over the moon' ])
1271 let save_mouse = &mouse
1272 let save_term = &term
1273 let save_ttymouse = &ttymouse
1274 let save_mousemodel = &mousemodel
1275 call test_override('no_query_mouse', 1)
1276 set mouse=a term=xterm mousemodel=popup_setpos
1277
1278 nmenu PopUp.foo :let g:menustr = 'foo'<CR>
1279 nmenu PopUp.bar :let g:menustr = 'bar'<CR>
1280 nmenu PopUp.baz :let g:menustr = 'baz'<CR>
1281 vmenu PopUp.foo y:<C-U>let g:menustr = 'foo'<CR>
1282 vmenu PopUp.bar y:<C-U>let g:menustr = 'bar'<CR>
1283 vmenu PopUp.baz y:<C-U>let g:menustr = 'baz'<CR>
1284
1285 for ttymouse_val in g:Ttymouse_values
Bram Moolenaar2764d062020-07-18 12:59:19 +02001286 let msg = 'ttymouse=' .. ttymouse_val
Bram Moolenaar297bec02020-07-14 22:11:04 +02001287 exe 'set ttymouse=' .. ttymouse_val
1288 let g:menustr = ''
1289 call cursor(1, 1)
1290 call feedkeys(MouseRightClickCode(1, 5)
1291 \ .. MouseRightReleaseCode(1, 5) .. "\<Down>\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001292 call assert_equal('bar', g:menustr, msg)
1293 call assert_equal([1, 5], [line('.'), col('.')], msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001294
1295 " Test for right click in visual mode inside the selection
1296 let @" = ''
1297 call cursor(1, 10)
1298 call feedkeys('vee' .. MouseRightClickCode(1, 12)
1299 \ .. MouseRightReleaseCode(1, 12) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001300 call assert_equal([1, 10], [line('.'), col('.')], msg)
1301 call assert_equal('ran away', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001302
1303 " Test for right click in visual mode before the selection
1304 let @" = ''
1305 call cursor(1, 10)
1306 call feedkeys('vee' .. MouseRightClickCode(1, 2)
1307 \ .. MouseRightReleaseCode(1, 2) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001308 call assert_equal([1, 2], [line('.'), col('.')], msg)
1309 call assert_equal('', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001310
1311 " Test for right click in visual mode after the selection
1312 let @" = ''
1313 call cursor(1, 10)
1314 call feedkeys('vee' .. MouseRightClickCode(1, 20)
1315 \ .. MouseRightReleaseCode(1, 20) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001316 call assert_equal([1, 20], [line('.'), col('.')], msg)
1317 call assert_equal('', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001318
1319 " Test for right click in block-wise visual mode inside the selection
1320 let @" = ''
1321 call cursor(1, 16)
1322 call feedkeys("\<C-V>j3l" .. MouseRightClickCode(2, 17)
1323 \ .. MouseRightReleaseCode(2, 17) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001324 call assert_equal([1, 16], [line('.'), col('.')], msg)
1325 call assert_equal("\<C-V>4", getregtype('"'), msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001326
1327 " Test for right click in block-wise visual mode outside the selection
1328 let @" = ''
1329 call cursor(1, 16)
1330 call feedkeys("\<C-V>j3l" .. MouseRightClickCode(2, 2)
1331 \ .. MouseRightReleaseCode(2, 2) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001332 call assert_equal([2, 2], [line('.'), col('.')], msg)
1333 call assert_equal('v', getregtype('"'), msg)
1334 call assert_equal('', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001335
1336 " Try clicking on the status line
1337 let @" = ''
1338 call cursor(1, 10)
1339 call feedkeys('vee' .. MouseRightClickCode(6, 2)
1340 \ .. MouseRightReleaseCode(6, 2) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001341 call assert_equal([1, 10], [line('.'), col('.')], msg)
1342 call assert_equal('ran away', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001343
1344 " Try clicking outside the window
1345 let @" = ''
1346 call cursor(7, 2)
1347 call feedkeys('vee' .. MouseRightClickCode(7, 2)
1348 \ .. MouseRightReleaseCode(7, 2) .. "\<Down>\<CR>", "x")
Bram Moolenaar2764d062020-07-18 12:59:19 +02001349 call assert_equal(2, winnr(), msg)
1350 call assert_equal('', @", msg)
Bram Moolenaar297bec02020-07-14 22:11:04 +02001351 wincmd w
1352 endfor
1353
1354 unmenu PopUp
1355 let &mouse = save_mouse
1356 let &term = save_term
1357 let &ttymouse = save_ttymouse
1358 let &mousemodel = save_mousemodel
1359 call test_override('no_query_mouse', 0)
1360 close!
1361endfunc
1362
1363" Test for searching for the word under the cursor using Shift-Right or
1364" Shift-Left click.
1365func Test_term_mouse_search()
1366 new
1367 let save_mouse = &mouse
1368 let save_term = &term
1369 let save_ttymouse = &ttymouse
1370 call test_override('no_query_mouse', 1)
1371 set mouse=a term=xterm ttymouse=xterm2
1372 set mousemodel=
1373
1374 " In normal mode, Shift-Left or Shift-Right click should search for the word
1375 " under the cursor.
1376 call setline(1, ['one two three four', 'four three two one'])
1377 call test_setmouse(1, 4)
1378 exe "normal \<S-LeftMouse>"
1379 call assert_equal([2, 12], [line('.'), col('.')])
1380 call test_setmouse(2, 16)
1381 exe "normal \<S-RightMouse>"
1382 call assert_equal([1, 1], [line('.'), col('.')])
1383
1384 " In visual mode, Shift-Left or Shift-Right click should search for the word
1385 " under the cursor and extend the selection.
1386 call test_setmouse(1, 4)
1387 exe "normal 4|ve\<S-LeftMouse>y"
1388 call assert_equal([2, 12], [line("'>"), col("'>")])
1389 call test_setmouse(2, 16)
1390 exe "normal 2G16|ve\<S-RightMouse>y"
1391 call assert_equal([1, 1], [line("'<"), col("'<")])
1392
1393 set mousemodel&
1394 let &mouse = save_mouse
1395 let &term = save_term
1396 let &ttymouse = save_ttymouse
1397 call test_override('no_query_mouse', 0)
1398 close!
1399endfunc
1400
1401" Test for selecting an entry in the quickfix/location list window using the
1402" mouse.
1403func Test_term_mouse_quickfix_window()
1404 let save_mouse = &mouse
1405 let save_term = &term
1406 let save_ttymouse = &ttymouse
1407 call test_override('no_query_mouse', 1)
1408 set mouse=a term=xterm ttymouse=xterm2
1409 set mousemodel=
1410
1411 cgetexpr "Xfile1:1:L1"
1412 copen 5
1413 call test_setmouse(&lines - 7, 1)
1414 exe "normal \<2-LeftMouse>"
1415 call assert_equal('Xfile1', @%)
1416 %bw!
1417
1418 lgetexpr "Xfile2:1:L1"
1419 lopen 5
1420 call test_setmouse(&lines - 7, 1)
1421 exe "normal \<2-LeftMouse>"
1422 call assert_equal('Xfile2', @%)
1423 %bw!
1424
1425 set mousemodel&
1426 let &mouse = save_mouse
1427 let &term = save_term
1428 let &ttymouse = save_ttymouse
1429 call test_override('no_query_mouse', 0)
1430endfunc
1431
Bram Moolenaar2764d062020-07-18 12:59:19 +02001432" Test for the 'h' flag in the 'mouse' option. Using mouse in the help window.
1433func Test_term_mouse_help_window()
1434 let save_mouse = &mouse
1435 let save_term = &term
1436 let save_ttymouse = &ttymouse
1437 call test_override('no_query_mouse', 1)
1438 set mouse=h term=xterm mousetime=200
1439
1440 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
1441 let msg = 'ttymouse=' .. ttymouse_val
1442 exe 'set ttymouse=' .. ttymouse_val
1443 help
1444 let @" = ''
1445 call MouseLeftClick(2, 5)
1446 call MouseLeftRelease(2, 5)
1447 call MouseLeftClick(1, 1)
1448 call MouseLeftDrag(1, 10)
1449 call MouseLeftRelease(1, 10)
1450 norm! y
1451 call assert_equal('*help.txt*', @", msg)
1452 helpclose
1453
1454 " Click somewhere else to make sure the left click above is not combined
1455 " with the next left click and treated as a double click
1456 call MouseRightClick(5, 10)
1457 call MouseRightRelease(5, 10)
1458 endfor
1459
1460 let &mouse = save_mouse
1461 let &term = save_term
1462 let &ttymouse = save_ttymouse
1463 set mousetime&
1464 call test_override('no_query_mouse', 0)
1465 %bw!
1466endfunc
1467
1468" Test for the translation of various mouse terminal codes
1469func Test_mouse_termcodes()
1470 let save_mouse = &mouse
1471 let save_term = &term
1472 let save_ttymouse = &ttymouse
1473 call test_override('no_query_mouse', 1)
1474 set mouse=a term=xterm mousetime=200
1475
1476 new
1477 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm
1478 let msg = 'ttymouse=' .. ttymouse_val
1479 exe 'set ttymouse=' .. ttymouse_val
1480
1481 let mouse_codes = [
1482 \ ["\<LeftMouse>", "<LeftMouse>"],
1483 \ ["\<MiddleMouse>", "<MiddleMouse>"],
1484 \ ["\<RightMouse>", "<RightMouse>"],
1485 \ ["\<S-LeftMouse>", "<S-LeftMouse>"],
1486 \ ["\<S-MiddleMouse>", "<S-MiddleMouse>"],
1487 \ ["\<S-RightMouse>", "<S-RightMouse>"],
1488 \ ["\<C-LeftMouse>", "<C-LeftMouse>"],
1489 \ ["\<C-MiddleMouse>", "<C-MiddleMouse>"],
1490 \ ["\<C-RightMouse>", "<C-RightMouse>"],
1491 \ ["\<M-LeftMouse>", "<M-LeftMouse>"],
1492 \ ["\<M-MiddleMouse>", "<M-MiddleMouse>"],
1493 \ ["\<M-RightMouse>", "<M-RightMouse>"],
1494 \ ["\<2-LeftMouse>", "<2-LeftMouse>"],
1495 \ ["\<2-MiddleMouse>", "<2-MiddleMouse>"],
1496 \ ["\<2-RightMouse>", "<2-RightMouse>"],
1497 \ ["\<3-LeftMouse>", "<3-LeftMouse>"],
1498 \ ["\<3-MiddleMouse>", "<3-MiddleMouse>"],
1499 \ ["\<3-RightMouse>", "<3-RightMouse>"],
1500 \ ["\<4-LeftMouse>", "<4-LeftMouse>"],
1501 \ ["\<4-MiddleMouse>", "<4-MiddleMouse>"],
1502 \ ["\<4-RightMouse>", "<4-RightMouse>"],
1503 \ ["\<LeftDrag>", "<LeftDrag>"],
1504 \ ["\<MiddleDrag>", "<MiddleDrag>"],
1505 \ ["\<RightDrag>", "<RightDrag>"],
1506 \ ["\<LeftRelease>", "<LeftRelease>"],
1507 \ ["\<MiddleRelease>", "<MiddleRelease>"],
1508 \ ["\<RightRelease>", "<RightRelease>"],
1509 \ ["\<ScrollWheelUp>", "<ScrollWheelUp>"],
1510 \ ["\<S-ScrollWheelUp>", "<S-ScrollWheelUp>"],
1511 \ ["\<C-ScrollWheelUp>", "<C-ScrollWheelUp>"],
1512 \ ["\<ScrollWheelDown>", "<ScrollWheelDown>"],
1513 \ ["\<S-ScrollWheelDown>", "<S-ScrollWheelDown>"],
1514 \ ["\<C-ScrollWheelDown>", "<C-ScrollWheelDown>"],
1515 \ ["\<ScrollWheelLeft>", "<ScrollWheelLeft>"],
1516 \ ["\<S-ScrollWheelLeft>", "<S-ScrollWheelLeft>"],
1517 \ ["\<C-ScrollWheelLeft>", "<C-ScrollWheelLeft>"],
1518 \ ["\<ScrollWheelRight>", "<ScrollWheelRight>"],
1519 \ ["\<S-ScrollWheelRight>", "<S-ScrollWheelRight>"],
1520 \ ["\<C-ScrollWheelRight>", "<C-ScrollWheelRight>"]
1521 \ ]
1522
1523 for [code, outstr] in mouse_codes
1524 exe "normal ggC\<C-K>" . code
1525 call assert_equal(outstr, getline(1), msg)
1526 endfor
1527 endfor
1528
1529 let &mouse = save_mouse
1530 let &term = save_term
1531 let &ttymouse = save_ttymouse
1532 set mousetime&
1533 call test_override('no_query_mouse', 0)
1534 %bw!
1535endfunc
1536
Bram Moolenaar66761db2019-06-05 22:07:51 +02001537" This only checks if the sequence is recognized.
Bram Moolenaar66761db2019-06-05 22:07:51 +02001538func Test_term_rgb_response()
1539 set t_RF=x
1540 set t_RB=y
1541
1542 " response to t_RF, 4 digits
1543 let red = 0x12
1544 let green = 0x34
1545 let blue = 0x56
1546 let seq = printf("\<Esc>]10;rgb:%02x00/%02x00/%02x00\x07", red, green, blue)
1547 call feedkeys(seq, 'Lx!')
1548 call assert_equal(seq, v:termrfgresp)
1549
1550 " response to t_RF, 2 digits
1551 let red = 0x78
1552 let green = 0x9a
1553 let blue = 0xbc
1554 let seq = printf("\<Esc>]10;rgb:%02x/%02x/%02x\x07", red, green, blue)
1555 call feedkeys(seq, 'Lx!')
1556 call assert_equal(seq, v:termrfgresp)
1557
Bram Moolenaar32e19772019-06-05 22:57:04 +02001558 " response to t_RB, 4 digits, dark
1559 set background=light
Bram Moolenaarce90e362019-09-08 18:58:44 +02001560 eval 'background'->test_option_not_set()
Bram Moolenaar32e19772019-06-05 22:57:04 +02001561 let red = 0x29
1562 let green = 0x4a
1563 let blue = 0x6b
1564 let seq = printf("\<Esc>]11;rgb:%02x00/%02x00/%02x00\x07", red, green, blue)
1565 call feedkeys(seq, 'Lx!')
1566 call assert_equal(seq, v:termrbgresp)
1567 call assert_equal('dark', &background)
1568
1569 " response to t_RB, 4 digits, light
1570 set background=dark
1571 call test_option_not_set('background')
1572 let red = 0x81
1573 let green = 0x63
Bram Moolenaar66761db2019-06-05 22:07:51 +02001574 let blue = 0x65
1575 let seq = printf("\<Esc>]11;rgb:%02x00/%02x00/%02x00\x07", red, green, blue)
1576 call feedkeys(seq, 'Lx!')
1577 call assert_equal(seq, v:termrbgresp)
Bram Moolenaar32e19772019-06-05 22:57:04 +02001578 call assert_equal('light', &background)
Bram Moolenaar66761db2019-06-05 22:07:51 +02001579
Bram Moolenaar32e19772019-06-05 22:57:04 +02001580 " response to t_RB, 2 digits, dark
1581 set background=light
1582 call test_option_not_set('background')
1583 let red = 0x47
1584 let green = 0x59
1585 let blue = 0x5b
Bram Moolenaar66761db2019-06-05 22:07:51 +02001586 let seq = printf("\<Esc>]11;rgb:%02x/%02x/%02x\x07", red, green, blue)
1587 call feedkeys(seq, 'Lx!')
1588 call assert_equal(seq, v:termrbgresp)
Bram Moolenaar32e19772019-06-05 22:57:04 +02001589 call assert_equal('dark', &background)
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001590
Bram Moolenaar32e19772019-06-05 22:57:04 +02001591 " response to t_RB, 2 digits, light
1592 set background=dark
1593 call test_option_not_set('background')
1594 let red = 0x83
1595 let green = 0xa4
1596 let blue = 0xc2
1597 let seq = printf("\<Esc>]11;rgb:%02x/%02x/%02x\x07", red, green, blue)
1598 call feedkeys(seq, 'Lx!')
1599 call assert_equal(seq, v:termrbgresp)
1600 call assert_equal('light', &background)
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001601
Bram Moolenaar66761db2019-06-05 22:07:51 +02001602 set t_RF= t_RB=
1603endfunc
1604
1605" This only checks if the sequence is recognized.
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001606" This must be after other tests, because it has side effects to xterm
1607" properties.
1608func Test_xx01_term_style_response()
Bram Moolenaar66761db2019-06-05 22:07:51 +02001609 " Termresponse is only parsed when t_RV is not empty.
1610 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001611 call test_override('term_props', 1)
Bram Moolenaar66761db2019-06-05 22:07:51 +02001612
1613 " send the termresponse to trigger requesting the XT codes
1614 let seq = "\<Esc>[>41;337;0c"
1615 call feedkeys(seq, 'Lx!')
1616 call assert_equal(seq, v:termresponse)
1617
1618 let seq = "\<Esc>P1$r2 q\<Esc>\\"
1619 call feedkeys(seq, 'Lx!')
1620 call assert_equal(seq, v:termstyleresp)
1621
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001622 call assert_equal(#{
1623 \ cursor_style: 'u',
1624 \ cursor_blink_mode: 'u',
1625 \ underline_rgb: 'u',
1626 \ mouse: 's'
1627 \ }, terminalprops())
1628
Bram Moolenaar66761db2019-06-05 22:07:51 +02001629 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001630 call test_override('term_props', 0)
Bram Moolenaar66761db2019-06-05 22:07:51 +02001631endfunc
Bram Moolenaarde6dbb42019-06-06 11:59:18 +02001632
Bram Moolenaar89577b32019-10-18 21:26:05 +02001633" This checks the iTerm2 version response.
1634" This must be after other tests, because it has side effects to xterm
1635" properties.
1636func Test_xx02_iTerm2_response()
1637 " Termresponse is only parsed when t_RV is not empty.
1638 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001639 call test_override('term_props', 1)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001640
1641 " Old versions of iTerm2 used a different style term response.
1642 set ttymouse=xterm
1643 call test_option_not_set('ttymouse')
1644 let seq = "\<Esc>[>0;95;c"
1645 call feedkeys(seq, 'Lx!')
1646 call assert_equal(seq, v:termresponse)
1647 call assert_equal('xterm', &ttymouse)
1648
1649 set ttymouse=xterm
1650 call test_option_not_set('ttymouse')
1651 let seq = "\<Esc>[>0;95;0c"
1652 call feedkeys(seq, 'Lx!')
1653 call assert_equal(seq, v:termresponse)
1654 call assert_equal('sgr', &ttymouse)
1655
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001656 call assert_equal(#{
1657 \ cursor_style: 'n',
1658 \ cursor_blink_mode: 'u',
1659 \ underline_rgb: 'u',
1660 \ mouse: 's'
1661 \ }, terminalprops())
1662
Bram Moolenaar89577b32019-10-18 21:26:05 +02001663 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001664 call test_override('term_props', 0)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001665endfunc
1666
Bram Moolenaard55f9ef2022-08-26 12:26:07 +01001667func Run_libvterm_konsole_response(code)
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001668 set ttymouse=xterm
1669 call test_option_not_set('ttymouse')
Bram Moolenaard55f9ef2022-08-26 12:26:07 +01001670 let seq = "\<Esc>[>0;" .. a:code .. ";0c"
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001671 call feedkeys(seq, 'Lx!')
1672 call assert_equal(seq, v:termresponse)
1673 call assert_equal('sgr', &ttymouse)
1674
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001675 call assert_equal(#{
1676 \ cursor_style: 'n',
1677 \ cursor_blink_mode: 'u',
1678 \ underline_rgb: 'u',
1679 \ mouse: 's'
1680 \ }, terminalprops())
Bram Moolenaard55f9ef2022-08-26 12:26:07 +01001681endfunc
1682
1683" This checks the libvterm version response.
1684" This must be after other tests, because it has side effects to xterm
1685" properties.
1686func Test_xx03_libvterm_konsole_response()
1687 " Termresponse is only parsed when t_RV is not empty.
1688 set t_RV=x
1689 call test_override('term_props', 1)
1690
1691 " libvterm
1692 call Run_libvterm_konsole_response(100)
1693 " Konsole
1694 call Run_libvterm_konsole_response(115)
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001695
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001696 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001697 call test_override('term_props', 0)
Bram Moolenaar1a4cbb12019-10-12 13:25:44 +02001698endfunc
1699
Bram Moolenaar89577b32019-10-18 21:26:05 +02001700" This checks the Mac Terminal.app version response.
1701" This must be after other tests, because it has side effects to xterm
1702" properties.
1703func Test_xx04_Mac_Terminal_response()
1704 " Termresponse is only parsed when t_RV is not empty.
1705 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001706 call test_override('term_props', 1)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001707
1708 set ttymouse=xterm
Bram Moolenaar8dff4cb2020-06-14 14:34:16 +02001709 " t_8u is not reset
1710 let &t_8u = "\<Esc>[58;2;%lu;%lu;%lum"
Bram Moolenaar89577b32019-10-18 21:26:05 +02001711 call test_option_not_set('ttymouse')
1712 let seq = "\<Esc>[>1;95;0c"
1713 call feedkeys(seq, 'Lx!')
1714 call assert_equal(seq, v:termresponse)
1715 call assert_equal('sgr', &ttymouse)
1716
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001717 call assert_equal(#{
1718 \ cursor_style: 'n',
1719 \ cursor_blink_mode: 'u',
1720 \ underline_rgb: 'y',
1721 \ mouse: 's'
1722 \ }, terminalprops())
Bram Moolenaar8dff4cb2020-06-14 14:34:16 +02001723 call assert_equal("\<Esc>[58;2;%lu;%lu;%lum", &t_8u)
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001724
Bram Moolenaar89577b32019-10-18 21:26:05 +02001725 " Reset is_not_xterm and is_mac_terminal.
1726 set t_RV=
1727 set term=xterm
1728 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001729 call test_override('term_props', 0)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001730endfunc
1731
1732" This checks the mintty version response.
1733" This must be after other tests, because it has side effects to xterm
1734" properties.
1735func Test_xx05_mintty_response()
1736 " Termresponse is only parsed when t_RV is not empty.
1737 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001738 call test_override('term_props', 1)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001739
1740 set ttymouse=xterm
1741 call test_option_not_set('ttymouse')
1742 let seq = "\<Esc>[>77;20905;0c"
1743 call feedkeys(seq, 'Lx!')
1744 call assert_equal(seq, v:termresponse)
1745 call assert_equal('sgr', &ttymouse)
1746
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001747 call assert_equal(#{
1748 \ cursor_style: 'n',
1749 \ cursor_blink_mode: 'u',
1750 \ underline_rgb: 'y',
1751 \ mouse: 's'
1752 \ }, terminalprops())
1753
Bram Moolenaar89577b32019-10-18 21:26:05 +02001754 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001755 call test_override('term_props', 0)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001756endfunc
1757
1758" This checks the screen version response.
1759" This must be after other tests, because it has side effects to xterm
1760" properties.
1761func Test_xx06_screen_response()
1762 " Termresponse is only parsed when t_RV is not empty.
1763 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001764 call test_override('term_props', 1)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001765
1766 " Old versions of screen don't support SGR mouse mode.
1767 set ttymouse=xterm
1768 call test_option_not_set('ttymouse')
1769 let seq = "\<Esc>[>83;40500;0c"
1770 call feedkeys(seq, 'Lx!')
1771 call assert_equal(seq, v:termresponse)
1772 call assert_equal('xterm', &ttymouse)
1773
1774 " screen supports SGR mouse mode starting in version 4.7.
1775 set ttymouse=xterm
1776 call test_option_not_set('ttymouse')
1777 let seq = "\<Esc>[>83;40700;0c"
1778 call feedkeys(seq, 'Lx!')
1779 call assert_equal(seq, v:termresponse)
1780 call assert_equal('sgr', &ttymouse)
1781
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001782 call assert_equal(#{
1783 \ cursor_style: 'n',
1784 \ cursor_blink_mode: 'n',
1785 \ underline_rgb: 'y',
1786 \ mouse: 's'
1787 \ }, terminalprops())
1788
Bram Moolenaar89577b32019-10-18 21:26:05 +02001789 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001790 call test_override('term_props', 0)
Bram Moolenaar89577b32019-10-18 21:26:05 +02001791endfunc
1792
Bram Moolenaard0eaf672022-04-20 19:55:37 +01001793func Do_check_t_8u_set_reset(set_by_user)
1794 set ttymouse=xterm
1795 call test_option_not_set('ttymouse')
1796 let default_value = "\<Esc>[58;2;%lu;%lu;%lum"
1797 let &t_8u = default_value
1798 if !a:set_by_user
1799 call test_option_not_set('t_8u')
1800 endif
1801 let seq = "\<Esc>[>0;279;0c"
1802 call feedkeys(seq, 'Lx!')
1803 call assert_equal(seq, v:termresponse)
1804 call assert_equal('sgr', &ttymouse)
1805
1806 call assert_equal(#{
1807 \ cursor_style: 'u',
1808 \ cursor_blink_mode: 'u',
1809 \ underline_rgb: 'u',
1810 \ mouse: 's'
1811 \ }, terminalprops())
1812 call assert_equal(a:set_by_user ? default_value : '', &t_8u)
1813endfunc
1814
Bram Moolenaar03b00472019-10-14 22:22:03 +02001815" This checks the xterm version response.
1816" This must be after other tests, because it has side effects to xterm
1817" properties.
Bram Moolenaar89577b32019-10-18 21:26:05 +02001818func Test_xx07_xterm_response()
Bram Moolenaar03b00472019-10-14 22:22:03 +02001819 " Termresponse is only parsed when t_RV is not empty.
1820 set t_RV=x
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001821 call test_override('term_props', 1)
Bram Moolenaar03b00472019-10-14 22:22:03 +02001822
Bram Moolenaar3cea8a92019-10-17 21:55:24 +02001823 " Do Terminal.app first to check that is_mac_terminal is reset.
1824 set ttymouse=xterm
1825 call test_option_not_set('ttymouse')
1826 let seq = "\<Esc>[>1;95;0c"
1827 call feedkeys(seq, 'Lx!')
1828 call assert_equal(seq, v:termresponse)
1829 call assert_equal('sgr', &ttymouse)
1830
Bram Moolenaar03b00472019-10-14 22:22:03 +02001831 " xterm < 95: "xterm" (actually unmodified)
Bram Moolenaar3cea8a92019-10-17 21:55:24 +02001832 set t_RV=
1833 set term=xterm
1834 set t_RV=x
Bram Moolenaar03b00472019-10-14 22:22:03 +02001835 set ttymouse=xterm
1836 call test_option_not_set('ttymouse')
1837 let seq = "\<Esc>[>0;94;0c"
1838 call feedkeys(seq, 'Lx!')
1839 call assert_equal(seq, v:termresponse)
1840 call assert_equal('xterm', &ttymouse)
1841
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001842 call assert_equal(#{
1843 \ cursor_style: 'n',
1844 \ cursor_blink_mode: 'u',
1845 \ underline_rgb: 'y',
1846 \ mouse: 'u'
1847 \ }, terminalprops())
1848
Bram Moolenaar03b00472019-10-14 22:22:03 +02001849 " xterm >= 95 < 277 "xterm2"
1850 set ttymouse=xterm
1851 call test_option_not_set('ttymouse')
1852 let seq = "\<Esc>[>0;267;0c"
1853 call feedkeys(seq, 'Lx!')
1854 call assert_equal(seq, v:termresponse)
1855 call assert_equal('xterm2', &ttymouse)
1856
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001857 call assert_equal(#{
1858 \ cursor_style: 'n',
1859 \ cursor_blink_mode: 'u',
1860 \ underline_rgb: 'u',
1861 \ mouse: '2'
1862 \ }, terminalprops())
1863
Bram Moolenaar03b00472019-10-14 22:22:03 +02001864 " xterm >= 277: "sgr"
1865 set ttymouse=xterm
1866 call test_option_not_set('ttymouse')
1867 let seq = "\<Esc>[>0;277;0c"
1868 call feedkeys(seq, 'Lx!')
1869 call assert_equal(seq, v:termresponse)
1870 call assert_equal('sgr', &ttymouse)
1871
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001872 call assert_equal(#{
1873 \ cursor_style: 'n',
1874 \ cursor_blink_mode: 'u',
1875 \ underline_rgb: 'u',
1876 \ mouse: 's'
1877 \ }, terminalprops())
1878
Bram Moolenaard0eaf672022-04-20 19:55:37 +01001879 " xterm >= 279: "sgr" and cursor_style not reset; also check t_8u reset,
1880 " except when it was set by the user
1881 call Do_check_t_8u_set_reset(0)
1882 call Do_check_t_8u_set_reset(1)
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001883
Bram Moolenaar03b00472019-10-14 22:22:03 +02001884 set t_RV=
Bram Moolenaar0c0eddd2020-06-13 15:47:25 +02001885 call test_override('term_props', 0)
Bram Moolenaar03b00472019-10-14 22:22:03 +02001886endfunc
1887
Bram Moolenaar92e5df82021-01-30 15:39:47 +01001888func Test_focus_events()
1889 let save_term = &term
1890 let save_ttymouse = &ttymouse
1891 set term=xterm ttymouse=xterm2
1892
1893 au FocusGained * let g:focus_gained += 1
1894 au FocusLost * let g:focus_lost += 1
1895 let g:focus_gained = 0
1896 let g:focus_lost = 0
1897
1898 call feedkeys("\<Esc>[O", "Lx!")
1899 call assert_equal(1, g:focus_lost)
1900 call feedkeys("\<Esc>[I", "Lx!")
1901 call assert_equal(1, g:focus_gained)
1902
1903 " still works when 'ttymouse' is empty
1904 set ttymouse=
1905 call feedkeys("\<Esc>[O", "Lx!")
1906 call assert_equal(2, g:focus_lost)
1907 call feedkeys("\<Esc>[I", "Lx!")
1908 call assert_equal(2, g:focus_gained)
1909
1910 au! FocusGained
1911 au! FocusLost
1912 let &term = save_term
1913 let &ttymouse = save_ttymouse
1914endfunc
1915
Bram Moolenaarde6dbb42019-06-06 11:59:18 +02001916func Test_get_termcode()
Bram Moolenaareb663282019-10-06 12:02:15 +02001917 try
1918 let k1 = &t_k1
1919 catch /E113/
1920 throw 'Skipped: Unable to query termcodes'
1921 endtry
Bram Moolenaarde6dbb42019-06-06 11:59:18 +02001922 set t_k1=
1923 set t_k1&
1924 call assert_equal(k1, &t_k1)
Bram Moolenaar9aeb3362019-06-06 12:36:15 +02001925
1926 " use external termcap first
1927 set nottybuiltin
1928 set t_k1=
1929 set t_k1&
1930 " when using external termcap may get something else, but it must not be
1931 " empty, since we would fallback to the builtin one.
1932 call assert_notequal('', &t_k1)
1933
1934 if &term =~ 'xterm'
1935 " use internal termcap first
1936 let term_save = &term
1937 let &term = 'builtin_' .. &term
1938 set t_k1=
1939 set t_k1&
1940 call assert_equal(k1, &t_k1)
1941 let &term = term_save
1942 endif
1943
1944 set ttybuiltin
Bram Moolenaarde6dbb42019-06-06 11:59:18 +02001945endfunc
Bram Moolenaar18a79a62019-10-12 15:36:11 +02001946
Bram Moolenaarecd34bf2020-08-04 20:17:31 +02001947func Test_list_builtin_terminals()
Bram Moolenaare46a2ed2020-08-04 21:04:57 +02001948 CheckRunVimInTerminal
Bram Moolenaar4d05af02020-11-27 20:55:00 +01001949 call RunVimInTerminal('', #{rows: 14})
1950 call term_sendkeys('', ":set cmdheight=3\<CR>")
1951 call TermWait('', 100)
1952 call term_sendkeys('', ":set term=xxx\<CR>")
1953 call TermWait('', 100)
1954 call assert_match('builtin_dumb', term_getline('', 11))
1955 call assert_match('Not found in termcap', term_getline('', 12))
1956 call StopVimInTerminal('')
Bram Moolenaarecd34bf2020-08-04 20:17:31 +02001957endfunc
1958
Bram Moolenaar18a79a62019-10-12 15:36:11 +02001959func GetEscCodeCSI27(key, modifier)
1960 let key = printf("%d", char2nr(a:key))
1961 let mod = printf("%d", a:modifier)
1962 return "\<Esc>[27;" .. mod .. ';' .. key .. '~'
1963endfunc
1964
1965func GetEscCodeCSIu(key, modifier)
1966 let key = printf("%d", char2nr(a:key))
1967 let mod = printf("%d", a:modifier)
1968 return "\<Esc>[" .. key .. ';' .. mod .. 'u'
1969endfunc
1970
1971" This checks the CSI sequences when in modifyOtherKeys mode.
1972" The mode doesn't need to be enabled, the codes are always detected.
1973func RunTest_modifyOtherKeys(func)
1974 new
Bram Moolenaar459fd782019-10-13 16:43:39 +02001975 set timeoutlen=10
Bram Moolenaar18a79a62019-10-12 15:36:11 +02001976
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01001977 " Shift-X is sent as 'X' with the shift modifier
Bram Moolenaar18a79a62019-10-12 15:36:11 +02001978 call feedkeys('a' .. a:func('X', 2) .. "\<Esc>", 'Lx!')
1979 call assert_equal('X', getline(1))
1980
1981 " Ctrl-i is Tab
1982 call setline(1, '')
1983 call feedkeys('a' .. a:func('i', 5) .. "\<Esc>", 'Lx!')
1984 call assert_equal("\t", getline(1))
1985
1986 " Ctrl-I is also Tab
1987 call setline(1, '')
1988 call feedkeys('a' .. a:func('I', 5) .. "\<Esc>", 'Lx!')
1989 call assert_equal("\t", getline(1))
1990
1991 " Alt-x is ø
1992 call setline(1, '')
1993 call feedkeys('a' .. a:func('x', 3) .. "\<Esc>", 'Lx!')
1994 call assert_equal("ø", getline(1))
1995
1996 " Meta-x is also ø
1997 call setline(1, '')
1998 call feedkeys('a' .. a:func('x', 9) .. "\<Esc>", 'Lx!')
1999 call assert_equal("ø", getline(1))
2000
2001 " Alt-X is Ø
2002 call setline(1, '')
2003 call feedkeys('a' .. a:func('X', 3) .. "\<Esc>", 'Lx!')
2004 call assert_equal("Ø", getline(1))
2005
2006 " Meta-X is ø
2007 call setline(1, '')
2008 call feedkeys('a' .. a:func('X', 9) .. "\<Esc>", 'Lx!')
2009 call assert_equal("Ø", getline(1))
2010
Bram Moolenaar828ffd52019-11-21 23:24:00 +01002011 " Ctrl-6 is Ctrl-^
2012 split aaa
2013 edit bbb
2014 call feedkeys(a:func('6', 5), 'Lx!')
2015 call assert_equal("aaa", bufname())
2016 bwipe aaa
2017 bwipe bbb
2018
Bram Moolenaar0684e362020-12-03 19:54:42 +01002019 " Ctrl-V X 33 is 3
2020 call setline(1, '')
2021 call feedkeys("a\<C-V>" .. a:func('X', 2) .. "33\<Esc>", 'Lx!')
2022 call assert_equal("3", getline(1))
2023
2024 " Ctrl-V U 12345 is Unicode 12345
2025 call setline(1, '')
2026 call feedkeys("a\<C-V>" .. a:func('U', 2) .. "12345\<Esc>", 'Lx!')
2027 call assert_equal("\U12345", getline(1))
2028
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002029 bwipe!
2030 set timeoutlen&
2031endfunc
2032
Bram Moolenaar459fd782019-10-13 16:43:39 +02002033func Test_modifyOtherKeys_basic()
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002034 call RunTest_modifyOtherKeys(function('GetEscCodeCSI27'))
Bram Moolenaar18a79a62019-10-12 15:36:11 +02002035 call RunTest_modifyOtherKeys(function('GetEscCodeCSIu'))
2036endfunc
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002037
Bram Moolenaar38571a02019-11-26 14:28:15 +01002038func Test_modifyOtherKeys_no_mapping()
2039 set timeoutlen=10
2040
2041 let @a = 'aaa'
2042 call feedkeys(":let x = '" .. GetEscCodeCSI27('R', 5) .. GetEscCodeCSI27('R', 5) .. "a'\<CR>", 'Lx!')
2043 call assert_equal("let x = 'aaa'", @:)
2044
2045 new
2046 call feedkeys("a" .. GetEscCodeCSI27('R', 5) .. GetEscCodeCSI27('R', 5) .. "a\<Esc>", 'Lx!')
2047 call assert_equal("aaa", getline(1))
2048 bwipe!
2049
2050 new
2051 call feedkeys("axx\<CR>yy" .. GetEscCodeCSI27('G', 5) .. GetEscCodeCSI27('K', 5) .. "a\<Esc>", 'Lx!')
2052 call assert_equal("axx", getline(1))
2053 call assert_equal("yy", getline(2))
2054 bwipe!
2055
2056 set timeoutlen&
2057endfunc
2058
Bram Moolenaarc14b57c2021-12-03 13:20:29 +00002059" Check that when DEC mouse codes are recognized a special key is handled.
2060func Test_ignore_dec_mouse()
Dominique Pellef589fd32021-12-05 12:39:21 +00002061 silent !infocmp gnome >/dev/null 2>&1
2062 if v:shell_error != 0
2063 throw 'Skipped: gnome entry missing in the terminfo db'
2064 endif
Bram Moolenaarc14b57c2021-12-03 13:20:29 +00002065
2066 new
2067 let save_mouse = &mouse
2068 let save_term = &term
2069 let save_ttymouse = &ttymouse
2070 call test_override('no_query_mouse', 1)
2071 set mouse=a term=gnome ttymouse=
2072
2073 execute "set <xF1>=\<Esc>[1;*P"
2074 nnoremap <S-F1> agot it<Esc>
2075 call feedkeys("\<Esc>[1;2P", 'Lx!')
2076 call assert_equal('got it', getline(1))
2077
2078 let &mouse = save_mouse
2079 let &term = save_term
2080 let &ttymouse = save_ttymouse
2081 call test_override('no_query_mouse', 0)
2082 bwipe!
2083endfunc
2084
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002085func RunTest_mapping_shift(key, func)
2086 call setline(1, '')
2087 if a:key == '|'
2088 exe 'inoremap \| xyz'
2089 else
2090 exe 'inoremap ' .. a:key .. ' xyz'
2091 endif
2092 call feedkeys('a' .. a:func(a:key, 2) .. "\<Esc>", 'Lx!')
2093 call assert_equal("xyz", getline(1))
2094 if a:key == '|'
2095 exe 'iunmap \|'
2096 else
2097 exe 'iunmap ' .. a:key
2098 endif
2099endfunc
2100
Bram Moolenaar975a8802020-06-06 22:36:24 +02002101func Test_modifyOtherKeys_mapped()
2102 set timeoutlen=10
2103 imap ' <C-W>
2104 imap <C-W><C-A> c-a
2105 call setline(1, '')
2106
2107 " single quote is turned into single byte CTRL-W
2108 " CTRL-A is added with a separate modifier, and needs to be simplified before
2109 " the mapping can match.
2110 call feedkeys("a'" .. GetEscCodeCSI27('A', 5) .. "\<Esc>", 'Lx!')
2111 call assert_equal('c-a', getline(1))
2112
2113 iunmap '
2114 iunmap <C-W><C-A>
2115 set timeoutlen&
2116endfunc
2117
Bram Moolenaar196c3852022-03-04 19:22:36 +00002118func Test_modifyOtherKeys_ambiguous_mapping()
2119 new
2120 set timeoutlen=10
2121 map <C-J> a
2122 map <C-J>x <Nop>
2123 call setline(1, 'x')
2124
2125 " CTRL-J b should have trigger the <C-J> mapping and then insert "b"
2126 call feedkeys(GetEscCodeCSI27('J', 5) .. "b\<Esc>", 'Lx!')
2127 call assert_equal('xb', getline(1))
2128
2129 unmap <C-J>
2130 unmap <C-J>x
Bram Moolenaarf35fd8e2022-03-18 15:41:17 +00002131
2132 " if a special character is following there should be a check for a termcode
2133 nnoremap s aX<Esc>
2134 nnoremap s<BS> aY<Esc>
2135 set t_kb=
2136 call setline(1, 'x')
2137 call feedkeys("s\x08", 'Lx!')
2138 call assert_equal('xY', getline(1))
2139
Bram Moolenaar196c3852022-03-04 19:22:36 +00002140 set timeoutlen&
2141 bwipe!
2142endfunc
2143
Bram Moolenaar749bc952020-10-31 16:33:47 +01002144" Whether Shift-Tab sends "ESC [ Z" or "ESC [ 27 ; 2 ; 9 ~" is unpredictable,
2145" both should work.
2146func Test_modifyOtherKeys_shift_tab()
2147 set timeoutlen=10
2148
2149 call setline(1, '')
2150 call feedkeys("a\<C-K>" .. GetEscCodeCSI27("\t", '2') .. "\<Esc>", 'Lx!')
2151 eval getline(1)->assert_equal('<S-Tab>')
2152
2153 call setline(1, '')
2154 call feedkeys("a\<C-K>\<Esc>[Z\<Esc>", 'Lx!')
2155 eval getline(1)->assert_equal('<S-Tab>')
2156
2157 set timeoutlen&
2158 bwipe!
2159endfunc
2160
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002161func RunTest_mapping_works_with_shift(func)
2162 new
Bram Moolenaar459fd782019-10-13 16:43:39 +02002163 set timeoutlen=10
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002164
2165 call RunTest_mapping_shift('@', a:func)
2166 call RunTest_mapping_shift('A', a:func)
2167 call RunTest_mapping_shift('Z', a:func)
2168 call RunTest_mapping_shift('^', a:func)
2169 call RunTest_mapping_shift('_', a:func)
2170 call RunTest_mapping_shift('{', a:func)
2171 call RunTest_mapping_shift('|', a:func)
2172 call RunTest_mapping_shift('}', a:func)
2173 call RunTest_mapping_shift('~', a:func)
2174
2175 bwipe!
2176 set timeoutlen&
2177endfunc
2178
Bram Moolenaar459fd782019-10-13 16:43:39 +02002179func Test_mapping_works_with_shift_plain()
Bram Moolenaard1e2f392019-10-12 18:22:50 +02002180 call RunTest_mapping_works_with_shift(function('GetEscCodeCSI27'))
2181 call RunTest_mapping_works_with_shift(function('GetEscCodeCSIu'))
2182endfunc
Bram Moolenaar459fd782019-10-13 16:43:39 +02002183
2184func RunTest_mapping_mods(map, key, func, code)
2185 call setline(1, '')
2186 exe 'inoremap ' .. a:map .. ' xyz'
2187 call feedkeys('a' .. a:func(a:key, a:code) .. "\<Esc>", 'Lx!')
2188 call assert_equal("xyz", getline(1))
2189 exe 'iunmap ' .. a:map
2190endfunc
2191
2192func RunTest_mapping_works_with_mods(func, mods, code)
2193 new
2194 set timeoutlen=10
2195
2196 if a:mods !~ 'S'
2197 " Shift by itself has no effect
2198 call RunTest_mapping_mods('<' .. a:mods .. '-@>', '@', a:func, a:code)
2199 endif
2200 call RunTest_mapping_mods('<' .. a:mods .. '-A>', 'A', a:func, a:code)
2201 call RunTest_mapping_mods('<' .. a:mods .. '-Z>', 'Z', a:func, a:code)
2202 if a:mods !~ 'S'
2203 " with Shift code is always upper case
2204 call RunTest_mapping_mods('<' .. a:mods .. '-a>', 'a', a:func, a:code)
2205 call RunTest_mapping_mods('<' .. a:mods .. '-z>', 'z', a:func, a:code)
2206 endif
2207 if a:mods != 'A'
2208 " with Alt code is not in upper case
2209 call RunTest_mapping_mods('<' .. a:mods .. '-a>', 'A', a:func, a:code)
2210 call RunTest_mapping_mods('<' .. a:mods .. '-z>', 'Z', a:func, a:code)
2211 endif
2212 call RunTest_mapping_mods('<' .. a:mods .. '-á>', 'á', a:func, a:code)
2213 if a:mods !~ 'S'
2214 " Shift by itself has no effect
2215 call RunTest_mapping_mods('<' .. a:mods .. '-^>', '^', a:func, a:code)
2216 call RunTest_mapping_mods('<' .. a:mods .. '-_>', '_', a:func, a:code)
2217 call RunTest_mapping_mods('<' .. a:mods .. '-{>', '{', a:func, a:code)
2218 call RunTest_mapping_mods('<' .. a:mods .. '-\|>', '|', a:func, a:code)
2219 call RunTest_mapping_mods('<' .. a:mods .. '-}>', '}', a:func, a:code)
2220 call RunTest_mapping_mods('<' .. a:mods .. '-~>', '~', a:func, a:code)
2221 endif
2222
2223 bwipe!
2224 set timeoutlen&
2225endfunc
2226
2227func Test_mapping_works_with_shift()
2228 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'S', 2)
2229 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'S', 2)
2230endfunc
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002231
Bram Moolenaar459fd782019-10-13 16:43:39 +02002232func Test_mapping_works_with_ctrl()
2233 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C', 5)
2234 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C', 5)
Bram Moolenaar4e2114e2020-10-07 16:12:37 +02002235
2236 new
2237 set timeoutlen=10
2238
2239 " CTRL-@ actually produces the code for CTRL-2, which is converted
2240 call RunTest_mapping_mods('<C-@>', '2', function('GetEscCodeCSI27'), 5)
2241 call RunTest_mapping_mods('<C-@>', '2', function('GetEscCodeCSIu'), 5)
2242
2243 " CTRL-^ actually produces the code for CTRL-6, which is converted
2244 call RunTest_mapping_mods('<C-^>', '6', function('GetEscCodeCSI27'), 5)
2245 call RunTest_mapping_mods('<C-^>', '6', function('GetEscCodeCSIu'), 5)
2246
2247 " CTRL-_ actually produces the code for CTRL--, which is converted
2248 call RunTest_mapping_mods('<C-_>', '-', function('GetEscCodeCSI27'), 5)
2249 call RunTest_mapping_mods('<C-_>', '-', function('GetEscCodeCSIu'), 5)
2250
2251 bwipe!
2252 set timeoutlen&
Bram Moolenaar459fd782019-10-13 16:43:39 +02002253endfunc
2254
2255func Test_mapping_works_with_shift_ctrl()
2256 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-S', 6)
2257 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-S', 6)
Bram Moolenaar9a033d72020-10-07 17:29:48 +02002258
2259 new
2260 set timeoutlen=10
2261
2262 " Ctrl-Shift-[ actually produces CTRL-Shift-{ which is mapped as <C-{>
2263 call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSI27'), 6)
2264 call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSIu'), 6)
2265
2266 " Ctrl-Shift-] actually produces CTRL-Shift-} which is mapped as <C-}>
2267 call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSI27'), 6)
2268 call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSIu'), 6)
2269
2270 " Ctrl-Shift-\ actually produces CTRL-Shift-| which is mapped as <C-|>
2271 call RunTest_mapping_mods('<C-\|>', '|', function('GetEscCodeCSI27'), 6)
2272 call RunTest_mapping_mods('<C-\|>', '|', function('GetEscCodeCSIu'), 6)
2273
2274 bwipe!
2275 set timeoutlen&
Bram Moolenaar459fd782019-10-13 16:43:39 +02002276endfunc
2277
2278" Below we also test the "u" code with Alt, This works, but libvterm would not
2279" send the Alt key like this but by prefixing an Esc.
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002280
Bram Moolenaar459fd782019-10-13 16:43:39 +02002281func Test_mapping_works_with_alt()
2282 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'A', 3)
2283 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'A', 3)
2284endfunc
2285
2286func Test_mapping_works_with_shift_alt()
2287 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'S-A', 4)
2288 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'S-A', 4)
2289endfunc
2290
Bram Moolenaardaff0fb2020-09-27 13:16:46 +02002291func Test_mapping_works_with_alt_and_shift()
2292 new
2293 set timeoutlen=10
2294
2295 " mapping <A-?> works even though the code is A-S-?
2296 for c in ['!', '$', '+', ':', '?', '^', '~']
2297 call RunTest_mapping_mods('<A-' .. c .. '>', c, function('GetEscCodeCSI27'), 4)
2298 call RunTest_mapping_mods('<A-' .. c .. '>', c, function('GetEscCodeCSIu'), 4)
2299 endfor
2300
2301 bwipe!
2302 set timeoutlen&
2303endfunc
2304
Bram Moolenaar459fd782019-10-13 16:43:39 +02002305func Test_mapping_works_with_ctrl_alt()
2306 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-A', 7)
2307 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-A', 7)
2308endfunc
2309
2310func Test_mapping_works_with_shift_ctrl_alt()
2311 call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-S-A', 8)
2312 call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-S-A', 8)
2313endfunc
Bram Moolenaarfc4ea2a2019-11-26 19:33:22 +01002314
2315func Test_insert_literal()
2316 set timeoutlen=10
2317 new
2318 " CTRL-V CTRL-X inserts a ^X
2319 call feedkeys('a' .. GetEscCodeCSIu('V', '5') .. GetEscCodeCSIu('X', '5') .. "\<Esc>", 'Lx!')
2320 call assert_equal("\<C-X>", getline(1))
2321
2322 call setline(1, '')
2323 call feedkeys('a' .. GetEscCodeCSI27('V', '5') .. GetEscCodeCSI27('X', '5') .. "\<Esc>", 'Lx!')
2324 call assert_equal("\<C-X>", getline(1))
2325
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002326 " CTRL-SHIFT-V CTRL-X inserts escape sequence
Bram Moolenaarfc4ea2a2019-11-26 19:33:22 +01002327 call setline(1, '')
2328 call feedkeys('a' .. GetEscCodeCSIu('V', '6') .. GetEscCodeCSIu('X', '5') .. "\<Esc>", 'Lx!')
2329 call assert_equal("\<Esc>[88;5u", getline(1))
2330
2331 call setline(1, '')
2332 call feedkeys('a' .. GetEscCodeCSI27('V', '6') .. GetEscCodeCSI27('X', '5') .. "\<Esc>", 'Lx!')
2333 call assert_equal("\<Esc>[27;5;88~", getline(1))
2334
2335 bwipe!
2336 set timeoutlen&
2337endfunc
2338
2339func Test_cmdline_literal()
2340 set timeoutlen=10
2341
2342 " CTRL-V CTRL-Y inserts a ^Y
2343 call feedkeys(':' .. GetEscCodeCSIu('V', '5') .. GetEscCodeCSIu('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!')
2344 call assert_equal("\"\<C-Y>", @:)
2345
2346 call feedkeys(':' .. GetEscCodeCSI27('V', '5') .. GetEscCodeCSI27('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!')
2347 call assert_equal("\"\<C-Y>", @:)
2348
Bram Moolenaarf19f8d12019-12-18 19:36:23 +01002349 " CTRL-SHIFT-V CTRL-Y inserts escape sequence
Bram Moolenaarfc4ea2a2019-11-26 19:33:22 +01002350 call feedkeys(':' .. GetEscCodeCSIu('V', '6') .. GetEscCodeCSIu('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!')
2351 call assert_equal("\"\<Esc>[89;5u", @:)
2352
2353 call setline(1, '')
2354 call feedkeys(':' .. GetEscCodeCSI27('V', '6') .. GetEscCodeCSI27('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!')
2355 call assert_equal("\"\<Esc>[27;5;89~", @:)
2356
2357 set timeoutlen&
2358endfunc
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01002359
Bram Moolenaarbbf84e22022-03-12 13:48:39 +00002360func Test_mapping_esc()
2361 set timeoutlen=10
2362
2363 new
2364 nnoremap <Up> iHello<Esc>
2365 nnoremap <Esc> <Nop>
2366
2367 call feedkeys(substitute(&t_ku, '\*', '', 'g'), 'Lx!')
2368 call assert_equal("Hello", getline(1))
2369
2370 bwipe!
2371 nunmap <Up>
2372 nunmap <Esc>
2373 set timeoutlen&
2374endfunc
2375
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +02002376" Test for translation of special key codes (<xF1>, <xF2>, etc.)
Bram Moolenaar92e5df82021-01-30 15:39:47 +01002377func Test_Keycode_Translation()
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +02002378 let keycodes = [
2379 \ ["<xUp>", "<Up>"],
2380 \ ["<xDown>", "<Down>"],
2381 \ ["<xLeft>", "<Left>"],
2382 \ ["<xRight>", "<Right>"],
2383 \ ["<xHome>", "<Home>"],
2384 \ ["<xEnd>", "<End>"],
2385 \ ["<zHome>", "<Home>"],
2386 \ ["<zEnd>", "<End>"],
2387 \ ["<xF1>", "<F1>"],
2388 \ ["<xF2>", "<F2>"],
2389 \ ["<xF3>", "<F3>"],
2390 \ ["<xF4>", "<F4>"],
2391 \ ["<S-xF1>", "<S-F1>"],
2392 \ ["<S-xF2>", "<S-F2>"],
2393 \ ["<S-xF3>", "<S-F3>"],
2394 \ ["<S-xF4>", "<S-F4>"]]
2395 for [k1, k2] in keycodes
2396 exe "nnoremap " .. k1 .. " 2wx"
2397 call assert_true(maparg(k1, 'n', 0, 1).lhs == k2)
2398 exe "nunmap " .. k1
2399 endfor
2400endfunc
2401
Bram Moolenaar1f448d92021-03-22 19:37:06 +01002402" Test for terminal keycodes that doesn't have termcap entries
2403func Test_special_term_keycodes()
2404 new
2405 " Test for <xHome>, <S-xHome> and <C-xHome>
2406 " send <K_SPECIAL> <KS_EXTRA> keycode
2407 call feedkeys("i\<C-K>\x80\xfd\x3f\n", 'xt')
2408 " send <K_SPECIAL> <KS_MODIFIER> bitmap <K_SPECIAL> <KS_EXTRA> keycode
2409 call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3f\n", 'xt')
2410 call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3f\n", 'xt')
2411 " Test for <xEnd>, <S-xEnd> and <C-xEnd>
2412 call feedkeys("i\<C-K>\x80\xfd\x3d\n", 'xt')
2413 call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3d\n", 'xt')
2414 call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3d\n", 'xt')
2415 " Test for <zHome>, <S-zHome> and <C-zHome>
2416 call feedkeys("i\<C-K>\x80\xfd\x40\n", 'xt')
2417 call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x40\n", 'xt')
2418 call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x40\n", 'xt')
2419 " Test for <zEnd>, <S-zEnd> and <C-zEnd>
2420 call feedkeys("i\<C-K>\x80\xfd\x3e\n", 'xt')
2421 call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3e\n", 'xt')
2422 call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3e\n", 'xt')
2423 " Test for <xUp>, <xDown>, <xLeft> and <xRight>
2424 call feedkeys("i\<C-K>\x80\xfd\x41\n", 'xt')
2425 call feedkeys("i\<C-K>\x80\xfd\x42\n", 'xt')
2426 call feedkeys("i\<C-K>\x80\xfd\x43\n", 'xt')
2427 call feedkeys("i\<C-K>\x80\xfd\x44\n", 'xt')
2428 call assert_equal(['<Home>', '<S-Home>', '<C-Home>',
2429 \ '<End>', '<S-End>', '<C-End>',
2430 \ '<Home>', '<S-Home>', '<C-Home>',
2431 \ '<End>', '<S-End>', '<C-End>',
2432 \ '<Up>', '<Down>', '<Left>', '<Right>', ''], getline(1, '$'))
2433 bw!
2434endfunc
2435
Bram Moolenaar0f5575d2021-07-30 21:18:03 +02002436func Test_terminal_builtin_without_gui()
2437 CheckNotMSWindows
2438
2439 " builtin_gui should not be output by :set term=xxx
2440 let output = systemlist("TERM=dumb " .. v:progpath .. " --clean -c ':set t_ti= t_te=' -c 'set term=xxx' -c ':q!'")
2441 redraw!
2442 call map(output, {_, val -> trim(val)})
2443 call assert_equal(-1, index(output, 'builtin_gui'))
2444 call assert_notequal(-1, index(output, 'builtin_dumb'))
2445endfunc
2446
2447
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +01002448" vim: shiftwidth=2 sts=2 expandtab