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 |
| 4 | if has('gui_running') || !has('unix') |
| 5 | finish |
| 6 | endif |
| 7 | |
Bram Moolenaar | 564344a | 2019-04-28 13:00:12 +0200 | [diff] [blame] | 8 | source shared.vim |
| 9 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 10 | " Helper function to emit a terminal escape code. |
| 11 | func TerminalEscapeCode(code_xterm, code_sgr, row, col, m) |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 12 | if &ttymouse ==# 'xterm2' |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 13 | " need to use byte encoding here. |
| 14 | let str = list2str([a:code_xterm, a:col + 0x20, a:row + 0x20]) |
| 15 | if has('iconv') |
| 16 | let bytes = iconv(str, 'utf-8', 'latin1') |
| 17 | else |
| 18 | " Hopefully the numbers are not too big. |
| 19 | let bytes = str |
| 20 | endif |
| 21 | call feedkeys("\<Esc>[M" .. bytes, 'Lx!') |
| 22 | elseif &ttymouse ==# 'sgr' |
| 23 | call feedkeys(printf("\<Esc>[<%d;%d;%d%s", a:code_sgr, a:col, a:row, a:m), 'Lx!') |
| 24 | endif |
| 25 | endfunc |
| 26 | |
| 27 | func MouseLeftClick(row, col) |
| 28 | call TerminalEscapeCode(0x20, 0, a:row, a:col, 'M') |
| 29 | endfunc |
| 30 | |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 31 | func MouseMiddleClick(row, col) |
| 32 | call TerminalEscapeCode(0x21, 1, a:row, a:col, 'M') |
| 33 | endfunc |
| 34 | |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 35 | func MouseCtrlLeftClick(row, col) |
| 36 | let ctrl = 0x10 |
| 37 | call TerminalEscapeCode(0x20 + ctrl, 0 + ctrl, a:row, a:col, 'M') |
| 38 | endfunc |
| 39 | |
| 40 | func MouseCtrlRightClick(row, col) |
| 41 | let ctrl = 0x10 |
| 42 | call TerminalEscapeCode(0x22 + ctrl, 2 + ctrl, a:row, a:col, 'M') |
| 43 | endfunc |
| 44 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 45 | func MouseLeftRelease(row, col) |
| 46 | call TerminalEscapeCode(0x23, 3, a:row, a:col, 'm') |
| 47 | endfunc |
| 48 | |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 49 | func MouseMiddleRelease(row, col) |
| 50 | call TerminalEscapeCode(0x23, 3, a:row, a:col, 'm') |
| 51 | endfunc |
| 52 | |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 53 | func MouseRightRelease(row, col) |
| 54 | call TerminalEscapeCode(0x23, 3, a:row, a:col, 'm') |
| 55 | endfunc |
| 56 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 57 | func MouseLeftDrag(row, col) |
| 58 | call TerminalEscapeCode(0x43, 0x20, a:row, a:col, 'M') |
| 59 | endfunc |
| 60 | |
| 61 | func MouseWheelUp(row, col) |
| 62 | call TerminalEscapeCode(0x40, 0x40, a:row, a:col, 'M') |
| 63 | endfunc |
| 64 | |
| 65 | func MouseWheelDown(row, col) |
| 66 | call TerminalEscapeCode(0x41, 0x41, a:row, a:col, 'M') |
| 67 | endfunc |
| 68 | |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 69 | func Test_xterm_mouse_left_click() |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 70 | new |
| 71 | let save_mouse = &mouse |
| 72 | let save_term = &term |
| 73 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 74 | set mouse=a term=xterm |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 75 | 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] | 76 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 77 | for ttymouse_val in ['xterm2', 'sgr'] |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 78 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 79 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 80 | go |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 81 | call assert_equal([0, 1, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 82 | let row = 2 |
| 83 | let col = 6 |
| 84 | call MouseLeftClick(row, col) |
| 85 | call MouseLeftRelease(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 86 | call assert_equal([0, 2, 6, 0], getpos('.'), msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 87 | endfor |
Bram Moolenaar | 905dd90 | 2019-04-07 14:21:47 +0200 | [diff] [blame] | 88 | |
| 89 | let &mouse = save_mouse |
| 90 | let &term = save_term |
| 91 | let &ttymouse = save_ttymouse |
| 92 | bwipe! |
| 93 | endfunc |
| 94 | |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 95 | " Test that <C-LeftMouse> jumps to help tag and <C-RightMouse> jumps back. |
| 96 | func Test_xterm_mouse_ctrl_click() |
| 97 | let save_mouse = &mouse |
| 98 | let save_term = &term |
| 99 | let save_ttymouse = &ttymouse |
| 100 | set mouse=a term=xterm |
| 101 | |
| 102 | for ttymouse_val in ['xterm2', 'sgr'] |
| 103 | let msg = 'ttymouse=' .. ttymouse_val |
| 104 | exe 'set ttymouse=' .. ttymouse_val |
| 105 | help |
| 106 | /usr_02.txt |
| 107 | norm! zt |
| 108 | let row = 1 |
| 109 | let col = 1 |
| 110 | call MouseCtrlLeftClick(row, col) |
| 111 | call MouseLeftRelease(row, col) |
| 112 | call assert_match('usr_02.txt$', bufname('%'), msg) |
| 113 | call assert_equal('*usr_02.txt*', expand('<cWORD>')) |
| 114 | |
| 115 | call MouseCtrlRightClick(row, col) |
| 116 | call MouseLeftRelease(row, col) |
| 117 | call assert_match('help.txt$', bufname('%'), msg) |
| 118 | call assert_equal('|usr_02.txt|', expand('<cWORD>')) |
| 119 | |
| 120 | helpclose |
| 121 | endfor |
| 122 | |
| 123 | let &mouse = save_mouse |
| 124 | let &term = save_term |
| 125 | let &ttymouse = save_ttymouse |
| 126 | endfunc |
| 127 | |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 128 | func Test_xterm_mouse_middle_click() |
Bram Moolenaar | 564344a | 2019-04-28 13:00:12 +0200 | [diff] [blame] | 129 | if !WorkingClipboard() |
| 130 | throw 'Skipped: No working clipboard' |
| 131 | endif |
| 132 | |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 133 | new |
| 134 | let save_mouse = &mouse |
| 135 | let save_term = &term |
| 136 | let save_ttymouse = &ttymouse |
| 137 | let save_quotestar = @* |
| 138 | let @* = 'abc' |
| 139 | set mouse=a term=xterm |
| 140 | |
| 141 | for ttymouse_val in ['xterm2', 'sgr'] |
| 142 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 143 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | c1b8160 | 2019-04-27 19:11:35 +0200 | [diff] [blame] | 144 | call setline(1, ['123456789', '123456789']) |
| 145 | |
| 146 | " Middle-click in the middle of the line pastes text where clicked. |
| 147 | let row = 1 |
| 148 | let col = 6 |
| 149 | call MouseMiddleClick(row, col) |
| 150 | call MouseMiddleRelease(row, col) |
| 151 | call assert_equal(['12345abc6789', '123456789'], getline(1, '$'), msg) |
| 152 | |
| 153 | " Middle-click beyond end of the line pastes text at the end of the line. |
| 154 | let col = 20 |
| 155 | call MouseMiddleClick(row, col) |
| 156 | call MouseMiddleRelease(row, col) |
| 157 | call assert_equal(['12345abc6789abc', '123456789'], getline(1, '$'), msg) |
| 158 | |
| 159 | " Middle-click beyond the last line pastes in the last line. |
| 160 | let row = 5 |
| 161 | let col = 3 |
| 162 | call MouseMiddleClick(row, col) |
| 163 | call MouseMiddleRelease(row, col) |
| 164 | call assert_equal(['12345abc6789abc', '12abc3456789'], getline(1, '$'), msg) |
| 165 | endfor |
| 166 | |
| 167 | let &mouse = save_mouse |
| 168 | let &term = save_term |
| 169 | let &ttymouse = save_ttymouse |
| 170 | let @* = save_quotestar |
| 171 | bwipe! |
| 172 | endfunc |
| 173 | |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 174 | func Test_xterm_mouse_wheel() |
| 175 | new |
| 176 | let save_mouse = &mouse |
| 177 | let save_term = &term |
| 178 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 179 | set mouse=a term=xterm |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 180 | call setline(1, range(1, 100)) |
| 181 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 182 | for ttymouse_val in ['xterm2', 'sgr'] |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 183 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 184 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 185 | go |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 186 | call assert_equal(1, line('w0'), msg) |
| 187 | call assert_equal([0, 1, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 188 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 189 | call MouseWheelDown(1, 1) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 190 | call assert_equal(4, line('w0'), msg) |
| 191 | call assert_equal([0, 4, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 192 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 193 | call MouseWheelDown(1, 1) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 194 | call assert_equal(7, line('w0'), msg) |
| 195 | call assert_equal([0, 7, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 196 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 197 | call MouseWheelUp(1, 1) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 198 | call assert_equal(4, line('w0'), msg) |
| 199 | call assert_equal([0, 7, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 200 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 201 | call MouseWheelUp(1, 1) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 202 | call assert_equal(1, line('w0'), msg) |
| 203 | call assert_equal([0, 7, 1, 0], getpos('.'), msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 204 | endfor |
Bram Moolenaar | 049736f | 2019-04-07 21:55:07 +0200 | [diff] [blame] | 205 | |
| 206 | let &mouse = save_mouse |
| 207 | let &term = save_term |
| 208 | let &ttymouse = save_ttymouse |
| 209 | bwipe! |
| 210 | endfunc |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 211 | |
| 212 | func Test_xterm_mouse_drag_window_separator() |
| 213 | let save_mouse = &mouse |
| 214 | let save_term = &term |
| 215 | let save_ttymouse = &ttymouse |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 216 | set mouse=a term=xterm |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 217 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 218 | for ttymouse_val in ['xterm2', 'sgr'] |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 219 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 220 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 221 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 222 | " Split horizontally and test dragging the horizontal window separator. |
| 223 | split |
| 224 | let rowseparator = winheight(0) + 1 |
| 225 | let row = rowseparator |
| 226 | let col = 1 |
Bram Moolenaar | c8b3dda | 2019-04-12 21:42:52 +0200 | [diff] [blame] | 227 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 228 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
| 229 | if ttymouse_val !=# 'xterm2' || row <= 223 |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 230 | call MouseLeftClick(row, col) |
| 231 | let row -= 1 |
| 232 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 233 | call assert_equal(rowseparator - 1, winheight(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 234 | let row += 1 |
| 235 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 236 | call assert_equal(rowseparator, winheight(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 237 | call MouseLeftRelease(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 238 | call assert_equal(rowseparator, winheight(0) + 1, msg) |
Bram Moolenaar | c8b3dda | 2019-04-12 21:42:52 +0200 | [diff] [blame] | 239 | endif |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 240 | bwipe! |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 241 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 242 | " Split vertically and test dragging the vertical window separator. |
| 243 | vsplit |
| 244 | let colseparator = winwidth(0) + 1 |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 245 | let row = 1 |
| 246 | let col = colseparator |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 247 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 248 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
| 249 | if ttymouse_val !=# 'xterm2' || col <= 223 |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 250 | call MouseLeftClick(row, col) |
| 251 | let col -= 1 |
| 252 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 253 | call assert_equal(colseparator - 1, winwidth(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 254 | let col += 1 |
| 255 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 256 | call assert_equal(colseparator, winwidth(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 257 | call MouseLeftRelease(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 258 | call assert_equal(colseparator, winwidth(0) + 1, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 259 | endif |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 260 | bwipe! |
| 261 | endfor |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 262 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 263 | let &mouse = save_mouse |
| 264 | let &term = save_term |
| 265 | let &ttymouse = save_ttymouse |
| 266 | endfunc |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 267 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 268 | func Test_xterm_mouse_drag_statusline() |
| 269 | let save_mouse = &mouse |
| 270 | let save_term = &term |
| 271 | let save_ttymouse = &ttymouse |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 272 | let save_laststatus = &laststatus |
| 273 | set mouse=a term=xterm laststatus=2 |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 274 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 275 | for ttymouse_val in ['xterm2', 'sgr'] |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 276 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 277 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 278 | |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 279 | call assert_equal(1, &cmdheight, msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 280 | let rowstatusline = winheight(0) + 1 |
| 281 | let row = rowstatusline |
| 282 | let col = 1 |
Bram Moolenaar | c8b3dda | 2019-04-12 21:42:52 +0200 | [diff] [blame] | 283 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 284 | if ttymouse_val ==# 'xterm2' && row > 223 |
| 285 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
Bram Moolenaar | c8b3dda | 2019-04-12 21:42:52 +0200 | [diff] [blame] | 286 | continue |
| 287 | endif |
| 288 | |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 289 | call MouseLeftClick(row, col) |
| 290 | let row -= 1 |
| 291 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 292 | call assert_equal(2, &cmdheight, msg) |
| 293 | call assert_equal(rowstatusline - 1, winheight(0) + 1, msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 294 | let row += 1 |
| 295 | call MouseLeftDrag(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 296 | call assert_equal(1, &cmdheight, msg) |
| 297 | call assert_equal(rowstatusline, winheight(0) + 1, msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 298 | call MouseLeftRelease(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 299 | call assert_equal(1, &cmdheight, msg) |
| 300 | call assert_equal(rowstatusline, winheight(0) + 1, msg) |
Bram Moolenaar | 3fbd2d7 | 2019-04-11 23:56:16 +0200 | [diff] [blame] | 301 | endfor |
| 302 | |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 303 | let &mouse = save_mouse |
| 304 | let &term = save_term |
| 305 | let &ttymouse = save_ttymouse |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 306 | let &laststatus = save_laststatus |
| 307 | endfunc |
| 308 | |
| 309 | func Test_xterm_mouse_click_tab() |
| 310 | let save_mouse = &mouse |
| 311 | let save_term = &term |
| 312 | let save_ttymouse = &ttymouse |
| 313 | set mouse=a term=xterm |
| 314 | let row = 1 |
| 315 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 316 | for ttymouse_val in ['xterm2', 'sgr'] |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 317 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 318 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 319 | e Xfoo |
| 320 | tabnew Xbar |
| 321 | |
| 322 | let a = split(execute(':tabs'), "\n") |
| 323 | call assert_equal(['Tab page 1', |
| 324 | \ ' Xfoo', |
| 325 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 326 | \ '> Xbar'], a, msg) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 327 | |
| 328 | " Test clicking on tab names in the tabline at the top. |
| 329 | let col = 2 |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 330 | redraw |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 331 | call MouseLeftClick(row, col) |
| 332 | call MouseLeftRelease(row, col) |
| 333 | let a = split(execute(':tabs'), "\n") |
| 334 | call assert_equal(['Tab page 1', |
| 335 | \ '> Xfoo', |
| 336 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 337 | \ ' Xbar'], a, msg) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 338 | |
| 339 | let col = 9 |
| 340 | call MouseLeftClick(row, col) |
| 341 | call MouseLeftRelease(row, col) |
| 342 | let a = split(execute(':tabs'), "\n") |
| 343 | call assert_equal(['Tab page 1', |
| 344 | \ ' Xfoo', |
| 345 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 346 | \ '> Xbar'], a, msg) |
Bram Moolenaar | ca57ab5 | 2019-04-13 14:53:16 +0200 | [diff] [blame] | 347 | |
| 348 | %bwipe! |
| 349 | endfor |
| 350 | |
| 351 | let &mouse = save_mouse |
| 352 | let &term = save_term |
| 353 | let &ttymouse = save_ttymouse |
Bram Moolenaar | 3fb01a5 | 2019-04-09 21:52:02 +0200 | [diff] [blame] | 354 | endfunc |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 355 | |
| 356 | func Test_xterm_mouse_click_X_to_close_tab() |
| 357 | let save_mouse = &mouse |
| 358 | let save_term = &term |
| 359 | let save_ttymouse = &ttymouse |
| 360 | set mouse=a term=xterm |
| 361 | let row = 1 |
| 362 | let col = &columns |
| 363 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 364 | for ttymouse_val in ['xterm2', 'sgr'] |
| 365 | if ttymouse_val ==# 'xterm2' && col > 223 |
| 366 | " When 'ttymouse' is 'xterm2', row/col bigger than 223 are not supported. |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 367 | continue |
| 368 | endif |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 369 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 370 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 371 | e Xtab1 |
| 372 | tabnew Xtab2 |
| 373 | tabnew Xtab3 |
| 374 | tabn 2 |
| 375 | |
| 376 | let a = split(execute(':tabs'), "\n") |
| 377 | call assert_equal(['Tab page 1', |
| 378 | \ ' Xtab1', |
| 379 | \ 'Tab page 2', |
| 380 | \ '> Xtab2', |
| 381 | \ 'Tab page 3', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 382 | \ ' Xtab3'], a, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 383 | |
| 384 | " Click on "X" in tabline to close current tab i.e. Xtab2. |
| 385 | redraw |
| 386 | call MouseLeftClick(row, col) |
| 387 | call MouseLeftRelease(row, col) |
| 388 | let a = split(execute(':tabs'), "\n") |
| 389 | call assert_equal(['Tab page 1', |
| 390 | \ ' Xtab1', |
| 391 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 392 | \ '> Xtab3'], a, msg) |
Bram Moolenaar | 39f76c6 | 2019-04-13 22:13:23 +0200 | [diff] [blame] | 393 | |
| 394 | %bwipe! |
| 395 | endfor |
| 396 | |
| 397 | let &mouse = save_mouse |
| 398 | let &term = save_term |
| 399 | let &ttymouse = save_ttymouse |
| 400 | endfunc |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 401 | |
| 402 | func Test_xterm_mouse_drag_to_move_tab() |
| 403 | let save_mouse = &mouse |
| 404 | let save_term = &term |
| 405 | let save_ttymouse = &ttymouse |
| 406 | " Set 'mousetime' to 1 to avoid recognizing a double-click in the loop |
| 407 | set mouse=a term=xterm mousetime=1 |
| 408 | let row = 1 |
| 409 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 410 | for ttymouse_val in ['xterm2', 'sgr'] |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 411 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 412 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 413 | e Xtab1 |
| 414 | tabnew Xtab2 |
| 415 | |
| 416 | let a = split(execute(':tabs'), "\n") |
| 417 | call assert_equal(['Tab page 1', |
| 418 | \ ' Xtab1', |
| 419 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 420 | \ '> Xtab2'], a, msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 421 | redraw |
| 422 | |
| 423 | " Click in tab2 and drag it to tab1. |
| 424 | " Check getcharmod() to verify that click is not |
| 425 | " interpreted as a spurious double-click. |
| 426 | call MouseLeftClick(row, 10) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 427 | call assert_equal(0, getcharmod(), msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 428 | for col in [9, 8, 7, 6] |
| 429 | call MouseLeftDrag(row, col) |
| 430 | endfor |
| 431 | call MouseLeftRelease(row, col) |
| 432 | let a = split(execute(':tabs'), "\n") |
| 433 | call assert_equal(['Tab page 1', |
| 434 | \ '> Xtab2', |
| 435 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 436 | \ ' Xtab1'], a, msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 437 | |
Bram Moolenaar | 7f27976 | 2019-04-15 21:48:22 +0200 | [diff] [blame] | 438 | " brief sleep to avoid causing a double-click |
| 439 | sleep 20m |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 440 | %bwipe! |
| 441 | endfor |
| 442 | |
| 443 | let &mouse = save_mouse |
| 444 | let &term = save_term |
| 445 | let &ttymouse = save_ttymouse |
| 446 | set mousetime& |
| 447 | endfunc |
| 448 | |
| 449 | func Test_xterm_mouse_double_click_to_create_tab() |
| 450 | let save_mouse = &mouse |
| 451 | let save_term = &term |
| 452 | let save_ttymouse = &ttymouse |
| 453 | " Set 'mousetime' to a small value, so that double-click works but we don't |
| 454 | " have to wait long to avoid a triple-click. |
| 455 | set mouse=a term=xterm mousetime=100 |
| 456 | let row = 1 |
| 457 | let col = 10 |
| 458 | |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 459 | for ttymouse_val in ['xterm2', 'sgr'] |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 460 | let msg = 'ttymouse=' .. ttymouse_val |
Bram Moolenaar | 1ee36d6 | 2019-05-01 23:13:56 +0200 | [diff] [blame] | 461 | exe 'set ttymouse=' .. ttymouse_val |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 462 | e Xtab1 |
| 463 | tabnew Xtab2 |
| 464 | |
| 465 | let a = split(execute(':tabs'), "\n") |
| 466 | call assert_equal(['Tab page 1', |
| 467 | \ ' Xtab1', |
| 468 | \ 'Tab page 2', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 469 | \ '> Xtab2'], a, msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 470 | |
| 471 | redraw |
| 472 | call MouseLeftClick(row, col) |
| 473 | " Check getcharmod() to verify that first click is not |
| 474 | " interpreted as a spurious double-click. |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 475 | call assert_equal(0, getcharmod(), msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 476 | call MouseLeftRelease(row, col) |
| 477 | call MouseLeftClick(row, col) |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 478 | call assert_equal(32, getcharmod(), msg) " double-click |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 479 | call MouseLeftRelease(row, col) |
| 480 | let a = split(execute(':tabs'), "\n") |
| 481 | call assert_equal(['Tab page 1', |
| 482 | \ ' Xtab1', |
| 483 | \ 'Tab page 2', |
| 484 | \ '> [No Name]', |
| 485 | \ 'Tab page 3', |
Bram Moolenaar | 4945219 | 2019-04-17 16:27:02 +0200 | [diff] [blame] | 486 | \ ' Xtab2'], a, msg) |
Bram Moolenaar | e3e3828 | 2019-04-15 20:55:31 +0200 | [diff] [blame] | 487 | |
| 488 | if ttymouse_val !=# 'sgr' |
| 489 | " We need to sleep, or else MouseLeftClick() in next loop |
| 490 | " iteration will be interpreted as a spurious triple-click. |
| 491 | sleep 100m |
| 492 | endif |
| 493 | %bwipe! |
| 494 | endfor |
| 495 | |
| 496 | let &mouse = save_mouse |
| 497 | let &term = save_term |
| 498 | let &ttymouse = save_ttymouse |
| 499 | set mousetime& |
| 500 | endfunc |
Bram Moolenaar | 696d637 | 2019-04-17 16:33:46 +0200 | [diff] [blame] | 501 | |
| 502 | func Test_xterm_mouse_click_in_fold_columns() |
| 503 | new |
| 504 | let save_mouse = &mouse |
| 505 | let save_term = &term |
| 506 | let save_ttymouse = &ttymouse |
| 507 | let save_foldcolumn = &foldcolumn |
Bram Moolenaar | 2b00b9b | 2019-04-17 17:08:27 +0200 | [diff] [blame] | 508 | set mouse=a term=xterm foldcolumn=3 ttymouse=xterm2 |
Bram Moolenaar | 696d637 | 2019-04-17 16:33:46 +0200 | [diff] [blame] | 509 | |
| 510 | " Create 2 nested folds. |
| 511 | call setline(1, range(1, 7)) |
| 512 | 2,6fold |
| 513 | norm! zR |
| 514 | 4,5fold |
| 515 | call assert_equal([-1, -1, -1, 4, 4, -1, -1], |
| 516 | \ map(range(1, 7), 'foldclosed(v:val)')) |
| 517 | |
| 518 | " Click in "+" of inner fold in foldcolumn should open it. |
| 519 | redraw |
| 520 | let row = 4 |
| 521 | let col = 2 |
| 522 | call MouseLeftClick(row, col) |
| 523 | call MouseLeftRelease(row, col) |
| 524 | call assert_equal([-1, -1, -1, -1, -1, -1, -1], |
| 525 | \ map(range(1, 7), 'foldclosed(v:val)')) |
| 526 | |
| 527 | " Click in "-" of outer fold in foldcolumn should close it. |
| 528 | redraw |
| 529 | let row = 2 |
| 530 | let col = 1 |
| 531 | call MouseLeftClick(row, col) |
| 532 | call MouseLeftRelease(row, col) |
| 533 | call assert_equal([-1, 2, 2, 2, 2, 2, -1], |
| 534 | \ map(range(1, 7), 'foldclosed(v:val)')) |
| 535 | norm! zR |
| 536 | |
| 537 | " Click in "|" of inner fold in foldcolumn should close it. |
| 538 | redraw |
| 539 | let row = 5 |
| 540 | let col = 2 |
| 541 | call MouseLeftClick(row, col) |
| 542 | call MouseLeftRelease(row, col) |
| 543 | call assert_equal([-1, -1, -1, 4, 4, -1, -1], |
| 544 | \ map(range(1, 7), 'foldclosed(v:val)')) |
| 545 | |
| 546 | let &foldcolumn = save_foldcolumn |
| 547 | let &ttymouse = save_ttymouse |
| 548 | let &term = save_term |
| 549 | let &mouse = save_mouse |
| 550 | bwipe! |
| 551 | endfunc |