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