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