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