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