window_cmd_spec.lua (18884B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 local Screen = require('test.functional.ui.screen') 4 5 local clear = n.clear 6 local eq = t.eq 7 local exec = n.exec 8 local exec_lua = n.exec_lua 9 local command = n.command 10 local feed = n.feed 11 local fn = n.fn 12 13 -- oldtest: Test_window_cmd_ls0_split_scrolling() 14 it('scrolling with laststatus=0 and :botright split', function() 15 clear('--cmd', 'set ruler') 16 local screen = Screen.new(40, 10) 17 exec([[ 18 set laststatus=0 19 call setline(1, range(1, 100)) 20 normal! G 21 ]]) 22 command('botright split') 23 screen:expect([[ 24 97 | 25 98 | 26 99 | 27 100 | 28 {2:[No Name] [+] 100,1 Bot}| 29 97 | 30 98 | 31 99 | 32 ^100 | 33 100,1 Bot | 34 ]]) 35 end) 36 37 describe('splitkeep', function() 38 local screen 39 40 before_each(function() 41 clear('--cmd', 'set splitkeep=screen') 42 screen = Screen.new() 43 end) 44 45 -- oldtest: Test_splitkeep_cursor() 46 it('does not adjust cursor in window that did not change size', function() 47 screen:try_resize(75, 8) 48 -- FIXME: bottom window is different without the "vsplit | close" 49 exec([[ 50 vsplit | close 51 set scrolloff=5 52 set splitkeep=screen 53 autocmd CursorMoved * wincmd p | wincmd p 54 call setline(1, range(1, 200)) 55 func CursorEqualize() 56 call cursor(100, 1) 57 wincmd = 58 endfunc 59 wincmd s 60 call CursorEqualize() 61 ]]) 62 63 screen:expect([[ 64 99 | 65 ^100 | 66 101 | 67 {3:[No Name] [+] }| 68 5 | 69 6 | 70 {2:[No Name] [+] }| 71 | 72 ]]) 73 74 feed('j') 75 screen:expect([[ 76 100 | 77 ^101 | 78 102 | 79 {3:[No Name] [+] }| 80 5 | 81 6 | 82 {2:[No Name] [+] }| 83 | 84 ]]) 85 86 command('set scrolloff=0') 87 feed('G') 88 screen:expect([[ 89 198 | 90 199 | 91 ^200 | 92 {3:[No Name] [+] }| 93 5 | 94 6 | 95 {2:[No Name] [+] }| 96 | 97 ]]) 98 end) 99 100 -- oldtest: Test_splitkeep_callback() 101 it('does not scroll when split in callback', function() 102 exec([[ 103 call setline(1, range(&lines)) 104 function C1(a, b, c) 105 split | wincmd p 106 endfunction 107 function C2(a, b, c) 108 close | split 109 endfunction 110 ]]) 111 exec_lua([[ 112 vim.api.nvim_set_keymap("n", "j", "", { callback = function() 113 vim.cmd("call jobstart([&sh, &shcf, 'true'], { 'on_exit': 'C1' })") 114 end 115 })]]) 116 exec_lua([[ 117 vim.api.nvim_set_keymap("n", "t", "", { callback = function() 118 vim.api.nvim_set_current_win( 119 vim.api.nvim_open_win(vim.api.nvim_create_buf(false, {}), false, { 120 width = 10, 121 relative = "cursor", 122 height = 4, 123 row = 0, 124 col = 0, 125 })) 126 vim.cmd("call jobstart([&sh, &shcf, 'true'], { 'term': v:true, 'on_exit': 'C2' })") 127 end 128 })]]) 129 feed('j') 130 screen:expect([[ 131 0 | 132 1 | 133 2 | 134 3 | 135 4 | 136 5 | 137 {2:[No Name] [+] }| 138 ^7 | 139 8 | 140 9 | 141 10 | 142 11 | 143 {3:[No Name] [+] }| 144 | 145 ]]) 146 feed(':quit<CR>Ht') 147 screen:expect([[ 148 ^0 | 149 1 | 150 2 | 151 3 | 152 4 | 153 5 | 154 {3:[No Name] [+] }| 155 7 | 156 8 | 157 9 | 158 10 | 159 11 | 160 {2:[No Name] [+] }| 161 :quit | 162 ]]) 163 feed(':set sb<CR>:quit<CR>Gj') 164 screen:expect([[ 165 1 | 166 2 | 167 3 | 168 4 | 169 ^5 | 170 {3:[No Name] [+] }| 171 7 | 172 8 | 173 9 | 174 10 | 175 11 | 176 12 | 177 {2:[No Name] [+] }| 178 :quit | 179 ]]) 180 feed(':quit<CR>Gt') 181 screen:expect([[ 182 1 | 183 2 | 184 3 | 185 4 | 186 5 | 187 {2:[No Name] [+] }| 188 7 | 189 8 | 190 9 | 191 10 | 192 11 | 193 ^12 | 194 {3:[No Name] [+] }| 195 :quit | 196 ]]) 197 end) 198 199 -- oldtest: Test_splitkeep_fold() 200 it('does not scroll when window has closed folds', function() 201 exec([[ 202 set commentstring=/*%s*/ 203 set splitkeep=screen 204 set foldmethod=marker 205 set number 206 let line = 1 207 for n in range(1, &lines) 208 call setline(line, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/', 209 \ 'after fold']) 210 let line += 8 211 endfor 212 ]]) 213 feed('L:wincmd s<CR>') 214 screen:expect([[ 215 {8: 1 }{13:+-- 7 lines: int FuncName() {···················}| 216 {8: 8 }after fold | 217 {8: 9 }{13:+-- 7 lines: int FuncName() {···················}| 218 {8: 16 }after fold | 219 {8: 17 }{13:+-- 7 lines: int FuncName() {···················}| 220 {8: 24 }^after fold | 221 {3:[No Name] [+] }| 222 {8: 32 }after fold | 223 {8: 33 }{13:+-- 7 lines: int FuncName() {···················}| 224 {8: 40 }after fold | 225 {8: 41 }{13:+-- 7 lines: int FuncName() {···················}| 226 {8: 48 }after fold | 227 {2:[No Name] [+] }| 228 :wincmd s | 229 ]]) 230 feed(':quit<CR>') 231 screen:expect([[ 232 {8: 1 }{13:+-- 7 lines: int FuncName() {···················}| 233 {8: 8 }after fold | 234 {8: 9 }{13:+-- 7 lines: int FuncName() {···················}| 235 {8: 16 }after fold | 236 {8: 17 }{13:+-- 7 lines: int FuncName() {···················}| 237 {8: 24 }after fold | 238 {8: 25 }{13:+-- 7 lines: int FuncName() {···················}| 239 {8: 32 }after fold | 240 {8: 33 }{13:+-- 7 lines: int FuncName() {···················}| 241 {8: 40 }after fold | 242 {8: 41 }{13:+-- 7 lines: int FuncName() {···················}| 243 {8: 48 }after fold | 244 {8: 49 }{13:^+-- 7 lines: int FuncName() {···················}| 245 :quit | 246 ]]) 247 feed('H:below split<CR>') 248 screen:expect([[ 249 {8: 1 }{13:+-- 7 lines: int FuncName() {···················}| 250 {8: 8 }after fold | 251 {8: 9 }{13:+-- 7 lines: int FuncName() {···················}| 252 {8: 16 }after fold | 253 {8: 17 }{13:+-- 7 lines: int FuncName() {···················}| 254 {2:[No Name] [+] }| 255 {8: 25 }{13:^+-- 7 lines: int FuncName() {···················}| 256 {8: 32 }after fold | 257 {8: 33 }{13:+-- 7 lines: int FuncName() {···················}| 258 {8: 40 }after fold | 259 {8: 41 }{13:+-- 7 lines: int FuncName() {···················}| 260 {8: 48 }after fold | 261 {3:[No Name] [+] }| 262 :below split | 263 ]]) 264 feed(':wincmd k<CR>:quit<CR>') 265 screen:expect([[ 266 {8: 1 }{13:+-- 7 lines: int FuncName() {···················}| 267 {8: 8 }after fold | 268 {8: 9 }{13:+-- 7 lines: int FuncName() {···················}| 269 {8: 16 }after fold | 270 {8: 17 }{13:+-- 7 lines: int FuncName() {···················}| 271 {8: 24 }after fold | 272 {8: 25 }{13:^+-- 7 lines: int FuncName() {···················}| 273 {8: 32 }after fold | 274 {8: 33 }{13:+-- 7 lines: int FuncName() {···················}| 275 {8: 40 }after fold | 276 {8: 41 }{13:+-- 7 lines: int FuncName() {···················}| 277 {8: 48 }after fold | 278 {8: 49 }{13:+-- 7 lines: int FuncName() {···················}| 279 :quit | 280 ]]) 281 end) 282 283 -- oldtest: Test_splitkeep_status() 284 it('does not scroll when split in callback', function() 285 exec([[ 286 call setline(1, ['a', 'b', 'c']) 287 set nomodified 288 set splitkeep=screen 289 let win = winnr() 290 wincmd s 291 wincmd j 292 ]]) 293 feed(':call win_move_statusline(win, 1)<CR>') 294 screen:expect([[ 295 a | 296 b | 297 c | 298 {1:~ }|*4 299 {2:[No Name] }| 300 ^a | 301 b | 302 c | 303 {1:~ }| 304 {3:[No Name] }| 305 :call win_move_statusline(win, 1) | 306 ]]) 307 end) 308 309 -- oldtest: Test_splitkeep_skipcol() 310 it('skipcol is not reset unnecessarily and is copied to new window', function() 311 screen:try_resize(40, 12) 312 exec([[ 313 set splitkeep=topline smoothscroll splitbelow scrolloff=0 314 call setline(1, 'with lots of text in one line '->repeat(6)) 315 norm 2 316 wincmd s 317 ]]) 318 screen:expect([[ 319 {1:<<<}e line with lots of text in one line | 320 with lots of text in one line with lots | 321 of text in one line | 322 {1:~ }| 323 {2:[No Name] [+] }| 324 {1:<<<}e line with lots of text in one line | 325 ^with lots of text in one line with lots | 326 of text in one line | 327 {1:~ }|*2 328 {3:[No Name] [+] }| 329 | 330 ]]) 331 end) 332 333 -- oldtest: Test_splitkeep_line() 334 it("no scrolling with 'splitkeep' and line()", function() 335 screen:try_resize(40, 6) 336 exec([[ 337 set splitkeep=screen nosplitbelow 338 autocmd WinResized * call line('w0', 1000) 339 call setline(1, range(1000)) 340 ]]) 341 screen:expect([[ 342 ^0 | 343 1 | 344 2 | 345 3 | 346 4 | 347 | 348 ]]) 349 feed(':wincmd s<CR>') 350 screen:expect([[ 351 ^0 | 352 1 | 353 {3:[No Name] [+] }| 354 3 | 355 {2:[No Name] [+] }| 356 :wincmd s | 357 ]]) 358 end) 359 end) 360 361 -- oldtest: Test_winfixsize_vsep_statusline() 362 it("'winfixwidth/height' does not leave stray vseps/statuslines", function() 363 clear() 364 local screen = Screen.new(75, 8) 365 exec([[ 366 set noequalalways splitbelow splitright 367 vsplit 368 setlocal winfixwidth 369 vsplit 370 ]]) 371 eq(16, fn.winwidth(1)) 372 eq(37, fn.winwidth(2)) 373 eq(20, fn.winwidth(3)) 374 375 command('quit') 376 screen:expect([[ 377 ^ │ | 378 {1:~ }│{1:~ }|*5 379 {3:[No Name] }{2:[No Name] }| 380 | 381 ]]) 382 -- Checks w_view_width in Nvim; especially important as the screen test may still pass if only 383 -- w_width changed to make room for the vsep. 384 eq(36, fn.winwidth(1)) 385 eq(38, fn.winwidth(2)) 386 387 exec([[ 388 set laststatus=0 389 only 390 split 391 set winfixheight 392 split 393 ]]) 394 eq(1, fn.winheight(1)) 395 eq(3, fn.winheight(2)) 396 eq(1, fn.winheight(3)) 397 398 command('quit') 399 screen:expect([[ 400 ^ | 401 {1:~ }| 402 {3:[No Name] }| 403 | 404 {1:~ }|*3 405 | 406 ]]) 407 eq(2, fn.winheight(1)) 408 eq(4, fn.winheight(2)) 409 end) 410 411 -- oldtest: Test_resize_from_another_tabpage() 412 it('resizing window from another tabpage', function() 413 clear() 414 local screen = Screen.new(75, 8) 415 screen:add_extra_attr_ids({ 416 [100] = { foreground = Screen.colors.Magenta1, bold = true }, 417 }) 418 exec([[ 419 set laststatus=2 420 vnew 421 let w = win_getid() 422 tabnew 423 call win_execute(w, 'vertical resize 20') 424 tabprev 425 ]]) 426 screen:expect([[ 427 {5: }{100:2}{5: [No Name] }{24: [No Name] }{2: }{24:X}| 428 ^ │ | 429 {1:~ }│{1:~ }|*4 430 {3:[No Name] }{2:[No Name] }| 431 | 432 ]]) 433 end)