Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 1 | " Tests for decoding escape sequences sent by the terminal. |
| 2 | |
| 3 | " This only works for Unix in a terminal |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 4 | source check.vim |
| 5 | CheckNotGui |
| 6 | CheckUnix |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 7 | |
Bram Moolenaar | 564344a | 2019-04-28 13:00:12 +0200 | [diff] [blame] | 8 | source shared.vim |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 9 | source mouse.vim |
Bram Moolenaar | ecd34bf | 2020-08-04 20:17:31 +0200 | [diff] [blame] | 10 | source view_util.vim |
Bram Moolenaar | e46a2ed | 2020-08-04 21:04:57 +0200 | [diff] [blame] | 11 | source term_util.vim |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 12 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 13 | func Test_term_mouse_left_click() |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 14 | new |
| 15 | let save_mouse = &mouse |
| 16 | let save_term = &term |
| 17 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 18 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 19 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 20 | call WaitForResponses() |
| 21 | |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 22 | call setline(1, ['line 1', 'line 2', 'line 3 is a bit longer']) |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 23 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 24 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 25 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 26 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 27 | go |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 28 | call assert_equal([0, 1, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 29 | let row = 2 |
| 30 | let col = 6 |
| 31 | call MouseLeftClick(row, col) |
| 32 | call MouseLeftRelease(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 33 | call assert_equal([0, 2, 6, 0], getpos('.'), msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 34 | endfor |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 35 | |
| 36 | let &mouse = save_mouse |
| 37 | let &term = save_term |
| 38 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 39 | call test_override('no_query_mouse', 0) |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 40 | bwipe! |
| 41 | endfunc |
| 42 | |
Bram Moolenaar | 6aa7523 | 2019-10-13 21:01:34 +0200 | [diff] [blame] | 43 | func Test_xterm_mouse_right_click_extends_visual() |
| 44 | if has('mac') |
| 45 | throw "Skipped: test right click in visual mode does not work on macOs (why?)" |
| 46 | endif |
| 47 | let save_mouse = &mouse |
| 48 | let save_term = &term |
| 49 | let save_ttymouse = &ttymouse |
| 50 | call test_override('no_query_mouse', 1) |
| 51 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 52 | call WaitForResponses() |
Bram Moolenaar | 6aa7523 | 2019-10-13 21:01:34 +0200 | [diff] [blame] | 53 | |
| 54 | for visual_mode in ["v", "V", "\<C-V>"] |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 55 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | 6aa7523 | 2019-10-13 21:01:34 +0200 | [diff] [blame] | 56 | let msg = 'visual=' .. visual_mode .. ' ttymouse=' .. ttymouse_val |
| 57 | exe 'set ttymouse=' .. ttymouse_val |
| 58 | |
| 59 | call setline(1, repeat([repeat('-', 7)], 7)) |
| 60 | call MouseLeftClick(4, 4) |
| 61 | call MouseLeftRelease(4, 4) |
| 62 | exe "norm! " .. visual_mode |
| 63 | |
| 64 | " Right click extends top left of visual area. |
| 65 | call MouseRightClick(2, 2) |
| 66 | call MouseRightRelease(2, 2) |
| 67 | |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 68 | " Right click extends bottom right of visual area. |
Bram Moolenaar | 6aa7523 | 2019-10-13 21:01:34 +0200 | [diff] [blame] | 69 | call MouseRightClick(6, 6) |
| 70 | call MouseRightRelease(6, 6) |
| 71 | norm! r1gv |
| 72 | |
| 73 | " Right click shrinks top left of visual area. |
| 74 | call MouseRightClick(3, 3) |
| 75 | call MouseRightRelease(3, 3) |
| 76 | |
| 77 | " Right click shrinks bottom right of visual area. |
| 78 | call MouseRightClick(5, 5) |
| 79 | call MouseRightRelease(5, 5) |
| 80 | norm! r2 |
| 81 | |
| 82 | if visual_mode ==# 'v' |
| 83 | call assert_equal(['-------', |
| 84 | \ '-111111', |
| 85 | \ '1122222', |
| 86 | \ '2222222', |
| 87 | \ '2222211', |
| 88 | \ '111111-', |
| 89 | \ '-------'], getline(1, '$'), msg) |
| 90 | elseif visual_mode ==# 'V' |
| 91 | call assert_equal(['-------', |
| 92 | \ '1111111', |
| 93 | \ '2222222', |
| 94 | \ '2222222', |
| 95 | \ '2222222', |
| 96 | \ '1111111', |
| 97 | \ '-------'], getline(1, '$'), msg) |
| 98 | else |
| 99 | call assert_equal(['-------', |
| 100 | \ '-11111-', |
| 101 | \ '-12221-', |
| 102 | \ '-12221-', |
| 103 | \ '-12221-', |
| 104 | \ '-11111-', |
| 105 | \ '-------'], getline(1, '$'), msg) |
| 106 | endif |
| 107 | endfor |
| 108 | endfor |
| 109 | |
| 110 | let &mouse = save_mouse |
| 111 | let &term = save_term |
| 112 | let &ttymouse = save_ttymouse |
| 113 | call test_override('no_query_mouse', 0) |
| 114 | bwipe! |
| 115 | endfunc |
| 116 | |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 117 | " Test that <C-LeftMouse> jumps to help tag and <C-RightMouse> jumps back. |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 118 | " Also test for g<LeftMouse> and g<RightMouse>. |
| 119 | func Test_xterm_mouse_tagjump() |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 120 | let save_mouse = &mouse |
| 121 | let save_term = &term |
| 122 | let save_ttymouse = &ttymouse |
| 123 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 124 | call WaitForResponses() |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 125 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 126 | for ttymouse_val in g:Ttymouse_values |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 127 | let msg = 'ttymouse=' .. ttymouse_val |
| 128 | exe 'set ttymouse=' .. ttymouse_val |
| 129 | help |
| 130 | /usr_02.txt |
| 131 | norm! zt |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 132 | |
| 133 | " CTRL-left click to jump to a tag |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 134 | let row = 1 |
| 135 | let col = 1 |
| 136 | call MouseCtrlLeftClick(row, col) |
| 137 | call MouseLeftRelease(row, col) |
| 138 | call assert_match('usr_02.txt$', bufname('%'), msg) |
Bram Moolenaar | b4367b7 | 2019-10-01 14:19:07 +0200 | [diff] [blame] | 139 | call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg) |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 140 | |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 141 | " CTRL-right click to pop a tag |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 142 | call MouseCtrlRightClick(row, col) |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 143 | call MouseRightRelease(row, col) |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 144 | call assert_match('help.txt$', bufname('%'), msg) |
Bram Moolenaar | b4367b7 | 2019-10-01 14:19:07 +0200 | [diff] [blame] | 145 | call assert_equal('|usr_02.txt|', expand('<cWORD>'), msg) |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 146 | |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 147 | " Jump to a tag |
| 148 | exe "normal \<C-]>" |
| 149 | call assert_match('usr_02.txt$', bufname('%'), msg) |
| 150 | call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg) |
| 151 | |
| 152 | " Use CTRL-right click in insert mode to pop the tag |
| 153 | new |
| 154 | let str = 'iHello' .. MouseCtrlRightClickCode(row, col) |
| 155 | \ .. MouseRightReleaseCode(row, col) .. "\<C-C>" |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 156 | call assert_fails('call feedkeys(str, "Lx!")', 'E37:', msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 157 | close! |
| 158 | |
| 159 | " CTRL-right click with a count |
| 160 | let str = "4" .. MouseCtrlRightClickCode(row, col) |
| 161 | \ .. MouseRightReleaseCode(row, col) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 162 | call assert_fails('call feedkeys(str, "Lx!")', 'E555:', msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 163 | call assert_match('help.txt$', bufname('%'), msg) |
| 164 | call assert_equal(1, line('.'), msg) |
| 165 | |
| 166 | " g<LeftMouse> to jump to a tag |
| 167 | /usr_02.txt |
| 168 | norm! zt |
| 169 | call test_setmouse(row, col) |
| 170 | exe "normal g\<LeftMouse>" |
| 171 | call assert_match('usr_02.txt$', bufname('%'), msg) |
| 172 | call assert_equal('*usr_02.txt*', expand('<cWORD>'), msg) |
| 173 | |
| 174 | " g<RightMouse> to pop to a tag |
| 175 | call test_setmouse(row, col) |
| 176 | exe "normal g\<RightMouse>" |
| 177 | call assert_match('help.txt$', bufname('%'), msg) |
| 178 | call assert_equal('|usr_02.txt|', expand('<cWORD>'), msg) |
| 179 | |
| 180 | %bw! |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 181 | endfor |
| 182 | |
| 183 | let &mouse = save_mouse |
| 184 | let &term = save_term |
| 185 | let &ttymouse = save_ttymouse |
| 186 | endfunc |
| 187 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 188 | func Test_term_mouse_middle_click() |
Bram Moolenaar | 52992fe | 2019-08-12 14:20:33 +0200 | [diff] [blame] | 189 | CheckFeature clipboard_working |
Bram Moolenaar | 564344a | 2019-04-28 13:00:12 +0200 | [diff] [blame] | 190 | |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 191 | new |
| 192 | let save_mouse = &mouse |
| 193 | let save_term = &term |
| 194 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 195 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 196 | let save_quotestar = @* |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 197 | let save_quoteplus = @+ |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 198 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 199 | call WaitForResponses() |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 200 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 201 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 202 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 203 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 204 | call setline(1, ['123456789', '123456789']) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 205 | let @* = 'abc' |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 206 | |
| 207 | " Middle-click in the middle of the line pastes text where clicked. |
| 208 | let row = 1 |
| 209 | let col = 6 |
| 210 | call MouseMiddleClick(row, col) |
| 211 | call MouseMiddleRelease(row, col) |
| 212 | call assert_equal(['12345abc6789', '123456789'], getline(1, '$'), msg) |
| 213 | |
| 214 | " Middle-click beyond end of the line pastes text at the end of the line. |
| 215 | let col = 20 |
| 216 | call MouseMiddleClick(row, col) |
| 217 | call MouseMiddleRelease(row, col) |
| 218 | call assert_equal(['12345abc6789abc', '123456789'], getline(1, '$'), msg) |
| 219 | |
| 220 | " Middle-click beyond the last line pastes in the last line. |
| 221 | let row = 5 |
| 222 | let col = 3 |
| 223 | call MouseMiddleClick(row, col) |
| 224 | call MouseMiddleRelease(row, col) |
| 225 | call assert_equal(['12345abc6789abc', '12abc3456789'], getline(1, '$'), msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 226 | |
| 227 | " Middle mouse click in operator pending mode beeps |
| 228 | call assert_beeps('exe "normal c\<MiddleMouse>"') |
| 229 | |
| 230 | " Clicking middle mouse in visual mode, yanks the selection and pastes the |
| 231 | " clipboard contents |
| 232 | let save_clipboard = &clipboard |
| 233 | set clipboard= |
| 234 | let @" = '' |
| 235 | call cursor(1, 1) |
| 236 | call feedkeys("v3l" .. |
| 237 | \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7), 'Lx!') |
| 238 | call assert_equal(['12345abc6789abc', '12abc3abc456789'], |
| 239 | \ getline(1, '$'), msg) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 240 | call assert_equal('1234', @", msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 241 | let &clipboard = save_clipboard |
| 242 | |
| 243 | " Clicking middle mouse in select mode, replaces the selected text with |
| 244 | " the clipboard contents |
| 245 | let @+ = 'xyz' |
| 246 | call cursor(1, 3) |
| 247 | exe "normal gh\<Right>\<Right>\<MiddleMouse>" |
| 248 | call assert_equal(['12xyzabc6789abc', '12abc3abc456789'], |
| 249 | \ getline(1, '$'), msg) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 250 | |
| 251 | " Prefixing middle click with [ or ] fixes the indent after pasting. |
| 252 | %d |
| 253 | call setline(1, " one two") |
| 254 | call setreg('r', 'red blue', 'l') |
| 255 | call test_setmouse(1, 5) |
| 256 | exe "normal \"r[\<MiddleMouse>" |
| 257 | call assert_equal(' red blue', getline(1), msg) |
| 258 | call test_setmouse(2, 5) |
| 259 | exe "normal \"r]\<MiddleMouse>" |
| 260 | call assert_equal(' red blue', getline(3), msg) |
| 261 | %d |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 262 | endfor |
| 263 | |
| 264 | let &mouse = save_mouse |
| 265 | let &term = save_term |
| 266 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 267 | call test_override('no_query_mouse', 0) |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 268 | let @* = save_quotestar |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 269 | let @+ = save_quotestar |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 270 | bwipe! |
| 271 | endfunc |
| 272 | |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 273 | " If clipboard is not working, then clicking the middle mouse button in visual |
| 274 | " mode, will copy and paste the selected text. |
| 275 | func Test_term_mouse_middle_click_no_clipboard() |
| 276 | if has('clipboard_working') |
| 277 | throw 'Skipped: clipboard support works' |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 278 | endif |
| 279 | new |
| 280 | let save_mouse = &mouse |
| 281 | let save_term = &term |
| 282 | let save_ttymouse = &ttymouse |
| 283 | call test_override('no_query_mouse', 1) |
| 284 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 285 | call WaitForResponses() |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 286 | |
| 287 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
| 288 | let msg = 'ttymouse=' .. ttymouse_val |
| 289 | exe 'set ttymouse=' .. ttymouse_val |
| 290 | call setline(1, ['123456789', '123456789']) |
| 291 | |
| 292 | " Clicking middle mouse in visual mode, yanks the selection and pastes it |
| 293 | call cursor(1, 1) |
| 294 | call feedkeys("v3l" .. |
| 295 | \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7), 'Lx!') |
| 296 | call assert_equal(['123456789', '1234561234789'], |
| 297 | \ getline(1, '$'), msg) |
| 298 | endfor |
| 299 | |
| 300 | call test_override('no_query_mouse', 0) |
| 301 | let &ttymouse = save_ttymouse |
| 302 | let &term = save_term |
| 303 | let &mouse = save_mouse |
| 304 | close! |
| 305 | endfunc |
| 306 | |
| 307 | func Test_term_mouse_middle_click_insert_mode() |
| 308 | CheckFeature clipboard_working |
| 309 | |
| 310 | new |
| 311 | let save_mouse = &mouse |
| 312 | let save_term = &term |
| 313 | let save_ttymouse = &ttymouse |
| 314 | call test_override('no_query_mouse', 1) |
| 315 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 316 | call WaitForResponses() |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 317 | |
| 318 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
| 319 | let msg = 'ttymouse=' .. ttymouse_val |
| 320 | exe 'set ttymouse=' .. ttymouse_val |
| 321 | call setline(1, ['123456789', '123456789']) |
| 322 | let @* = 'abc' |
| 323 | |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 324 | " Middle-click in insert mode doesn't move the cursor but inserts the |
| 325 | " contents of a register |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 326 | call cursor(1, 4) |
| 327 | call feedkeys('i' .. |
| 328 | \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7) .. |
| 329 | \ "\<C-C>", 'Lx!') |
| 330 | call assert_equal(['123abc456789', '123456789'], |
| 331 | \ getline(1, '$'), msg) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 332 | call assert_equal([1, 6], [line('.'), col('.')], msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 333 | |
| 334 | " Middle-click in replace mode |
| 335 | call cursor(1, 1) |
| 336 | call feedkeys('$R' .. |
| 337 | \ MouseMiddleClickCode(2, 7) .. MouseMiddleReleaseCode(2, 7) .. |
| 338 | \ "\<C-C>", 'Lx!') |
| 339 | call assert_equal(['123abc45678abc', '123456789'], |
| 340 | \ getline(1, '$'), msg) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 341 | call assert_equal([1, 14], [line('.'), col('.')], msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 342 | endfor |
| 343 | |
| 344 | let &mouse = save_mouse |
| 345 | let &term = save_term |
| 346 | let &ttymouse = save_ttymouse |
| 347 | call test_override('no_query_mouse', 0) |
| 348 | close! |
| 349 | endfunc |
| 350 | |
| 351 | " Test for switching window using mouse in insert mode |
| 352 | func Test_term_mouse_switch_win_insert_mode() |
| 353 | 5new |
| 354 | let save_mouse = &mouse |
| 355 | let save_term = &term |
| 356 | let save_ttymouse = &ttymouse |
| 357 | call test_override('no_query_mouse', 1) |
| 358 | set mouse=a term=xterm ttymouse=xterm2 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 359 | call WaitForResponses() |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 360 | |
| 361 | call feedkeys('ivim' .. |
| 362 | \ MouseLeftClickCode(8, 6) .. MouseLeftReleaseCode(8, 6) .. |
| 363 | \ "\<C-C>", 'Lx!') |
| 364 | call assert_equal(2, winnr()) |
| 365 | wincmd w |
| 366 | call assert_equal('n', mode()) |
| 367 | call assert_equal(['vim'], getline(1, '$')) |
| 368 | |
| 369 | let &mouse = save_mouse |
| 370 | let &term = save_term |
| 371 | let &ttymouse = save_ttymouse |
| 372 | call test_override('no_query_mouse', 0) |
| 373 | close! |
| 374 | endfunc |
| 375 | |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 376 | " Test for using the mouse to increase the height of the cmdline window |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 377 | func Test_mouse_cmdwin_resize() |
| 378 | let save_mouse = &mouse |
| 379 | let save_term = &term |
| 380 | let save_ttymouse = &ttymouse |
| 381 | call test_override('no_query_mouse', 1) |
| 382 | set mouse=a term=xterm ttymouse=xterm2 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 383 | call WaitForResponses() |
| 384 | |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 385 | 5new |
| 386 | redraw! |
| 387 | |
| 388 | let h = 0 |
| 389 | let row = &lines - &cmdwinheight - 2 |
| 390 | call feedkeys("q:" .. |
| 391 | \ MouseLeftClickCode(row, 1) .. |
| 392 | \ MouseLeftDragCode(row - 1, 1) .. |
| 393 | \ MouseLeftReleaseCode(row - 2, 1) .. |
| 394 | \ "alet h = \<C-R>=winheight(0)\<CR>\<CR>", 'Lx!') |
| 395 | call assert_equal(&cmdwinheight + 2, h) |
| 396 | |
| 397 | let &mouse = save_mouse |
| 398 | let &term = save_term |
| 399 | let &ttymouse = save_ttymouse |
| 400 | call test_override('no_query_mouse', 0) |
| 401 | close! |
| 402 | endfunc |
| 403 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 404 | " TODO: for unclear reasons this test fails if it comes after |
| 405 | " Test_xterm_mouse_ctrl_click() |
| 406 | func Test_1xterm_mouse_wheel() |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 407 | new |
| 408 | let save_mouse = &mouse |
| 409 | let save_term = &term |
Bram Moolenaar | d58d4f9 | 2020-07-01 15:49:29 +0200 | [diff] [blame] | 410 | let save_wrap = &wrap |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 411 | let save_ttymouse = &ttymouse |
Bram Moolenaar | d58d4f9 | 2020-07-01 15:49:29 +0200 | [diff] [blame] | 412 | set mouse=a term=xterm nowrap |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 413 | call WaitForResponses() |
| 414 | |
Bram Moolenaar | d58d4f9 | 2020-07-01 15:49:29 +0200 | [diff] [blame] | 415 | call setline(1, range(100000000000000, 100000000000100)) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 416 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 417 | for ttymouse_val in g:Ttymouse_values |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 418 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 419 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 420 | go |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 421 | call assert_equal(1, line('w0'), msg) |
| 422 | call assert_equal([0, 1, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 423 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 424 | call MouseWheelDown(1, 1) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 425 | call assert_equal(4, line('w0'), msg) |
| 426 | call assert_equal([0, 4, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 427 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 428 | call MouseWheelDown(1, 1) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 429 | call assert_equal(7, line('w0'), msg) |
| 430 | call assert_equal([0, 7, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 431 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 432 | call MouseWheelUp(1, 1) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 433 | call assert_equal(4, line('w0'), msg) |
| 434 | call assert_equal([0, 7, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 435 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 436 | call MouseWheelUp(1, 1) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 437 | call assert_equal(1, line('w0'), msg) |
| 438 | call assert_equal([0, 7, 1, 0], getpos('.'), msg) |
Bram Moolenaar | d58d4f9 | 2020-07-01 15:49:29 +0200 | [diff] [blame] | 439 | |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 440 | call MouseWheelRight(1, 1) |
| 441 | call assert_equal(7, 1 + virtcol(".") - wincol(), msg) |
| 442 | call assert_equal([0, 7, 7, 0], getpos('.'), msg) |
Bram Moolenaar | d58d4f9 | 2020-07-01 15:49:29 +0200 | [diff] [blame] | 443 | |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 444 | call MouseWheelRight(1, 1) |
| 445 | call assert_equal(13, 1 + virtcol(".") - wincol(), msg) |
| 446 | call assert_equal([0, 7, 13, 0], getpos('.'), msg) |
Bram Moolenaar | d58d4f9 | 2020-07-01 15:49:29 +0200 | [diff] [blame] | 447 | |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 448 | call MouseWheelLeft(1, 1) |
| 449 | call assert_equal(7, 1 + virtcol(".") - wincol(), msg) |
| 450 | call assert_equal([0, 7, 13, 0], getpos('.'), msg) |
Bram Moolenaar | d58d4f9 | 2020-07-01 15:49:29 +0200 | [diff] [blame] | 451 | |
Christopher Plewright | 20b795e | 2022-12-20 20:01:58 +0000 | [diff] [blame] | 452 | call MouseWheelLeft(1, 1) |
| 453 | call assert_equal(1, 1 + virtcol(".") - wincol(), msg) |
| 454 | call assert_equal([0, 7, 13, 0], getpos('.'), msg) |
| 455 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 456 | endfor |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 457 | |
| 458 | let &mouse = save_mouse |
| 459 | let &term = save_term |
Bram Moolenaar | d58d4f9 | 2020-07-01 15:49:29 +0200 | [diff] [blame] | 460 | let &wrap = save_wrap |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 461 | let &ttymouse = save_ttymouse |
| 462 | bwipe! |
| 463 | endfunc |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 464 | |
Bram Moolenaar | b4367b7 | 2019-10-01 14:19:07 +0200 | [diff] [blame] | 465 | " Test that dragging beyond the window (at the bottom and at the top) |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 466 | " scrolls window content by the number of lines beyond the window. |
Bram Moolenaar | b4367b7 | 2019-10-01 14:19:07 +0200 | [diff] [blame] | 467 | func Test_term_mouse_drag_beyond_window() |
| 468 | let save_mouse = &mouse |
| 469 | let save_term = &term |
| 470 | let save_ttymouse = &ttymouse |
| 471 | call test_override('no_query_mouse', 1) |
| 472 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 473 | call WaitForResponses() |
| 474 | |
Bram Moolenaar | b4367b7 | 2019-10-01 14:19:07 +0200 | [diff] [blame] | 475 | let col = 1 |
| 476 | call setline(1, range(1, 100)) |
| 477 | |
| 478 | " Split into 3 windows, and go into the middle window |
| 479 | " so we test dragging mouse below and above the window. |
| 480 | 2split |
| 481 | wincmd j |
| 482 | 2split |
| 483 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 484 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | b4367b7 | 2019-10-01 14:19:07 +0200 | [diff] [blame] | 485 | let msg = 'ttymouse=' .. ttymouse_val |
| 486 | exe 'set ttymouse=' .. ttymouse_val |
| 487 | |
| 488 | " Line #10 at the top. |
| 489 | norm! 10zt |
| 490 | redraw |
| 491 | call assert_equal(10, winsaveview().topline, msg) |
| 492 | call assert_equal(2, winheight(0), msg) |
| 493 | |
| 494 | let row = 4 |
| 495 | call MouseLeftClick(row, col) |
| 496 | call assert_equal(10, winsaveview().topline, msg) |
| 497 | |
| 498 | " Drag downwards. We're still in the window so topline should |
| 499 | " not change yet. |
| 500 | let row += 1 |
| 501 | call MouseLeftDrag(row, col) |
| 502 | call assert_equal(10, winsaveview().topline, msg) |
| 503 | |
| 504 | " We now leave the window at the bottom, so the window content should |
| 505 | " scroll by 1 line, then 2 lines (etc) as we drag further away. |
| 506 | let row += 1 |
| 507 | call MouseLeftDrag(row, col) |
| 508 | call assert_equal(11, winsaveview().topline, msg) |
| 509 | |
| 510 | let row += 1 |
| 511 | call MouseLeftDrag(row, col) |
| 512 | call assert_equal(13, winsaveview().topline, msg) |
| 513 | |
| 514 | " Now drag upwards. |
| 515 | let row -= 1 |
| 516 | call MouseLeftDrag(row, col) |
| 517 | call assert_equal(14, winsaveview().topline, msg) |
| 518 | |
| 519 | " We're now back in the window so the topline should not change. |
| 520 | let row -= 1 |
| 521 | call MouseLeftDrag(row, col) |
| 522 | call assert_equal(14, winsaveview().topline, msg) |
| 523 | |
| 524 | let row -= 1 |
| 525 | call MouseLeftDrag(row, col) |
| 526 | call assert_equal(14, winsaveview().topline, msg) |
| 527 | |
| 528 | " We now leave the window at the top so the window content should |
| 529 | " scroll by 1 line, then 2, then 3 (etc) in the opposite direction. |
| 530 | let row -= 1 |
| 531 | call MouseLeftDrag(row, col) |
| 532 | call assert_equal(13, winsaveview().topline, msg) |
| 533 | |
| 534 | let row -= 1 |
| 535 | call MouseLeftDrag(row, col) |
| 536 | call assert_equal(11, winsaveview().topline, msg) |
| 537 | |
| 538 | let row -= 1 |
| 539 | call MouseLeftDrag(row, col) |
| 540 | call assert_equal(8, winsaveview().topline, msg) |
| 541 | |
| 542 | call MouseLeftRelease(row, col) |
| 543 | call assert_equal(8, winsaveview().topline, msg) |
| 544 | call assert_equal(2, winheight(0), msg) |
| 545 | endfor |
| 546 | |
| 547 | let &mouse = save_mouse |
| 548 | let &term = save_term |
| 549 | let &ttymouse = save_ttymouse |
| 550 | call test_override('no_query_mouse', 0) |
| 551 | bwipe! |
| 552 | endfunc |
| 553 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 554 | func Test_term_mouse_drag_window_separator() |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 555 | let save_mouse = &mouse |
| 556 | let save_term = &term |
| 557 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 558 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 559 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 560 | call WaitForResponses() |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 561 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 562 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 563 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 564 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 565 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 566 | " Split horizontally and test dragging the horizontal window separator. |
| 567 | split |
| 568 | let rowseparator = winheight(0) + 1 |
| 569 | let row = rowseparator |
| 570 | let col = 1 |
Bram Moolenaar | c8b3dda | 2019-04-12 21:42:52 +0200 | [diff] [blame] | 571 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 572 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
| 573 | if ttymouse_val !=# 'xterm2' || row <= 223 |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 574 | call MouseLeftClick(row, col) |
| 575 | let row -= 1 |
| 576 | call MouseLeftDrag(row, col) |
zeertzjq | 8e0ccb6 | 2022-11-01 18:35:27 +0000 | [diff] [blame] | 577 | call assert_equal(rowseparator - 1, winheight(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 578 | let row += 1 |
| 579 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 580 | call assert_equal(rowseparator, winheight(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 581 | call MouseLeftRelease(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 582 | call assert_equal(rowseparator, winheight(0) + 1, msg) |
Bram Moolenaar | c8b3dda | 2019-04-12 21:42:52 +0200 | [diff] [blame] | 583 | endif |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 584 | bwipe! |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 585 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 586 | " Split vertically and test dragging the vertical window separator. |
| 587 | vsplit |
| 588 | let colseparator = winwidth(0) + 1 |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 589 | let row = 1 |
| 590 | let col = colseparator |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 591 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 592 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
| 593 | if ttymouse_val !=# 'xterm2' || col <= 223 |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 594 | call MouseLeftClick(row, col) |
| 595 | let col -= 1 |
| 596 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 597 | call assert_equal(colseparator - 1, winwidth(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 598 | let col += 1 |
| 599 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 600 | call assert_equal(colseparator, winwidth(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 601 | call MouseLeftRelease(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 602 | call assert_equal(colseparator, winwidth(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 603 | endif |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 604 | bwipe! |
| 605 | endfor |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 606 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 607 | let &mouse = save_mouse |
| 608 | let &term = save_term |
| 609 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 610 | call test_override('no_query_mouse', 0) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 611 | endfunc |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 612 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 613 | func Test_term_mouse_drag_statusline() |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 614 | let save_mouse = &mouse |
| 615 | let save_term = &term |
| 616 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 617 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 618 | let save_laststatus = &laststatus |
| 619 | set mouse=a term=xterm laststatus=2 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 620 | call WaitForResponses() |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 621 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 622 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 623 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 624 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 625 | |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 626 | call assert_equal(1, &cmdheight, msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 627 | let rowstatusline = winheight(0) + 1 |
| 628 | let row = rowstatusline |
| 629 | let col = 1 |
Bram Moolenaar | c8b3dda | 2019-04-12 21:42:52 +0200 | [diff] [blame] | 630 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 631 | if ttymouse_val ==# 'xterm2' && row > 223 |
| 632 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
Bram Moolenaar | c8b3dda | 2019-04-12 21:42:52 +0200 | [diff] [blame] | 633 | continue |
| 634 | endif |
| 635 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 636 | call MouseLeftClick(row, col) |
| 637 | let row -= 1 |
| 638 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 639 | call assert_equal(2, &cmdheight, msg) |
| 640 | call assert_equal(rowstatusline - 1, winheight(0) + 1, msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 641 | let row += 1 |
| 642 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 643 | call assert_equal(1, &cmdheight, msg) |
| 644 | call assert_equal(rowstatusline, winheight(0) + 1, msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 645 | call MouseLeftRelease(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 646 | call assert_equal(1, &cmdheight, msg) |
| 647 | call assert_equal(rowstatusline, winheight(0) + 1, msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 648 | endfor |
| 649 | |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 650 | let &mouse = save_mouse |
| 651 | let &term = save_term |
| 652 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 653 | call test_override('no_query_mouse', 0) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 654 | let &laststatus = save_laststatus |
| 655 | endfunc |
| 656 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 657 | func Test_term_mouse_click_tab() |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 658 | let save_mouse = &mouse |
| 659 | let save_term = &term |
| 660 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 661 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 662 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 663 | call WaitForResponses() |
| 664 | |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 665 | let row = 1 |
| 666 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 667 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 668 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 669 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 670 | e Xfoo |
| 671 | tabnew Xbar |
| 672 | |
| 673 | let a = split(execute(':tabs'), "\n") |
| 674 | call assert_equal(['Tab page 1', |
| 675 | \ ' Xfoo', |
| 676 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 677 | \ '> Xbar'], a, msg) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 678 | |
| 679 | " Test clicking on tab names in the tabline at the top. |
| 680 | let col = 2 |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 681 | redraw |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 682 | call MouseLeftClick(row, col) |
| 683 | call MouseLeftRelease(row, col) |
| 684 | let a = split(execute(':tabs'), "\n") |
| 685 | call assert_equal(['Tab page 1', |
| 686 | \ '> Xfoo', |
| 687 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 688 | \ ' Xbar'], a, msg) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 689 | |
| 690 | let col = 9 |
| 691 | call MouseLeftClick(row, col) |
| 692 | call MouseLeftRelease(row, col) |
| 693 | let a = split(execute(':tabs'), "\n") |
| 694 | call assert_equal(['Tab page 1', |
| 695 | \ ' Xfoo', |
| 696 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 697 | \ '> Xbar'], a, msg) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 698 | |
| 699 | %bwipe! |
| 700 | endfor |
| 701 | |
| 702 | let &mouse = save_mouse |
| 703 | let &term = save_term |
| 704 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 705 | call test_override('no_query_mouse', 0) |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 706 | endfunc |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 707 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 708 | func Test_term_mouse_click_X_to_close_tab() |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 709 | let save_mouse = &mouse |
| 710 | let save_term = &term |
| 711 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 712 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 713 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 714 | call WaitForResponses() |
| 715 | |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 716 | let row = 1 |
| 717 | let col = &columns |
| 718 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 719 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 720 | if ttymouse_val ==# 'xterm2' && col > 223 |
| 721 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 722 | continue |
| 723 | endif |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 724 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 725 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 726 | e Xtab1 |
| 727 | tabnew Xtab2 |
| 728 | tabnew Xtab3 |
| 729 | tabn 2 |
| 730 | |
| 731 | let a = split(execute(':tabs'), "\n") |
| 732 | call assert_equal(['Tab page 1', |
| 733 | \ ' Xtab1', |
| 734 | \ 'Tab page 2', |
| 735 | \ '> Xtab2', |
| 736 | \ 'Tab page 3', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 737 | \ ' Xtab3'], a, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 738 | |
| 739 | " Click on "X" in tabline to close current tab i.e. Xtab2. |
| 740 | redraw |
| 741 | call MouseLeftClick(row, col) |
| 742 | call MouseLeftRelease(row, col) |
| 743 | let a = split(execute(':tabs'), "\n") |
| 744 | call assert_equal(['Tab page 1', |
| 745 | \ ' Xtab1', |
| 746 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 747 | \ '> Xtab3'], a, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 748 | |
| 749 | %bwipe! |
| 750 | endfor |
| 751 | |
| 752 | let &mouse = save_mouse |
| 753 | let &term = save_term |
| 754 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 755 | call test_override('no_query_mouse', 0) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 756 | endfunc |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 757 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 758 | func Test_term_mouse_drag_to_move_tab() |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 759 | let save_mouse = &mouse |
| 760 | let save_term = &term |
| 761 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 762 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 763 | " Set 'mousetime' to 1 to avoid recognizing a double-click in the loop |
| 764 | set mouse=a term=xterm mousetime=1 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 765 | call WaitForResponses() |
| 766 | |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 767 | let row = 1 |
| 768 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 769 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 770 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 771 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 772 | e Xtab1 |
| 773 | tabnew Xtab2 |
| 774 | |
| 775 | let a = split(execute(':tabs'), "\n") |
| 776 | call assert_equal(['Tab page 1', |
| 777 | \ ' Xtab1', |
| 778 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 779 | \ '> Xtab2'], a, msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 780 | redraw |
| 781 | |
| 782 | " Click in tab2 and drag it to tab1. |
| 783 | " Check getcharmod() to verify that click is not |
| 784 | " interpreted as a spurious double-click. |
| 785 | call MouseLeftClick(row, 10) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 786 | call assert_equal(0, getcharmod(), msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 787 | for col in [9, 8, 7, 6] |
| 788 | call MouseLeftDrag(row, col) |
| 789 | endfor |
| 790 | call MouseLeftRelease(row, col) |
| 791 | let a = split(execute(':tabs'), "\n") |
| 792 | call assert_equal(['Tab page 1', |
| 793 | \ '> Xtab2', |
| 794 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 795 | \ ' Xtab1'], a, msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 796 | |
zeertzjq | 8e0ccb6 | 2022-11-01 18:35:27 +0000 | [diff] [blame] | 797 | " Switch to tab1 |
| 798 | tabnext |
| 799 | let a = split(execute(':tabs'), "\n") |
| 800 | call assert_equal(['Tab page 1', |
| 801 | \ ' Xtab2', |
| 802 | \ 'Tab page 2', |
| 803 | \ '> Xtab1'], a, msg) |
| 804 | |
| 805 | " Click in tab2 and drag it to tab1. |
| 806 | " This time it is non-current tab. |
| 807 | call MouseLeftClick(row, 6) |
| 808 | call assert_equal(0, getcharmod(), msg) |
| 809 | for col in [7, 8, 9, 10] |
| 810 | call MouseLeftDrag(row, col) |
| 811 | endfor |
| 812 | call MouseLeftRelease(row, col) |
| 813 | let a = split(execute(':tabs'), "\n") |
| 814 | call assert_equal(['Tab page 1', |
| 815 | \ ' Xtab1', |
| 816 | \ 'Tab page 2', |
| 817 | \ '> Xtab2'], a, msg) |
| 818 | |
Bram Moolenaar | f36a2c7 | 2019-11-16 18:57:16 +0100 | [diff] [blame] | 819 | " Click elsewhere so that click in next iteration is not |
| 820 | " interpreted as unwanted double-click. |
| 821 | call MouseLeftClick(row, 11) |
| 822 | call MouseLeftRelease(row, 11) |
| 823 | |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 824 | %bwipe! |
| 825 | endfor |
| 826 | |
| 827 | let &mouse = save_mouse |
| 828 | let &term = save_term |
| 829 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 830 | call test_override('no_query_mouse', 0) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 831 | set mousetime& |
| 832 | endfunc |
| 833 | |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 834 | func Test_term_mouse_double_click_to_create_tab() |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 835 | let save_mouse = &mouse |
| 836 | let save_term = &term |
| 837 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 838 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 839 | " Set 'mousetime' to a small value, so that double-click works but we don't |
| 840 | " have to wait long to avoid a triple-click. |
Bram Moolenaar | f36a2c7 | 2019-11-16 18:57:16 +0100 | [diff] [blame] | 841 | set mouse=a term=xterm mousetime=200 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 842 | call WaitForResponses() |
| 843 | |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 844 | let row = 1 |
| 845 | let col = 10 |
| 846 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 847 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 848 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 849 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 850 | e Xtab1 |
| 851 | tabnew Xtab2 |
| 852 | |
| 853 | let a = split(execute(':tabs'), "\n") |
| 854 | call assert_equal(['Tab page 1', |
| 855 | \ ' Xtab1', |
| 856 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 857 | \ '> Xtab2'], a, msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 858 | |
| 859 | redraw |
| 860 | call MouseLeftClick(row, col) |
| 861 | " Check getcharmod() to verify that first click is not |
| 862 | " interpreted as a spurious double-click. |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 863 | call assert_equal(0, getcharmod(), msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 864 | call MouseLeftRelease(row, col) |
| 865 | call MouseLeftClick(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 866 | call assert_equal(32, getcharmod(), msg) " double-click |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 867 | call MouseLeftRelease(row, col) |
| 868 | let a = split(execute(':tabs'), "\n") |
| 869 | call assert_equal(['Tab page 1', |
| 870 | \ ' Xtab1', |
| 871 | \ 'Tab page 2', |
| 872 | \ '> [No Name]', |
| 873 | \ 'Tab page 3', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 874 | \ ' Xtab2'], a, msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 875 | |
Bram Moolenaar | f36a2c7 | 2019-11-16 18:57:16 +0100 | [diff] [blame] | 876 | " Click elsewhere so that click in next iteration is not |
| 877 | " interpreted as unwanted double click. |
| 878 | call MouseLeftClick(row, col + 1) |
| 879 | call MouseLeftRelease(row, col + 1) |
| 880 | |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 881 | %bwipe! |
| 882 | endfor |
| 883 | |
| 884 | let &mouse = save_mouse |
| 885 | let &term = save_term |
| 886 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 92fd599 | 2019-05-02 23:00:22 +0200 | [diff] [blame] | 887 | call test_override('no_query_mouse', 0) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 888 | set mousetime& |
| 889 | endfunc |
Bram Moolenaar | 696d637 | 2019-04-17 16:33:46 +0200 | [diff] [blame] | 890 | |
Bram Moolenaar | f36a2c7 | 2019-11-16 18:57:16 +0100 | [diff] [blame] | 891 | " Test double/triple/quadruple click in normal mode to visually select. |
| 892 | func Test_term_mouse_multiple_clicks_to_visually_select() |
| 893 | let save_mouse = &mouse |
| 894 | let save_term = &term |
| 895 | let save_ttymouse = &ttymouse |
| 896 | call test_override('no_query_mouse', 1) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 897 | |
Bram Moolenaar | 2a5c61a | 2020-12-30 14:59:23 +0100 | [diff] [blame] | 898 | " 'mousetime' must be sufficiently large, or else the test is flaky when |
| 899 | " using a ssh connection with X forwarding; i.e. ssh -X (issue #7563). |
| 900 | set mouse=a term=xterm mousetime=600 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 901 | call WaitForResponses() |
| 902 | |
Bram Moolenaar | f36a2c7 | 2019-11-16 18:57:16 +0100 | [diff] [blame] | 903 | new |
| 904 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 905 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | f36a2c7 | 2019-11-16 18:57:16 +0100 | [diff] [blame] | 906 | let msg = 'ttymouse=' .. ttymouse_val |
| 907 | exe 'set ttymouse=' .. ttymouse_val |
| 908 | call setline(1, ['foo [foo bar] foo', 'foo']) |
| 909 | |
| 910 | " Double-click on word should visually select the word. |
| 911 | call MouseLeftClick(1, 2) |
| 912 | call assert_equal(0, getcharmod(), msg) |
| 913 | call MouseLeftRelease(1, 2) |
| 914 | call MouseLeftClick(1, 2) |
| 915 | call assert_equal(32, getcharmod(), msg) " double-click |
| 916 | call MouseLeftRelease(1, 2) |
| 917 | call assert_equal('v', mode(), msg) |
| 918 | norm! r1 |
| 919 | call assert_equal(['111 [foo bar] foo', 'foo'], getline(1, '$'), msg) |
| 920 | |
| 921 | " Double-click on opening square bracket should visually |
| 922 | " select the whole [foo bar]. |
| 923 | call MouseLeftClick(1, 5) |
| 924 | call assert_equal(0, getcharmod(), msg) |
| 925 | call MouseLeftRelease(1, 5) |
| 926 | call MouseLeftClick(1, 5) |
| 927 | call assert_equal(32, getcharmod(), msg) " double-click |
| 928 | call MouseLeftRelease(1, 5) |
| 929 | call assert_equal('v', mode(), msg) |
| 930 | norm! r2 |
| 931 | call assert_equal(['111 222222222 foo', 'foo'], getline(1, '$'), msg) |
| 932 | |
| 933 | " Triple-click should visually select the whole line. |
| 934 | call MouseLeftClick(1, 3) |
| 935 | call assert_equal(0, getcharmod(), msg) |
| 936 | call MouseLeftRelease(1, 3) |
| 937 | call MouseLeftClick(1, 3) |
| 938 | call assert_equal(32, getcharmod(), msg) " double-click |
| 939 | call MouseLeftRelease(1, 3) |
| 940 | call MouseLeftClick(1, 3) |
| 941 | call assert_equal(64, getcharmod(), msg) " triple-click |
| 942 | call MouseLeftRelease(1, 3) |
| 943 | call assert_equal('V', mode(), msg) |
| 944 | norm! r3 |
| 945 | call assert_equal(['33333333333333333', 'foo'], getline(1, '$'), msg) |
| 946 | |
| 947 | " Quadruple-click should start visual block select. |
| 948 | call MouseLeftClick(1, 2) |
| 949 | call assert_equal(0, getcharmod(), msg) |
| 950 | call MouseLeftRelease(1, 2) |
| 951 | call MouseLeftClick(1, 2) |
| 952 | call assert_equal(32, getcharmod(), msg) " double-click |
| 953 | call MouseLeftRelease(1, 2) |
| 954 | call MouseLeftClick(1, 2) |
| 955 | call assert_equal(64, getcharmod(), msg) " triple-click |
| 956 | call MouseLeftRelease(1, 2) |
| 957 | call MouseLeftClick(1, 2) |
| 958 | call assert_equal(96, getcharmod(), msg) " quadruple-click |
| 959 | call MouseLeftRelease(1, 2) |
| 960 | call assert_equal("\<c-v>", mode(), msg) |
| 961 | norm! r4 |
| 962 | call assert_equal(['34333333333333333', 'foo'], getline(1, '$'), msg) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 963 | |
| 964 | " Double-click on a space character should visually select all the |
| 965 | " consecutive space characters. |
| 966 | %d |
| 967 | call setline(1, ' one two') |
| 968 | call MouseLeftClick(1, 2) |
| 969 | call MouseLeftRelease(1, 2) |
| 970 | call MouseLeftClick(1, 2) |
| 971 | call MouseLeftRelease(1, 2) |
| 972 | call assert_equal('v', mode(), msg) |
| 973 | norm! r1 |
| 974 | call assert_equal(['1111one two'], getline(1, '$'), msg) |
| 975 | |
| 976 | " Double-click on a word with exclusive selection |
| 977 | set selection=exclusive |
| 978 | let @" = '' |
| 979 | call MouseLeftClick(1, 10) |
| 980 | call MouseLeftRelease(1, 10) |
| 981 | call MouseLeftClick(1, 10) |
| 982 | call MouseLeftRelease(1, 10) |
| 983 | norm! y |
| 984 | call assert_equal('two', @", msg) |
| 985 | |
| 986 | " Double click to select a block of text with exclusive selection |
| 987 | %d |
| 988 | call setline(1, 'one (two) three') |
| 989 | call MouseLeftClick(1, 5) |
| 990 | call MouseLeftRelease(1, 5) |
| 991 | call MouseLeftClick(1, 5) |
| 992 | call MouseLeftRelease(1, 5) |
| 993 | norm! y |
| 994 | call assert_equal(5, col("'<"), msg) |
| 995 | call assert_equal(10, col("'>"), msg) |
| 996 | |
| 997 | call MouseLeftClick(1, 9) |
| 998 | call MouseLeftRelease(1, 9) |
| 999 | call MouseLeftClick(1, 9) |
| 1000 | call MouseLeftRelease(1, 9) |
| 1001 | norm! y |
| 1002 | call assert_equal(5, col("'<"), msg) |
| 1003 | call assert_equal(10, col("'>"), msg) |
| 1004 | set selection& |
| 1005 | |
| 1006 | " Click somewhere else so that the clicks above is not combined with the |
| 1007 | " clicks in the next iteration. |
| 1008 | call MouseRightClick(3, 10) |
| 1009 | call MouseRightRelease(3, 10) |
Bram Moolenaar | f36a2c7 | 2019-11-16 18:57:16 +0100 | [diff] [blame] | 1010 | endfor |
| 1011 | |
| 1012 | let &mouse = save_mouse |
| 1013 | let &term = save_term |
| 1014 | let &ttymouse = save_ttymouse |
| 1015 | set mousetime& |
| 1016 | call test_override('no_query_mouse', 0) |
| 1017 | bwipe! |
| 1018 | endfunc |
| 1019 | |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1020 | " Test for selecting text in visual blockwise mode using Alt-LeftClick |
| 1021 | func Test_mouse_alt_leftclick() |
| 1022 | let save_mouse = &mouse |
| 1023 | let save_term = &term |
| 1024 | let save_ttymouse = &ttymouse |
| 1025 | call test_override('no_query_mouse', 1) |
| 1026 | set mouse=a term=xterm mousetime=200 |
| 1027 | set mousemodel=popup |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1028 | call WaitForResponses() |
| 1029 | |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1030 | new |
| 1031 | call setline(1, 'one (two) three') |
| 1032 | |
| 1033 | for ttymouse_val in g:Ttymouse_values |
| 1034 | let msg = 'ttymouse=' .. ttymouse_val |
| 1035 | exe 'set ttymouse=' .. ttymouse_val |
| 1036 | |
| 1037 | " Left click with the Alt modifier key should extend the selection in |
| 1038 | " blockwise visual mode. |
| 1039 | let @" = '' |
| 1040 | call MouseLeftClick(1, 3) |
| 1041 | call MouseLeftRelease(1, 3) |
| 1042 | call MouseAltLeftClick(1, 11) |
| 1043 | call MouseLeftRelease(1, 11) |
| 1044 | call assert_equal("\<C-V>", mode(), msg) |
| 1045 | normal! y |
| 1046 | call assert_equal('e (two) t', @") |
| 1047 | endfor |
| 1048 | |
| 1049 | let &mouse = save_mouse |
| 1050 | let &term = save_term |
| 1051 | let &ttymouse = save_ttymouse |
| 1052 | set mousetime& mousemodel& |
| 1053 | call test_override('no_query_mouse', 0) |
| 1054 | close! |
| 1055 | endfunc |
| 1056 | |
Bram Moolenaar | 696d637 | 2019-04-17 16:33:46 +0200 | [diff] [blame] | 1057 | func Test_xterm_mouse_click_in_fold_columns() |
| 1058 | new |
| 1059 | let save_mouse = &mouse |
| 1060 | let save_term = &term |
| 1061 | let save_ttymouse = &ttymouse |
| 1062 | let save_foldcolumn = &foldcolumn |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 1063 | set mouse=a term=xterm foldcolumn=3 ttymouse=xterm2 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1064 | call WaitForResponses() |
Bram Moolenaar | 696d637 | 2019-04-17 16:33:46 +0200 | [diff] [blame] | 1065 | |
| 1066 | " Create 2 nested folds. |
| 1067 | call setline(1, range(1, 7)) |
| 1068 | 2,6fold |
| 1069 | norm! zR |
| 1070 | 4,5fold |
| 1071 | call assert_equal([-1, -1, -1, 4, 4, -1, -1], |
| 1072 | \ map(range(1, 7), 'foldclosed(v:val)')) |
| 1073 | |
| 1074 | " Click in "+" of inner fold in foldcolumn should open it. |
| 1075 | redraw |
| 1076 | let row = 4 |
| 1077 | let col = 2 |
| 1078 | call MouseLeftClick(row, col) |
| 1079 | call MouseLeftRelease(row, col) |
| 1080 | call assert_equal([-1, -1, -1, -1, -1, -1, -1], |
| 1081 | \ map(range(1, 7), 'foldclosed(v:val)')) |
| 1082 | |
| 1083 | " Click in "-" of outer fold in foldcolumn should close it. |
| 1084 | redraw |
| 1085 | let row = 2 |
| 1086 | let col = 1 |
| 1087 | call MouseLeftClick(row, col) |
| 1088 | call MouseLeftRelease(row, col) |
| 1089 | call assert_equal([-1, 2, 2, 2, 2, 2, -1], |
| 1090 | \ map(range(1, 7), 'foldclosed(v:val)')) |
| 1091 | norm! zR |
| 1092 | |
| 1093 | " Click in "|" of inner fold in foldcolumn should close it. |
| 1094 | redraw |
| 1095 | let row = 5 |
| 1096 | let col = 2 |
| 1097 | call MouseLeftClick(row, col) |
| 1098 | call MouseLeftRelease(row, col) |
| 1099 | call assert_equal([-1, -1, -1, 4, 4, -1, -1], |
| 1100 | \ map(range(1, 7), 'foldclosed(v:val)')) |
| 1101 | |
| 1102 | let &foldcolumn = save_foldcolumn |
| 1103 | let &ttymouse = save_ttymouse |
| 1104 | let &term = save_term |
| 1105 | let &mouse = save_mouse |
| 1106 | bwipe! |
| 1107 | endfunc |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1108 | |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 1109 | " Left or right click in Ex command line sets position of the cursor. |
| 1110 | func Test_term_mouse_click_in_cmdline_to_set_pos() |
| 1111 | let save_mouse = &mouse |
| 1112 | let save_term = &term |
| 1113 | let save_ttymouse = &ttymouse |
| 1114 | call test_override('no_query_mouse', 1) |
| 1115 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1116 | call WaitForResponses() |
| 1117 | |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 1118 | let row = &lines |
| 1119 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 1120 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 1121 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
| 1122 | if ttymouse_val !=# 'xterm2' || row <= 223 |
| 1123 | let msg = 'ttymouse=' .. ttymouse_val |
| 1124 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 1125 | |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 1126 | |
| 1127 | call feedkeys(':"3456789' |
| 1128 | \ .. MouseLeftClickCode(row, 7) |
| 1129 | \ .. MouseLeftReleaseCode(row, 7) .. 'L' |
| 1130 | \ .. MouseRightClickCode(row, 4) |
| 1131 | \ .. MouseRightReleaseCode(row, 4) .. 'R' |
| 1132 | \ .. "\<CR>", 'Lx!') |
| 1133 | call assert_equal('"3R456L789', @:, msg) |
| 1134 | endif |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 1135 | endfor |
| 1136 | |
| 1137 | let &mouse = save_mouse |
| 1138 | let &term = save_term |
| 1139 | let &ttymouse = save_ttymouse |
| 1140 | set mousetime& |
| 1141 | call test_override('no_query_mouse', 0) |
| 1142 | endfunc |
| 1143 | |
| 1144 | " Middle click in command line pastes at position of cursor. |
| 1145 | func Test_term_mouse_middle_click_in_cmdline_to_paste() |
| 1146 | CheckFeature clipboard_working |
| 1147 | let save_mouse = &mouse |
| 1148 | let save_term = &term |
| 1149 | let save_ttymouse = &ttymouse |
| 1150 | call test_override('no_query_mouse', 1) |
| 1151 | set mouse=a term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1152 | call WaitForResponses() |
| 1153 | |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 1154 | let row = &lines |
| 1155 | " Column values does not matter, paste is done at position of cursor. |
| 1156 | let col = 1 |
| 1157 | let @* = 'paste' |
| 1158 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 1159 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 1160 | let msg = 'ttymouse=' .. ttymouse_val |
| 1161 | exe 'set ttymouse=' .. ttymouse_val |
| 1162 | |
| 1163 | call feedkeys(":\"->" |
| 1164 | \ .. MouseMiddleReleaseCode(row, col) |
| 1165 | \ .. MouseMiddleClickCode(row, col) |
| 1166 | \ .. "<-" |
| 1167 | \ .. MouseMiddleReleaseCode(row, col) |
| 1168 | \ .. MouseMiddleClickCode(row, col) |
| 1169 | \ .. "\<CR>", 'Lx!') |
| 1170 | call assert_equal('"->paste<-paste', @:, msg) |
| 1171 | endfor |
| 1172 | |
| 1173 | let &mouse = save_mouse |
| 1174 | let &term = save_term |
| 1175 | let &ttymouse = save_ttymouse |
| 1176 | let @* = '' |
| 1177 | call test_override('no_query_mouse', 0) |
| 1178 | endfunc |
| 1179 | |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1180 | " Test for making sure S-Middlemouse doesn't do anything |
| 1181 | func Test_term_mouse_shift_middle_click() |
| 1182 | new |
| 1183 | let save_mouse = &mouse |
| 1184 | let save_term = &term |
| 1185 | let save_ttymouse = &ttymouse |
| 1186 | call test_override('no_query_mouse', 1) |
| 1187 | set mouse=a term=xterm ttymouse=xterm2 mousemodel= |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1188 | call WaitForResponses() |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1189 | |
| 1190 | call test_setmouse(1, 1) |
| 1191 | exe "normal \<S-MiddleMouse>" |
| 1192 | call assert_equal([''], getline(1, '$')) |
| 1193 | call assert_equal(1, winnr()) |
| 1194 | |
| 1195 | let &mouse = save_mouse |
| 1196 | let &term = save_term |
| 1197 | let &ttymouse = save_ttymouse |
| 1198 | set mousemodel& |
| 1199 | call test_override('no_query_mouse', 0) |
| 1200 | close! |
| 1201 | endfunc |
| 1202 | |
| 1203 | " Test for using mouse in visual mode |
| 1204 | func Test_term_mouse_visual_mode() |
| 1205 | new |
| 1206 | let save_mouse = &mouse |
| 1207 | let save_term = &term |
| 1208 | let save_ttymouse = &ttymouse |
| 1209 | call test_override('no_query_mouse', 1) |
| 1210 | set term=xterm ttymouse=xterm2 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1211 | call WaitForResponses() |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1212 | |
| 1213 | " If visual mode is not present in 'mouse', then left click should not |
| 1214 | " do anything in visal mode. |
| 1215 | call setline(1, ['one two three four']) |
| 1216 | set mouse=nci |
| 1217 | call cursor(1, 5) |
| 1218 | let @" = '' |
| 1219 | call feedkeys("ve" |
| 1220 | \ .. MouseLeftClickCode(1, 15) .. MouseLeftReleaseCode(1, 15) |
| 1221 | \ .. 'y', 'Lx!') |
| 1222 | call assert_equal(5, col('.')) |
| 1223 | call assert_equal('two', @") |
| 1224 | |
| 1225 | " Pressing right click in visual mode should change the visual selection |
| 1226 | " if 'mousemodel' doesn't contain popup. |
| 1227 | " Right click after the visual selection |
| 1228 | set mousemodel= |
| 1229 | set mouse=a |
| 1230 | call test_setmouse(1, 13) |
| 1231 | exe "normal 5|ve\<RightMouse>y" |
| 1232 | call assert_equal('two three', @") |
| 1233 | call assert_equal(5, col('.')) |
| 1234 | |
| 1235 | " Right click before the visual selection |
| 1236 | call test_setmouse(1, 9) |
| 1237 | exe "normal 15|ve\<RightMouse>y" |
| 1238 | call assert_equal('three four', @") |
| 1239 | call assert_equal(9, col('.')) |
| 1240 | |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1241 | " Right click inside the selection closer to the start of the selection |
| 1242 | call test_setmouse(1, 7) |
| 1243 | exe "normal 5|vee\<RightMouse>lly" |
| 1244 | call assert_equal('three', @") |
| 1245 | call assert_equal(9, col('.')) |
| 1246 | call assert_equal(9, col("'<")) |
| 1247 | call assert_equal(13, col("'>")) |
| 1248 | |
| 1249 | " Right click inside the selection closer to the end of the selection |
| 1250 | call test_setmouse(1, 11) |
| 1251 | exe "normal 5|vee\<RightMouse>ly" |
| 1252 | call assert_equal('two thre', @") |
| 1253 | call assert_equal(5, col('.')) |
| 1254 | call assert_equal(5, col("'<")) |
| 1255 | call assert_equal(12, col("'>")) |
| 1256 | |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 1257 | " Multi-line selection. Right click inside the selection. |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1258 | call setline(1, repeat(['aaaaaa'], 7)) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1259 | call test_setmouse(3, 1) |
| 1260 | exe "normal ggVG\<RightMouse>y" |
| 1261 | call assert_equal(3, line("'<")) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1262 | call test_setmouse(5, 1) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1263 | exe "normal ggVG\<RightMouse>y" |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1264 | call assert_equal(5, line("'>")) |
| 1265 | |
| 1266 | " Click right in the middle line of the selection |
| 1267 | call test_setmouse(4, 3) |
| 1268 | exe "normal ggVG$\<RightMouse>y" |
| 1269 | call assert_equal(4, line("'<")) |
| 1270 | call test_setmouse(4, 4) |
| 1271 | exe "normal ggVG$\<RightMouse>y" |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1272 | call assert_equal(4, line("'>")) |
| 1273 | |
| 1274 | set mousemodel& |
| 1275 | let &mouse = save_mouse |
| 1276 | let &term = save_term |
| 1277 | let &ttymouse = save_ttymouse |
| 1278 | call test_override('no_query_mouse', 0) |
| 1279 | close! |
| 1280 | endfunc |
| 1281 | |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 1282 | " Test for displaying the popup menu using the right mouse click |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1283 | func Test_term_mouse_popup_menu() |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 1284 | CheckFeature menu |
| 1285 | new |
| 1286 | call setline(1, 'popup menu test') |
| 1287 | let save_mouse = &mouse |
| 1288 | let save_term = &term |
| 1289 | let save_ttymouse = &ttymouse |
| 1290 | let save_mousemodel = &mousemodel |
| 1291 | call test_override('no_query_mouse', 1) |
| 1292 | set mouse=a term=xterm mousemodel=popup |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1293 | call WaitForResponses() |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 1294 | |
| 1295 | menu PopUp.foo :let g:menustr = 'foo'<CR> |
| 1296 | menu PopUp.bar :let g:menustr = 'bar'<CR> |
| 1297 | menu PopUp.baz :let g:menustr = 'baz'<CR> |
| 1298 | |
Bram Moolenaar | 515545e | 2020-03-22 14:08:59 +0100 | [diff] [blame] | 1299 | for ttymouse_val in g:Ttymouse_values |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1300 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 1301 | exe 'set ttymouse=' .. ttymouse_val |
| 1302 | let g:menustr = '' |
| 1303 | call feedkeys(MouseRightClickCode(1, 4) |
| 1304 | \ .. MouseRightReleaseCode(1, 4) .. "\<Down>\<Down>\<CR>", "x") |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1305 | call assert_equal('bar', g:menustr, msg) |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 1306 | endfor |
| 1307 | |
| 1308 | unmenu PopUp |
| 1309 | let &mouse = save_mouse |
| 1310 | let &term = save_term |
| 1311 | let &ttymouse = save_ttymouse |
| 1312 | let &mousemodel = save_mousemodel |
| 1313 | call test_override('no_query_mouse', 0) |
| 1314 | close! |
| 1315 | endfunc |
| 1316 | |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1317 | " Test for 'mousemodel' set to popup_setpos to move the cursor where the popup |
| 1318 | " menu is displayed. |
| 1319 | func Test_term_mouse_popup_menu_setpos() |
| 1320 | CheckFeature menu |
| 1321 | 5new |
| 1322 | call setline(1, ['the dish ran away with the spoon', |
| 1323 | \ 'the cow jumped over the moon' ]) |
| 1324 | let save_mouse = &mouse |
| 1325 | let save_term = &term |
| 1326 | let save_ttymouse = &ttymouse |
| 1327 | let save_mousemodel = &mousemodel |
| 1328 | call test_override('no_query_mouse', 1) |
| 1329 | set mouse=a term=xterm mousemodel=popup_setpos |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1330 | call WaitForResponses() |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1331 | |
| 1332 | nmenu PopUp.foo :let g:menustr = 'foo'<CR> |
| 1333 | nmenu PopUp.bar :let g:menustr = 'bar'<CR> |
| 1334 | nmenu PopUp.baz :let g:menustr = 'baz'<CR> |
| 1335 | vmenu PopUp.foo y:<C-U>let g:menustr = 'foo'<CR> |
| 1336 | vmenu PopUp.bar y:<C-U>let g:menustr = 'bar'<CR> |
| 1337 | vmenu PopUp.baz y:<C-U>let g:menustr = 'baz'<CR> |
| 1338 | |
| 1339 | for ttymouse_val in g:Ttymouse_values |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1340 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1341 | exe 'set ttymouse=' .. ttymouse_val |
| 1342 | let g:menustr = '' |
| 1343 | call cursor(1, 1) |
| 1344 | call feedkeys(MouseRightClickCode(1, 5) |
| 1345 | \ .. MouseRightReleaseCode(1, 5) .. "\<Down>\<Down>\<CR>", "x") |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1346 | call assert_equal('bar', g:menustr, msg) |
| 1347 | call assert_equal([1, 5], [line('.'), col('.')], msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1348 | |
| 1349 | " Test for right click in visual mode inside the selection |
| 1350 | let @" = '' |
| 1351 | call cursor(1, 10) |
| 1352 | call feedkeys('vee' .. MouseRightClickCode(1, 12) |
| 1353 | \ .. MouseRightReleaseCode(1, 12) .. "\<Down>\<CR>", "x") |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1354 | call assert_equal([1, 10], [line('.'), col('.')], msg) |
| 1355 | call assert_equal('ran away', @", msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1356 | |
Yee Cheng Chin | 17822c5 | 2022-10-13 13:17:40 +0100 | [diff] [blame] | 1357 | " Test for right click in visual mode right before the selection |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1358 | let @" = '' |
| 1359 | call cursor(1, 10) |
Yee Cheng Chin | 17822c5 | 2022-10-13 13:17:40 +0100 | [diff] [blame] | 1360 | call feedkeys('vee' .. MouseRightClickCode(1, 9) |
| 1361 | \ .. MouseRightReleaseCode(1, 9) .. "\<Down>\<CR>", "x") |
| 1362 | call assert_equal([1, 9], [line('.'), col('.')], msg) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1363 | call assert_equal('', @", msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1364 | |
Yee Cheng Chin | 17822c5 | 2022-10-13 13:17:40 +0100 | [diff] [blame] | 1365 | " Test for right click in visual mode right after the selection |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1366 | let @" = '' |
| 1367 | call cursor(1, 10) |
Yee Cheng Chin | 17822c5 | 2022-10-13 13:17:40 +0100 | [diff] [blame] | 1368 | call feedkeys('vee' .. MouseRightClickCode(1, 18) |
| 1369 | \ .. MouseRightReleaseCode(1, 18) .. "\<Down>\<CR>", "x") |
| 1370 | call assert_equal([1, 18], [line('.'), col('.')], msg) |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1371 | call assert_equal('', @", msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1372 | |
| 1373 | " Test for right click in block-wise visual mode inside the selection |
| 1374 | let @" = '' |
| 1375 | call cursor(1, 16) |
| 1376 | call feedkeys("\<C-V>j3l" .. MouseRightClickCode(2, 17) |
| 1377 | \ .. MouseRightReleaseCode(2, 17) .. "\<Down>\<CR>", "x") |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1378 | call assert_equal([1, 16], [line('.'), col('.')], msg) |
| 1379 | call assert_equal("\<C-V>4", getregtype('"'), msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1380 | |
| 1381 | " Test for right click in block-wise visual mode outside the selection |
| 1382 | let @" = '' |
| 1383 | call cursor(1, 16) |
| 1384 | call feedkeys("\<C-V>j3l" .. MouseRightClickCode(2, 2) |
| 1385 | \ .. MouseRightReleaseCode(2, 2) .. "\<Down>\<CR>", "x") |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1386 | call assert_equal([2, 2], [line('.'), col('.')], msg) |
| 1387 | call assert_equal('v', getregtype('"'), msg) |
| 1388 | call assert_equal('', @", msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1389 | |
Yee Cheng Chin | 17822c5 | 2022-10-13 13:17:40 +0100 | [diff] [blame] | 1390 | " Test for right click in line-wise visual mode inside the selection |
| 1391 | let @" = '' |
| 1392 | call cursor(1, 16) |
| 1393 | call feedkeys("V" .. MouseRightClickCode(1, 10) |
| 1394 | \ .. MouseRightReleaseCode(1, 10) .. "\<Down>\<CR>", "x") |
| 1395 | call assert_equal([1, 1], [line('.'), col('.')], msg) " After yanking, the cursor goes to 1,1 |
| 1396 | call assert_equal("V", getregtype('"'), msg) |
zeertzjq | df63f05 | 2022-10-19 15:12:54 +0100 | [diff] [blame] | 1397 | call assert_equal(1, len(getreg('"', 1, v:true)), msg) |
Yee Cheng Chin | 17822c5 | 2022-10-13 13:17:40 +0100 | [diff] [blame] | 1398 | |
| 1399 | " Test for right click in multi-line line-wise visual mode inside the selection |
| 1400 | let @" = '' |
| 1401 | call cursor(1, 16) |
| 1402 | call feedkeys("Vj" .. MouseRightClickCode(2, 20) |
| 1403 | \ .. MouseRightReleaseCode(2, 20) .. "\<Down>\<CR>", "x") |
| 1404 | call assert_equal([1, 1], [line('.'), col('.')], msg) " After yanking, the cursor goes to 1,1 |
| 1405 | call assert_equal("V", getregtype('"'), msg) |
zeertzjq | df63f05 | 2022-10-19 15:12:54 +0100 | [diff] [blame] | 1406 | call assert_equal(2, len(getreg('"', 1, v:true)), msg) |
Yee Cheng Chin | 17822c5 | 2022-10-13 13:17:40 +0100 | [diff] [blame] | 1407 | |
| 1408 | " Test for right click in line-wise visual mode outside the selection |
| 1409 | let @" = '' |
| 1410 | call cursor(1, 16) |
| 1411 | call feedkeys("V" .. MouseRightClickCode(2, 10) |
| 1412 | \ .. MouseRightReleaseCode(2, 10) .. "\<Down>\<CR>", "x") |
| 1413 | call assert_equal([2, 10], [line('.'), col('.')], msg) |
| 1414 | call assert_equal("", @", msg) |
| 1415 | |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1416 | " Try clicking on the status line |
| 1417 | let @" = '' |
| 1418 | call cursor(1, 10) |
| 1419 | call feedkeys('vee' .. MouseRightClickCode(6, 2) |
| 1420 | \ .. MouseRightReleaseCode(6, 2) .. "\<Down>\<CR>", "x") |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1421 | call assert_equal([1, 10], [line('.'), col('.')], msg) |
| 1422 | call assert_equal('ran away', @", msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1423 | |
| 1424 | " Try clicking outside the window |
| 1425 | let @" = '' |
zeertzjq | df63f05 | 2022-10-19 15:12:54 +0100 | [diff] [blame] | 1426 | call cursor(2, 2) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1427 | call feedkeys('vee' .. MouseRightClickCode(7, 2) |
| 1428 | \ .. MouseRightReleaseCode(7, 2) .. "\<Down>\<CR>", "x") |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1429 | call assert_equal(2, winnr(), msg) |
| 1430 | call assert_equal('', @", msg) |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1431 | wincmd w |
| 1432 | endfor |
| 1433 | |
| 1434 | unmenu PopUp |
| 1435 | let &mouse = save_mouse |
| 1436 | let &term = save_term |
| 1437 | let &ttymouse = save_ttymouse |
| 1438 | let &mousemodel = save_mousemodel |
| 1439 | call test_override('no_query_mouse', 0) |
| 1440 | close! |
| 1441 | endfunc |
| 1442 | |
| 1443 | " Test for searching for the word under the cursor using Shift-Right or |
| 1444 | " Shift-Left click. |
| 1445 | func Test_term_mouse_search() |
| 1446 | new |
| 1447 | let save_mouse = &mouse |
| 1448 | let save_term = &term |
| 1449 | let save_ttymouse = &ttymouse |
| 1450 | call test_override('no_query_mouse', 1) |
| 1451 | set mouse=a term=xterm ttymouse=xterm2 |
| 1452 | set mousemodel= |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1453 | call WaitForResponses() |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1454 | |
| 1455 | " In normal mode, Shift-Left or Shift-Right click should search for the word |
| 1456 | " under the cursor. |
| 1457 | call setline(1, ['one two three four', 'four three two one']) |
| 1458 | call test_setmouse(1, 4) |
| 1459 | exe "normal \<S-LeftMouse>" |
| 1460 | call assert_equal([2, 12], [line('.'), col('.')]) |
| 1461 | call test_setmouse(2, 16) |
| 1462 | exe "normal \<S-RightMouse>" |
| 1463 | call assert_equal([1, 1], [line('.'), col('.')]) |
| 1464 | |
| 1465 | " In visual mode, Shift-Left or Shift-Right click should search for the word |
| 1466 | " under the cursor and extend the selection. |
| 1467 | call test_setmouse(1, 4) |
| 1468 | exe "normal 4|ve\<S-LeftMouse>y" |
| 1469 | call assert_equal([2, 12], [line("'>"), col("'>")]) |
| 1470 | call test_setmouse(2, 16) |
| 1471 | exe "normal 2G16|ve\<S-RightMouse>y" |
| 1472 | call assert_equal([1, 1], [line("'<"), col("'<")]) |
| 1473 | |
| 1474 | set mousemodel& |
| 1475 | let &mouse = save_mouse |
| 1476 | let &term = save_term |
| 1477 | let &ttymouse = save_ttymouse |
| 1478 | call test_override('no_query_mouse', 0) |
| 1479 | close! |
| 1480 | endfunc |
| 1481 | |
| 1482 | " Test for selecting an entry in the quickfix/location list window using the |
| 1483 | " mouse. |
| 1484 | func Test_term_mouse_quickfix_window() |
| 1485 | let save_mouse = &mouse |
| 1486 | let save_term = &term |
| 1487 | let save_ttymouse = &ttymouse |
| 1488 | call test_override('no_query_mouse', 1) |
| 1489 | set mouse=a term=xterm ttymouse=xterm2 |
| 1490 | set mousemodel= |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1491 | call WaitForResponses() |
Bram Moolenaar | 297bec0 | 2020-07-14 22:11:04 +0200 | [diff] [blame] | 1492 | |
| 1493 | cgetexpr "Xfile1:1:L1" |
| 1494 | copen 5 |
| 1495 | call test_setmouse(&lines - 7, 1) |
| 1496 | exe "normal \<2-LeftMouse>" |
| 1497 | call assert_equal('Xfile1', @%) |
| 1498 | %bw! |
| 1499 | |
| 1500 | lgetexpr "Xfile2:1:L1" |
| 1501 | lopen 5 |
| 1502 | call test_setmouse(&lines - 7, 1) |
| 1503 | exe "normal \<2-LeftMouse>" |
| 1504 | call assert_equal('Xfile2', @%) |
| 1505 | %bw! |
| 1506 | |
| 1507 | set mousemodel& |
| 1508 | let &mouse = save_mouse |
| 1509 | let &term = save_term |
| 1510 | let &ttymouse = save_ttymouse |
| 1511 | call test_override('no_query_mouse', 0) |
| 1512 | endfunc |
| 1513 | |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1514 | " Test for the 'h' flag in the 'mouse' option. Using mouse in the help window. |
| 1515 | func Test_term_mouse_help_window() |
| 1516 | let save_mouse = &mouse |
| 1517 | let save_term = &term |
| 1518 | let save_ttymouse = &ttymouse |
| 1519 | call test_override('no_query_mouse', 1) |
| 1520 | set mouse=h term=xterm mousetime=200 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1521 | call WaitForResponses() |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1522 | |
| 1523 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec |
| 1524 | let msg = 'ttymouse=' .. ttymouse_val |
| 1525 | exe 'set ttymouse=' .. ttymouse_val |
| 1526 | help |
| 1527 | let @" = '' |
| 1528 | call MouseLeftClick(2, 5) |
| 1529 | call MouseLeftRelease(2, 5) |
| 1530 | call MouseLeftClick(1, 1) |
| 1531 | call MouseLeftDrag(1, 10) |
| 1532 | call MouseLeftRelease(1, 10) |
| 1533 | norm! y |
| 1534 | call assert_equal('*help.txt*', @", msg) |
| 1535 | helpclose |
| 1536 | |
| 1537 | " Click somewhere else to make sure the left click above is not combined |
| 1538 | " with the next left click and treated as a double click |
| 1539 | call MouseRightClick(5, 10) |
| 1540 | call MouseRightRelease(5, 10) |
| 1541 | endfor |
| 1542 | |
| 1543 | let &mouse = save_mouse |
| 1544 | let &term = save_term |
| 1545 | let &ttymouse = save_ttymouse |
| 1546 | set mousetime& |
| 1547 | call test_override('no_query_mouse', 0) |
| 1548 | %bw! |
| 1549 | endfunc |
| 1550 | |
| 1551 | " Test for the translation of various mouse terminal codes |
| 1552 | func Test_mouse_termcodes() |
| 1553 | let save_mouse = &mouse |
| 1554 | let save_term = &term |
| 1555 | let save_ttymouse = &ttymouse |
| 1556 | call test_override('no_query_mouse', 1) |
| 1557 | set mouse=a term=xterm mousetime=200 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1558 | call WaitForResponses() |
Bram Moolenaar | 2764d06 | 2020-07-18 12:59:19 +0200 | [diff] [blame] | 1559 | |
| 1560 | new |
| 1561 | for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec + g:Ttymouse_netterm |
| 1562 | let msg = 'ttymouse=' .. ttymouse_val |
| 1563 | exe 'set ttymouse=' .. ttymouse_val |
| 1564 | |
| 1565 | let mouse_codes = [ |
| 1566 | \ ["\<LeftMouse>", "<LeftMouse>"], |
| 1567 | \ ["\<MiddleMouse>", "<MiddleMouse>"], |
| 1568 | \ ["\<RightMouse>", "<RightMouse>"], |
| 1569 | \ ["\<S-LeftMouse>", "<S-LeftMouse>"], |
| 1570 | \ ["\<S-MiddleMouse>", "<S-MiddleMouse>"], |
| 1571 | \ ["\<S-RightMouse>", "<S-RightMouse>"], |
| 1572 | \ ["\<C-LeftMouse>", "<C-LeftMouse>"], |
| 1573 | \ ["\<C-MiddleMouse>", "<C-MiddleMouse>"], |
| 1574 | \ ["\<C-RightMouse>", "<C-RightMouse>"], |
| 1575 | \ ["\<M-LeftMouse>", "<M-LeftMouse>"], |
| 1576 | \ ["\<M-MiddleMouse>", "<M-MiddleMouse>"], |
| 1577 | \ ["\<M-RightMouse>", "<M-RightMouse>"], |
| 1578 | \ ["\<2-LeftMouse>", "<2-LeftMouse>"], |
| 1579 | \ ["\<2-MiddleMouse>", "<2-MiddleMouse>"], |
| 1580 | \ ["\<2-RightMouse>", "<2-RightMouse>"], |
| 1581 | \ ["\<3-LeftMouse>", "<3-LeftMouse>"], |
| 1582 | \ ["\<3-MiddleMouse>", "<3-MiddleMouse>"], |
| 1583 | \ ["\<3-RightMouse>", "<3-RightMouse>"], |
| 1584 | \ ["\<4-LeftMouse>", "<4-LeftMouse>"], |
| 1585 | \ ["\<4-MiddleMouse>", "<4-MiddleMouse>"], |
| 1586 | \ ["\<4-RightMouse>", "<4-RightMouse>"], |
| 1587 | \ ["\<LeftDrag>", "<LeftDrag>"], |
| 1588 | \ ["\<MiddleDrag>", "<MiddleDrag>"], |
| 1589 | \ ["\<RightDrag>", "<RightDrag>"], |
| 1590 | \ ["\<LeftRelease>", "<LeftRelease>"], |
| 1591 | \ ["\<MiddleRelease>", "<MiddleRelease>"], |
| 1592 | \ ["\<RightRelease>", "<RightRelease>"], |
| 1593 | \ ["\<ScrollWheelUp>", "<ScrollWheelUp>"], |
| 1594 | \ ["\<S-ScrollWheelUp>", "<S-ScrollWheelUp>"], |
| 1595 | \ ["\<C-ScrollWheelUp>", "<C-ScrollWheelUp>"], |
| 1596 | \ ["\<ScrollWheelDown>", "<ScrollWheelDown>"], |
| 1597 | \ ["\<S-ScrollWheelDown>", "<S-ScrollWheelDown>"], |
| 1598 | \ ["\<C-ScrollWheelDown>", "<C-ScrollWheelDown>"], |
| 1599 | \ ["\<ScrollWheelLeft>", "<ScrollWheelLeft>"], |
| 1600 | \ ["\<S-ScrollWheelLeft>", "<S-ScrollWheelLeft>"], |
| 1601 | \ ["\<C-ScrollWheelLeft>", "<C-ScrollWheelLeft>"], |
| 1602 | \ ["\<ScrollWheelRight>", "<ScrollWheelRight>"], |
| 1603 | \ ["\<S-ScrollWheelRight>", "<S-ScrollWheelRight>"], |
| 1604 | \ ["\<C-ScrollWheelRight>", "<C-ScrollWheelRight>"] |
| 1605 | \ ] |
| 1606 | |
| 1607 | for [code, outstr] in mouse_codes |
| 1608 | exe "normal ggC\<C-K>" . code |
| 1609 | call assert_equal(outstr, getline(1), msg) |
| 1610 | endfor |
| 1611 | endfor |
| 1612 | |
| 1613 | let &mouse = save_mouse |
| 1614 | let &term = save_term |
| 1615 | let &ttymouse = save_ttymouse |
| 1616 | set mousetime& |
| 1617 | call test_override('no_query_mouse', 0) |
| 1618 | %bw! |
| 1619 | endfunc |
| 1620 | |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1621 | " This only checks if the sequence is recognized. |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1622 | func Test_term_rgb_response() |
| 1623 | set t_RF=x |
| 1624 | set t_RB=y |
| 1625 | |
| 1626 | " response to t_RF, 4 digits |
| 1627 | let red = 0x12 |
| 1628 | let green = 0x34 |
| 1629 | let blue = 0x56 |
| 1630 | let seq = printf("\<Esc>]10;rgb:%02x00/%02x00/%02x00\x07", red, green, blue) |
| 1631 | call feedkeys(seq, 'Lx!') |
| 1632 | call assert_equal(seq, v:termrfgresp) |
| 1633 | |
| 1634 | " response to t_RF, 2 digits |
| 1635 | let red = 0x78 |
| 1636 | let green = 0x9a |
| 1637 | let blue = 0xbc |
| 1638 | let seq = printf("\<Esc>]10;rgb:%02x/%02x/%02x\x07", red, green, blue) |
| 1639 | call feedkeys(seq, 'Lx!') |
| 1640 | call assert_equal(seq, v:termrfgresp) |
| 1641 | |
Bram Moolenaar | 32e1977 | 2019-06-05 22:57:04 +0200 | [diff] [blame] | 1642 | " response to t_RB, 4 digits, dark |
| 1643 | set background=light |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 1644 | eval 'background'->test_option_not_set() |
Bram Moolenaar | 32e1977 | 2019-06-05 22:57:04 +0200 | [diff] [blame] | 1645 | let red = 0x29 |
| 1646 | let green = 0x4a |
| 1647 | let blue = 0x6b |
| 1648 | let seq = printf("\<Esc>]11;rgb:%02x00/%02x00/%02x00\x07", red, green, blue) |
| 1649 | call feedkeys(seq, 'Lx!') |
| 1650 | call assert_equal(seq, v:termrbgresp) |
| 1651 | call assert_equal('dark', &background) |
| 1652 | |
| 1653 | " response to t_RB, 4 digits, light |
| 1654 | set background=dark |
| 1655 | call test_option_not_set('background') |
| 1656 | let red = 0x81 |
| 1657 | let green = 0x63 |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1658 | let blue = 0x65 |
| 1659 | let seq = printf("\<Esc>]11;rgb:%02x00/%02x00/%02x00\x07", red, green, blue) |
| 1660 | call feedkeys(seq, 'Lx!') |
| 1661 | call assert_equal(seq, v:termrbgresp) |
Bram Moolenaar | 32e1977 | 2019-06-05 22:57:04 +0200 | [diff] [blame] | 1662 | call assert_equal('light', &background) |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1663 | |
Bram Moolenaar | 32e1977 | 2019-06-05 22:57:04 +0200 | [diff] [blame] | 1664 | " response to t_RB, 2 digits, dark |
| 1665 | set background=light |
| 1666 | call test_option_not_set('background') |
| 1667 | let red = 0x47 |
| 1668 | let green = 0x59 |
| 1669 | let blue = 0x5b |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1670 | let seq = printf("\<Esc>]11;rgb:%02x/%02x/%02x\x07", red, green, blue) |
| 1671 | call feedkeys(seq, 'Lx!') |
| 1672 | call assert_equal(seq, v:termrbgresp) |
Bram Moolenaar | 32e1977 | 2019-06-05 22:57:04 +0200 | [diff] [blame] | 1673 | call assert_equal('dark', &background) |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 1674 | |
Bram Moolenaar | 32e1977 | 2019-06-05 22:57:04 +0200 | [diff] [blame] | 1675 | " response to t_RB, 2 digits, light |
| 1676 | set background=dark |
| 1677 | call test_option_not_set('background') |
| 1678 | let red = 0x83 |
| 1679 | let green = 0xa4 |
| 1680 | let blue = 0xc2 |
| 1681 | let seq = printf("\<Esc>]11;rgb:%02x/%02x/%02x\x07", red, green, blue) |
| 1682 | call feedkeys(seq, 'Lx!') |
| 1683 | call assert_equal(seq, v:termrbgresp) |
| 1684 | call assert_equal('light', &background) |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 1685 | |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1686 | set t_RF= t_RB= |
| 1687 | endfunc |
| 1688 | |
| 1689 | " This only checks if the sequence is recognized. |
Bram Moolenaar | 1a4cbb1 | 2019-10-12 13:25:44 +0200 | [diff] [blame] | 1690 | " This must be after other tests, because it has side effects to xterm |
| 1691 | " properties. |
| 1692 | func Test_xx01_term_style_response() |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1693 | " Termresponse is only parsed when t_RV is not empty. |
| 1694 | set t_RV=x |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1695 | call test_override('term_props', 1) |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1696 | |
| 1697 | " send the termresponse to trigger requesting the XT codes |
| 1698 | let seq = "\<Esc>[>41;337;0c" |
| 1699 | call feedkeys(seq, 'Lx!') |
| 1700 | call assert_equal(seq, v:termresponse) |
| 1701 | |
| 1702 | let seq = "\<Esc>P1$r2 q\<Esc>\\" |
| 1703 | call feedkeys(seq, 'Lx!') |
| 1704 | call assert_equal(seq, v:termstyleresp) |
| 1705 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1706 | call assert_equal(#{ |
| 1707 | \ cursor_style: 'u', |
| 1708 | \ cursor_blink_mode: 'u', |
| 1709 | \ underline_rgb: 'u', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1710 | \ mouse: 's', |
| 1711 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1712 | \ }, terminalprops()) |
| 1713 | |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1714 | set t_RV= |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1715 | call test_override('term_props', 0) |
Bram Moolenaar | 66761db | 2019-06-05 22:07:51 +0200 | [diff] [blame] | 1716 | endfunc |
Bram Moolenaar | de6dbb4 | 2019-06-06 11:59:18 +0200 | [diff] [blame] | 1717 | |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1718 | " This checks the iTerm2 version response. |
| 1719 | " This must be after other tests, because it has side effects to xterm |
| 1720 | " properties. |
| 1721 | func Test_xx02_iTerm2_response() |
| 1722 | " Termresponse is only parsed when t_RV is not empty. |
| 1723 | set t_RV=x |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1724 | call test_override('term_props', 1) |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1725 | |
| 1726 | " Old versions of iTerm2 used a different style term response. |
| 1727 | set ttymouse=xterm |
| 1728 | call test_option_not_set('ttymouse') |
| 1729 | let seq = "\<Esc>[>0;95;c" |
| 1730 | call feedkeys(seq, 'Lx!') |
| 1731 | call assert_equal(seq, v:termresponse) |
| 1732 | call assert_equal('xterm', &ttymouse) |
| 1733 | |
| 1734 | set ttymouse=xterm |
| 1735 | call test_option_not_set('ttymouse') |
| 1736 | let seq = "\<Esc>[>0;95;0c" |
| 1737 | call feedkeys(seq, 'Lx!') |
| 1738 | call assert_equal(seq, v:termresponse) |
| 1739 | call assert_equal('sgr', &ttymouse) |
| 1740 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1741 | call assert_equal(#{ |
| 1742 | \ cursor_style: 'n', |
| 1743 | \ cursor_blink_mode: 'u', |
| 1744 | \ underline_rgb: 'u', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1745 | \ mouse: 's', |
| 1746 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1747 | \ }, terminalprops()) |
| 1748 | |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1749 | set t_RV= |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1750 | call test_override('term_props', 0) |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1751 | endfunc |
| 1752 | |
Bram Moolenaar | d55f9ef | 2022-08-26 12:26:07 +0100 | [diff] [blame] | 1753 | func Run_libvterm_konsole_response(code) |
Bram Moolenaar | 1a4cbb1 | 2019-10-12 13:25:44 +0200 | [diff] [blame] | 1754 | set ttymouse=xterm |
| 1755 | call test_option_not_set('ttymouse') |
Bram Moolenaar | d55f9ef | 2022-08-26 12:26:07 +0100 | [diff] [blame] | 1756 | let seq = "\<Esc>[>0;" .. a:code .. ";0c" |
Bram Moolenaar | 1a4cbb1 | 2019-10-12 13:25:44 +0200 | [diff] [blame] | 1757 | call feedkeys(seq, 'Lx!') |
| 1758 | call assert_equal(seq, v:termresponse) |
| 1759 | call assert_equal('sgr', &ttymouse) |
| 1760 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1761 | call assert_equal(#{ |
| 1762 | \ cursor_style: 'n', |
| 1763 | \ cursor_blink_mode: 'u', |
| 1764 | \ underline_rgb: 'u', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1765 | \ mouse: 's', |
| 1766 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1767 | \ }, terminalprops()) |
Bram Moolenaar | d55f9ef | 2022-08-26 12:26:07 +0100 | [diff] [blame] | 1768 | endfunc |
| 1769 | |
| 1770 | " This checks the libvterm version response. |
| 1771 | " This must be after other tests, because it has side effects to xterm |
| 1772 | " properties. |
| 1773 | func Test_xx03_libvterm_konsole_response() |
| 1774 | " Termresponse is only parsed when t_RV is not empty. |
| 1775 | set t_RV=x |
| 1776 | call test_override('term_props', 1) |
| 1777 | |
| 1778 | " libvterm |
| 1779 | call Run_libvterm_konsole_response(100) |
| 1780 | " Konsole |
| 1781 | call Run_libvterm_konsole_response(115) |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1782 | |
Bram Moolenaar | 1a4cbb1 | 2019-10-12 13:25:44 +0200 | [diff] [blame] | 1783 | set t_RV= |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1784 | call test_override('term_props', 0) |
Bram Moolenaar | 1a4cbb1 | 2019-10-12 13:25:44 +0200 | [diff] [blame] | 1785 | endfunc |
| 1786 | |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1787 | " This checks the Mac Terminal.app version response. |
| 1788 | " This must be after other tests, because it has side effects to xterm |
| 1789 | " properties. |
| 1790 | func Test_xx04_Mac_Terminal_response() |
| 1791 | " Termresponse is only parsed when t_RV is not empty. |
| 1792 | set t_RV=x |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1793 | call test_override('term_props', 1) |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1794 | |
| 1795 | set ttymouse=xterm |
Bram Moolenaar | 8dff4cb | 2020-06-14 14:34:16 +0200 | [diff] [blame] | 1796 | " t_8u is not reset |
| 1797 | let &t_8u = "\<Esc>[58;2;%lu;%lu;%lum" |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1798 | call test_option_not_set('ttymouse') |
| 1799 | let seq = "\<Esc>[>1;95;0c" |
| 1800 | call feedkeys(seq, 'Lx!') |
| 1801 | call assert_equal(seq, v:termresponse) |
| 1802 | call assert_equal('sgr', &ttymouse) |
| 1803 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1804 | call assert_equal(#{ |
| 1805 | \ cursor_style: 'n', |
| 1806 | \ cursor_blink_mode: 'u', |
| 1807 | \ underline_rgb: 'y', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1808 | \ mouse: 's', |
| 1809 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1810 | \ }, terminalprops()) |
Bram Moolenaar | 8dff4cb | 2020-06-14 14:34:16 +0200 | [diff] [blame] | 1811 | call assert_equal("\<Esc>[58;2;%lu;%lu;%lum", &t_8u) |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1812 | |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1813 | " Reset is_not_xterm and is_mac_terminal. |
| 1814 | set t_RV= |
| 1815 | set term=xterm |
| 1816 | set t_RV=x |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1817 | call test_override('term_props', 0) |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1818 | endfunc |
| 1819 | |
| 1820 | " This checks the mintty version response. |
| 1821 | " This must be after other tests, because it has side effects to xterm |
| 1822 | " properties. |
| 1823 | func Test_xx05_mintty_response() |
| 1824 | " Termresponse is only parsed when t_RV is not empty. |
| 1825 | set t_RV=x |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1826 | call test_override('term_props', 1) |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1827 | |
| 1828 | set ttymouse=xterm |
| 1829 | call test_option_not_set('ttymouse') |
| 1830 | let seq = "\<Esc>[>77;20905;0c" |
| 1831 | call feedkeys(seq, 'Lx!') |
| 1832 | call assert_equal(seq, v:termresponse) |
| 1833 | call assert_equal('sgr', &ttymouse) |
| 1834 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1835 | call assert_equal(#{ |
| 1836 | \ cursor_style: 'n', |
| 1837 | \ cursor_blink_mode: 'u', |
| 1838 | \ underline_rgb: 'y', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1839 | \ mouse: 's', |
| 1840 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1841 | \ }, terminalprops()) |
| 1842 | |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1843 | set t_RV= |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1844 | call test_override('term_props', 0) |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1845 | endfunc |
| 1846 | |
| 1847 | " This checks the screen version response. |
| 1848 | " This must be after other tests, because it has side effects to xterm |
| 1849 | " properties. |
| 1850 | func Test_xx06_screen_response() |
| 1851 | " Termresponse is only parsed when t_RV is not empty. |
| 1852 | set t_RV=x |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1853 | call test_override('term_props', 1) |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1854 | |
| 1855 | " Old versions of screen don't support SGR mouse mode. |
| 1856 | set ttymouse=xterm |
| 1857 | call test_option_not_set('ttymouse') |
| 1858 | let seq = "\<Esc>[>83;40500;0c" |
| 1859 | call feedkeys(seq, 'Lx!') |
| 1860 | call assert_equal(seq, v:termresponse) |
| 1861 | call assert_equal('xterm', &ttymouse) |
| 1862 | |
| 1863 | " screen supports SGR mouse mode starting in version 4.7. |
| 1864 | set ttymouse=xterm |
| 1865 | call test_option_not_set('ttymouse') |
| 1866 | let seq = "\<Esc>[>83;40700;0c" |
| 1867 | call feedkeys(seq, 'Lx!') |
| 1868 | call assert_equal(seq, v:termresponse) |
| 1869 | call assert_equal('sgr', &ttymouse) |
| 1870 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1871 | call assert_equal(#{ |
| 1872 | \ cursor_style: 'n', |
| 1873 | \ cursor_blink_mode: 'n', |
| 1874 | \ underline_rgb: 'y', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1875 | \ mouse: 's', |
| 1876 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1877 | \ }, terminalprops()) |
| 1878 | |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1879 | set t_RV= |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1880 | call test_override('term_props', 0) |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1881 | endfunc |
| 1882 | |
Bram Moolenaar | d0eaf67 | 2022-04-20 19:55:37 +0100 | [diff] [blame] | 1883 | func Do_check_t_8u_set_reset(set_by_user) |
| 1884 | set ttymouse=xterm |
| 1885 | call test_option_not_set('ttymouse') |
| 1886 | let default_value = "\<Esc>[58;2;%lu;%lu;%lum" |
| 1887 | let &t_8u = default_value |
| 1888 | if !a:set_by_user |
| 1889 | call test_option_not_set('t_8u') |
| 1890 | endif |
| 1891 | let seq = "\<Esc>[>0;279;0c" |
| 1892 | call feedkeys(seq, 'Lx!') |
| 1893 | call assert_equal(seq, v:termresponse) |
| 1894 | call assert_equal('sgr', &ttymouse) |
| 1895 | |
| 1896 | call assert_equal(#{ |
| 1897 | \ cursor_style: 'u', |
| 1898 | \ cursor_blink_mode: 'u', |
| 1899 | \ underline_rgb: 'u', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1900 | \ mouse: 's', |
| 1901 | \ kitty: 'u', |
Bram Moolenaar | d0eaf67 | 2022-04-20 19:55:37 +0100 | [diff] [blame] | 1902 | \ }, terminalprops()) |
| 1903 | call assert_equal(a:set_by_user ? default_value : '', &t_8u) |
| 1904 | endfunc |
| 1905 | |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1906 | " This checks the xterm version response. |
| 1907 | " This must be after other tests, because it has side effects to xterm |
| 1908 | " properties. |
Bram Moolenaar | 89577b3 | 2019-10-18 21:26:05 +0200 | [diff] [blame] | 1909 | func Test_xx07_xterm_response() |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1910 | " Termresponse is only parsed when t_RV is not empty. |
| 1911 | set t_RV=x |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1912 | call test_override('term_props', 1) |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1913 | |
Bram Moolenaar | 3cea8a9 | 2019-10-17 21:55:24 +0200 | [diff] [blame] | 1914 | " Do Terminal.app first to check that is_mac_terminal is reset. |
| 1915 | set ttymouse=xterm |
| 1916 | call test_option_not_set('ttymouse') |
| 1917 | let seq = "\<Esc>[>1;95;0c" |
| 1918 | call feedkeys(seq, 'Lx!') |
| 1919 | call assert_equal(seq, v:termresponse) |
| 1920 | call assert_equal('sgr', &ttymouse) |
| 1921 | |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1922 | " xterm < 95: "xterm" (actually unmodified) |
Bram Moolenaar | 3cea8a9 | 2019-10-17 21:55:24 +0200 | [diff] [blame] | 1923 | set t_RV= |
| 1924 | set term=xterm |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 1925 | call WaitForResponses() |
| 1926 | |
Bram Moolenaar | 3cea8a9 | 2019-10-17 21:55:24 +0200 | [diff] [blame] | 1927 | set t_RV=x |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1928 | set ttymouse=xterm |
| 1929 | call test_option_not_set('ttymouse') |
| 1930 | let seq = "\<Esc>[>0;94;0c" |
| 1931 | call feedkeys(seq, 'Lx!') |
| 1932 | call assert_equal(seq, v:termresponse) |
| 1933 | call assert_equal('xterm', &ttymouse) |
| 1934 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1935 | call assert_equal(#{ |
| 1936 | \ cursor_style: 'n', |
| 1937 | \ cursor_blink_mode: 'u', |
| 1938 | \ underline_rgb: 'y', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1939 | \ mouse: 'u', |
| 1940 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1941 | \ }, terminalprops()) |
| 1942 | |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1943 | " xterm >= 95 < 277 "xterm2" |
| 1944 | set ttymouse=xterm |
| 1945 | call test_option_not_set('ttymouse') |
| 1946 | let seq = "\<Esc>[>0;267;0c" |
| 1947 | call feedkeys(seq, 'Lx!') |
| 1948 | call assert_equal(seq, v:termresponse) |
| 1949 | call assert_equal('xterm2', &ttymouse) |
| 1950 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1951 | call assert_equal(#{ |
| 1952 | \ cursor_style: 'n', |
| 1953 | \ cursor_blink_mode: 'u', |
| 1954 | \ underline_rgb: 'u', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1955 | \ mouse: '2', |
| 1956 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1957 | \ }, terminalprops()) |
| 1958 | |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1959 | " xterm >= 277: "sgr" |
| 1960 | set ttymouse=xterm |
| 1961 | call test_option_not_set('ttymouse') |
| 1962 | let seq = "\<Esc>[>0;277;0c" |
| 1963 | call feedkeys(seq, 'Lx!') |
| 1964 | call assert_equal(seq, v:termresponse) |
| 1965 | call assert_equal('sgr', &ttymouse) |
| 1966 | |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1967 | call assert_equal(#{ |
| 1968 | \ cursor_style: 'n', |
| 1969 | \ cursor_blink_mode: 'u', |
| 1970 | \ underline_rgb: 'u', |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1971 | \ mouse: 's', |
| 1972 | \ kitty: 'u', |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1973 | \ }, terminalprops()) |
| 1974 | |
Bram Moolenaar | d0eaf67 | 2022-04-20 19:55:37 +0100 | [diff] [blame] | 1975 | " xterm >= 279: "sgr" and cursor_style not reset; also check t_8u reset, |
| 1976 | " except when it was set by the user |
| 1977 | call Do_check_t_8u_set_reset(0) |
| 1978 | call Do_check_t_8u_set_reset(1) |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1979 | |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1980 | set t_RV= |
Bram Moolenaar | 0c0eddd | 2020-06-13 15:47:25 +0200 | [diff] [blame] | 1981 | call test_override('term_props', 0) |
Bram Moolenaar | 03b0047 | 2019-10-14 22:22:03 +0200 | [diff] [blame] | 1982 | endfunc |
| 1983 | |
Bram Moolenaar | 4bc85f2 | 2022-10-21 14:17:24 +0100 | [diff] [blame] | 1984 | func Test_xx08_kitty_response() |
| 1985 | " Termresponse is only parsed when t_RV is not empty. |
| 1986 | set t_RV=x |
| 1987 | call test_override('term_props', 1) |
| 1988 | |
| 1989 | set ttymouse=xterm |
| 1990 | call test_option_not_set('ttymouse') |
| 1991 | let seq = "\<Esc>[>1;4001;12c" |
| 1992 | call feedkeys(seq, 'Lx!') |
| 1993 | call assert_equal(seq, v:termresponse) |
| 1994 | call assert_equal('sgr', &ttymouse) |
| 1995 | |
| 1996 | call assert_equal(#{ |
| 1997 | \ cursor_style: 'u', |
| 1998 | \ cursor_blink_mode: 'u', |
| 1999 | \ underline_rgb: 'y', |
| 2000 | \ mouse: 's', |
| 2001 | \ kitty: 'y', |
| 2002 | \ }, terminalprops()) |
| 2003 | |
| 2004 | set t_RV= |
| 2005 | call test_override('term_props', 0) |
| 2006 | endfunc |
| 2007 | |
Bram Moolenaar | 92e5df8 | 2021-01-30 15:39:47 +0100 | [diff] [blame] | 2008 | func Test_focus_events() |
| 2009 | let save_term = &term |
| 2010 | let save_ttymouse = &ttymouse |
| 2011 | set term=xterm ttymouse=xterm2 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 2012 | call WaitForResponses() |
Bram Moolenaar | 92e5df8 | 2021-01-30 15:39:47 +0100 | [diff] [blame] | 2013 | |
| 2014 | au FocusGained * let g:focus_gained += 1 |
| 2015 | au FocusLost * let g:focus_lost += 1 |
| 2016 | let g:focus_gained = 0 |
| 2017 | let g:focus_lost = 0 |
| 2018 | |
| 2019 | call feedkeys("\<Esc>[O", "Lx!") |
| 2020 | call assert_equal(1, g:focus_lost) |
| 2021 | call feedkeys("\<Esc>[I", "Lx!") |
| 2022 | call assert_equal(1, g:focus_gained) |
| 2023 | |
| 2024 | " still works when 'ttymouse' is empty |
| 2025 | set ttymouse= |
| 2026 | call feedkeys("\<Esc>[O", "Lx!") |
| 2027 | call assert_equal(2, g:focus_lost) |
| 2028 | call feedkeys("\<Esc>[I", "Lx!") |
| 2029 | call assert_equal(2, g:focus_gained) |
| 2030 | |
| 2031 | au! FocusGained |
| 2032 | au! FocusLost |
| 2033 | let &term = save_term |
| 2034 | let &ttymouse = save_ttymouse |
| 2035 | endfunc |
| 2036 | |
Bram Moolenaar | de6dbb4 | 2019-06-06 11:59:18 +0200 | [diff] [blame] | 2037 | func Test_get_termcode() |
Bram Moolenaar | eb66328 | 2019-10-06 12:02:15 +0200 | [diff] [blame] | 2038 | try |
| 2039 | let k1 = &t_k1 |
| 2040 | catch /E113/ |
| 2041 | throw 'Skipped: Unable to query termcodes' |
| 2042 | endtry |
Bram Moolenaar | de6dbb4 | 2019-06-06 11:59:18 +0200 | [diff] [blame] | 2043 | set t_k1= |
| 2044 | set t_k1& |
| 2045 | call assert_equal(k1, &t_k1) |
Bram Moolenaar | 9aeb336 | 2019-06-06 12:36:15 +0200 | [diff] [blame] | 2046 | |
| 2047 | " use external termcap first |
| 2048 | set nottybuiltin |
| 2049 | set t_k1= |
| 2050 | set t_k1& |
| 2051 | " when using external termcap may get something else, but it must not be |
| 2052 | " empty, since we would fallback to the builtin one. |
| 2053 | call assert_notequal('', &t_k1) |
| 2054 | |
| 2055 | if &term =~ 'xterm' |
| 2056 | " use internal termcap first |
| 2057 | let term_save = &term |
| 2058 | let &term = 'builtin_' .. &term |
| 2059 | set t_k1= |
| 2060 | set t_k1& |
| 2061 | call assert_equal(k1, &t_k1) |
| 2062 | let &term = term_save |
| 2063 | endif |
| 2064 | |
| 2065 | set ttybuiltin |
Bram Moolenaar | de6dbb4 | 2019-06-06 11:59:18 +0200 | [diff] [blame] | 2066 | endfunc |
Bram Moolenaar | 18a79a6 | 2019-10-12 15:36:11 +0200 | [diff] [blame] | 2067 | |
Bram Moolenaar | ecd34bf | 2020-08-04 20:17:31 +0200 | [diff] [blame] | 2068 | func Test_list_builtin_terminals() |
Bram Moolenaar | e46a2ed | 2020-08-04 21:04:57 +0200 | [diff] [blame] | 2069 | CheckRunVimInTerminal |
Bram Moolenaar | 4654d63 | 2022-11-17 22:05:12 +0000 | [diff] [blame] | 2070 | |
Bram Moolenaar | 4d05af0 | 2020-11-27 20:55:00 +0100 | [diff] [blame] | 2071 | call RunVimInTerminal('', #{rows: 14}) |
| 2072 | call term_sendkeys('', ":set cmdheight=3\<CR>") |
| 2073 | call TermWait('', 100) |
| 2074 | call term_sendkeys('', ":set term=xxx\<CR>") |
| 2075 | call TermWait('', 100) |
Bram Moolenaar | 4654d63 | 2022-11-17 22:05:12 +0000 | [diff] [blame] | 2076 | |
| 2077 | " Check that the list ends in "builtin_dumb" and "builtin_debug". |
| 2078 | let dumb_idx = 0 |
| 2079 | for n in range(8, 12) |
| 2080 | if term_getline('', n) =~ 'builtin_dumb' |
| 2081 | let dumb_idx = n |
| 2082 | break |
| 2083 | endif |
| 2084 | endfor |
| 2085 | call assert_notequal(0, dumb_idx, 'builtin_dumb not found') |
| 2086 | |
| 2087 | call assert_match('builtin_dumb', term_getline('', dumb_idx)) |
| 2088 | call assert_match('builtin_debug', term_getline('', dumb_idx + 1)) |
| 2089 | call assert_match('Not found in termcap', term_getline('', dumb_idx + 2)) |
| 2090 | |
Bram Moolenaar | 4d05af0 | 2020-11-27 20:55:00 +0100 | [diff] [blame] | 2091 | call StopVimInTerminal('') |
Bram Moolenaar | ecd34bf | 2020-08-04 20:17:31 +0200 | [diff] [blame] | 2092 | endfunc |
| 2093 | |
Bram Moolenaar | 18a79a6 | 2019-10-12 15:36:11 +0200 | [diff] [blame] | 2094 | " This checks the CSI sequences when in modifyOtherKeys mode. |
| 2095 | " The mode doesn't need to be enabled, the codes are always detected. |
| 2096 | func RunTest_modifyOtherKeys(func) |
| 2097 | new |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2098 | set timeoutlen=10 |
Bram Moolenaar | 18a79a6 | 2019-10-12 15:36:11 +0200 | [diff] [blame] | 2099 | |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 2100 | " Shift-X is sent as 'X' with the shift modifier |
Bram Moolenaar | 18a79a6 | 2019-10-12 15:36:11 +0200 | [diff] [blame] | 2101 | call feedkeys('a' .. a:func('X', 2) .. "\<Esc>", 'Lx!') |
| 2102 | call assert_equal('X', getline(1)) |
| 2103 | |
| 2104 | " Ctrl-i is Tab |
| 2105 | call setline(1, '') |
| 2106 | call feedkeys('a' .. a:func('i', 5) .. "\<Esc>", 'Lx!') |
| 2107 | call assert_equal("\t", getline(1)) |
| 2108 | |
| 2109 | " Ctrl-I is also Tab |
| 2110 | call setline(1, '') |
| 2111 | call feedkeys('a' .. a:func('I', 5) .. "\<Esc>", 'Lx!') |
| 2112 | call assert_equal("\t", getline(1)) |
| 2113 | |
| 2114 | " Alt-x is ø |
| 2115 | call setline(1, '') |
| 2116 | call feedkeys('a' .. a:func('x', 3) .. "\<Esc>", 'Lx!') |
| 2117 | call assert_equal("ø", getline(1)) |
| 2118 | |
| 2119 | " Meta-x is also ø |
| 2120 | call setline(1, '') |
| 2121 | call feedkeys('a' .. a:func('x', 9) .. "\<Esc>", 'Lx!') |
| 2122 | call assert_equal("ø", getline(1)) |
| 2123 | |
| 2124 | " Alt-X is Ø |
| 2125 | call setline(1, '') |
| 2126 | call feedkeys('a' .. a:func('X', 3) .. "\<Esc>", 'Lx!') |
| 2127 | call assert_equal("Ø", getline(1)) |
| 2128 | |
| 2129 | " Meta-X is ø |
| 2130 | call setline(1, '') |
| 2131 | call feedkeys('a' .. a:func('X', 9) .. "\<Esc>", 'Lx!') |
| 2132 | call assert_equal("Ø", getline(1)) |
| 2133 | |
Bram Moolenaar | 828ffd5 | 2019-11-21 23:24:00 +0100 | [diff] [blame] | 2134 | " Ctrl-6 is Ctrl-^ |
| 2135 | split aaa |
| 2136 | edit bbb |
| 2137 | call feedkeys(a:func('6', 5), 'Lx!') |
| 2138 | call assert_equal("aaa", bufname()) |
| 2139 | bwipe aaa |
| 2140 | bwipe bbb |
| 2141 | |
Bram Moolenaar | 0684e36 | 2020-12-03 19:54:42 +0100 | [diff] [blame] | 2142 | " Ctrl-V X 33 is 3 |
| 2143 | call setline(1, '') |
| 2144 | call feedkeys("a\<C-V>" .. a:func('X', 2) .. "33\<Esc>", 'Lx!') |
| 2145 | call assert_equal("3", getline(1)) |
| 2146 | |
| 2147 | " Ctrl-V U 12345 is Unicode 12345 |
| 2148 | call setline(1, '') |
| 2149 | call feedkeys("a\<C-V>" .. a:func('U', 2) .. "12345\<Esc>", 'Lx!') |
| 2150 | call assert_equal("\U12345", getline(1)) |
| 2151 | |
Bram Moolenaar | 18a79a6 | 2019-10-12 15:36:11 +0200 | [diff] [blame] | 2152 | bwipe! |
| 2153 | set timeoutlen& |
| 2154 | endfunc |
| 2155 | |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2156 | func Test_modifyOtherKeys_basic() |
Bram Moolenaar | 18a79a6 | 2019-10-12 15:36:11 +0200 | [diff] [blame] | 2157 | call RunTest_modifyOtherKeys(function('GetEscCodeCSI27')) |
Bram Moolenaar | 18a79a6 | 2019-10-12 15:36:11 +0200 | [diff] [blame] | 2158 | call RunTest_modifyOtherKeys(function('GetEscCodeCSIu')) |
| 2159 | endfunc |
Bram Moolenaar | d1e2f39 | 2019-10-12 18:22:50 +0200 | [diff] [blame] | 2160 | |
Bram Moolenaar | 38571a0 | 2019-11-26 14:28:15 +0100 | [diff] [blame] | 2161 | func Test_modifyOtherKeys_no_mapping() |
| 2162 | set timeoutlen=10 |
| 2163 | |
| 2164 | let @a = 'aaa' |
| 2165 | call feedkeys(":let x = '" .. GetEscCodeCSI27('R', 5) .. GetEscCodeCSI27('R', 5) .. "a'\<CR>", 'Lx!') |
| 2166 | call assert_equal("let x = 'aaa'", @:) |
| 2167 | |
| 2168 | new |
| 2169 | call feedkeys("a" .. GetEscCodeCSI27('R', 5) .. GetEscCodeCSI27('R', 5) .. "a\<Esc>", 'Lx!') |
| 2170 | call assert_equal("aaa", getline(1)) |
| 2171 | bwipe! |
| 2172 | |
| 2173 | new |
| 2174 | call feedkeys("axx\<CR>yy" .. GetEscCodeCSI27('G', 5) .. GetEscCodeCSI27('K', 5) .. "a\<Esc>", 'Lx!') |
| 2175 | call assert_equal("axx", getline(1)) |
| 2176 | call assert_equal("yy", getline(2)) |
| 2177 | bwipe! |
| 2178 | |
| 2179 | set timeoutlen& |
| 2180 | endfunc |
| 2181 | |
Trygve Aaberge | b9c09c1 | 2022-10-14 12:08:24 +0100 | [diff] [blame] | 2182 | func Test_CSIu_keys_without_modifiers() |
Bram Moolenaar | ebed1b0 | 2022-11-24 14:05:19 +0000 | [diff] [blame] | 2183 | " make this execute faster |
| 2184 | set timeoutlen=10 |
| 2185 | |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 2186 | call WaitForResponses() |
| 2187 | |
Trygve Aaberge | b9c09c1 | 2022-10-14 12:08:24 +0100 | [diff] [blame] | 2188 | " Escape sent as `CSI 27 u` should act as normal escape and not undo |
| 2189 | call setline(1, 'a') |
| 2190 | call feedkeys('a' .. GetEscCodeCSIuWithoutModifier("\e"), 'Lx!') |
| 2191 | call assert_equal('n', mode()) |
| 2192 | call assert_equal('a', getline(1)) |
| 2193 | |
| 2194 | " Tab sent as `CSI 9 u` should work |
| 2195 | call setline(1, '') |
| 2196 | call feedkeys('a' .. GetEscCodeCSIuWithoutModifier("\t") .. "\<Esc>", 'Lx!') |
| 2197 | call assert_equal("\t", getline(1)) |
Bram Moolenaar | ebed1b0 | 2022-11-24 14:05:19 +0000 | [diff] [blame] | 2198 | |
| 2199 | set timeoutlen& |
Trygve Aaberge | b9c09c1 | 2022-10-14 12:08:24 +0100 | [diff] [blame] | 2200 | endfunc |
| 2201 | |
Bram Moolenaar | c14b57c | 2021-12-03 13:20:29 +0000 | [diff] [blame] | 2202 | " Check that when DEC mouse codes are recognized a special key is handled. |
| 2203 | func Test_ignore_dec_mouse() |
Dominique Pelle | f589fd3 | 2021-12-05 12:39:21 +0000 | [diff] [blame] | 2204 | silent !infocmp gnome >/dev/null 2>&1 |
| 2205 | if v:shell_error != 0 |
| 2206 | throw 'Skipped: gnome entry missing in the terminfo db' |
| 2207 | endif |
Bram Moolenaar | c14b57c | 2021-12-03 13:20:29 +0000 | [diff] [blame] | 2208 | |
| 2209 | new |
| 2210 | let save_mouse = &mouse |
| 2211 | let save_term = &term |
| 2212 | let save_ttymouse = &ttymouse |
| 2213 | call test_override('no_query_mouse', 1) |
| 2214 | set mouse=a term=gnome ttymouse= |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 2215 | call WaitForResponses() |
Bram Moolenaar | c14b57c | 2021-12-03 13:20:29 +0000 | [diff] [blame] | 2216 | |
| 2217 | execute "set <xF1>=\<Esc>[1;*P" |
| 2218 | nnoremap <S-F1> agot it<Esc> |
| 2219 | call feedkeys("\<Esc>[1;2P", 'Lx!') |
| 2220 | call assert_equal('got it', getline(1)) |
| 2221 | |
| 2222 | let &mouse = save_mouse |
| 2223 | let &term = save_term |
| 2224 | let &ttymouse = save_ttymouse |
| 2225 | call test_override('no_query_mouse', 0) |
| 2226 | bwipe! |
| 2227 | endfunc |
| 2228 | |
Bram Moolenaar | d1e2f39 | 2019-10-12 18:22:50 +0200 | [diff] [blame] | 2229 | func RunTest_mapping_shift(key, func) |
| 2230 | call setline(1, '') |
| 2231 | if a:key == '|' |
| 2232 | exe 'inoremap \| xyz' |
| 2233 | else |
| 2234 | exe 'inoremap ' .. a:key .. ' xyz' |
| 2235 | endif |
| 2236 | call feedkeys('a' .. a:func(a:key, 2) .. "\<Esc>", 'Lx!') |
| 2237 | call assert_equal("xyz", getline(1)) |
| 2238 | if a:key == '|' |
| 2239 | exe 'iunmap \|' |
| 2240 | else |
| 2241 | exe 'iunmap ' .. a:key |
| 2242 | endif |
| 2243 | endfunc |
| 2244 | |
Bram Moolenaar | 975a880 | 2020-06-06 22:36:24 +0200 | [diff] [blame] | 2245 | func Test_modifyOtherKeys_mapped() |
| 2246 | set timeoutlen=10 |
| 2247 | imap ' <C-W> |
| 2248 | imap <C-W><C-A> c-a |
| 2249 | call setline(1, '') |
| 2250 | |
| 2251 | " single quote is turned into single byte CTRL-W |
| 2252 | " CTRL-A is added with a separate modifier, and needs to be simplified before |
| 2253 | " the mapping can match. |
| 2254 | call feedkeys("a'" .. GetEscCodeCSI27('A', 5) .. "\<Esc>", 'Lx!') |
| 2255 | call assert_equal('c-a', getline(1)) |
| 2256 | |
| 2257 | iunmap ' |
| 2258 | iunmap <C-W><C-A> |
| 2259 | set timeoutlen& |
| 2260 | endfunc |
| 2261 | |
Bram Moolenaar | 196c385 | 2022-03-04 19:22:36 +0000 | [diff] [blame] | 2262 | func Test_modifyOtherKeys_ambiguous_mapping() |
| 2263 | new |
| 2264 | set timeoutlen=10 |
| 2265 | map <C-J> a |
| 2266 | map <C-J>x <Nop> |
| 2267 | call setline(1, 'x') |
| 2268 | |
| 2269 | " CTRL-J b should have trigger the <C-J> mapping and then insert "b" |
| 2270 | call feedkeys(GetEscCodeCSI27('J', 5) .. "b\<Esc>", 'Lx!') |
| 2271 | call assert_equal('xb', getline(1)) |
| 2272 | |
| 2273 | unmap <C-J> |
| 2274 | unmap <C-J>x |
Bram Moolenaar | f35fd8e | 2022-03-18 15:41:17 +0000 | [diff] [blame] | 2275 | |
| 2276 | " if a special character is following there should be a check for a termcode |
| 2277 | nnoremap s aX<Esc> |
| 2278 | nnoremap s<BS> aY<Esc> |
| 2279 | set t_kb= |
| 2280 | call setline(1, 'x') |
| 2281 | call feedkeys("s\x08", 'Lx!') |
| 2282 | call assert_equal('xY', getline(1)) |
| 2283 | |
Bram Moolenaar | 196c385 | 2022-03-04 19:22:36 +0000 | [diff] [blame] | 2284 | set timeoutlen& |
| 2285 | bwipe! |
| 2286 | endfunc |
| 2287 | |
Bram Moolenaar | 749bc95 | 2020-10-31 16:33:47 +0100 | [diff] [blame] | 2288 | " Whether Shift-Tab sends "ESC [ Z" or "ESC [ 27 ; 2 ; 9 ~" is unpredictable, |
| 2289 | " both should work. |
| 2290 | func Test_modifyOtherKeys_shift_tab() |
| 2291 | set timeoutlen=10 |
| 2292 | |
| 2293 | call setline(1, '') |
| 2294 | call feedkeys("a\<C-K>" .. GetEscCodeCSI27("\t", '2') .. "\<Esc>", 'Lx!') |
| 2295 | eval getline(1)->assert_equal('<S-Tab>') |
| 2296 | |
| 2297 | call setline(1, '') |
| 2298 | call feedkeys("a\<C-K>\<Esc>[Z\<Esc>", 'Lx!') |
| 2299 | eval getline(1)->assert_equal('<S-Tab>') |
| 2300 | |
| 2301 | set timeoutlen& |
| 2302 | bwipe! |
| 2303 | endfunc |
| 2304 | |
Bram Moolenaar | d1e2f39 | 2019-10-12 18:22:50 +0200 | [diff] [blame] | 2305 | func RunTest_mapping_works_with_shift(func) |
| 2306 | new |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2307 | set timeoutlen=10 |
Bram Moolenaar | d1e2f39 | 2019-10-12 18:22:50 +0200 | [diff] [blame] | 2308 | |
| 2309 | call RunTest_mapping_shift('@', a:func) |
| 2310 | call RunTest_mapping_shift('A', a:func) |
| 2311 | call RunTest_mapping_shift('Z', a:func) |
| 2312 | call RunTest_mapping_shift('^', a:func) |
| 2313 | call RunTest_mapping_shift('_', a:func) |
| 2314 | call RunTest_mapping_shift('{', a:func) |
| 2315 | call RunTest_mapping_shift('|', a:func) |
| 2316 | call RunTest_mapping_shift('}', a:func) |
| 2317 | call RunTest_mapping_shift('~', a:func) |
| 2318 | |
| 2319 | bwipe! |
| 2320 | set timeoutlen& |
| 2321 | endfunc |
| 2322 | |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2323 | func Test_mapping_works_with_shift_plain() |
Bram Moolenaar | d1e2f39 | 2019-10-12 18:22:50 +0200 | [diff] [blame] | 2324 | call RunTest_mapping_works_with_shift(function('GetEscCodeCSI27')) |
| 2325 | call RunTest_mapping_works_with_shift(function('GetEscCodeCSIu')) |
| 2326 | endfunc |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2327 | |
| 2328 | func RunTest_mapping_mods(map, key, func, code) |
| 2329 | call setline(1, '') |
| 2330 | exe 'inoremap ' .. a:map .. ' xyz' |
| 2331 | call feedkeys('a' .. a:func(a:key, a:code) .. "\<Esc>", 'Lx!') |
| 2332 | call assert_equal("xyz", getline(1)) |
| 2333 | exe 'iunmap ' .. a:map |
| 2334 | endfunc |
| 2335 | |
| 2336 | func RunTest_mapping_works_with_mods(func, mods, code) |
| 2337 | new |
| 2338 | set timeoutlen=10 |
| 2339 | |
| 2340 | if a:mods !~ 'S' |
| 2341 | " Shift by itself has no effect |
| 2342 | call RunTest_mapping_mods('<' .. a:mods .. '-@>', '@', a:func, a:code) |
| 2343 | endif |
| 2344 | call RunTest_mapping_mods('<' .. a:mods .. '-A>', 'A', a:func, a:code) |
| 2345 | call RunTest_mapping_mods('<' .. a:mods .. '-Z>', 'Z', a:func, a:code) |
| 2346 | if a:mods !~ 'S' |
| 2347 | " with Shift code is always upper case |
| 2348 | call RunTest_mapping_mods('<' .. a:mods .. '-a>', 'a', a:func, a:code) |
| 2349 | call RunTest_mapping_mods('<' .. a:mods .. '-z>', 'z', a:func, a:code) |
| 2350 | endif |
| 2351 | if a:mods != 'A' |
| 2352 | " with Alt code is not in upper case |
| 2353 | call RunTest_mapping_mods('<' .. a:mods .. '-a>', 'A', a:func, a:code) |
| 2354 | call RunTest_mapping_mods('<' .. a:mods .. '-z>', 'Z', a:func, a:code) |
| 2355 | endif |
| 2356 | call RunTest_mapping_mods('<' .. a:mods .. '-á>', 'á', a:func, a:code) |
| 2357 | if a:mods !~ 'S' |
| 2358 | " Shift by itself has no effect |
| 2359 | call RunTest_mapping_mods('<' .. a:mods .. '-^>', '^', a:func, a:code) |
| 2360 | call RunTest_mapping_mods('<' .. a:mods .. '-_>', '_', a:func, a:code) |
| 2361 | call RunTest_mapping_mods('<' .. a:mods .. '-{>', '{', a:func, a:code) |
| 2362 | call RunTest_mapping_mods('<' .. a:mods .. '-\|>', '|', a:func, a:code) |
| 2363 | call RunTest_mapping_mods('<' .. a:mods .. '-}>', '}', a:func, a:code) |
| 2364 | call RunTest_mapping_mods('<' .. a:mods .. '-~>', '~', a:func, a:code) |
| 2365 | endif |
| 2366 | |
| 2367 | bwipe! |
| 2368 | set timeoutlen& |
| 2369 | endfunc |
| 2370 | |
| 2371 | func Test_mapping_works_with_shift() |
| 2372 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'S', 2) |
| 2373 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'S', 2) |
| 2374 | endfunc |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 2375 | |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2376 | func Test_mapping_works_with_ctrl() |
| 2377 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C', 5) |
| 2378 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C', 5) |
Bram Moolenaar | 4e2114e | 2020-10-07 16:12:37 +0200 | [diff] [blame] | 2379 | |
| 2380 | new |
| 2381 | set timeoutlen=10 |
| 2382 | |
| 2383 | " CTRL-@ actually produces the code for CTRL-2, which is converted |
| 2384 | call RunTest_mapping_mods('<C-@>', '2', function('GetEscCodeCSI27'), 5) |
| 2385 | call RunTest_mapping_mods('<C-@>', '2', function('GetEscCodeCSIu'), 5) |
| 2386 | |
| 2387 | " CTRL-^ actually produces the code for CTRL-6, which is converted |
| 2388 | call RunTest_mapping_mods('<C-^>', '6', function('GetEscCodeCSI27'), 5) |
| 2389 | call RunTest_mapping_mods('<C-^>', '6', function('GetEscCodeCSIu'), 5) |
| 2390 | |
| 2391 | " CTRL-_ actually produces the code for CTRL--, which is converted |
| 2392 | call RunTest_mapping_mods('<C-_>', '-', function('GetEscCodeCSI27'), 5) |
| 2393 | call RunTest_mapping_mods('<C-_>', '-', function('GetEscCodeCSIu'), 5) |
| 2394 | |
| 2395 | bwipe! |
| 2396 | set timeoutlen& |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2397 | endfunc |
| 2398 | |
| 2399 | func Test_mapping_works_with_shift_ctrl() |
| 2400 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-S', 6) |
| 2401 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-S', 6) |
Bram Moolenaar | 9a033d7 | 2020-10-07 17:29:48 +0200 | [diff] [blame] | 2402 | |
| 2403 | new |
| 2404 | set timeoutlen=10 |
| 2405 | |
| 2406 | " Ctrl-Shift-[ actually produces CTRL-Shift-{ which is mapped as <C-{> |
| 2407 | call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSI27'), 6) |
| 2408 | call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSIu'), 6) |
| 2409 | |
| 2410 | " Ctrl-Shift-] actually produces CTRL-Shift-} which is mapped as <C-}> |
| 2411 | call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSI27'), 6) |
| 2412 | call RunTest_mapping_mods('<C-{>', '{', function('GetEscCodeCSIu'), 6) |
| 2413 | |
| 2414 | " Ctrl-Shift-\ actually produces CTRL-Shift-| which is mapped as <C-|> |
| 2415 | call RunTest_mapping_mods('<C-\|>', '|', function('GetEscCodeCSI27'), 6) |
| 2416 | call RunTest_mapping_mods('<C-\|>', '|', function('GetEscCodeCSIu'), 6) |
| 2417 | |
| 2418 | bwipe! |
| 2419 | set timeoutlen& |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2420 | endfunc |
| 2421 | |
| 2422 | " Below we also test the "u" code with Alt, This works, but libvterm would not |
| 2423 | " send the Alt key like this but by prefixing an Esc. |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 2424 | |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2425 | func Test_mapping_works_with_alt() |
| 2426 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'A', 3) |
| 2427 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'A', 3) |
| 2428 | endfunc |
| 2429 | |
| 2430 | func Test_mapping_works_with_shift_alt() |
| 2431 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'S-A', 4) |
| 2432 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'S-A', 4) |
| 2433 | endfunc |
| 2434 | |
Bram Moolenaar | daff0fb | 2020-09-27 13:16:46 +0200 | [diff] [blame] | 2435 | func Test_mapping_works_with_alt_and_shift() |
| 2436 | new |
| 2437 | set timeoutlen=10 |
| 2438 | |
| 2439 | " mapping <A-?> works even though the code is A-S-? |
| 2440 | for c in ['!', '$', '+', ':', '?', '^', '~'] |
| 2441 | call RunTest_mapping_mods('<A-' .. c .. '>', c, function('GetEscCodeCSI27'), 4) |
| 2442 | call RunTest_mapping_mods('<A-' .. c .. '>', c, function('GetEscCodeCSIu'), 4) |
| 2443 | endfor |
| 2444 | |
| 2445 | bwipe! |
| 2446 | set timeoutlen& |
| 2447 | endfunc |
| 2448 | |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 2449 | func Test_mapping_works_with_ctrl_alt() |
| 2450 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-A', 7) |
| 2451 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-A', 7) |
| 2452 | endfunc |
| 2453 | |
| 2454 | func Test_mapping_works_with_shift_ctrl_alt() |
| 2455 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C-S-A', 8) |
| 2456 | call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C-S-A', 8) |
| 2457 | endfunc |
Bram Moolenaar | fc4ea2a | 2019-11-26 19:33:22 +0100 | [diff] [blame] | 2458 | |
Bram Moolenaar | 064fd67 | 2022-11-29 18:32:32 +0000 | [diff] [blame] | 2459 | func Test_mapping_works_with_unknown_modifiers() |
| 2460 | new |
| 2461 | set timeoutlen=10 |
| 2462 | |
| 2463 | for Func in [function('GetEscCodeCSI27'), function('GetEscCodeCSIu')] |
| 2464 | call RunTest_mapping_mods('<C-z>', 'z', Func, 5) |
| 2465 | " Add 16, 32, 64 or 128 for modifiers we currently don't support. |
| 2466 | call RunTest_mapping_mods('<C-z>', 'z', Func, 5 + 16) |
| 2467 | call RunTest_mapping_mods('<C-z>', 'z', Func, 5 + 32) |
| 2468 | call RunTest_mapping_mods('<C-z>', 'z', Func, 5 + 64) |
| 2469 | call RunTest_mapping_mods('<C-z>', 'z', Func, 5 + 128) |
| 2470 | |
| 2471 | call RunTest_mapping_mods('<S-X>', 'X', Func, 2) |
| 2472 | " Add 16, 32, 64 or 128 for modifiers we currently don't support. |
| 2473 | call RunTest_mapping_mods('<S-X>', 'X', Func, 2 + 16) |
| 2474 | call RunTest_mapping_mods('<S-X>', 'X', Func, 2 + 32) |
| 2475 | call RunTest_mapping_mods('<S-X>', 'X', Func, 2 + 64) |
| 2476 | call RunTest_mapping_mods('<S-X>', 'X', Func, 2 + 128) |
| 2477 | endfor |
| 2478 | |
| 2479 | bwipe! |
| 2480 | set timeoutlen& |
| 2481 | endfunc |
| 2482 | |
Bram Moolenaar | 1a17340 | 2022-12-02 12:28:47 +0000 | [diff] [blame] | 2483 | func RunTest_mapping_funckey(map, func, key, code) |
| 2484 | call setline(1, '') |
| 2485 | exe 'inoremap ' .. a:map .. ' xyz' |
| 2486 | call feedkeys('a' .. a:func(a:key, a:code) .. "\<Esc>", 'Lx!') |
| 2487 | call assert_equal("xyz", getline(1), 'mapping ' .. a:map) |
| 2488 | exe 'iunmap ' .. a:map |
| 2489 | endfunc |
| 2490 | |
| 2491 | func Test_mapping_kitty_function_keys() |
| 2492 | new |
| 2493 | set timeoutlen=10 |
| 2494 | |
| 2495 | " Function keys made with CSI and ending in [ABCDEFHPQRS]. |
| 2496 | " 'E' is keypad BEGIN, not supported |
| 2497 | let maps = [ |
| 2498 | \ ['<Up>', 'A', 0], |
| 2499 | \ ['<S-Up>', 'A', 2], |
| 2500 | \ ['<C-Up>', 'A', 5], |
| 2501 | \ ['<C-S-Up>', 'A', 6], |
| 2502 | \ |
| 2503 | \ ['<Down>', 'B', 0], |
| 2504 | \ ['<S-Down>', 'B', 2], |
| 2505 | \ ['<C-Down>', 'B', 5], |
| 2506 | \ ['<C-S-Down>', 'B', 6], |
| 2507 | \ |
| 2508 | \ ['<Right>', 'C', 0], |
| 2509 | \ ['<S-Right>', 'C', 2], |
| 2510 | \ ['<C-Right>', 'C', 5], |
| 2511 | \ ['<C-S-Right>', 'C', 6], |
| 2512 | \ |
| 2513 | \ ['<Left>', 'D', 0], |
| 2514 | \ ['<S-Left>', 'D', 2], |
| 2515 | \ ['<C-Left>', 'D', 5], |
| 2516 | \ ['<C-S-Left>', 'D', 6], |
| 2517 | \ |
| 2518 | \ ['<End>', 'F', 0], |
| 2519 | \ ['<S-End>', 'F', 2], |
| 2520 | \ ['<C-End>', 'F', 5], |
| 2521 | \ ['<C-S-End>', 'F', 6], |
| 2522 | \ |
| 2523 | \ ['<Home>', 'H', 0], |
| 2524 | \ ['<S-Home>', 'H', 2], |
| 2525 | \ ['<C-Home>', 'H', 5], |
| 2526 | \ ['<C-S-Home>', 'H', 6], |
| 2527 | \ |
| 2528 | \ ['<F1>', 'P', 0], |
| 2529 | \ ['<S-F1>', 'P', 2], |
| 2530 | \ ['<C-F1>', 'P', 5], |
| 2531 | \ ['<C-S-F1>', 'P', 6], |
| 2532 | \ |
| 2533 | \ ['<F2>', 'Q', 0], |
| 2534 | \ ['<S-F2>', 'Q', 2], |
| 2535 | \ ['<C-F2>', 'Q', 5], |
| 2536 | \ ['<C-S-F2>', 'Q', 6], |
| 2537 | \ |
| 2538 | \ ['<F3>', 'R', 0], |
| 2539 | \ ['<S-F3>', 'R', 2], |
| 2540 | \ ['<C-F3>', 'R', 5], |
| 2541 | \ ['<C-S-F3>', 'R', 6], |
| 2542 | \ |
| 2543 | \ ['<F4>', 'S', 0], |
| 2544 | \ ['<S-F4>', 'S', 2], |
| 2545 | \ ['<C-F4>', 'S', 5], |
| 2546 | \ ['<C-S-F4>', 'S', 6], |
| 2547 | \ ] |
| 2548 | |
| 2549 | for map in maps |
| 2550 | call RunTest_mapping_funckey(map[0], function('GetEscCodeFunckey'), map[1], map[2]) |
| 2551 | endfor |
| 2552 | |
| 2553 | bwipe! |
| 2554 | set timeoutlen& |
| 2555 | endfunc |
| 2556 | |
Bram Moolenaar | fc4ea2a | 2019-11-26 19:33:22 +0100 | [diff] [blame] | 2557 | func Test_insert_literal() |
| 2558 | set timeoutlen=10 |
Bram Moolenaar | c255b78 | 2022-11-26 19:16:48 +0000 | [diff] [blame] | 2559 | |
| 2560 | call WaitForResponses() |
| 2561 | |
Bram Moolenaar | fc4ea2a | 2019-11-26 19:33:22 +0100 | [diff] [blame] | 2562 | new |
| 2563 | " CTRL-V CTRL-X inserts a ^X |
| 2564 | call feedkeys('a' .. GetEscCodeCSIu('V', '5') .. GetEscCodeCSIu('X', '5') .. "\<Esc>", 'Lx!') |
| 2565 | call assert_equal("\<C-X>", getline(1)) |
| 2566 | |
| 2567 | call setline(1, '') |
| 2568 | call feedkeys('a' .. GetEscCodeCSI27('V', '5') .. GetEscCodeCSI27('X', '5') .. "\<Esc>", 'Lx!') |
| 2569 | call assert_equal("\<C-X>", getline(1)) |
| 2570 | |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 2571 | " CTRL-SHIFT-V CTRL-X inserts escape sequence |
Bram Moolenaar | fc4ea2a | 2019-11-26 19:33:22 +0100 | [diff] [blame] | 2572 | call setline(1, '') |
| 2573 | call feedkeys('a' .. GetEscCodeCSIu('V', '6') .. GetEscCodeCSIu('X', '5') .. "\<Esc>", 'Lx!') |
| 2574 | call assert_equal("\<Esc>[88;5u", getline(1)) |
| 2575 | |
| 2576 | call setline(1, '') |
| 2577 | call feedkeys('a' .. GetEscCodeCSI27('V', '6') .. GetEscCodeCSI27('X', '5') .. "\<Esc>", 'Lx!') |
| 2578 | call assert_equal("\<Esc>[27;5;88~", getline(1)) |
| 2579 | |
| 2580 | bwipe! |
| 2581 | set timeoutlen& |
| 2582 | endfunc |
| 2583 | |
| 2584 | func Test_cmdline_literal() |
| 2585 | set timeoutlen=10 |
| 2586 | |
| 2587 | " CTRL-V CTRL-Y inserts a ^Y |
| 2588 | call feedkeys(':' .. GetEscCodeCSIu('V', '5') .. GetEscCodeCSIu('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!') |
| 2589 | call assert_equal("\"\<C-Y>", @:) |
| 2590 | |
| 2591 | call feedkeys(':' .. GetEscCodeCSI27('V', '5') .. GetEscCodeCSI27('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!') |
| 2592 | call assert_equal("\"\<C-Y>", @:) |
| 2593 | |
Bram Moolenaar | f19f8d1 | 2019-12-18 19:36:23 +0100 | [diff] [blame] | 2594 | " CTRL-SHIFT-V CTRL-Y inserts escape sequence |
Bram Moolenaar | fc4ea2a | 2019-11-26 19:33:22 +0100 | [diff] [blame] | 2595 | call feedkeys(':' .. GetEscCodeCSIu('V', '6') .. GetEscCodeCSIu('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!') |
| 2596 | call assert_equal("\"\<Esc>[89;5u", @:) |
| 2597 | |
| 2598 | call setline(1, '') |
| 2599 | call feedkeys(':' .. GetEscCodeCSI27('V', '6') .. GetEscCodeCSI27('Y', '5') .. "\<C-B>\"\<CR>", 'Lx!') |
| 2600 | call assert_equal("\"\<Esc>[27;5;89~", @:) |
| 2601 | |
| 2602 | set timeoutlen& |
| 2603 | endfunc |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 2604 | |
Bram Moolenaar | bbf84e2 | 2022-03-12 13:48:39 +0000 | [diff] [blame] | 2605 | func Test_mapping_esc() |
| 2606 | set timeoutlen=10 |
| 2607 | |
| 2608 | new |
| 2609 | nnoremap <Up> iHello<Esc> |
| 2610 | nnoremap <Esc> <Nop> |
| 2611 | |
| 2612 | call feedkeys(substitute(&t_ku, '\*', '', 'g'), 'Lx!') |
| 2613 | call assert_equal("Hello", getline(1)) |
| 2614 | |
| 2615 | bwipe! |
| 2616 | nunmap <Up> |
| 2617 | nunmap <Esc> |
| 2618 | set timeoutlen& |
| 2619 | endfunc |
| 2620 | |
Bram Moolenaar | 0ff5ded | 2020-05-07 18:43:44 +0200 | [diff] [blame] | 2621 | " Test for translation of special key codes (<xF1>, <xF2>, etc.) |
Bram Moolenaar | 92e5df8 | 2021-01-30 15:39:47 +0100 | [diff] [blame] | 2622 | func Test_Keycode_Translation() |
Bram Moolenaar | 0ff5ded | 2020-05-07 18:43:44 +0200 | [diff] [blame] | 2623 | let keycodes = [ |
| 2624 | \ ["<xUp>", "<Up>"], |
| 2625 | \ ["<xDown>", "<Down>"], |
| 2626 | \ ["<xLeft>", "<Left>"], |
| 2627 | \ ["<xRight>", "<Right>"], |
| 2628 | \ ["<xHome>", "<Home>"], |
| 2629 | \ ["<xEnd>", "<End>"], |
| 2630 | \ ["<zHome>", "<Home>"], |
| 2631 | \ ["<zEnd>", "<End>"], |
| 2632 | \ ["<xF1>", "<F1>"], |
| 2633 | \ ["<xF2>", "<F2>"], |
| 2634 | \ ["<xF3>", "<F3>"], |
| 2635 | \ ["<xF4>", "<F4>"], |
| 2636 | \ ["<S-xF1>", "<S-F1>"], |
| 2637 | \ ["<S-xF2>", "<S-F2>"], |
| 2638 | \ ["<S-xF3>", "<S-F3>"], |
| 2639 | \ ["<S-xF4>", "<S-F4>"]] |
| 2640 | for [k1, k2] in keycodes |
| 2641 | exe "nnoremap " .. k1 .. " 2wx" |
| 2642 | call assert_true(maparg(k1, 'n', 0, 1).lhs == k2) |
| 2643 | exe "nunmap " .. k1 |
| 2644 | endfor |
| 2645 | endfunc |
| 2646 | |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 2647 | " Test for terminal keycodes that doesn't have termcap entries |
| 2648 | func Test_special_term_keycodes() |
| 2649 | new |
| 2650 | " Test for <xHome>, <S-xHome> and <C-xHome> |
| 2651 | " send <K_SPECIAL> <KS_EXTRA> keycode |
| 2652 | call feedkeys("i\<C-K>\x80\xfd\x3f\n", 'xt') |
| 2653 | " send <K_SPECIAL> <KS_MODIFIER> bitmap <K_SPECIAL> <KS_EXTRA> keycode |
| 2654 | call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3f\n", 'xt') |
| 2655 | call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3f\n", 'xt') |
| 2656 | " Test for <xEnd>, <S-xEnd> and <C-xEnd> |
| 2657 | call feedkeys("i\<C-K>\x80\xfd\x3d\n", 'xt') |
| 2658 | call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3d\n", 'xt') |
| 2659 | call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3d\n", 'xt') |
| 2660 | " Test for <zHome>, <S-zHome> and <C-zHome> |
| 2661 | call feedkeys("i\<C-K>\x80\xfd\x40\n", 'xt') |
| 2662 | call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x40\n", 'xt') |
| 2663 | call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x40\n", 'xt') |
| 2664 | " Test for <zEnd>, <S-zEnd> and <C-zEnd> |
| 2665 | call feedkeys("i\<C-K>\x80\xfd\x3e\n", 'xt') |
| 2666 | call feedkeys("i\<C-K>\x80\xfc\x2\x80\xfd\x3e\n", 'xt') |
| 2667 | call feedkeys("i\<C-K>\x80\xfc\x4\x80\xfd\x3e\n", 'xt') |
| 2668 | " Test for <xUp>, <xDown>, <xLeft> and <xRight> |
| 2669 | call feedkeys("i\<C-K>\x80\xfd\x41\n", 'xt') |
| 2670 | call feedkeys("i\<C-K>\x80\xfd\x42\n", 'xt') |
| 2671 | call feedkeys("i\<C-K>\x80\xfd\x43\n", 'xt') |
| 2672 | call feedkeys("i\<C-K>\x80\xfd\x44\n", 'xt') |
| 2673 | call assert_equal(['<Home>', '<S-Home>', '<C-Home>', |
| 2674 | \ '<End>', '<S-End>', '<C-End>', |
| 2675 | \ '<Home>', '<S-Home>', '<C-Home>', |
| 2676 | \ '<End>', '<S-End>', '<C-End>', |
| 2677 | \ '<Up>', '<Down>', '<Left>', '<Right>', ''], getline(1, '$')) |
| 2678 | bw! |
| 2679 | endfunc |
| 2680 | |
Bram Moolenaar | 1573e73 | 2022-11-16 20:33:21 +0000 | [diff] [blame] | 2681 | func Test_home_key_works() |
| 2682 | " The '@' character in K_HOME must only match "1" when followed by ";", |
| 2683 | " otherwise this code for Home is not recognized: "<Esc>[1~" |
Bram Moolenaar | 1d8765d | 2022-11-17 16:43:35 +0000 | [diff] [blame] | 2684 | " Set termcap values like "xterm" uses them. Except using F2 for xHome, |
| 2685 | " because that termcap entry can't be set here. |
| 2686 | let save_K1 = exists('&t_K1') ? &t_K1 : '' |
| 2687 | let save_kh = exists('&t_kh') ? &t_kh : '' |
| 2688 | let save_k2 = exists('&t_k2') ? &t_k2 : '' |
| 2689 | let save_k3 = exists('&t_k3') ? &t_k3 : '' |
| 2690 | let save_end = exists('&t_@7') ? &t_@7 : '' |
| 2691 | |
Bram Moolenaar | 1573e73 | 2022-11-16 20:33:21 +0000 | [diff] [blame] | 2692 | let &t_K1 = "\<Esc>[1;*~" " <kHome> |
| 2693 | let &t_kh = "\<Esc>[@;*H" " <Home> |
Bram Moolenaar | 1d8765d | 2022-11-17 16:43:35 +0000 | [diff] [blame] | 2694 | let &t_k2 = "\<Esc>O*H" " use <F2> for <xHome> |
Bram Moolenaar | 1573e73 | 2022-11-16 20:33:21 +0000 | [diff] [blame] | 2695 | let &t_k3 = "\<Esc>[7;*~" " use <F3> for <zHome> |
| 2696 | let &t_@7 = "\<Esc>[@;*F" " <End> |
| 2697 | |
| 2698 | new |
| 2699 | call feedkeys("i\<C-K>\<Esc>OH\n\<Esc>", 'tx') |
| 2700 | call feedkeys("i\<C-K>\<Esc>[1~\n\<Esc>", 'tx') |
| 2701 | call assert_equal([ |
Bram Moolenaar | 1d8765d | 2022-11-17 16:43:35 +0000 | [diff] [blame] | 2702 | \ '<F2>', |
Bram Moolenaar | 1573e73 | 2022-11-16 20:33:21 +0000 | [diff] [blame] | 2703 | \ '<kHome>', |
| 2704 | \ ''], getline(1, '$')) |
| 2705 | |
| 2706 | bwipe! |
Bram Moolenaar | 1573e73 | 2022-11-16 20:33:21 +0000 | [diff] [blame] | 2707 | let &t_K1 = save_K1 |
Bram Moolenaar | 1d8765d | 2022-11-17 16:43:35 +0000 | [diff] [blame] | 2708 | let &t_kh = save_kh |
Bram Moolenaar | 1573e73 | 2022-11-16 20:33:21 +0000 | [diff] [blame] | 2709 | let &t_k2 = save_k2 |
| 2710 | let &t_k3 = save_k3 |
| 2711 | let &t_@7 = save_end |
| 2712 | endfunc |
| 2713 | |
Bram Moolenaar | 0f5575d | 2021-07-30 21:18:03 +0200 | [diff] [blame] | 2714 | func Test_terminal_builtin_without_gui() |
| 2715 | CheckNotMSWindows |
| 2716 | |
| 2717 | " builtin_gui should not be output by :set term=xxx |
| 2718 | let output = systemlist("TERM=dumb " .. v:progpath .. " --clean -c ':set t_ti= t_te=' -c 'set term=xxx' -c ':q!'") |
| 2719 | redraw! |
| 2720 | call map(output, {_, val -> trim(val)}) |
| 2721 | call assert_equal(-1, index(output, 'builtin_gui')) |
| 2722 | call assert_notequal(-1, index(output, 'builtin_dumb')) |
| 2723 | endfunc |
| 2724 | |
| 2725 | |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 2726 | " vim: shiftwidth=2 sts=2 expandtab |