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