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