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