Bram Moolenaar | 991dea3 | 2016-05-24 11:31:32 +0200 | [diff] [blame] | 1 | " Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...) |
| 2 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 3 | source check.vim |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 4 | source screendump.vim |
Bram Moolenaar | a27e1dc | 2019-10-07 22:27:36 +0200 | [diff] [blame] | 5 | |
Bram Moolenaar | 991dea3 | 2016-05-24 11:31:32 +0200 | [diff] [blame] | 6 | func Test_window_cmd_ls0_with_split() |
| 7 | set ls=0 |
| 8 | set splitbelow |
| 9 | split |
| 10 | quit |
| 11 | call assert_equal(0, &lines - &cmdheight - winheight(0)) |
| 12 | new | only! |
| 13 | " |
| 14 | set splitbelow&vim |
| 15 | botright split |
| 16 | quit |
| 17 | call assert_equal(0, &lines - &cmdheight - winheight(0)) |
| 18 | new | only! |
| 19 | set ls&vim |
| 20 | endfunc |
| 21 | |
| 22 | func Test_window_cmd_cmdwin_with_vsp() |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 23 | let efmt = 'Expected 0 but got %d (in ls=%d, %s window)' |
Bram Moolenaar | 991dea3 | 2016-05-24 11:31:32 +0200 | [diff] [blame] | 24 | for v in range(0, 2) |
| 25 | exec "set ls=" . v |
| 26 | vsplit |
| 27 | call feedkeys("q:\<CR>") |
| 28 | let ac = &lines - (&cmdheight + winheight(0) + !!v) |
| 29 | let emsg = printf(efmt, ac, v, 'left') |
| 30 | call assert_equal(0, ac, emsg) |
| 31 | wincmd w |
| 32 | let ac = &lines - (&cmdheight + winheight(0) + !!v) |
| 33 | let emsg = printf(efmt, ac, v, 'right') |
| 34 | call assert_equal(0, ac, emsg) |
| 35 | new | only! |
| 36 | endfor |
| 37 | set ls&vim |
| 38 | endfunc |
| 39 | |
Bram Moolenaar | 96bde99 | 2022-08-10 17:23:12 +0100 | [diff] [blame] | 40 | func Test_cmdheight_not_changed() |
| 41 | set cmdheight=2 |
| 42 | set winminheight=0 |
| 43 | augroup Maximize |
| 44 | autocmd WinEnter * wincmd _ |
| 45 | augroup END |
| 46 | split |
| 47 | tabnew |
| 48 | tabfirst |
| 49 | call assert_equal(2, &cmdheight) |
| 50 | |
| 51 | tabonly! |
| 52 | only |
| 53 | set winminwidth& cmdheight& |
| 54 | augroup Maximize |
| 55 | au! |
| 56 | augroup END |
| 57 | augroup! Maximize |
| 58 | endfunc |
| 59 | |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 60 | " Test for jumping to windows |
| 61 | func Test_window_jump() |
| 62 | new |
| 63 | " jumping to a window with a count greater than the max windows |
| 64 | exe "normal 4\<C-W>w" |
| 65 | call assert_equal(2, winnr()) |
| 66 | only |
| 67 | endfunc |
| 68 | |
| 69 | func Test_window_cmd_wincmd_gf() |
Bram Moolenaar | 5d2ca04 | 2016-06-26 17:11:21 +0200 | [diff] [blame] | 70 | let fname = 'test_gf.txt' |
| 71 | let swp_fname = '.' . fname . '.swp' |
Bram Moolenaar | db4c947 | 2022-10-15 22:06:06 +0100 | [diff] [blame^] | 72 | call writefile([], fname, 'D') |
| 73 | call writefile([], swp_fname, 'D') |
Bram Moolenaar | 5d2ca04 | 2016-06-26 17:11:21 +0200 | [diff] [blame] | 74 | function s:swap_exists() |
| 75 | let v:swapchoice = s:swap_choice |
| 76 | endfunc |
Bram Moolenaar | eaa49e4 | 2019-07-13 18:08:59 +0200 | [diff] [blame] | 77 | " Remove the catch-all that runtest.vim adds |
| 78 | au! SwapExists |
Bram Moolenaar | 5d2ca04 | 2016-06-26 17:11:21 +0200 | [diff] [blame] | 79 | augroup test_window_cmd_wincmd_gf |
| 80 | autocmd! |
| 81 | exec "autocmd SwapExists " . fname . " call s:swap_exists()" |
| 82 | augroup END |
| 83 | |
| 84 | call setline(1, fname) |
| 85 | " (E)dit anyway |
| 86 | let s:swap_choice = 'e' |
| 87 | wincmd gf |
| 88 | call assert_equal(2, tabpagenr()) |
| 89 | call assert_equal(fname, bufname("%")) |
| 90 | quit! |
| 91 | |
| 92 | " (Q)uit |
| 93 | let s:swap_choice = 'q' |
| 94 | wincmd gf |
| 95 | call assert_equal(1, tabpagenr()) |
| 96 | call assert_notequal(fname, bufname("%")) |
| 97 | new | only! |
| 98 | |
Bram Moolenaar | 5d2ca04 | 2016-06-26 17:11:21 +0200 | [diff] [blame] | 99 | augroup! test_window_cmd_wincmd_gf |
| 100 | endfunc |
| 101 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 102 | func Test_window_quit() |
| 103 | e Xa |
| 104 | split Xb |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 105 | call assert_equal(2, '$'->winnr()) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 106 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 107 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 108 | |
| 109 | wincmd q |
| 110 | call assert_equal(1, winnr('$')) |
| 111 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 112 | |
| 113 | bw Xa Xb |
| 114 | endfunc |
| 115 | |
| 116 | func Test_window_horizontal_split() |
| 117 | call assert_equal(1, winnr('$')) |
| 118 | 3wincmd s |
| 119 | call assert_equal(2, winnr('$')) |
| 120 | call assert_equal(3, winheight(0)) |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 121 | call assert_equal(winwidth(1), 2->winwidth()) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 122 | |
| 123 | call assert_fails('botright topleft wincmd s', 'E442:') |
| 124 | bw |
| 125 | endfunc |
| 126 | |
| 127 | func Test_window_vertical_split() |
| 128 | call assert_equal(1, winnr('$')) |
| 129 | 3wincmd v |
| 130 | call assert_equal(2, winnr('$')) |
| 131 | call assert_equal(3, winwidth(0)) |
| 132 | call assert_equal(winheight(1), winheight(2)) |
| 133 | |
| 134 | call assert_fails('botright topleft wincmd v', 'E442:') |
| 135 | bw |
| 136 | endfunc |
| 137 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 138 | " Test the ":wincmd ^" and "<C-W>^" commands. |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 139 | func Test_window_split_edit_alternate() |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 140 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 141 | " Test for failure when the alternate buffer/file no longer exists. |
| 142 | edit Xfoo | %bw |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 143 | call assert_fails(':wincmd ^', 'E23:') |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 144 | |
| 145 | " Test for the expected behavior when we have two named buffers. |
| 146 | edit Xfoo | edit Xbar |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 147 | wincmd ^ |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 148 | call assert_equal('Xfoo', bufname(winbufnr(1))) |
| 149 | call assert_equal('Xbar', bufname(winbufnr(2))) |
| 150 | only |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 151 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 152 | " Test for the expected behavior when the alternate buffer is not named. |
| 153 | enew | let l:nr1 = bufnr('%') |
| 154 | edit Xfoo | let l:nr2 = bufnr('%') |
| 155 | wincmd ^ |
| 156 | call assert_equal(l:nr1, winbufnr(1)) |
| 157 | call assert_equal(l:nr2, winbufnr(2)) |
| 158 | only |
| 159 | |
Bram Moolenaar | d42333d | 2018-11-10 20:28:19 +0100 | [diff] [blame] | 160 | " FIXME: this currently fails on AppVeyor, but passes locally |
| 161 | if !has('win32') |
| 162 | " Test the Normal mode command. |
| 163 | call feedkeys("\<C-W>\<C-^>", 'tx') |
| 164 | call assert_equal(l:nr2, winbufnr(1)) |
| 165 | call assert_equal(l:nr1, winbufnr(2)) |
| 166 | endif |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 167 | |
| 168 | %bw! |
| 169 | endfunc |
| 170 | |
| 171 | " Test the ":[count]wincmd ^" and "[count]<C-W>^" commands. |
| 172 | func Test_window_split_edit_bufnr() |
| 173 | |
| 174 | %bwipeout |
| 175 | let l:nr = bufnr('%') + 1 |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 176 | call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92:') |
| 177 | call assert_fails(':' . l:nr . 'wincmd ^', 'E16:') |
| 178 | call assert_fails(':0wincmd ^', 'E16:') |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 179 | |
| 180 | edit Xfoo | edit Xbar | edit Xbaz |
| 181 | let l:foo_nr = bufnr('Xfoo') |
| 182 | let l:bar_nr = bufnr('Xbar') |
| 183 | let l:baz_nr = bufnr('Xbaz') |
| 184 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 185 | " FIXME: this currently fails on AppVeyor, but passes locally |
| 186 | if !has('win32') |
| 187 | call feedkeys(l:foo_nr . "\<C-W>\<C-^>", 'tx') |
| 188 | call assert_equal('Xfoo', bufname(winbufnr(1))) |
| 189 | call assert_equal('Xbaz', bufname(winbufnr(2))) |
| 190 | only |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 191 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 192 | call feedkeys(l:bar_nr . "\<C-W>\<C-^>", 'tx') |
| 193 | call assert_equal('Xbar', bufname(winbufnr(1))) |
| 194 | call assert_equal('Xfoo', bufname(winbufnr(2))) |
| 195 | only |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 196 | |
Bram Moolenaar | 8617b40 | 2018-11-10 20:47:48 +0100 | [diff] [blame] | 197 | execute l:baz_nr . 'wincmd ^' |
| 198 | call assert_equal('Xbaz', bufname(winbufnr(1))) |
| 199 | call assert_equal('Xbar', bufname(winbufnr(2))) |
| 200 | endif |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 201 | |
| 202 | %bw! |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 203 | endfunc |
| 204 | |
Bram Moolenaar | 9b9be00 | 2020-03-22 14:41:22 +0100 | [diff] [blame] | 205 | func Test_window_split_no_room() |
| 206 | " N horizontal windows need >= 2*N + 1 lines: |
| 207 | " - 1 line + 1 status line in each window |
| 208 | " - 1 Ex command line |
| 209 | " |
| 210 | " 2*N + 1 <= &lines |
| 211 | " N <= (lines - 1)/2 |
| 212 | " |
| 213 | " Beyond that number of windows, E36: Not enough room is expected. |
| 214 | let hor_win_count = (&lines - 1)/2 |
| 215 | let hor_split_count = hor_win_count - 1 |
| 216 | for s in range(1, hor_split_count) | split | endfor |
| 217 | call assert_fails('split', 'E36:') |
| 218 | |
| 219 | " N vertical windows need >= 2*(N - 1) + 1 columns: |
| 220 | " - 1 column + 1 separator for each window (except last window) |
| 221 | " - 1 column for the last window which does not have separator |
| 222 | " |
| 223 | " 2*(N - 1) + 1 <= &columns |
| 224 | " 2*N - 1 <= &columns |
| 225 | " N <= (&columns + 1)/2 |
| 226 | let ver_win_count = (&columns + 1)/2 |
| 227 | let ver_split_count = ver_win_count - 1 |
| 228 | for s in range(1, ver_split_count) | vsplit | endfor |
| 229 | call assert_fails('vsplit', 'E36:') |
| 230 | |
| 231 | %bw! |
| 232 | endfunc |
| 233 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 234 | func Test_window_exchange() |
| 235 | e Xa |
| 236 | |
| 237 | " Nothing happens with window exchange when there is 1 window |
| 238 | wincmd x |
| 239 | call assert_equal(1, winnr('$')) |
| 240 | |
| 241 | split Xb |
| 242 | split Xc |
| 243 | |
| 244 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 245 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 246 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 247 | |
| 248 | " Exchange current window 1 with window 3 |
| 249 | 3wincmd x |
| 250 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 251 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 252 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 253 | |
| 254 | " Exchange window with next when at the top window |
| 255 | wincmd x |
| 256 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 257 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 258 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 259 | |
| 260 | " Exchange window with next when at the middle window |
| 261 | wincmd j |
| 262 | wincmd x |
| 263 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 264 | call assert_equal('Xc', bufname(winbufnr(2))) |
| 265 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 266 | |
| 267 | " Exchange window with next when at the bottom window. |
| 268 | " When there is no next window, it exchanges with the previous window. |
| 269 | wincmd j |
| 270 | wincmd x |
| 271 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 272 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 273 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 274 | |
| 275 | bw Xa Xb Xc |
| 276 | endfunc |
| 277 | |
| 278 | func Test_window_rotate() |
| 279 | e Xa |
| 280 | split Xb |
| 281 | split Xc |
| 282 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 283 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 284 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 285 | |
| 286 | " Rotate downwards |
| 287 | wincmd r |
| 288 | call assert_equal('Xa', bufname(winbufnr(1))) |
| 289 | call assert_equal('Xc', bufname(winbufnr(2))) |
| 290 | call assert_equal('Xb', bufname(winbufnr(3))) |
| 291 | |
| 292 | 2wincmd r |
| 293 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 294 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 295 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 296 | |
| 297 | " Rotate upwards |
| 298 | wincmd R |
| 299 | call assert_equal('Xb', bufname(winbufnr(1))) |
| 300 | call assert_equal('Xa', bufname(winbufnr(2))) |
| 301 | call assert_equal('Xc', bufname(winbufnr(3))) |
| 302 | |
| 303 | 2wincmd R |
| 304 | call assert_equal('Xc', bufname(winbufnr(1))) |
| 305 | call assert_equal('Xb', bufname(winbufnr(2))) |
| 306 | call assert_equal('Xa', bufname(winbufnr(3))) |
| 307 | |
| 308 | bot vsplit |
| 309 | call assert_fails('wincmd R', 'E443:') |
| 310 | |
| 311 | bw Xa Xb Xc |
| 312 | endfunc |
| 313 | |
| 314 | func Test_window_height() |
| 315 | e Xa |
| 316 | split Xb |
| 317 | |
| 318 | let [wh1, wh2] = [winheight(1), winheight(2)] |
| 319 | " Active window (1) should have the same height or 1 more |
| 320 | " than the other window. |
| 321 | call assert_inrange(wh2, wh2 + 1, wh1) |
| 322 | |
| 323 | wincmd - |
| 324 | call assert_equal(wh1 - 1, winheight(1)) |
| 325 | call assert_equal(wh2 + 1, winheight(2)) |
| 326 | |
| 327 | wincmd + |
| 328 | call assert_equal(wh1, winheight(1)) |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 329 | call assert_equal(wh2, 2->winheight()) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 330 | |
| 331 | 2wincmd _ |
| 332 | call assert_equal(2, winheight(1)) |
| 333 | call assert_equal(wh1 + wh2 - 2, winheight(2)) |
| 334 | |
| 335 | wincmd = |
| 336 | call assert_equal(wh1, winheight(1)) |
| 337 | call assert_equal(wh2, winheight(2)) |
| 338 | |
| 339 | 2wincmd _ |
| 340 | set winfixheight |
| 341 | split Xc |
| 342 | let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] |
| 343 | call assert_equal(2, winheight(2)) |
| 344 | call assert_inrange(wh3, wh3 + 1, wh1) |
| 345 | 3wincmd + |
| 346 | call assert_equal(2, winheight(2)) |
| 347 | call assert_equal(wh1 + 3, winheight(1)) |
| 348 | call assert_equal(wh3 - 3, winheight(3)) |
| 349 | wincmd = |
| 350 | call assert_equal(2, winheight(2)) |
| 351 | call assert_equal(wh1, winheight(1)) |
| 352 | call assert_equal(wh3, winheight(3)) |
| 353 | |
| 354 | wincmd j |
| 355 | set winfixheight& |
| 356 | |
| 357 | wincmd = |
| 358 | let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] |
| 359 | " Current window (2) should have the same height or 1 more |
| 360 | " than the other windows. |
| 361 | call assert_inrange(wh1, wh1 + 1, wh2) |
| 362 | call assert_inrange(wh3, wh3 + 1, wh2) |
| 363 | |
| 364 | bw Xa Xb Xc |
| 365 | endfunc |
| 366 | |
Bram Moolenaar | 21c3a80 | 2022-08-31 17:49:14 +0100 | [diff] [blame] | 367 | func Test_wincmd_equal() |
| 368 | edit Xone |
| 369 | below split Xtwo |
| 370 | rightbelow vsplit Xthree |
| 371 | call assert_equal('Xone', bufname(winbufnr(1))) |
| 372 | call assert_equal('Xtwo', bufname(winbufnr(2))) |
| 373 | call assert_equal('Xthree', bufname(winbufnr(3))) |
| 374 | |
| 375 | " Xone and Xtwo should be about the same height |
| 376 | let [wh1, wh2] = [winheight(1), winheight(2)] |
| 377 | call assert_inrange(wh1 - 1, wh1 + 1, wh2) |
| 378 | " Xtwo and Xthree should be about the same width |
| 379 | let [ww2, ww3] = [winwidth(2), winwidth(3)] |
| 380 | call assert_inrange(ww2 - 1, ww2 + 1, ww3) |
| 381 | |
| 382 | 1wincmd w |
| 383 | 10wincmd _ |
| 384 | 2wincmd w |
| 385 | 20wincmd | |
| 386 | call assert_equal(10, winheight(1)) |
| 387 | call assert_equal(20, winwidth(2)) |
| 388 | |
| 389 | " equalizing horizontally doesn't change the heights |
| 390 | hor wincmd = |
| 391 | call assert_equal(10, winheight(1)) |
| 392 | let [ww2, ww3] = [winwidth(2), winwidth(3)] |
| 393 | call assert_inrange(ww2 - 1, ww2 + 1, ww3) |
| 394 | |
| 395 | 2wincmd w |
| 396 | 20wincmd | |
| 397 | call assert_equal(20, winwidth(2)) |
| 398 | " equalizing vertically doesn't change the widths |
| 399 | vert wincmd = |
| 400 | call assert_equal(20, winwidth(2)) |
| 401 | let [wh1, wh2] = [winheight(1), winheight(2)] |
| 402 | call assert_inrange(wh1 - 1, wh1 + 1, wh2) |
| 403 | |
| 404 | bwipe Xone Xtwo Xthree |
| 405 | endfunc |
| 406 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 407 | func Test_window_width() |
| 408 | e Xa |
| 409 | vsplit Xb |
| 410 | |
| 411 | let [ww1, ww2] = [winwidth(1), winwidth(2)] |
| 412 | " Active window (1) should have the same width or 1 more |
| 413 | " than the other window. |
| 414 | call assert_inrange(ww2, ww2 + 1, ww1) |
| 415 | |
| 416 | wincmd < |
| 417 | call assert_equal(ww1 - 1, winwidth(1)) |
| 418 | call assert_equal(ww2 + 1, winwidth(2)) |
| 419 | |
| 420 | wincmd > |
| 421 | call assert_equal(ww1, winwidth(1)) |
| 422 | call assert_equal(ww2, winwidth(2)) |
| 423 | |
| 424 | 2wincmd | |
| 425 | call assert_equal(2, winwidth(1)) |
| 426 | call assert_equal(ww1 + ww2 - 2, winwidth(2)) |
| 427 | |
| 428 | wincmd = |
| 429 | call assert_equal(ww1, winwidth(1)) |
| 430 | call assert_equal(ww2, winwidth(2)) |
| 431 | |
| 432 | 2wincmd | |
| 433 | set winfixwidth |
| 434 | vsplit Xc |
| 435 | let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 436 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 437 | call assert_inrange(ww3, ww3 + 1, ww1) |
| 438 | 3wincmd > |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 439 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 440 | call assert_equal(ww1 + 3, winwidth(1)) |
| 441 | call assert_equal(ww3 - 3, winwidth(3)) |
| 442 | wincmd = |
Bram Moolenaar | 38e3483 | 2017-03-19 20:22:36 +0100 | [diff] [blame] | 443 | call assert_equal(2, winwidth(2)) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 444 | call assert_equal(ww1, winwidth(1)) |
| 445 | call assert_equal(ww3, winwidth(3)) |
| 446 | |
| 447 | wincmd l |
| 448 | set winfixwidth& |
| 449 | |
| 450 | wincmd = |
| 451 | let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] |
| 452 | " Current window (2) should have the same width or 1 more |
| 453 | " than the other windows. |
| 454 | call assert_inrange(ww1, ww1 + 1, ww2) |
| 455 | call assert_inrange(ww3, ww3 + 1, ww2) |
| 456 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 457 | " when the current window width is less than the new 'winwidth', the current |
| 458 | " window width should be increased. |
| 459 | enew | only |
| 460 | split |
| 461 | 10vnew |
| 462 | set winwidth=15 |
| 463 | call assert_equal(15, winwidth(0)) |
| 464 | |
| 465 | %bw! |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 466 | endfunc |
| 467 | |
Bram Moolenaar | 8eeeba8 | 2017-06-25 22:45:39 +0200 | [diff] [blame] | 468 | func Test_equalalways_on_close() |
| 469 | set equalalways |
| 470 | vsplit |
| 471 | windo split |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 472 | split |
Bram Moolenaar | 8eeeba8 | 2017-06-25 22:45:39 +0200 | [diff] [blame] | 473 | wincmd J |
| 474 | " now we have a frame top-left with two windows, a frame top-right with two |
| 475 | " windows and a frame at the bottom, full-width. |
| 476 | let height_1 = winheight(1) |
| 477 | let height_2 = winheight(2) |
| 478 | let height_3 = winheight(3) |
| 479 | let height_4 = winheight(4) |
| 480 | " closing the bottom window causes all windows to be resized. |
| 481 | close |
| 482 | call assert_notequal(height_1, winheight(1)) |
| 483 | call assert_notequal(height_2, winheight(2)) |
| 484 | call assert_notequal(height_3, winheight(3)) |
| 485 | call assert_notequal(height_4, winheight(4)) |
| 486 | call assert_equal(winheight(1), winheight(3)) |
| 487 | call assert_equal(winheight(2), winheight(4)) |
| 488 | |
| 489 | 1wincmd w |
| 490 | split |
| 491 | 4wincmd w |
| 492 | resize + 5 |
| 493 | " left column has three windows, equalized heights. |
| 494 | " right column has two windows, top one a bit higher |
| 495 | let height_1 = winheight(1) |
| 496 | let height_2 = winheight(2) |
| 497 | let height_4 = winheight(4) |
| 498 | let height_5 = winheight(5) |
| 499 | 3wincmd w |
| 500 | " closing window in left column equalizes heights in left column but not in |
| 501 | " the right column |
| 502 | close |
| 503 | call assert_notequal(height_1, winheight(1)) |
| 504 | call assert_notequal(height_2, winheight(2)) |
| 505 | call assert_equal(height_4, winheight(3)) |
| 506 | call assert_equal(height_5, winheight(4)) |
| 507 | |
| 508 | only |
| 509 | set equalalways& |
| 510 | endfunc |
| 511 | |
Bram Moolenaar | 22044dc | 2017-12-02 15:43:37 +0100 | [diff] [blame] | 512 | func Test_win_screenpos() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 513 | CheckFeature quickfix |
| 514 | |
Bram Moolenaar | 22044dc | 2017-12-02 15:43:37 +0100 | [diff] [blame] | 515 | call assert_equal(1, winnr('$')) |
| 516 | split |
| 517 | vsplit |
| 518 | 10wincmd _ |
| 519 | 30wincmd | |
| 520 | call assert_equal([1, 1], win_screenpos(1)) |
| 521 | call assert_equal([1, 32], win_screenpos(2)) |
| 522 | call assert_equal([12, 1], win_screenpos(3)) |
| 523 | call assert_equal([0, 0], win_screenpos(4)) |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 524 | call assert_fails('let l = win_screenpos([])', 'E745:') |
Bram Moolenaar | 22044dc | 2017-12-02 15:43:37 +0100 | [diff] [blame] | 525 | only |
| 526 | endfunc |
| 527 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 528 | func Test_window_jump_tag() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 529 | CheckFeature quickfix |
| 530 | |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 531 | help |
| 532 | /iccf |
| 533 | call assert_match('^|iccf|', getline('.')) |
| 534 | call assert_equal(2, winnr('$')) |
| 535 | 2wincmd } |
| 536 | call assert_equal(3, winnr('$')) |
| 537 | call assert_match('^|iccf|', getline('.')) |
| 538 | wincmd k |
| 539 | call assert_match('\*iccf\*', getline('.')) |
| 540 | call assert_equal(2, winheight(0)) |
| 541 | |
| 542 | wincmd z |
| 543 | set previewheight=4 |
| 544 | help |
| 545 | /bugs |
| 546 | wincmd } |
| 547 | wincmd k |
| 548 | call assert_match('\*bugs\*', getline('.')) |
| 549 | call assert_equal(4, winheight(0)) |
| 550 | set previewheight& |
| 551 | |
| 552 | %bw! |
| 553 | endfunc |
| 554 | |
| 555 | func Test_window_newtab() |
| 556 | e Xa |
| 557 | |
| 558 | call assert_equal(1, tabpagenr('$')) |
| 559 | call assert_equal("\nAlready only one window", execute('wincmd T')) |
| 560 | |
| 561 | split Xb |
| 562 | split Xc |
| 563 | |
| 564 | wincmd T |
| 565 | call assert_equal(2, tabpagenr('$')) |
| 566 | call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 567 | call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)')) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 568 | call assert_equal(['Xc' ], map(tabpagebuflist(), 'bufname(v:val)')) |
Bram Moolenaar | 4520d44 | 2017-03-19 16:09:46 +0100 | [diff] [blame] | 569 | |
| 570 | %bw! |
| 571 | endfunc |
| 572 | |
Bram Moolenaar | f79225e | 2017-03-18 23:11:04 +0100 | [diff] [blame] | 573 | func Test_next_split_all() |
| 574 | " This was causing an illegal memory access. |
| 575 | n x |
| 576 | norm axxx |
| 577 | split |
| 578 | split |
| 579 | s/x |
| 580 | s/x |
| 581 | all |
| 582 | bwipe! |
| 583 | endfunc |
| 584 | |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 585 | " Tests for adjusting window and contents |
| 586 | func GetScreenStr(row) |
| 587 | let str = "" |
| 588 | for c in range(1,3) |
| 589 | let str .= nr2char(screenchar(a:row, c)) |
| 590 | endfor |
| 591 | return str |
| 592 | endfunc |
| 593 | |
| 594 | func Test_window_contents() |
| 595 | enew! | only | new |
| 596 | call setline(1, range(1,256)) |
| 597 | |
| 598 | exe "norm! \<C-W>t\<C-W>=1Gzt\<C-W>w\<C-W>+" |
| 599 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 600 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 601 | wincmd p |
| 602 | call assert_equal(1, line("w0")) |
| 603 | call assert_equal('1 ', s3) |
| 604 | |
| 605 | exe "norm! \<C-W>t\<C-W>=50Gzt\<C-W>w\<C-W>+" |
| 606 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 607 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 608 | wincmd p |
| 609 | call assert_equal(50, line("w0")) |
| 610 | call assert_equal('50 ', s3) |
| 611 | |
| 612 | exe "norm! \<C-W>t\<C-W>=59Gzt\<C-W>w\<C-W>+" |
| 613 | redraw |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 614 | let s3 = GetScreenStr(1) |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 615 | wincmd p |
| 616 | call assert_equal(59, line("w0")) |
| 617 | call assert_equal('59 ', s3) |
| 618 | |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 619 | %d |
| 620 | call setline(1, ['one', 'two', 'three']) |
| 621 | call assert_equal(1, line('w0')) |
| 622 | call assert_equal(3, line('w$')) |
| 623 | |
Bram Moolenaar | 75373f3 | 2017-08-07 22:02:30 +0200 | [diff] [blame] | 624 | bwipeout! |
| 625 | call test_garbagecollect_now() |
| 626 | endfunc |
| 627 | |
Bram Moolenaar | 2efb323 | 2017-12-19 12:27:23 +0100 | [diff] [blame] | 628 | func Test_window_colon_command() |
| 629 | " This was reading invalid memory. |
| 630 | exe "norm! v\<C-W>:\<C-U>echo v:version" |
| 631 | endfunc |
| 632 | |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 633 | func Test_access_freed_mem() |
Bram Moolenaar | 1417c76 | 2019-07-27 17:31:36 +0200 | [diff] [blame] | 634 | call assert_equal(&columns, winwidth(0)) |
Bram Moolenaar | 9a046fd | 2021-01-28 13:47:59 +0100 | [diff] [blame] | 635 | " This was accessing freed memory (but with what events?) |
| 636 | au BufEnter,BufLeave,WinEnter,WinLeave 0 vs xxx |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 637 | arg 0 |
| 638 | argadd |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 639 | call assert_fails("all", "E242:") |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 640 | au! |
| 641 | bwipe xxx |
Bram Moolenaar | 1417c76 | 2019-07-27 17:31:36 +0200 | [diff] [blame] | 642 | call assert_equal(&columns, winwidth(0)) |
Bram Moolenaar | 6f361c9 | 2018-01-31 19:06:50 +0100 | [diff] [blame] | 643 | endfunc |
| 644 | |
Bram Moolenaar | a27e1dc | 2019-10-07 22:27:36 +0200 | [diff] [blame] | 645 | func Test_insert_cleared_on_switch_to_term() |
| 646 | CheckFeature terminal |
| 647 | |
| 648 | set showmode |
| 649 | terminal |
| 650 | wincmd p |
| 651 | |
| 652 | call feedkeys("i\<C-O>", 'ntx') |
| 653 | redraw |
| 654 | |
| 655 | " The "-- (insert) --" indicator should be visible. |
| 656 | let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))') |
| 657 | let str = trim(join(chars, '')) |
| 658 | call assert_equal('-- (insert) --', str) |
| 659 | |
| 660 | call feedkeys("\<C-W>p", 'ntx') |
| 661 | redraw |
| 662 | |
| 663 | " The "-- (insert) --" indicator should have been cleared. |
| 664 | let chars = map(range(1, &columns), 'nr2char(screenchar(&lines, v:val))') |
| 665 | let str = trim(join(chars, '')) |
| 666 | call assert_equal('', str) |
| 667 | |
| 668 | set showmode& |
| 669 | %bw! |
| 670 | endfunc |
| 671 | |
Bram Moolenaar | 5bab555 | 2018-04-13 20:41:29 +0200 | [diff] [blame] | 672 | func Test_visual_cleared_after_window_split() |
| 673 | new | only! |
| 674 | let smd_save = &showmode |
| 675 | set showmode |
| 676 | let ls_save = &laststatus |
| 677 | set laststatus=1 |
| 678 | call setline(1, ['a', 'b', 'c', 'd', '']) |
| 679 | norm! G |
| 680 | exe "norm! kkvk" |
| 681 | redraw |
| 682 | exe "norm! \<C-W>v" |
| 683 | redraw |
| 684 | " check if '-- VISUAL --' disappeared from command line |
| 685 | let columns = range(1, &columns) |
| 686 | let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))') |
| 687 | let cmdline = join(cmdlinechars, '') |
| 688 | let cmdline_ltrim = substitute(cmdline, '^\s*', "", "") |
| 689 | let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "") |
| 690 | call assert_equal('', mode_shown) |
| 691 | let &showmode = smd_save |
| 692 | let &laststatus = ls_save |
| 693 | bwipe! |
| 694 | endfunc |
| 695 | |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 696 | func Test_winrestcmd() |
| 697 | 2split |
| 698 | 3vsplit |
Bram Moolenaar | a0c8aea | 2021-03-20 19:55:35 +0100 | [diff] [blame] | 699 | let restcmd = winrestcmd() |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 700 | call assert_equal(2, winheight(0)) |
| 701 | call assert_equal(3, winwidth(0)) |
| 702 | wincmd = |
| 703 | call assert_notequal(2, winheight(0)) |
| 704 | call assert_notequal(3, winwidth(0)) |
Bram Moolenaar | a0c8aea | 2021-03-20 19:55:35 +0100 | [diff] [blame] | 705 | exe restcmd |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 706 | call assert_equal(2, winheight(0)) |
| 707 | call assert_equal(3, winwidth(0)) |
| 708 | only |
Bram Moolenaar | a0c8aea | 2021-03-20 19:55:35 +0100 | [diff] [blame] | 709 | |
| 710 | wincmd v |
| 711 | wincmd s |
| 712 | wincmd v |
| 713 | redraw |
| 714 | let restcmd = winrestcmd() |
| 715 | wincmd _ |
| 716 | wincmd | |
| 717 | exe restcmd |
| 718 | redraw |
| 719 | call assert_equal(restcmd, winrestcmd()) |
| 720 | |
| 721 | only |
Bram Moolenaar | 72cf47a | 2018-05-10 18:23:29 +0200 | [diff] [blame] | 722 | endfunc |
| 723 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 724 | func Fun_RenewFile() |
Bram Moolenaar | 026587b | 2019-08-17 15:08:00 +0200 | [diff] [blame] | 725 | " Need to wait a bit for the timestamp to be older. |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 726 | let old_ftime = getftime("tmp.txt") |
| 727 | while getftime("tmp.txt") == old_ftime |
| 728 | sleep 100m |
| 729 | silent execute '!echo "1" > tmp.txt' |
| 730 | endwhile |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 731 | sp |
| 732 | wincmd p |
| 733 | edit! tmp.txt |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 734 | endfunc |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 735 | |
| 736 | func Test_window_prevwin() |
| 737 | " Can we make this work on MS-Windows? |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 738 | CheckUnix |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 739 | |
| 740 | set hidden autoread |
Bram Moolenaar | db4c947 | 2022-10-15 22:06:06 +0100 | [diff] [blame^] | 741 | call writefile(['2'], 'tmp.txt', 'D') |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 742 | new tmp.txt |
| 743 | q |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 744 | call Fun_RenewFile() |
| 745 | call assert_equal(2, winnr()) |
| 746 | wincmd p |
| 747 | call assert_equal(1, winnr()) |
| 748 | wincmd p |
| 749 | q |
| 750 | call Fun_RenewFile() |
| 751 | call assert_equal(2, winnr()) |
| 752 | wincmd p |
| 753 | call assert_equal(1, winnr()) |
| 754 | wincmd p |
| 755 | " reset |
| 756 | q |
Bram Moolenaar | a42df59 | 2018-12-24 00:22:39 +0100 | [diff] [blame] | 757 | set hidden&vim autoread&vim |
| 758 | delfunc Fun_RenewFile |
| 759 | endfunc |
| 760 | |
Bram Moolenaar | 8fcb60f | 2019-03-04 13:18:30 +0100 | [diff] [blame] | 761 | func Test_relative_cursor_position_in_one_line_window() |
| 762 | new |
| 763 | only |
| 764 | call setline(1, range(1, 10000)) |
| 765 | normal 50% |
| 766 | let lnum = getcurpos()[1] |
| 767 | split |
| 768 | split |
| 769 | " make third window take as many lines as possible, other windows will |
| 770 | " become one line |
| 771 | 3wincmd w |
| 772 | for i in range(1, &lines - 6) |
| 773 | wincmd + |
| 774 | redraw! |
| 775 | endfor |
| 776 | |
| 777 | " first and second window should show cursor line |
| 778 | let wininfo = getwininfo() |
| 779 | call assert_equal(lnum, wininfo[0].topline) |
| 780 | call assert_equal(lnum, wininfo[1].topline) |
| 781 | |
| 782 | only! |
| 783 | bwipe! |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 784 | call assert_fails('call winrestview(test_null_dict())', 'E1297:') |
Bram Moolenaar | 8fcb60f | 2019-03-04 13:18:30 +0100 | [diff] [blame] | 785 | endfunc |
| 786 | |
| 787 | func Test_relative_cursor_position_after_move_and_resize() |
| 788 | let so_save = &so |
| 789 | set so=0 |
| 790 | enew |
| 791 | call setline(1, range(1, 10000)) |
| 792 | normal 50% |
| 793 | split |
| 794 | 1wincmd w |
| 795 | " Move cursor to first line in window |
| 796 | normal H |
| 797 | redraw! |
| 798 | " Reduce window height to two lines |
| 799 | let height = winheight(0) |
| 800 | while winheight(0) > 2 |
| 801 | wincmd - |
| 802 | redraw! |
| 803 | endwhile |
| 804 | " move cursor to second/last line in window |
| 805 | normal j |
| 806 | " restore previous height |
| 807 | while winheight(0) < height |
| 808 | wincmd + |
| 809 | redraw! |
| 810 | endwhile |
| 811 | " make window two lines again |
| 812 | while winheight(0) > 2 |
| 813 | wincmd - |
| 814 | redraw! |
| 815 | endwhile |
| 816 | |
| 817 | " cursor should be at bottom line |
| 818 | let info = getwininfo(win_getid())[0] |
| 819 | call assert_equal(info.topline + 1, getcurpos()[1]) |
| 820 | |
| 821 | only! |
| 822 | bwipe! |
| 823 | let &so = so_save |
| 824 | endfunc |
| 825 | |
| 826 | func Test_relative_cursor_position_after_resize() |
| 827 | let so_save = &so |
| 828 | set so=0 |
| 829 | enew |
| 830 | call setline(1, range(1, 10000)) |
| 831 | normal 50% |
| 832 | split |
| 833 | 1wincmd w |
| 834 | let winid1 = win_getid() |
| 835 | let info = getwininfo(winid1)[0] |
| 836 | " Move cursor to second line in window |
| 837 | exe "normal " . (info.topline + 1) . "G" |
| 838 | redraw! |
| 839 | let lnum = getcurpos()[1] |
| 840 | |
| 841 | " Make the window only two lines high, cursor should end up in top line |
| 842 | 2wincmd w |
| 843 | exe (info.height - 2) . "wincmd +" |
| 844 | redraw! |
| 845 | let info = getwininfo(winid1)[0] |
| 846 | call assert_equal(lnum, info.topline) |
| 847 | |
| 848 | only! |
| 849 | bwipe! |
| 850 | let &so = so_save |
| 851 | endfunc |
| 852 | |
| 853 | func Test_relative_cursor_second_line_after_resize() |
| 854 | let so_save = &so |
| 855 | set so=0 |
| 856 | enew |
| 857 | call setline(1, range(1, 10000)) |
| 858 | normal 50% |
| 859 | split |
| 860 | 1wincmd w |
| 861 | let winid1 = win_getid() |
| 862 | let info = getwininfo(winid1)[0] |
| 863 | |
| 864 | " Make the window only two lines high |
| 865 | 2wincmd _ |
| 866 | |
| 867 | " Move cursor to second line in window |
| 868 | normal H |
| 869 | normal j |
| 870 | |
| 871 | " Make window size bigger, then back to 2 lines |
| 872 | for i in range(1, 10) |
| 873 | wincmd + |
| 874 | redraw! |
| 875 | endfor |
| 876 | for i in range(1, 10) |
| 877 | wincmd - |
| 878 | redraw! |
| 879 | endfor |
| 880 | |
| 881 | " cursor should end up in bottom line |
| 882 | let info = getwininfo(winid1)[0] |
| 883 | call assert_equal(info.topline + 1, getcurpos()[1]) |
| 884 | |
| 885 | only! |
| 886 | bwipe! |
| 887 | let &so = so_save |
| 888 | endfunc |
| 889 | |
Bram Moolenaar | a9b2535 | 2019-05-12 14:25:30 +0200 | [diff] [blame] | 890 | func Test_split_noscroll() |
| 891 | let so_save = &so |
Bram Moolenaar | bd2d68c | 2019-05-18 15:36:11 +0200 | [diff] [blame] | 892 | enew |
| 893 | call setline(1, range(1, 8)) |
Bram Moolenaar | a9b2535 | 2019-05-12 14:25:30 +0200 | [diff] [blame] | 894 | normal 100% |
| 895 | split |
| 896 | |
| 897 | 1wincmd w |
| 898 | let winid1 = win_getid() |
| 899 | let info1 = getwininfo(winid1)[0] |
| 900 | |
| 901 | 2wincmd w |
| 902 | let winid2 = win_getid() |
| 903 | let info2 = getwininfo(winid2)[0] |
| 904 | |
| 905 | call assert_equal(1, info1.topline) |
| 906 | call assert_equal(1, info2.topline) |
| 907 | |
Bram Moolenaar | bd2d68c | 2019-05-18 15:36:11 +0200 | [diff] [blame] | 908 | " window that fits all lines by itself, but not when split: closing other |
| 909 | " window should restore fraction. |
Bram Moolenaar | a9b2535 | 2019-05-12 14:25:30 +0200 | [diff] [blame] | 910 | only! |
Bram Moolenaar | bd2d68c | 2019-05-18 15:36:11 +0200 | [diff] [blame] | 911 | call setline(1, range(1, &lines - 10)) |
| 912 | exe &lines / 4 |
| 913 | let winid1 = win_getid() |
| 914 | let info1 = getwininfo(winid1)[0] |
| 915 | call assert_equal(1, info1.topline) |
| 916 | new |
| 917 | redraw |
| 918 | close |
| 919 | let info1 = getwininfo(winid1)[0] |
| 920 | call assert_equal(1, info1.topline) |
| 921 | |
Bram Moolenaar | a9b2535 | 2019-05-12 14:25:30 +0200 | [diff] [blame] | 922 | bwipe! |
| 923 | let &so = so_save |
| 924 | endfunc |
| 925 | |
Bram Moolenaar | 46ad288 | 2019-04-08 20:01:47 +0200 | [diff] [blame] | 926 | " Tests for the winnr() function |
| 927 | func Test_winnr() |
| 928 | only | tabonly |
| 929 | call assert_equal(1, winnr('j')) |
| 930 | call assert_equal(1, winnr('k')) |
| 931 | call assert_equal(1, winnr('h')) |
| 932 | call assert_equal(1, winnr('l')) |
| 933 | |
| 934 | " create a set of horizontally and vertically split windows |
| 935 | leftabove new | wincmd p |
| 936 | leftabove new | wincmd p |
| 937 | rightbelow new | wincmd p |
| 938 | rightbelow new | wincmd p |
| 939 | leftabove vnew | wincmd p |
| 940 | leftabove vnew | wincmd p |
| 941 | rightbelow vnew | wincmd p |
| 942 | rightbelow vnew | wincmd p |
| 943 | |
| 944 | call assert_equal(8, winnr('j')) |
| 945 | call assert_equal(2, winnr('k')) |
| 946 | call assert_equal(4, winnr('h')) |
| 947 | call assert_equal(6, winnr('l')) |
| 948 | call assert_equal(9, winnr('2j')) |
| 949 | call assert_equal(1, winnr('2k')) |
| 950 | call assert_equal(3, winnr('2h')) |
| 951 | call assert_equal(7, winnr('2l')) |
| 952 | |
| 953 | " Error cases |
| 954 | call assert_fails("echo winnr('0.2k')", 'E15:') |
| 955 | call assert_equal(2, winnr('-2k')) |
| 956 | call assert_fails("echo winnr('-2xj')", 'E15:') |
| 957 | call assert_fails("echo winnr('j2j')", 'E15:') |
| 958 | call assert_fails("echo winnr('ll')", 'E15:') |
| 959 | call assert_fails("echo winnr('5')", 'E15:') |
| 960 | call assert_equal(4, winnr('0h')) |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 961 | call assert_fails("let w = winnr([])", 'E730:') |
| 962 | call assert_equal('unknown', win_gettype(-1)) |
| 963 | call assert_equal(-1, winheight(-1)) |
| 964 | call assert_equal(-1, winwidth(-1)) |
Bram Moolenaar | 46ad288 | 2019-04-08 20:01:47 +0200 | [diff] [blame] | 965 | |
| 966 | tabnew |
| 967 | call assert_equal(8, tabpagewinnr(1, 'j')) |
Bram Moolenaar | ce90e36 | 2019-09-08 18:58:44 +0200 | [diff] [blame] | 968 | call assert_equal(2, 1->tabpagewinnr('k')) |
Bram Moolenaar | 46ad288 | 2019-04-08 20:01:47 +0200 | [diff] [blame] | 969 | call assert_equal(4, tabpagewinnr(1, 'h')) |
| 970 | call assert_equal(6, tabpagewinnr(1, 'l')) |
| 971 | |
| 972 | only | tabonly |
| 973 | endfunc |
| 974 | |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 975 | func Test_winrestview() |
| 976 | split runtest.vim |
| 977 | normal 50% |
| 978 | let view = winsaveview() |
| 979 | close |
| 980 | split runtest.vim |
| 981 | eval view->winrestview() |
| 982 | call assert_equal(view, winsaveview()) |
| 983 | |
| 984 | bwipe! |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 985 | call assert_fails('call winrestview(test_null_dict())', 'E1297:') |
Bram Moolenaar | f92e58c | 2019-09-08 21:51:41 +0200 | [diff] [blame] | 986 | endfunc |
| 987 | |
Bram Moolenaar | d20dcb3 | 2019-09-10 21:22:58 +0200 | [diff] [blame] | 988 | func Test_win_splitmove() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 989 | CheckFeature quickfix |
| 990 | |
Bram Moolenaar | d20dcb3 | 2019-09-10 21:22:58 +0200 | [diff] [blame] | 991 | edit a |
| 992 | leftabove split b |
| 993 | leftabove vsplit c |
| 994 | leftabove split d |
| 995 | call assert_equal(0, win_splitmove(winnr(), winnr('l'))) |
| 996 | call assert_equal(bufname(winbufnr(1)), 'c') |
| 997 | call assert_equal(bufname(winbufnr(2)), 'd') |
| 998 | call assert_equal(bufname(winbufnr(3)), 'b') |
| 999 | call assert_equal(bufname(winbufnr(4)), 'a') |
| 1000 | call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1})) |
| 1001 | call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'vertical': 1})) |
| 1002 | call assert_equal(bufname(winbufnr(1)), 'c') |
| 1003 | call assert_equal(bufname(winbufnr(2)), 'b') |
| 1004 | call assert_equal(bufname(winbufnr(3)), 'd') |
| 1005 | call assert_equal(bufname(winbufnr(4)), 'a') |
| 1006 | call assert_equal(0, win_splitmove(winnr(), winnr('k'), {'vertical': 1})) |
| 1007 | call assert_equal(bufname(winbufnr(1)), 'd') |
| 1008 | call assert_equal(bufname(winbufnr(2)), 'c') |
| 1009 | call assert_equal(bufname(winbufnr(3)), 'b') |
| 1010 | call assert_equal(bufname(winbufnr(4)), 'a') |
| 1011 | call assert_equal(0, win_splitmove(winnr(), winnr('j'), {'rightbelow': v:true})) |
| 1012 | call assert_equal(bufname(winbufnr(1)), 'c') |
| 1013 | call assert_equal(bufname(winbufnr(2)), 'b') |
| 1014 | call assert_equal(bufname(winbufnr(3)), 'a') |
| 1015 | call assert_equal(bufname(winbufnr(4)), 'd') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1016 | call assert_fails('call win_splitmove(winnr(), winnr("k"), test_null_dict())', 'E1297:') |
Bram Moolenaar | d20dcb3 | 2019-09-10 21:22:58 +0200 | [diff] [blame] | 1017 | only | bd |
| 1018 | |
| 1019 | call assert_fails('call win_splitmove(winnr(), 123)', 'E957:') |
| 1020 | call assert_fails('call win_splitmove(123, winnr())', 'E957:') |
| 1021 | call assert_fails('call win_splitmove(winnr(), winnr())', 'E957:') |
Bram Moolenaar | 7b94e77 | 2020-01-06 21:03:24 +0100 | [diff] [blame] | 1022 | |
| 1023 | tabnew |
| 1024 | call assert_fails('call win_splitmove(1, win_getid(1, 1))', 'E957:') |
| 1025 | tabclose |
Bram Moolenaar | d20dcb3 | 2019-09-10 21:22:58 +0200 | [diff] [blame] | 1026 | endfunc |
| 1027 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 1028 | " Test for the :only command |
| 1029 | func Test_window_only() |
| 1030 | new |
| 1031 | set modified |
| 1032 | new |
| 1033 | call assert_fails('only', 'E445:') |
| 1034 | only! |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 1035 | " Test for :only with a count |
| 1036 | let wid = win_getid() |
| 1037 | new |
| 1038 | new |
| 1039 | 3only |
| 1040 | call assert_equal(1, winnr('$')) |
| 1041 | call assert_equal(wid, win_getid()) |
| 1042 | call assert_fails('close', 'E444:') |
| 1043 | call assert_fails('%close', 'E16:') |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 1044 | endfunc |
| 1045 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1046 | " Test for errors with :wincmd |
| 1047 | func Test_wincmd_errors() |
| 1048 | call assert_fails('wincmd g', 'E474:') |
| 1049 | call assert_fails('wincmd ab', 'E474:') |
| 1050 | endfunc |
| 1051 | |
| 1052 | " Test for errors with :winpos |
| 1053 | func Test_winpos_errors() |
| 1054 | if !has("gui_running") && !has('win32') |
| 1055 | call assert_fails('winpos', 'E188:') |
| 1056 | endif |
| 1057 | call assert_fails('winpos 10', 'E466:') |
| 1058 | endfunc |
| 1059 | |
Bram Moolenaar | 406cd90 | 2020-02-18 21:54:41 +0100 | [diff] [blame] | 1060 | " Test for +cmd in a :split command |
| 1061 | func Test_split_cmd() |
| 1062 | split +set\ readonly |
| 1063 | call assert_equal(1, &readonly) |
| 1064 | call assert_equal(2, winnr('$')) |
| 1065 | close |
| 1066 | endfunc |
| 1067 | |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1068 | " Create maximum number of horizontally or vertically split windows and then |
| 1069 | " run commands that create a new horizontally/vertically split window |
| 1070 | func Run_noroom_for_newwindow_test(dir_arg) |
| 1071 | let dir = (a:dir_arg == 'v') ? 'vert ' : '' |
| 1072 | |
| 1073 | " Open as many windows as possible |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 1074 | while v:true |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1075 | try |
| 1076 | exe dir . 'new' |
| 1077 | catch /E36:/ |
| 1078 | break |
| 1079 | endtry |
Bram Moolenaar | ab505b1 | 2020-03-23 19:28:44 +0100 | [diff] [blame] | 1080 | endwhile |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1081 | |
Bram Moolenaar | db4c947 | 2022-10-15 22:06:06 +0100 | [diff] [blame^] | 1082 | call writefile(['first', 'second', 'third'], 'Xnorfile1', 'D') |
| 1083 | call writefile([], 'Xnorfile2', 'D') |
| 1084 | call writefile([], 'Xnorfile3', 'D') |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1085 | |
| 1086 | " Argument list related commands |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1087 | args Xnorfile1 Xnorfile2 Xnorfile3 |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1088 | next |
| 1089 | for cmd in ['sargument 2', 'snext', 'sprevious', 'sNext', 'srewind', |
| 1090 | \ 'sfirst', 'slast'] |
| 1091 | call assert_fails(dir .. cmd, 'E36:') |
| 1092 | endfor |
| 1093 | %argdelete |
| 1094 | |
| 1095 | " Buffer related commands |
| 1096 | set modified |
| 1097 | hide enew |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1098 | for cmd in ['sbuffer Xnorfile1', 'sbnext', 'sbprevious', 'sbNext', 'sbrewind', |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1099 | \ 'sbfirst', 'sblast', 'sball', 'sbmodified', 'sunhide'] |
| 1100 | call assert_fails(dir .. cmd, 'E36:') |
| 1101 | endfor |
| 1102 | |
| 1103 | " Window related commands |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1104 | for cmd in ['split', 'split Xnorfile2', 'new', 'new Xnorfile3', 'sview Xnorfile1', |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1105 | \ 'sfind runtest.vim'] |
| 1106 | call assert_fails(dir .. cmd, 'E36:') |
| 1107 | endfor |
| 1108 | |
| 1109 | " Help |
| 1110 | call assert_fails(dir .. 'help', 'E36:') |
| 1111 | call assert_fails(dir .. 'helpgrep window', 'E36:') |
| 1112 | |
| 1113 | " Command-line window |
| 1114 | if a:dir_arg == 'h' |
| 1115 | " Cmd-line window is always a horizontally split window |
| 1116 | call assert_beeps('call feedkeys("q:\<CR>", "xt")') |
| 1117 | endif |
| 1118 | |
| 1119 | " Quickfix and location list window |
| 1120 | if has('quickfix') |
| 1121 | cexpr '' |
| 1122 | call assert_fails(dir .. 'copen', 'E36:') |
| 1123 | lexpr '' |
| 1124 | call assert_fails(dir .. 'lopen', 'E36:') |
| 1125 | |
| 1126 | " Preview window |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1127 | call assert_fails(dir .. 'pedit Xnorfile2', 'E36:') |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1128 | call setline(1, 'abc') |
| 1129 | call assert_fails(dir .. 'psearch abc', 'E36:') |
| 1130 | endif |
| 1131 | |
| 1132 | " Window commands (CTRL-W ^ and CTRL-W f) |
| 1133 | if a:dir_arg == 'h' |
| 1134 | call assert_fails('call feedkeys("\<C-W>^", "xt")', 'E36:') |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1135 | call setline(1, 'Xnorfile1') |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1136 | call assert_fails('call feedkeys("gg\<C-W>f", "xt")', 'E36:') |
| 1137 | endif |
| 1138 | enew! |
| 1139 | |
| 1140 | " Tag commands (:stag, :stselect and :stjump) |
| 1141 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1142 | \ "second\tXnorfile1\t2", |
| 1143 | \ "third\tXnorfile1\t3",], |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1144 | \ 'Xtags') |
| 1145 | set tags=Xtags |
| 1146 | call assert_fails(dir .. 'stag second', 'E36:') |
| 1147 | call assert_fails('call feedkeys(":" .. dir .. "stselect second\n1\n", "xt")', 'E36:') |
| 1148 | call assert_fails(dir .. 'stjump second', 'E36:') |
| 1149 | call assert_fails(dir .. 'ptag second', 'E36:') |
| 1150 | set tags& |
| 1151 | call delete('Xtags') |
| 1152 | |
| 1153 | " :isplit and :dsplit |
| 1154 | call setline(1, ['#define FOO 1', 'FOO']) |
| 1155 | normal 2G |
| 1156 | call assert_fails(dir .. 'isplit FOO', 'E36:') |
| 1157 | call assert_fails(dir .. 'dsplit FOO', 'E36:') |
| 1158 | |
| 1159 | " terminal |
| 1160 | if has('terminal') |
| 1161 | call assert_fails(dir .. 'terminal', 'E36:') |
| 1162 | endif |
| 1163 | |
| 1164 | %bwipe! |
Bram Moolenaar | 5080b0a | 2020-03-22 21:23:47 +0100 | [diff] [blame] | 1165 | only |
| 1166 | endfunc |
| 1167 | |
| 1168 | func Test_split_cmds_with_no_room() |
| 1169 | call Run_noroom_for_newwindow_test('h') |
| 1170 | call Run_noroom_for_newwindow_test('v') |
| 1171 | endfunc |
| 1172 | |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 1173 | " Test for various wincmd failures |
| 1174 | func Test_wincmd_fails() |
| 1175 | only! |
| 1176 | call assert_beeps("normal \<C-W>w") |
| 1177 | call assert_beeps("normal \<C-W>p") |
| 1178 | call assert_beeps("normal \<C-W>gk") |
| 1179 | call assert_beeps("normal \<C-W>r") |
| 1180 | call assert_beeps("normal \<C-W>K") |
| 1181 | call assert_beeps("normal \<C-W>H") |
| 1182 | call assert_beeps("normal \<C-W>2gt") |
| 1183 | endfunc |
| 1184 | |
Bram Moolenaar | fe6dce8 | 2020-09-04 14:41:21 +0200 | [diff] [blame] | 1185 | func Test_window_resize() |
| 1186 | " Vertical :resize (absolute, relative, min and max size). |
| 1187 | vsplit |
| 1188 | vert resize 8 |
| 1189 | call assert_equal(8, winwidth(0)) |
| 1190 | vert resize +2 |
| 1191 | call assert_equal(10, winwidth(0)) |
| 1192 | vert resize -2 |
| 1193 | call assert_equal(8, winwidth(0)) |
| 1194 | vert resize |
| 1195 | call assert_equal(&columns - 2, winwidth(0)) |
| 1196 | vert resize 0 |
| 1197 | call assert_equal(1, winwidth(0)) |
| 1198 | vert resize 99999 |
| 1199 | call assert_equal(&columns - 2, winwidth(0)) |
| 1200 | |
| 1201 | %bwipe! |
| 1202 | |
| 1203 | " Horizontal :resize (with absolute, relative size, min and max size). |
| 1204 | split |
| 1205 | resize 8 |
| 1206 | call assert_equal(8, winheight(0)) |
| 1207 | resize +2 |
| 1208 | call assert_equal(10, winheight(0)) |
| 1209 | resize -2 |
| 1210 | call assert_equal(8, winheight(0)) |
| 1211 | resize |
| 1212 | call assert_equal(&lines - 4, winheight(0)) |
| 1213 | resize 0 |
| 1214 | call assert_equal(1, winheight(0)) |
| 1215 | resize 99999 |
| 1216 | call assert_equal(&lines - 4, winheight(0)) |
| 1217 | |
| 1218 | " :resize with explicit window number. |
| 1219 | let other_winnr = winnr('j') |
| 1220 | exe other_winnr .. 'resize 10' |
| 1221 | call assert_equal(10, winheight(other_winnr)) |
| 1222 | call assert_equal(&lines - 10 - 3, winheight(0)) |
Bram Moolenaar | 9668cc5 | 2020-10-17 17:39:55 +0200 | [diff] [blame] | 1223 | exe other_winnr .. 'resize +1' |
| 1224 | exe other_winnr .. 'resize +1' |
| 1225 | call assert_equal(12, winheight(other_winnr)) |
| 1226 | call assert_equal(&lines - 10 - 3 -2, winheight(0)) |
Bram Moolenaar | 89015a6 | 2020-12-29 12:46:51 +0100 | [diff] [blame] | 1227 | close |
| 1228 | |
| 1229 | vsplit |
| 1230 | wincmd l |
| 1231 | let other_winnr = winnr('h') |
| 1232 | call assert_notequal(winnr(), other_winnr) |
Bram Moolenaar | 5efe0e5 | 2021-01-01 14:31:34 +0100 | [diff] [blame] | 1233 | exe 'vert ' .. other_winnr .. 'resize -' .. &columns |
Bram Moolenaar | 89015a6 | 2020-12-29 12:46:51 +0100 | [diff] [blame] | 1234 | call assert_equal(0, winwidth(other_winnr)) |
Bram Moolenaar | fe6dce8 | 2020-09-04 14:41:21 +0200 | [diff] [blame] | 1235 | |
| 1236 | %bwipe! |
| 1237 | endfunc |
| 1238 | |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 1239 | " Test for adjusting the window width when a window is closed with some |
| 1240 | " windows using 'winfixwidth' |
| 1241 | func Test_window_width_adjust() |
| 1242 | only |
| 1243 | " Three vertical windows. Windows 1 and 2 have 'winfixwidth' set and close |
| 1244 | " window 2. |
| 1245 | wincmd v |
| 1246 | vert resize 10 |
| 1247 | set winfixwidth |
| 1248 | wincmd v |
| 1249 | set winfixwidth |
| 1250 | wincmd c |
| 1251 | call assert_inrange(10, 12, winwidth(1)) |
| 1252 | " Three vertical windows. Windows 2 and 3 have 'winfixwidth' set and close |
| 1253 | " window 3. |
| 1254 | only |
| 1255 | set winfixwidth |
| 1256 | wincmd v |
| 1257 | vert resize 10 |
| 1258 | set winfixwidth |
| 1259 | wincmd v |
| 1260 | set nowinfixwidth |
| 1261 | wincmd b |
| 1262 | wincmd c |
| 1263 | call assert_inrange(10, 12, winwidth(2)) |
| 1264 | |
| 1265 | new | only |
| 1266 | endfunc |
| 1267 | |
| 1268 | " Test for jumping to a vertical/horizontal neighbor window based on the |
| 1269 | " current cursor position |
| 1270 | func Test_window_goto_neightbor() |
| 1271 | %bw! |
| 1272 | |
| 1273 | " Vertical window movement |
| 1274 | |
| 1275 | " create the following window layout: |
| 1276 | " +--+--+ |
| 1277 | " |w1|w3| |
| 1278 | " +--+ | |
| 1279 | " |w2| | |
| 1280 | " +--+--+ |
| 1281 | " |w4 | |
| 1282 | " +-----+ |
| 1283 | new |
| 1284 | vsplit |
| 1285 | split |
| 1286 | " vertically jump from w4 |
| 1287 | wincmd b |
| 1288 | call setline(1, repeat(' ', &columns)) |
| 1289 | call cursor(1, 1) |
| 1290 | wincmd k |
| 1291 | call assert_equal(2, winnr()) |
| 1292 | wincmd b |
| 1293 | call cursor(1, &columns) |
| 1294 | redraw! |
| 1295 | wincmd k |
| 1296 | call assert_equal(3, winnr()) |
| 1297 | %bw! |
| 1298 | |
| 1299 | " create the following window layout: |
| 1300 | " +--+--+--+ |
| 1301 | " |w1|w2|w3| |
| 1302 | " +--+--+--+ |
| 1303 | " |w4 | |
| 1304 | " +--------+ |
| 1305 | new |
| 1306 | vsplit |
| 1307 | vsplit |
| 1308 | wincmd b |
| 1309 | call setline(1, repeat(' ', &columns)) |
| 1310 | call cursor(1, 1) |
| 1311 | wincmd k |
| 1312 | call assert_equal(1, winnr()) |
| 1313 | wincmd b |
| 1314 | call cursor(1, &columns / 2) |
| 1315 | redraw! |
| 1316 | wincmd k |
| 1317 | call assert_equal(2, winnr()) |
| 1318 | wincmd b |
| 1319 | call cursor(1, &columns) |
| 1320 | redraw! |
| 1321 | wincmd k |
| 1322 | call assert_equal(3, winnr()) |
| 1323 | %bw! |
| 1324 | |
| 1325 | " Horizontal window movement |
| 1326 | |
| 1327 | " create the following window layout: |
| 1328 | " +--+--+--+ |
| 1329 | " |w1|w2|w4| |
| 1330 | " +--+--+ | |
| 1331 | " |w3 | | |
| 1332 | " +-----+--+ |
| 1333 | vsplit |
| 1334 | split |
| 1335 | vsplit |
| 1336 | 4wincmd l |
| 1337 | call setline(1, repeat([' '], &lines)) |
| 1338 | call cursor(1, 1) |
| 1339 | redraw! |
| 1340 | wincmd h |
| 1341 | call assert_equal(2, winnr()) |
| 1342 | 4wincmd l |
| 1343 | call cursor(&lines, 1) |
| 1344 | redraw! |
| 1345 | wincmd h |
| 1346 | call assert_equal(3, winnr()) |
| 1347 | %bw! |
| 1348 | |
| 1349 | " create the following window layout: |
| 1350 | " +--+--+ |
| 1351 | " |w1|w4| |
| 1352 | " +--+ + |
| 1353 | " |w2| | |
| 1354 | " +--+ + |
| 1355 | " |w3| | |
| 1356 | " +--+--+ |
| 1357 | vsplit |
| 1358 | split |
| 1359 | split |
| 1360 | wincmd l |
| 1361 | call setline(1, repeat([' '], &lines)) |
| 1362 | call cursor(1, 1) |
| 1363 | redraw! |
| 1364 | wincmd h |
| 1365 | call assert_equal(1, winnr()) |
| 1366 | wincmd l |
| 1367 | call cursor(&lines / 2, 1) |
| 1368 | redraw! |
| 1369 | wincmd h |
| 1370 | call assert_equal(2, winnr()) |
| 1371 | wincmd l |
| 1372 | call cursor(&lines, 1) |
| 1373 | redraw! |
| 1374 | wincmd h |
| 1375 | call assert_equal(3, winnr()) |
| 1376 | %bw! |
| 1377 | endfunc |
| 1378 | |
| 1379 | " Test for an autocmd closing the destination window when jumping from one |
| 1380 | " window to another. |
| 1381 | func Test_close_dest_window() |
| 1382 | split |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1383 | edit Xdstfile |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 1384 | |
| 1385 | " Test for BufLeave |
| 1386 | augroup T1 |
| 1387 | au! |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1388 | au BufLeave Xdstfile $wincmd c |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 1389 | augroup END |
| 1390 | wincmd b |
| 1391 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1392 | call assert_equal('Xdstfile', @%) |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 1393 | augroup T1 |
| 1394 | au! |
| 1395 | augroup END |
| 1396 | |
| 1397 | " Test for WinLeave |
| 1398 | new |
| 1399 | wincmd p |
| 1400 | augroup T1 |
| 1401 | au! |
| 1402 | au WinLeave * 1wincmd c |
| 1403 | augroup END |
| 1404 | wincmd t |
| 1405 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1406 | call assert_equal('Xdstfile', @%) |
Bram Moolenaar | 5d3c9f8 | 2020-06-26 20:41:39 +0200 | [diff] [blame] | 1407 | augroup T1 |
| 1408 | au! |
| 1409 | augroup END |
| 1410 | augroup! T1 |
| 1411 | %bw! |
| 1412 | endfunc |
| 1413 | |
Bram Moolenaar | d0fb907 | 2021-12-09 11:57:22 +0000 | [diff] [blame] | 1414 | func Test_window_minimal_size() |
| 1415 | set winminwidth=0 winminheight=0 |
| 1416 | |
| 1417 | " check size is fixed vertically |
| 1418 | new |
| 1419 | call win_execute(win_getid(2), 'wincmd _') |
| 1420 | call assert_equal(0, winheight(0)) |
| 1421 | call feedkeys('0', 'tx') |
| 1422 | call assert_equal(1, winheight(0)) |
| 1423 | bwipe! |
| 1424 | |
| 1425 | " check size is fixed horizontally |
| 1426 | vert new |
| 1427 | call win_execute(win_getid(2), 'wincmd |') |
| 1428 | call assert_equal(0, winwidth(0)) |
| 1429 | call feedkeys('0', 'tx') |
| 1430 | call assert_equal(1, winwidth(0)) |
| 1431 | bwipe! |
| 1432 | |
| 1433 | if has('timers') |
| 1434 | " check size is fixed in Insert mode |
ichizok | fa9a8e0 | 2021-12-12 16:42:09 +0000 | [diff] [blame] | 1435 | func s:CheckSize(timer) abort |
| 1436 | call win_execute(win_getid(2), 'wincmd _') |
| 1437 | call assert_equal(0, winheight(0)) |
| 1438 | call feedkeys(" \<Esc>", 't!') |
| 1439 | endfunc |
Bram Moolenaar | d0fb907 | 2021-12-09 11:57:22 +0000 | [diff] [blame] | 1440 | new |
ichizok | fa9a8e0 | 2021-12-12 16:42:09 +0000 | [diff] [blame] | 1441 | call timer_start(100, function('s:CheckSize')) |
Bram Moolenaar | d0fb907 | 2021-12-09 11:57:22 +0000 | [diff] [blame] | 1442 | call feedkeys('a', 'tx!') |
| 1443 | call assert_equal(1, winheight(0)) |
| 1444 | bwipe! |
ichizok | fa9a8e0 | 2021-12-12 16:42:09 +0000 | [diff] [blame] | 1445 | delfunc s:CheckSize |
Bram Moolenaar | d0fb907 | 2021-12-09 11:57:22 +0000 | [diff] [blame] | 1446 | endif |
| 1447 | |
| 1448 | set winminwidth& winminheight& |
| 1449 | endfunc |
| 1450 | |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 1451 | func Test_win_move_separator() |
| 1452 | edit a |
| 1453 | leftabove vsplit b |
| 1454 | let w = winwidth(0) |
| 1455 | " check win_move_separator from left window on left window |
| 1456 | call assert_equal(1, winnr()) |
| 1457 | for offset in range(5) |
| 1458 | call assert_true(win_move_separator(0, offset)) |
| 1459 | call assert_equal(w + offset, winwidth(0)) |
| 1460 | call assert_true(0->win_move_separator(-offset)) |
| 1461 | call assert_equal(w, winwidth(0)) |
| 1462 | endfor |
| 1463 | " check win_move_separator from right window on left window number |
| 1464 | wincmd l |
| 1465 | call assert_notequal(1, winnr()) |
| 1466 | for offset in range(5) |
| 1467 | call assert_true(1->win_move_separator(offset)) |
| 1468 | call assert_equal(w + offset, winwidth(1)) |
| 1469 | call assert_true(win_move_separator(1, -offset)) |
| 1470 | call assert_equal(w, winwidth(1)) |
| 1471 | endfor |
| 1472 | " check win_move_separator from right window on left window ID |
| 1473 | let id = win_getid(1) |
| 1474 | for offset in range(5) |
| 1475 | call assert_true(win_move_separator(id, offset)) |
| 1476 | call assert_equal(w + offset, winwidth(id)) |
| 1477 | call assert_true(id->win_move_separator(-offset)) |
| 1478 | call assert_equal(w, winwidth(id)) |
| 1479 | endfor |
zeertzjq | a0c4e2f | 2022-01-29 10:59:53 +0000 | [diff] [blame] | 1480 | " check win_move_separator from right window on right window is no-op |
| 1481 | let w0 = winwidth(0) |
| 1482 | call assert_true(win_move_separator(0, 1)) |
| 1483 | call assert_equal(w0, winwidth(0)) |
| 1484 | call assert_true(win_move_separator(0, -1)) |
| 1485 | call assert_equal(w0, winwidth(0)) |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 1486 | " check that win_move_separator doesn't error with offsets beyond moving |
| 1487 | " possibility |
| 1488 | call assert_true(win_move_separator(id, 5000)) |
| 1489 | call assert_true(winwidth(id) > w) |
| 1490 | call assert_true(win_move_separator(id, -5000)) |
| 1491 | call assert_true(winwidth(id) < w) |
| 1492 | " check that win_move_separator returns false for an invalid window |
| 1493 | wincmd = |
| 1494 | let w = winwidth(0) |
| 1495 | call assert_false(win_move_separator(-1, 1)) |
| 1496 | call assert_equal(w, winwidth(0)) |
| 1497 | " check that win_move_separator returns false for a popup window |
| 1498 | let id = popup_create(['hello', 'world'], {}) |
| 1499 | let w = winwidth(id) |
| 1500 | call assert_false(win_move_separator(id, 1)) |
| 1501 | call assert_equal(w, winwidth(id)) |
| 1502 | call popup_close(id) |
| 1503 | %bwipe! |
| 1504 | endfunc |
| 1505 | |
| 1506 | func Test_win_move_statusline() |
| 1507 | edit a |
| 1508 | leftabove split b |
| 1509 | let h = winheight(0) |
| 1510 | " check win_move_statusline from top window on top window |
| 1511 | call assert_equal(1, winnr()) |
| 1512 | for offset in range(5) |
| 1513 | call assert_true(win_move_statusline(0, offset)) |
| 1514 | call assert_equal(h + offset, winheight(0)) |
| 1515 | call assert_true(0->win_move_statusline(-offset)) |
| 1516 | call assert_equal(h, winheight(0)) |
| 1517 | endfor |
| 1518 | " check win_move_statusline from bottom window on top window number |
| 1519 | wincmd j |
| 1520 | call assert_notequal(1, winnr()) |
| 1521 | for offset in range(5) |
| 1522 | call assert_true(1->win_move_statusline(offset)) |
| 1523 | call assert_equal(h + offset, winheight(1)) |
| 1524 | call assert_true(win_move_statusline(1, -offset)) |
| 1525 | call assert_equal(h, winheight(1)) |
| 1526 | endfor |
zeertzjq | a0c4e2f | 2022-01-29 10:59:53 +0000 | [diff] [blame] | 1527 | " check win_move_statusline from bottom window on bottom window |
| 1528 | let h0 = winheight(0) |
| 1529 | for offset in range(5) |
| 1530 | call assert_true(0->win_move_statusline(-offset)) |
| 1531 | call assert_equal(h0 - offset, winheight(0)) |
| 1532 | call assert_equal(1 + offset, &cmdheight) |
| 1533 | call assert_true(win_move_statusline(0, offset)) |
| 1534 | call assert_equal(h0, winheight(0)) |
| 1535 | call assert_equal(1, &cmdheight) |
| 1536 | endfor |
| 1537 | call assert_true(win_move_statusline(0, 1)) |
Bram Moolenaar | a2a8973 | 2022-08-31 14:46:18 +0100 | [diff] [blame] | 1538 | call assert_equal(h0, winheight(0)) |
| 1539 | call assert_equal(1, &cmdheight) |
Daniel Steinberg | ee63031 | 2022-01-10 13:36:34 +0000 | [diff] [blame] | 1540 | " check win_move_statusline from bottom window on top window ID |
| 1541 | let id = win_getid(1) |
| 1542 | for offset in range(5) |
| 1543 | call assert_true(win_move_statusline(id, offset)) |
| 1544 | call assert_equal(h + offset, winheight(id)) |
| 1545 | call assert_true(id->win_move_statusline(-offset)) |
| 1546 | call assert_equal(h, winheight(id)) |
| 1547 | endfor |
| 1548 | " check that win_move_statusline doesn't error with offsets beyond moving |
| 1549 | " possibility |
| 1550 | call assert_true(win_move_statusline(id, 5000)) |
| 1551 | call assert_true(winheight(id) > h) |
| 1552 | call assert_true(win_move_statusline(id, -5000)) |
| 1553 | call assert_true(winheight(id) < h) |
| 1554 | " check that win_move_statusline returns false for an invalid window |
| 1555 | wincmd = |
| 1556 | let h = winheight(0) |
| 1557 | call assert_false(win_move_statusline(-1, 1)) |
| 1558 | call assert_equal(h, winheight(0)) |
| 1559 | " check that win_move_statusline returns false for a popup window |
| 1560 | let id = popup_create(['hello', 'world'], {}) |
| 1561 | let h = winheight(id) |
| 1562 | call assert_false(win_move_statusline(id, 1)) |
| 1563 | call assert_equal(h, winheight(id)) |
| 1564 | call popup_close(id) |
| 1565 | %bwipe! |
| 1566 | endfunc |
| 1567 | |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 1568 | " Test for window allocation failure |
| 1569 | func Test_window_alloc_failure() |
| 1570 | %bw! |
| 1571 | |
| 1572 | " test for creating a new window above current window |
| 1573 | call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0) |
| 1574 | call assert_fails('above new', 'E342:') |
| 1575 | call assert_equal(1, winnr('$')) |
| 1576 | |
| 1577 | " test for creating a new window below current window |
| 1578 | call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0) |
| 1579 | call assert_fails('below new', 'E342:') |
| 1580 | call assert_equal(1, winnr('$')) |
| 1581 | |
| 1582 | " test for popup window creation failure |
| 1583 | call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0) |
| 1584 | call assert_fails('call popup_create("Hello", {})', 'E342:') |
| 1585 | call assert_equal([], popup_list()) |
| 1586 | |
| 1587 | call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0) |
| 1588 | call assert_fails('split', 'E342:') |
| 1589 | call assert_equal(1, winnr('$')) |
| 1590 | |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1591 | edit Xwaffile1 |
| 1592 | edit Xwaffile2 |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 1593 | call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0) |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1594 | call assert_fails('sb Xwaffile1', 'E342:') |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 1595 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | b18b496 | 2022-09-02 21:55:50 +0100 | [diff] [blame] | 1596 | call assert_equal('Xwaffile2', @%) |
Yegappan Lakshmanan | 72bb47e | 2022-04-03 11:22:38 +0100 | [diff] [blame] | 1597 | %bw! |
| 1598 | |
| 1599 | " FIXME: The following test crashes Vim |
| 1600 | " test for new tabpage creation failure |
| 1601 | " call test_alloc_fail(GetAllocId('newwin_wvars'), 0, 0) |
| 1602 | " call assert_fails('tabnew', 'E342:') |
| 1603 | " call assert_equal(1, tabpagenr('$')) |
| 1604 | " call assert_equal(1, winnr('$')) |
| 1605 | |
| 1606 | " This test messes up the internal Vim window/frame information. So the |
| 1607 | " Test_window_cmd_cmdwin_with_vsp() test fails after running this test. |
| 1608 | " Open a new tab and close everything else to fix this issue. |
| 1609 | tabnew |
| 1610 | tabonly |
| 1611 | endfunc |
Bram Moolenaar | d0fb907 | 2021-12-09 11:57:22 +0000 | [diff] [blame] | 1612 | |
Luuk van Baal | fd7e60a | 2022-09-07 14:42:49 +0100 | [diff] [blame] | 1613 | func Test_win_equal_last_status() |
| 1614 | let save_lines = &lines |
| 1615 | set lines=20 |
| 1616 | set splitbelow |
| 1617 | set laststatus=0 |
| 1618 | |
| 1619 | split | split | quit |
| 1620 | call assert_equal(winheight(1), winheight(2)) |
| 1621 | |
| 1622 | let &lines = save_lines |
| 1623 | set splitbelow& |
| 1624 | set laststatus& |
| 1625 | endfunc |
| 1626 | |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1627 | " Test "screen" and "cursor" values for 'splitkeep' with a sequence of |
Luuk van Baal | faf1d41 | 2022-09-19 16:45:29 +0100 | [diff] [blame] | 1628 | " split operations for various options: with and without a winbar, |
| 1629 | " tabline, for each possible value of 'laststatus', 'scrolloff', |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1630 | " 'equalalways', and with the cursor at the top, middle and bottom. |
| 1631 | func Test_splitkeep_options() |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1632 | " disallow window resizing |
| 1633 | let save_WS = &t_WS |
| 1634 | set t_WS= |
| 1635 | |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1636 | let gui = has("gui_running") |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1637 | inoremap <expr> c "<cmd>copen<bar>wincmd k<CR>" |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1638 | for run in range(0, 20) |
| 1639 | let &splitkeep = run > 10 ? 'topline' : 'screen' |
| 1640 | let &scrolloff = (!(run % 4) ? 0 : run) |
| 1641 | let &laststatus = (run % 3) |
| 1642 | let &splitbelow = (run % 3) |
| 1643 | let &equalalways = (run % 2) |
| 1644 | let wsb = (run % 2) && &splitbelow |
| 1645 | let tl = (gui ? 0 : ((run % 5) ? 1 : 0)) |
| 1646 | let pos = !(run % 3) ? 'H' : ((run % 2) ? 'M' : 'L') |
| 1647 | tabnew | tabonly! | redraw |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1648 | execute (run % 5) ? 'tabnew' : '' |
| 1649 | execute (run % 2) ? 'nnoremenu 1.10 WinBar.Test :echo' : '' |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1650 | call setline(1, range(1, 256)) |
| 1651 | " No scroll for restore_snapshot |
| 1652 | norm G |
| 1653 | try |
| 1654 | copen | close | colder |
| 1655 | catch /E380/ |
| 1656 | endtry |
| 1657 | call assert_equal(257 - winheight(0), line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1658 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1659 | " No scroll for firstwin horizontal split |
| 1660 | execute 'norm gg' . pos |
| 1661 | split | redraw | wincmd k |
| 1662 | call assert_equal(1, line("w0")) |
| 1663 | call assert_equal(&scroll, winheight(0) / 2) |
| 1664 | wincmd j |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1665 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1666 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1667 | " No scroll when resizing windows |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1668 | wincmd k | resize +2 | redraw |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1669 | call assert_equal(1, line("w0")) |
| 1670 | wincmd j |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1671 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1672 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1673 | " No scroll when dragging statusline |
| 1674 | call win_move_statusline(1, -3) |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1675 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1676 | wincmd k |
| 1677 | call assert_equal(1, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1678 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1679 | " No scroll when changing shellsize |
| 1680 | set lines+=2 |
| 1681 | call assert_equal(1, line("w0")) |
| 1682 | wincmd j |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1683 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1684 | set lines-=2 |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1685 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1686 | wincmd k |
| 1687 | call assert_equal(1, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1688 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1689 | " No scroll when equalizing windows |
| 1690 | wincmd = |
| 1691 | call assert_equal(1, line("w0")) |
| 1692 | wincmd j |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1693 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1694 | wincmd k |
| 1695 | call assert_equal(1, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1696 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1697 | " No scroll in windows split multiple times |
| 1698 | vsplit | split | 4wincmd w |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1699 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1700 | 1wincmd w | quit | wincmd l | split |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1701 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1702 | wincmd j |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1703 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1704 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1705 | " No scroll in small window |
| 1706 | 2wincmd w | only | 5split | wincmd k |
| 1707 | call assert_equal(1, line("w0")) |
| 1708 | wincmd j |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1709 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1710 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1711 | " No scroll for vertical split |
| 1712 | quit | vsplit | wincmd l |
| 1713 | call assert_equal(1, line("w0")) |
| 1714 | wincmd h |
| 1715 | call assert_equal(1, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1716 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1717 | " No scroll in windows split and quit multiple times |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1718 | quit | redraw | split | split | quit | redraw |
| 1719 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1720 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1721 | " No scroll for new buffer |
| 1722 | 1wincmd w | only | copen | wincmd k |
| 1723 | call assert_equal(1, line("w0")) |
| 1724 | only |
| 1725 | call assert_equal(1, line("w0")) |
| 1726 | above copen | wincmd j |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1727 | call assert_equal(&spk == 'topline' ? 1 : win_screenpos(0)[0] - tl, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1728 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1729 | " No scroll when opening cmdwin, and no cursor move when closing cmdwin. |
| 1730 | only | norm ggL |
| 1731 | let curpos = getcurpos() |
| 1732 | norm q: |
| 1733 | call assert_equal(1, line("w0")) |
| 1734 | call assert_equal(curpos, getcurpos()) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1735 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1736 | " Scroll when cursor becomes invalid in insert mode |
| 1737 | norm Lic |
| 1738 | call assert_equal(curpos, getcurpos()) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1739 | |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1740 | " No scroll when topline not equal to 1 |
| 1741 | only | execute "norm gg5\<C-e>" | split | wincmd k |
| 1742 | call assert_equal(6, line("w0")) |
| 1743 | wincmd j |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1744 | call assert_equal(&spk == 'topline' ? 6 : 5 + win_screenpos(0)[0] - tl - wsb, line("w0")) |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1745 | endfor |
| 1746 | |
| 1747 | tabnew | tabonly! | %bwipeout! |
| 1748 | iunmap c |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1749 | set scrolloff& |
| 1750 | set splitbelow& |
| 1751 | set laststatus& |
| 1752 | set equalalways& |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1753 | set splitkeep& |
Luuk van Baal | 594f9e0 | 2022-09-16 12:52:58 +0100 | [diff] [blame] | 1754 | let &t_WS = save_WS |
Luuk van Baal | 29ab524 | 2022-09-11 16:59:53 +0100 | [diff] [blame] | 1755 | endfunc |
Luuk van Baal | fd7e60a | 2022-09-07 14:42:49 +0100 | [diff] [blame] | 1756 | |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1757 | function Test_splitkeep_cmdwin_cursor_position() |
| 1758 | set splitkeep=screen |
mityu | 12167d8 | 2022-09-15 17:44:07 +0100 | [diff] [blame] | 1759 | call setline(1, range(&lines)) |
| 1760 | |
| 1761 | " No scroll when cursor is at near bottom of window and cusor position |
| 1762 | " recompution (done by line('w0') in this test) happens while in cmdwin. |
| 1763 | normal! G |
| 1764 | let firstline = line('w0') |
| 1765 | autocmd CmdwinEnter * ++once autocmd WinEnter * ++once call line('w0') |
| 1766 | execute "normal! q:\<C-w>q" |
| 1767 | redraw! |
| 1768 | call assert_equal(firstline, line('w0')) |
| 1769 | |
| 1770 | " User script can change cursor position successfully while in cmdwin and it |
| 1771 | " shouldn't be changed when closing cmdwin. |
| 1772 | execute "normal! Gq:\<Cmd>call win_execute(winnr('#')->win_getid(), 'call cursor(1, 1)')\<CR>\<C-w>q" |
| 1773 | call assert_equal(1, line('.')) |
| 1774 | call assert_equal(1, col('.')) |
| 1775 | |
| 1776 | execute "normal! Gq:\<Cmd>autocmd WinEnter * ++once call cursor(1, 1)\<CR>\<C-w>q" |
| 1777 | call assert_equal(1, line('.')) |
| 1778 | call assert_equal(1, col('.')) |
| 1779 | |
| 1780 | %bwipeout! |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1781 | set splitkeep& |
mityu | 12167d8 | 2022-09-15 17:44:07 +0100 | [diff] [blame] | 1782 | endfunction |
Luuk van Baal | d5bc762 | 2022-09-17 16:16:35 +0100 | [diff] [blame] | 1783 | |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1784 | function Test_splitkeep_misc() |
| 1785 | set splitkeep=screen |
Luuk van Baal | faf1d41 | 2022-09-19 16:45:29 +0100 | [diff] [blame] | 1786 | set splitbelow |
Luuk van Baal | d5bc762 | 2022-09-17 16:16:35 +0100 | [diff] [blame] | 1787 | |
| 1788 | call setline(1, range(1, &lines)) |
| 1789 | norm Gzz |
| 1790 | let top = line('w0') |
Luuk van Baal | faf1d41 | 2022-09-19 16:45:29 +0100 | [diff] [blame] | 1791 | " No scroll when aucmd_win is opened |
Luuk van Baal | d5bc762 | 2022-09-17 16:16:35 +0100 | [diff] [blame] | 1792 | call setbufvar(bufnr("test", 1) , '&buftype', 'nofile') |
| 1793 | call assert_equal(top, line('w0')) |
Luuk van Baal | faf1d41 | 2022-09-19 16:45:29 +0100 | [diff] [blame] | 1794 | " No scroll when tab is changed/closed |
| 1795 | tab help | close |
| 1796 | call assert_equal(top, line('w0')) |
| 1797 | " No scroll when help is closed and buffer line count < window height |
| 1798 | norm ggdG |
| 1799 | call setline(1, range(1, &lines - 10)) |
Luuk van Baal | d5bc762 | 2022-09-17 16:16:35 +0100 | [diff] [blame] | 1800 | norm G |
| 1801 | let top = line('w0') |
| 1802 | help | quit |
| 1803 | call assert_equal(top, line('w0')) |
Luuk van Baal | 346823d | 2022-10-05 18:26:42 +0100 | [diff] [blame] | 1804 | " No error when resizing window in autocmd and buffer length changed |
| 1805 | autocmd FileType qf exe "resize" line('$') |
| 1806 | cexpr getline(1, '$') |
| 1807 | copen |
| 1808 | wincmd p |
| 1809 | norm dd |
| 1810 | cexpr getline(1, '$') |
Luuk van Baal | d5bc762 | 2022-09-17 16:16:35 +0100 | [diff] [blame] | 1811 | |
Luuk van Baal | faf1d41 | 2022-09-19 16:45:29 +0100 | [diff] [blame] | 1812 | %bwipeout! |
Luuk van Baal | d5bc762 | 2022-09-17 16:16:35 +0100 | [diff] [blame] | 1813 | set splitbelow& |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1814 | set splitkeep& |
Luuk van Baal | d5bc762 | 2022-09-17 16:16:35 +0100 | [diff] [blame] | 1815 | endfunc |
| 1816 | |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1817 | function Test_splitkeep_callback() |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1818 | CheckScreendump |
| 1819 | let lines =<< trim END |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1820 | set splitkeep=screen |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1821 | call setline(1, range(&lines)) |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1822 | function C1(a, b) |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1823 | split | wincmd p |
| 1824 | endfunction |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1825 | function C2(a, b) |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1826 | close | split |
| 1827 | endfunction |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1828 | nn j <cmd>call job_start([&sh, &shcf, "true"], { 'exit_cb': 'C1' })<CR> |
| 1829 | nn t <cmd>call popup_create(term_start([&sh, &shcf, "true"], |
| 1830 | \ { 'hidden': 1, 'exit_cb': 'C2' }), {})<CR> |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1831 | END |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1832 | call writefile(lines, 'XTestSplitkeepCallback', 'D') |
| 1833 | let buf = RunVimInTerminal('-S XTestSplitkeepCallback', #{rows: 8}) |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1834 | |
| 1835 | call term_sendkeys(buf, "j") |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1836 | call VerifyScreenDump(buf, 'Test_splitkeep_callback_1', {}) |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1837 | |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1838 | call term_sendkeys(buf, ":quit\<CR>Ht") |
| 1839 | call VerifyScreenDump(buf, 'Test_splitkeep_callback_2', {}) |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1840 | |
| 1841 | call term_sendkeys(buf, ":set sb\<CR>:quit\<CR>Gj") |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1842 | call VerifyScreenDump(buf, 'Test_splitkeep_callback_3', {}) |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1843 | |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1844 | call term_sendkeys(buf, ":quit\<CR>Gt") |
| 1845 | call VerifyScreenDump(buf, 'Test_splitkeep_callback_4', {}) |
Luuk van Baal | 20e5856 | 2022-09-23 12:57:09 +0100 | [diff] [blame] | 1846 | endfunc |
| 1847 | |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1848 | function Test_splitkeep_fold() |
| 1849 | CheckScreendump |
Luuk van Baal | 7c1cbb6 | 2022-09-27 12:31:15 +0100 | [diff] [blame] | 1850 | |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1851 | let lines =<< trim END |
| 1852 | set splitkeep=screen |
| 1853 | set foldmethod=marker |
| 1854 | set number |
| 1855 | let line = 1 |
| 1856 | for n in range(1, &lines) |
| 1857 | call setline(line, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/', |
| 1858 | \ 'after fold']) |
| 1859 | let line += 8 |
| 1860 | endfor |
| 1861 | END |
| 1862 | call writefile(lines, 'XTestSplitkeepFold', 'D') |
| 1863 | let buf = RunVimInTerminal('-S XTestSplitkeepFold', #{rows: 10}) |
Luuk van Baal | 7c1cbb6 | 2022-09-27 12:31:15 +0100 | [diff] [blame] | 1864 | |
| 1865 | call term_sendkeys(buf, "L:wincmd s\<CR>") |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1866 | call VerifyScreenDump(buf, 'Test_splitkeep_fold_1', {}) |
Luuk van Baal | 7c1cbb6 | 2022-09-27 12:31:15 +0100 | [diff] [blame] | 1867 | |
| 1868 | call term_sendkeys(buf, ":quit\<CR>") |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1869 | call VerifyScreenDump(buf, 'Test_splitkeep_fold_2', {}) |
Luuk van Baal | 7c1cbb6 | 2022-09-27 12:31:15 +0100 | [diff] [blame] | 1870 | |
| 1871 | call term_sendkeys(buf, "H:below split\<CR>") |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1872 | call VerifyScreenDump(buf, 'Test_splitkeep_fold_3', {}) |
Luuk van Baal | 7c1cbb6 | 2022-09-27 12:31:15 +0100 | [diff] [blame] | 1873 | |
| 1874 | call term_sendkeys(buf, ":wincmd k\<CR>:quit\<CR>") |
Luuk van Baal | 13ece2a | 2022-10-03 15:28:08 +0100 | [diff] [blame] | 1875 | call VerifyScreenDump(buf, 'Test_splitkeep_fold_4', {}) |
Luuk van Baal | 7c1cbb6 | 2022-09-27 12:31:15 +0100 | [diff] [blame] | 1876 | endfunction |
| 1877 | |
Bram Moolenaar | 9e4d821 | 2016-08-18 23:04:48 +0200 | [diff] [blame] | 1878 | " vim: shiftwidth=2 sts=2 expandtab |