robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1" Test for 'scroll', 'scrolloff', 'smoothscroll', etc. 2 3source check.vim 4source screendump.vim 5source mouse.vim 6 7func Test_reset_scroll () 8let scr = & l: scroll 9 10setlocal scroll = 1 11setlocal scroll & 12call assert_equal ( scr , & l: scroll ) 13 14setlocal scroll = 1 15setlocal scroll = 0 16call assert_equal ( scr , & l: scroll ) 17 18try 19execute 'setlocal scroll=' . ( winheight ( 0 ) + 1 ) 20" not reached 21call assert_false ( 1 ) 22catch 23call assert_exception ( 'E49:' ) 24endtry 25 26split 27 28let scr = & l: scroll 29 30setlocal scroll = 1 31setlocal scroll & 32call assert_equal ( scr , & l: scroll ) 33 34setlocal scroll = 1 35setlocal scroll = 0 36call assert_equal ( scr , & l: scroll ) 37 38quit ! 39endfunc 40 41func Test_scolloff_even_line_count () 42new 43resize 6 44setlocal scrolloff = 3 45call setline ( 1 , range ( 20 )) 46normal 2j 47call assert_equal ( 1 , getwininfo ( win_getid ())[ 0 ]. topline ) 48normal j 49call assert_equal ( 1 , getwininfo ( win_getid ())[ 0 ]. topline ) 50normal j 51call assert_equal ( 2 , getwininfo ( win_getid ())[ 0 ]. topline ) 52normal j 53call assert_equal ( 3 , getwininfo ( win_getid ())[ 0 ]. topline ) 54 55bwipe ! 56endfunc 57 58func Test_mouse_scroll_inactive_with_cursorbind () 59for scb in [ 0 , 1 ] 60for so in [ 0 , 1 , 2 ] 61let msg = $ 'scb={scb} so={so}' 62 63new |only 64let w1 = win_getid () 65setlocal cursorbind 66let & l: scb = scb 67let & l: so = so 68call setline ( 1 , range ( 101 , 109 )) 69rightbelow vnew 70let w2 = win_getid () 71setlocal cursorbind 72let & l: scb = scb 73let & l: so = so 74call setline ( 1 , range ( 101 , 109 )) 75 76normal ! $ 77call assert_equal ( 3 , col ( '.' , w1 ), msg ) 78call assert_equal ( 3 , col ( '.' , w2 ), msg ) 79call Ntest_setmouse ( 1 , 1 ) 80call feedkeys ( "\<ScrollWheelDown>" , 'xt' ) 81call assert_equal ( 4 , line ( 'w0' , w1 ), msg ) 82call assert_equal ( 4 + so , line ( '.' , w1 ), msg ) 83call assert_equal ( 1 , line ( 'w0' , w2 ), msg ) 84call assert_equal ( 1 , line ( '.' , w2 ), msg ) 85call feedkeys ( "\<ScrollWheelDown>" , 'xt' ) 86call assert_equal ( 7 , line ( 'w0' , w1 ), msg ) 87call assert_equal ( 7 + so , line ( '.' , w1 ), msg ) 88call assert_equal ( 1 , line ( 'w0' , w2 ), msg ) 89call assert_equal ( 1 , line ( '.' , w2 ), msg ) 90call feedkeys ( "\<ScrollWheelUp>" , 'xt' ) 91call assert_equal ( 4 , line ( 'w0' , w1 ), msg ) 92call assert_equal ( 7 + so , line ( '.' , w1 ), msg ) 93call assert_equal ( 1 , line ( 'w0' , w2 ), msg ) 94call assert_equal ( 1 , line ( '.' , w2 ), msg ) 95call feedkeys ( "\<ScrollWheelUp>" , 'xt' ) 96call assert_equal ( 1 , line ( 'w0' , w1 ), msg ) 97call assert_equal ( 7 + so , line ( '.' , w1 ), msg ) 98call assert_equal ( 1 , line ( 'w0' , w2 ), msg ) 99call assert_equal ( 1 , line ( '.' , w2 ), msg ) 100normal ! 0 101call assert_equal ( 1 , line ( '.' , w1 ), msg ) 102call assert_equal ( 1 , col ( '.' , w1 ), msg ) 103call assert_equal ( 1 , line ( '.' , w2 ), msg ) 104call assert_equal ( 1 , col ( '.' , w2 ), msg ) 105 106bwipe ! 107bwipe ! 108endfor 109endfor 110endfunc 111 112func Test_CtrlE_CtrlY_stop_at_end () 113enew 114call setline ( 1 , [ 'one' , 'two' ]) 115set number 116exe "normal \<C-Y>" 117call assert_equal ([ " 1 one " ], ScreenLines ( 1 , 10 )) 118exe "normal \<C-E>\<C-E>\<C-E>" 119call assert_equal ([ " 2 two " ], ScreenLines ( 1 , 10 )) 120 121bwipe ! 122set nonumber 123endfunc 124 125func Test_smoothscroll_CtrlE_CtrlY () 126CheckScreendump 127 128let lines =<< trim END 129vim9script 130setline(1, [ 131'line one', 132'word '->repeat(20), 133'line three', 134'long word '->repeat(7), 135'line', 136'line', 137'line', 138]) 139set smoothscroll 140:5 141END 142call writefile ( lines , 'XSmoothScroll' , 'D' ) 143let buf = RunVimInTerminal ( '-S XSmoothScroll' , #{ rows : 12 , cols : 40 }) 144 145call term_sendkeys ( buf , "\<C-E>" ) 146call VerifyScreenDump ( buf , 'Test_smoothscroll_1' , {}) 147call term_sendkeys ( buf , "\<C-E>" ) 148call VerifyScreenDump ( buf , 'Test_smoothscroll_2' , {}) 149call term_sendkeys ( buf , "\<C-E>" ) 150call VerifyScreenDump ( buf , 'Test_smoothscroll_3' , {}) 151call term_sendkeys ( buf , "\<C-E>" ) 152call VerifyScreenDump ( buf , 'Test_smoothscroll_4' , {}) 153 154call term_sendkeys ( buf , "\<C-Y>" ) 155call VerifyScreenDump ( buf , 'Test_smoothscroll_5' , {}) 156call term_sendkeys ( buf , "\<C-Y>" ) 157call VerifyScreenDump ( buf , 'Test_smoothscroll_6' , {}) 158call term_sendkeys ( buf , "\<C-Y>" ) 159call VerifyScreenDump ( buf , 'Test_smoothscroll_7' , {}) 160call term_sendkeys ( buf , "\<C-Y>" ) 161call VerifyScreenDump ( buf , 'Test_smoothscroll_8' , {}) 162 163if has ( 'folding' ) 164call term_sendkeys ( buf , ":set foldmethod=indent\<CR>" ) 165" move the cursor so we can reuse the same dumps 166call term_sendkeys ( buf , "5G" ) 167call term_sendkeys ( buf , "\<C-E>" ) 168call VerifyScreenDump ( buf , 'Test_smoothscroll_1' , {}) 169call term_sendkeys ( buf , "\<C-E>" ) 170call VerifyScreenDump ( buf , 'Test_smoothscroll_2' , {}) 171call term_sendkeys ( buf , "7G" ) 172call term_sendkeys ( buf , "\<C-Y>" ) 173call VerifyScreenDump ( buf , 'Test_smoothscroll_7' , {}) 174call term_sendkeys ( buf , "\<C-Y>" ) 175call VerifyScreenDump ( buf , 'Test_smoothscroll_8' , {}) 176endif 177 178call StopVimInTerminal ( buf ) 179endfunc 180 181func Test_smoothscroll_multibyte () 182CheckScreendump 183 184let lines =<< trim END 185set scrolloff=0 smoothscroll 186call setline(1, [repeat('ϛ', 45), repeat('2', 36)]) 187exe "normal G35l\<C-E>k" 188END 189call writefile ( lines , 'XSmoothMultibyte' , 'D' ) 190let buf = RunVimInTerminal ( '-S XSmoothMultibyte' , #{ rows : 6 , cols : 40 }) 191call VerifyScreenDump ( buf , 'Test_smoothscroll_multi_1' , {}) 192 193call StopVimInTerminal ( buf ) 194endfunc 195 196func Test_smoothscroll_number () 197CheckScreendump 198 199let lines =<< trim END 200vim9script 201setline(1, [ 202'one ' .. 'word '->repeat(20), 203'two ' .. 'long word '->repeat(7), 204'line', 205'line', 206'line', 207]) 208set smoothscroll 209set splitkeep=topline 210set number cpo+=n 211:3 212 213def g:DoRel() 214set number relativenumber scrolloff=0 215:%del 216setline(1, [ 217'one', 218'very long text '->repeat(12), 219'three', 220]) 221exe "normal 2Gzt\<C-E>" 222enddef 223END 224call writefile ( lines , 'XSmoothNumber' , 'D' ) 225let buf = RunVimInTerminal ( '-S XSmoothNumber' , #{ rows : 12 , cols : 40 }) 226 227call VerifyScreenDump ( buf , 'Test_smooth_number_1' , {}) 228call term_sendkeys ( buf , "\<C-E>" ) 229call VerifyScreenDump ( buf , 'Test_smooth_number_2' , {}) 230call term_sendkeys ( buf , "\<C-E>" ) 231call VerifyScreenDump ( buf , 'Test_smooth_number_3' , {}) 232 233call term_sendkeys ( buf , ":set cpo-=n\<CR>" ) 234call VerifyScreenDump ( buf , 'Test_smooth_number_4' , {}) 235call term_sendkeys ( buf , "\<C-Y>" ) 236call VerifyScreenDump ( buf , 'Test_smooth_number_5' , {}) 237call term_sendkeys ( buf , "\<C-Y>" ) 238call VerifyScreenDump ( buf , 'Test_smooth_number_6' , {}) 239 240call term_sendkeys ( buf , ":botright split\<CR>\<C-L>gg" ) 241call VerifyScreenDump ( buf , 'Test_smooth_number_7' , {}) 242call term_sendkeys ( buf , "\<C-E>" ) 243call VerifyScreenDump ( buf , 'Test_smooth_number_8' , {}) 244call term_sendkeys ( buf , "\<C-E>" ) 245call VerifyScreenDump ( buf , 'Test_smooth_number_9' , {}) 246call term_sendkeys ( buf , ":close\<CR>" ) 247 248call term_sendkeys ( buf , ":call DoRel()\<CR>" ) 249call VerifyScreenDump ( buf , 'Test_smooth_number_10' , {}) 250 251call StopVimInTerminal ( buf ) 252endfunc 253 254func Test_smoothscroll_list () 255CheckScreendump 256 257let lines =<< trim END 258vim9script 259set smoothscroll scrolloff=0 260set list 261setline(1, [ 262'one', 263'very long text '->repeat(12), 264'three', 265]) 266exe "normal 2Gzt\<C-E>" 267END 268call writefile ( lines , 'XSmoothList' , 'D' ) 269let buf = RunVimInTerminal ( '-S XSmoothList' , #{ rows : 8 , cols : 40 }) 270 271call VerifyScreenDump ( buf , 'Test_smooth_list_1' , {}) 272 273call term_sendkeys ( buf , ":set listchars+=precedes:#\<CR>" ) 274call VerifyScreenDump ( buf , 'Test_smooth_list_2' , {}) 275 276call StopVimInTerminal ( buf ) 277endfunc 278 279func Test_smoothscroll_diff_mode () 280CheckScreendump 281CheckFeature diff 282 283let lines =<< trim END 284vim9script 285var text = 'just some text here' 286setline(1, text) 287set smoothscroll 288diffthis 289new 290setline(1, text) 291set smoothscroll 292diffthis 293END 294call writefile ( lines , 'XSmoothDiff' , 'D' ) 295let buf = RunVimInTerminal ( '-S XSmoothDiff' , #{ rows : 8 }) 296 297call VerifyScreenDump ( buf , 'Test_smooth_diff_1' , {}) 298call term_sendkeys ( buf , "\<C-Y>" ) 299call VerifyScreenDump ( buf , 'Test_smooth_diff_1' , {}) 300call term_sendkeys ( buf , "\<C-E>" ) 301call VerifyScreenDump ( buf , 'Test_smooth_diff_1' , {}) 302 303call StopVimInTerminal ( buf ) 304endfunc 305 306func Test_smoothscroll_diff_change_line_default () 307CheckScreendump 308CheckFeature diff 309 310" Uses the new diffopt default with indent-heuristic and inline:char 311let lines =<< trim END 312set diffopt=internal,filler,closeoff,indent-heuristic,inline:char,followwrap smoothscroll 313call setline(1, repeat(' abc', &columns)) 314call setline(2, 'bar') 315call setline(3, repeat(' abc', &columns)) 316vnew 317call setline(1, repeat(' abc', &columns)) 318call setline(2, 'foo') 319call setline(3, 'bar') 320call setline(4, repeat(' abc', &columns)) 321windo exe "normal! 2gg5\<C-E>" 322windo diffthis 323END 324call writefile ( lines , 'XSmoothDiffChangeLine' , 'D' ) 325let buf = RunVimInTerminal ( '-S XSmoothDiffChangeLine' , #{ rows : 20 , columns : 55 }) 326 327call VerifyScreenDump ( buf , 'Test_smooth_diff_change_line_1' , {}) 328call term_sendkeys ( buf , "Abar" ) 329call VerifyScreenDump ( buf , 'Test_smooth_diff_change_line_2' , {}) 330call term_sendkeys ( buf , "\<Esc>" ) 331call VerifyScreenDump ( buf , 'Test_smooth_diff_change_line_3a' , {}) 332call term_sendkeys ( buf , "yyp" ) 333call VerifyScreenDump ( buf , 'Test_smooth_diff_change_line_4' , {}) 334 335call StopVimInTerminal ( buf ) 336endfunc 337 338func Test_smoothscroll_diff_change_line () 339CheckScreendump 340CheckFeature diff 341 342" Uses the old diffopt default 343let lines =<< trim END 344set diffopt=internal,filler,closeoff,followwrap,inline:simple smoothscroll 345call setline(1, repeat(' abc', &columns)) 346call setline(2, 'bar') 347call setline(3, repeat(' abc', &columns)) 348vnew 349call setline(1, repeat(' abc', &columns)) 350call setline(2, 'foo') 351call setline(3, 'bar') 352call setline(4, repeat(' abc', &columns)) 353windo exe "normal! 2gg5\<C-E>" 354windo diffthis 355END 356call writefile ( lines , 'XSmoothDiffChangeLine' , 'D' ) 357let buf = RunVimInTerminal ( '-S XSmoothDiffChangeLine' , #{ rows : 20 , columns : 55 }) 358 359call VerifyScreenDump ( buf , 'Test_smooth_diff_change_line_1' , {}) 360call term_sendkeys ( buf , "Abar" ) 361call VerifyScreenDump ( buf , 'Test_smooth_diff_change_line_2' , {}) 362call term_sendkeys ( buf , "\<Esc>" ) 363call VerifyScreenDump ( buf , 'Test_smooth_diff_change_line_3' , {}) 364call term_sendkeys ( buf , "yyp" ) 365call VerifyScreenDump ( buf , 'Test_smooth_diff_change_line_4' , {}) 366 367call StopVimInTerminal ( buf ) 368endfunc 369 370func Test_smoothscroll_wrap_scrolloff_zero () 371CheckScreendump 372 373let lines =<< trim END 374vim9script 375setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) 376set smoothscroll scrolloff=0 377:3 378END 379call writefile ( lines , 'XSmoothWrap' , 'D' ) 380let buf = RunVimInTerminal ( '-S XSmoothWrap' , #{ rows : 8 , cols : 40 }) 381 382call VerifyScreenDump ( buf , 'Test_smooth_wrap_1' , {}) 383 384" moving cursor down - whole bottom line shows 385call term_sendkeys ( buf , "j" ) 386call VerifyScreenDump ( buf , 'Test_smooth_wrap_2' , {}) 387 388call term_sendkeys ( buf , "\<C-E>j" ) 389call VerifyScreenDump ( buf , 'Test_smooth_wrap_3' , {}) 390 391call term_sendkeys ( buf , "G" ) 392call VerifyScreenDump ( buf , 'Test_smooth_wrap_4' , {}) 393 394call term_sendkeys ( buf , "4\<C-Y>G" ) 395call VerifyScreenDump ( buf , 'Test_smooth_wrap_4' , {}) 396 397" moving cursor up right after the <<< marker - no need to show whole line 398call term_sendkeys ( buf , "2gj3l2k" ) 399call VerifyScreenDump ( buf , 'Test_smooth_wrap_5' , {}) 400 401" moving cursor up where the <<< marker is - whole top line shows 402call term_sendkeys ( buf , "2j02k" ) 403call VerifyScreenDump ( buf , 'Test_smooth_wrap_6' , {}) 404 405call StopVimInTerminal ( buf ) 406endfunc 407 408func Test_smoothscroll_wrap_long_line () 409CheckScreendump 410 411let lines =<< trim END 412vim9script 413setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four']) 414set smoothscroll scrolloff=0 415normal 3G10|zt 416END 417call writefile ( lines , 'XSmoothWrap' , 'D' ) 418let buf = RunVimInTerminal ( '-S XSmoothWrap' , #{ rows : 6 , cols : 40 }) 419call VerifyScreenDump ( buf , 'Test_smooth_long_1' , {}) 420 421" scrolling up, cursor moves screen line down 422call term_sendkeys ( buf , "\<C-E>" ) 423call VerifyScreenDump ( buf , 'Test_smooth_long_2' , {}) 424call term_sendkeys ( buf , "5\<C-E>" ) 425call VerifyScreenDump ( buf , 'Test_smooth_long_3' , {}) 426 427" scrolling down, cursor moves screen line up 428call term_sendkeys ( buf , "5\<C-Y>" ) 429call VerifyScreenDump ( buf , 'Test_smooth_long_4' , {}) 430call term_sendkeys ( buf , "\<C-Y>" ) 431call VerifyScreenDump ( buf , 'Test_smooth_long_5' , {}) 432 433" 'scrolloff' set to 1, scrolling up, cursor moves screen line down 434call term_sendkeys ( buf , ":set scrolloff=1\<CR>" ) 435call term_sendkeys ( buf , "10|\<C-E>" ) 436call VerifyScreenDump ( buf , 'Test_smooth_long_6' , {}) 437 438" 'scrolloff' set to 1, scrolling down, cursor moves screen line up 439call term_sendkeys ( buf , "\<C-E>" ) 440call term_sendkeys ( buf , "gjgj" ) 441call term_sendkeys ( buf , "\<C-Y>" ) 442call VerifyScreenDump ( buf , 'Test_smooth_long_7' , {}) 443 444" 'scrolloff' set to 2, scrolling up, cursor moves screen line down 445call term_sendkeys ( buf , ":set scrolloff=2\<CR>" ) 446call term_sendkeys ( buf , "10|\<C-E>" ) 447call VerifyScreenDump ( buf , 'Test_smooth_long_8' , {}) 448 449" 'scrolloff' set to 2, scrolling down, cursor moves screen line up 450call term_sendkeys ( buf , "\<C-E>" ) 451call term_sendkeys ( buf , "gj" ) 452call term_sendkeys ( buf , "\<C-Y>" ) 453call VerifyScreenDump ( buf , 'Test_smooth_long_9' , {}) 454 455" 'scrolloff' set to 0, move cursor down one line. 456" Cursor should move properly, and since this is a really long line, it will 457" be put on top of the screen. 458call term_sendkeys ( buf , ":set scrolloff=0\<CR>" ) 459call term_sendkeys ( buf , "0j" ) 460call VerifyScreenDump ( buf , 'Test_smooth_long_10' , {}) 461 462" Test zt/zz/zb that they work properly when a long line is above it 463call term_sendkeys ( buf , "zt" ) 464call VerifyScreenDump ( buf , 'Test_smooth_long_11' , {}) 465call term_sendkeys ( buf , "zz" ) 466call VerifyScreenDump ( buf , 'Test_smooth_long_12' , {}) 467call term_sendkeys ( buf , "zb" ) 468call VerifyScreenDump ( buf , 'Test_smooth_long_13' , {}) 469 470" Repeat the step and move the cursor down again. 471" This time, use a shorter long line that is barely long enough to span more 472" than one window. Note that the cursor is at the bottom this time because 473" Vim prefers to do so if we are scrolling a few lines only. 474call term_sendkeys ( buf , ":call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])\<CR>" ) 475" Currently visible lines were replaced, test that the lines and cursor 476" are correctly displayed. 477call VerifyScreenDump ( buf , 'Test_smooth_long_14' , {}) 478call term_sendkeys ( buf , "3Gzt" ) 479call term_sendkeys ( buf , "j" ) 480call VerifyScreenDump ( buf , 'Test_smooth_long_15' , {}) 481 482" Repeat the step but this time start it when the line is smooth-scrolled by 483" one line. This tests that the offset calculation is still correct and 484" still end up scrolling down to the next line with cursor at bottom of 485" screen. 486call term_sendkeys ( buf , "3Gzt" ) 487call term_sendkeys ( buf , "\<C-E>j" ) 488call VerifyScreenDump ( buf , 'Test_smooth_long_16' , {}) 489 490call StopVimInTerminal ( buf ) 491endfunc 492 493func Test_smoothscroll_one_long_line () 494CheckScreendump 495 496let lines =<< trim END 497vim9script 498setline(1, 'with lots of text '->repeat(7)) 499set smoothscroll scrolloff=0 500END 501call writefile ( lines , 'XSmoothOneLong' , 'D' ) 502let buf = RunVimInTerminal ( '-S XSmoothOneLong' , #{ rows : 6 , cols : 40 }) 503call VerifyScreenDump ( buf , 'Test_smooth_one_long_1' , {}) 504 505call term_sendkeys ( buf , "\<C-E>" ) 506call VerifyScreenDump ( buf , 'Test_smooth_one_long_2' , {}) 507 508call term_sendkeys ( buf , "0" ) 509call VerifyScreenDump ( buf , 'Test_smooth_one_long_1' , {}) 510 511call StopVimInTerminal ( buf ) 512endfunc 513 514func Test_smoothscroll_long_line_showbreak () 515CheckScreendump 516 517let lines =<< trim END 518vim9script 519# a line that spans four screen lines 520setline(1, 'with lots of text in one line '->repeat(6)) 521set smoothscroll scrolloff=0 522&showbreak = '+++ ' 523END 524call writefile ( lines , 'XSmoothLongShowbreak' , 'D' ) 525let buf = RunVimInTerminal ( '-S XSmoothLongShowbreak' , #{ rows : 6 , cols : 40 }) 526call VerifyScreenDump ( buf , 'Test_smooth_long_showbreak_1' , {}) 527 528call term_sendkeys ( buf , "\<C-E>" ) 529call VerifyScreenDump ( buf , 'Test_smooth_long_showbreak_2' , {}) 530 531call term_sendkeys ( buf , "0" ) 532call VerifyScreenDump ( buf , 'Test_smooth_long_showbreak_1' , {}) 533 534call StopVimInTerminal ( buf ) 535endfunc 536 537" Check that 'smoothscroll' marker is drawn over double-width char correctly. 538" Run with multiple encodings. 539func Test_smoothscroll_marker_over_double_width () 540" Run this in a separate Vim instance to avoid messing up. 541let after =<< trim [CODE] 542scriptencoding utf-8 543call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10)) 544setlocal smoothscroll 545redraw 546exe "norm \<C-E>" 547redraw 548" Check the chars one by one. Don't check the whole line concatenated. 549call assert_equal('<', screenstring(1, 1)) 550call assert_equal('<', screenstring(1, 2)) 551call assert_equal('<', screenstring(1, 3)) 552call assert_equal(' ', screenstring(1, 4)) 553call assert_equal('口', screenstring(1, 5)) 554call assert_equal('口', screenstring(1, 7)) 555call assert_equal('口', screenstring(1, 9)) 556call assert_equal('口', screenstring(1, 11)) 557call assert_equal('口', screenstring(1, 13)) 558call assert_equal('口', screenstring(1, 15)) 559call writefile(v:errors, 'Xresult') 560qall! 561[CODE] 562 563let encodings = [ 'utf-8' , 'cp932' , 'cp936' , 'cp949' , 'cp950' ] 564if ! has ( 'win32' ) 565let encodings += [ 'euc-jp' ] 566endif 567if has ( 'nvim' ) 568let encodings = [ 'utf-8' ] 569endif 570for enc in encodings 571let msg = 'enc=' .. enc 572if RunVim ([], after , $ '--clean --cmd "set encoding={enc}"') 573call assert_equal ([], readfile ( 'Xresult' ), msg ) 574endif 575call delete ( 'Xresult' ) 576endfor 577endfunc 578 579" Same as the test above, but check the text actually shown on screen. 580" Only run with UTF-8 encoding. 581func Test_smoothscroll_marker_over_double_width_dump () 582CheckScreendump 583 584let lines =<< trim END 585call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10)) 586setlocal smoothscroll 587END 588call writefile ( lines , 'XSmoothMarkerOverDoubleWidth' , 'D' ) 589let buf = RunVimInTerminal ( '-S XSmoothMarkerOverDoubleWidth' , #{ rows : 6 , cols : 40 }) 590call VerifyScreenDump ( buf , 'Test_smooth_marker_over_double_width_1' , {}) 591 592call term_sendkeys ( buf , "\<C-E>" ) 593call VerifyScreenDump ( buf , 'Test_smooth_marker_over_double_width_2' , {}) 594 595call StopVimInTerminal ( buf ) 596endfunc 597 598func s: check_col_calc ( win_col , win_line , buf_col ) 599call assert_equal ( a: win_col , wincol ()) 600call assert_equal ( a: win_line , winline ()) 601call assert_equal ( a: buf_col , col ( '.' )) 602endfunc 603 604" Test that if the current cursor is on a smooth scrolled line, we correctly 605" reposition it. Also check that we don't miscalculate the values by checking 606" the consistency between wincol() and col('.') as they are calculated 607" separately in code. 608func Test_smoothscroll_cursor_position () 609call NewWindow ( 10 , 20 ) 610setl smoothscroll wrap 611call setline ( 1 , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ) 612 613call s: check_col_calc ( 1 , 1 , 1 ) 614exe "normal \<C-E>" 615 616" Move down another line to avoid blocking the <<< display 617call s: check_col_calc ( 1 , 2 , 41 ) 618exe "normal \<C-Y>" 619call s: check_col_calc ( 1 , 3 , 41 ) 620 621" Test "g0/g<Home>" 622exe "normal gg\<C-E>" 623norm $gkg0 624call s: check_col_calc ( 4 , 1 , 24 ) 625 626" Test moving the cursor behind the <<< display with 'virtualedit' 627set virtualedit = all 628exe "normal \<C-E>gkh" 629call s: check_col_calc ( 3 , 2 , 23 ) 630set virtualedit & 631 632normal gg3l 633exe "normal \<C-E>" 634 635" Move down only 1 line when we are out of the range of the <<< display 636call s: check_col_calc ( 4 , 1 , 24 ) 637exe "normal \<C-Y>" 638call s: check_col_calc ( 4 , 2 , 24 ) 639normal ggg$ 640exe "normal \<C-E>" 641call s: check_col_calc ( 20 , 1 , 40 ) 642exe "normal \<C-Y>" 643call s: check_col_calc ( 20 , 2 , 40 ) 644normal gg 645 646" Test number, where we have indented lines 647setl number 648call s: check_col_calc ( 5 , 1 , 1 ) 649exe "normal \<C-E>" 650 651" Move down only 1 line when the <<< display is on the number column 652call s: check_col_calc ( 5 , 1 , 17 ) 653exe "normal \<C-Y>" 654call s: check_col_calc ( 5 , 2 , 17 ) 655normal ggg$ 656exe "normal \<C-E>" 657call s: check_col_calc ( 20 , 1 , 32 ) 658exe "normal \<C-Y>" 659call s: check_col_calc ( 20 , 2 , 32 ) 660normal gg 661 662setl numberwidth = 1 663 664" Move down another line when numberwidth is too short to cover the whole 665" <<< display 666call s: check_col_calc ( 3 , 1 , 1 ) 667exe "normal \<C-E>" 668call s: check_col_calc ( 3 , 2 , 37 ) 669exe "normal \<C-Y>" 670call s: check_col_calc ( 3 , 3 , 37 ) 671normal ggl 672 673" Only move 1 line down when we are just past the <<< display 674call s: check_col_calc ( 4 , 1 , 2 ) 675exe "normal \<C-E>" 676call s: check_col_calc ( 4 , 1 , 20 ) 677exe "normal \<C-Y>" 678call s: check_col_calc ( 4 , 2 , 20 ) 679normal gg 680setl numberwidth & 681 682" Test number + showbreak, so test that the additional indentation works 683setl number showbreak = +++ 684call s: check_col_calc ( 5 , 1 , 1 ) 685exe "normal \<C-E>" 686call s: check_col_calc ( 8 , 1 , 17 ) 687exe "normal \<C-Y>" 688call s: check_col_calc ( 8 , 2 , 17 ) 689normal gg 690 691" Test number + cpo+=n mode, where wrapped lines aren't indented 692setl number cpo += nshowbreak = 693call s: check_col_calc ( 5 , 1 , 1 ) 694exe "normal \<C-E>" 695call s: check_col_calc ( 1 , 2 , 37 ) 696exe "normal \<C-Y>" 697call s: check_col_calc ( 1 , 3 , 37 ) 698normal gg 699 700" Test list + listchars "precedes", where there is always 1 overlap 701" regardless of number and cpo-=n. 702setl number list listchars = precedes:<cpo -= n 703call s: check_col_calc ( 5 , 1 , 1 ) 704exe "normal 3|\<C-E>h" 705call s: check_col_calc ( 6 , 1 , 18 ) 706norm h 707call s: check_col_calc ( 5 , 2 , 17 ) 708normal gg 709 710bwipe ! 711endfunc 712 713func Test_smoothscroll_cursor_scrolloff () 714call NewWindow ( 10 , 20 ) 715setl smoothscroll wrap 716setl scrolloff = 3 717 718" 120 chars are 6 screen lines 719call setline ( 1 , "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST" ) 720call setline ( 2 , "below" ) 721 722call s: check_col_calc ( 1 , 1 , 1 ) 723 724" CTRL-E shows "<<<DEFG...", cursor move four lines down 725exe "normal \<C-E>" 726call s: check_col_calc ( 1 , 4 , 81 ) 727 728" cursor on start of second line, "gk" moves into first line, skipcol doesn't 729" change 730exe "normal G0gk" 731call s: check_col_calc ( 1 , 5 , 101 ) 732 733" move cursor left one window width worth, scrolls one screen line 734exe "normal 20h" 735call s: check_col_calc ( 1 , 5 , 81 ) 736 737" move cursor left one window width worth, scrolls one screen line 738exe "normal 20h" 739call s: check_col_calc ( 1 , 4 , 61 ) 740 741" cursor on last line, "gk" should not cause a scroll 742set scrolloff = 0 743normal G0 744call s: check_col_calc ( 1 , 7 , 1 ) 745normal gk 746call s: check_col_calc ( 1 , 6 , 101 ) 747 748bwipe ! 749endfunc 750 751 752" Test that mouse picking is still accurate when we have smooth scrolled lines 753func Test_smoothscroll_mouse_pos () 754CheckNotGui 755CheckUnix 756 757let save_mouse = & mouse 758"let save_term = &term 759"let save_ttymouse = &ttymouse 760set mouse = a"term=xterm ttymouse=xterm2 761 762call NewWindow ( 10 , 20 ) 763setl smoothscroll wrap 764" First line will wrap to 3 physical lines. 2nd/3rd lines are short lines. 765call setline ( 1 , [ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" , "line 2" , "line 3" ]) 766 767func s: check_mouse_click ( row , col , buf_row , buf_col ) 768call MouseLeftClick ( a: row , a: col ) 769 770call assert_equal ( a: col , wincol ()) 771call assert_equal ( a: row , winline ()) 772call assert_equal ( a: buf_row , line ( '.' )) 773call assert_equal ( a: buf_col , col ( '.' )) 774endfunc 775 776" Check that clicking without scroll works first. 777call s: check_mouse_click ( 3 , 5 , 1 , 45 ) 778call s: check_mouse_click ( 4 , 1 , 2 , 1 ) 779call s: check_mouse_click ( 4 , 6 , 2 , 6 ) 780call s: check_mouse_click ( 5 , 1 , 3 , 1 ) 781call s: check_mouse_click ( 5 , 6 , 3 , 6 ) 782 783" Smooth scroll, and checks that this didn't mess up mouse clicking 784exe "normal \<C-E>" 785call s: check_mouse_click ( 2 , 5 , 1 , 45 ) 786call s: check_mouse_click ( 3 , 1 , 2 , 1 ) 787call s: check_mouse_click ( 3 , 6 , 2 , 6 ) 788call s: check_mouse_click ( 4 , 1 , 3 , 1 ) 789call s: check_mouse_click ( 4 , 6 , 3 , 6 ) 790 791exe "normal \<C-E>" 792call s: check_mouse_click ( 1 , 5 , 1 , 45 ) 793call s: check_mouse_click ( 2 , 1 , 2 , 1 ) 794call s: check_mouse_click ( 2 , 6 , 2 , 6 ) 795call s: check_mouse_click ( 3 , 1 , 3 , 1 ) 796call s: check_mouse_click ( 3 , 6 , 3 , 6 ) 797 798" Make a new first line 11 physical lines tall so it's taller than window 799" height, to test overflow calculations with really long lines wrapping. 800normal gg 801call setline ( 1 , "12345678901234567890" ->repeat ( 11 )) 802exe "normal 6\<C-E>" 803call s: check_mouse_click ( 5 , 1 , 1 , 201 ) 804call s: check_mouse_click ( 6 , 1 , 2 , 1 ) 805call s: check_mouse_click ( 7 , 1 , 3 , 1 ) 806 807let & mouse = save_mouse 808"let &term = save_term 809"let &ttymouse = save_ttymouse 810bwipe ! 811endfunc 812 813" this was dividing by zero 814func Test_smoothscroll_zero_width () 815CheckScreendump 816 817let lines =<< trim END 818winsize 0 0 819vsplit 820vsplit 821vsplit 822vsplit 823vsplit 824sil norm H 825set wrap 826set smoothscroll 827set number 828END 829call writefile ( lines , 'XSmoothScrollZero' , 'D' ) 830let buf = RunVimInTerminal ( '-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero' , #{ rows : 6 , cols : 60 , wait_for_ruler : 0 }) 831call VerifyScreenDump ( buf , 'Test_smoothscroll_zero_1' , {}) 832 833call term_sendkeys ( buf , ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>" ) 834call VerifyScreenDump ( buf , 'Test_smoothscroll_zero_2' , {}) 835 836call StopVimInTerminal ( buf ) 837endfunc 838 839" this was unnecessarily inserting lines 840func Test_smoothscroll_ins_lines () 841CheckScreendump 842 843let lines =<< trim END 844set wrap 845set smoothscroll 846set scrolloff=0 847set conceallevel=2 848call setline(1, [ 849\'line one' .. 'with lots of text in one line '->repeat(2), 850\'line two', 851\'line three', 852\'line four', 853\'line five' 854\]) 855END 856call writefile ( lines , 'XSmoothScrollInsLines' , 'D' ) 857let buf = RunVimInTerminal ( '-S XSmoothScrollInsLines' , #{ rows : 6 , cols : 40 }) 858 859call term_sendkeys ( buf , "\<C-E>gjgk" ) 860call VerifyScreenDump ( buf , 'Test_smooth_ins_lines' , {}) 861 862call StopVimInTerminal ( buf ) 863endfunc 864 865" this placed the cursor in the command line 866func Test_smoothscroll_cursormoved_line () 867CheckScreendump 868 869let lines =<< trim END 870set smoothscroll 871call setline(1, [ 872\'', 873\'_'->repeat(&lines * &columns), 874\(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2) 875\]) 876autocmd CursorMoved * eval [line('w0'), line('w$')] 877call search('xxx') 878END 879call writefile ( lines , 'XSmoothCursorMovedLine' , 'D' ) 880let buf = RunVimInTerminal ( '-S XSmoothCursorMovedLine' , #{ rows : 6 }) 881 882call VerifyScreenDump ( buf , 'Test_smooth_cursormoved_line' , {}) 883 884call StopVimInTerminal ( buf ) 885endfunc 886 887func Test_smoothscroll_eob () 888CheckScreendump 889 890let lines =<< trim END 891set smoothscroll 892call setline(1, ['']->repeat(100)) 893norm G 894END 895call writefile ( lines , 'XSmoothEob' , 'D' ) 896let buf = RunVimInTerminal ( '-S XSmoothEob' , #{ rows : 10 }) 897 898" does not scroll halfway when scrolling to end of buffer 899call VerifyScreenDump ( buf , 'Test_smooth_eob_1' , {}) 900 901" cursor is not placed below window 902call term_sendkeys ( buf , ":call setline(92, 'a'->repeat(100))\<CR>\<C-L>\<C-B>G" ) 903call VerifyScreenDump ( buf , 'Test_smooth_eob_2' , {}) 904 905call StopVimInTerminal ( buf ) 906endfunc 907 908" skipcol should not reset when doing incremental search on the same word 909func Test_smoothscroll_incsearch () 910CheckRunVimInTerminal 911 912let lines =<< trim END 913set smoothscroll number scrolloff=0 incsearch 914call setline(1, repeat([''], 20)) 915call setline(11, repeat('a', 100)) 916call setline(14, 'bbbb') 917END 918call writefile ( lines , 'XSmoothIncsearch' , 'D' ) 919let buf = RunVimInTerminal ( '-S XSmoothIncsearch' , #{ rows : 8 , cols : 40 }) 920let g: test_is_flaky = 1 921 922call term_sendkeys ( buf , "/b" ) 923call WaitForAssert ({ ->assert_match ( '^/b\s*$' , term_getline ( buf , 8 ))}, 1000 ) 924let view1 = map ( range ( 1 , 7 ), { _ , i ->term_getline ( buf , i )}) 925 926call term_sendkeys ( buf , "b" ) 927call WaitForAssert ({ ->assert_match ( '^/bb\s*$' , term_getline ( buf , 8 ))}, 1000 ) 928call assert_equal ( view1 , map ( range ( 1 , 7 ), { _ , i ->term_getline ( buf , i )})) 929 930call term_sendkeys ( buf , "b" ) 931call WaitForAssert ({ ->assert_match ( '^/bbb\s*$' , term_getline ( buf , 8 ))}, 1000 ) 932call assert_equal ( view1 , map ( range ( 1 , 7 ), { _ , i ->term_getline ( buf , i )})) 933 934call term_sendkeys ( buf , "b" ) 935call WaitForAssert ({ ->assert_match ( '^/bbbb\s*$' , term_getline ( buf , 8 ))}, 1000 ) 936call assert_equal ( view1 , map ( range ( 1 , 7 ), { _ , i ->term_getline ( buf , i )})) 937 938call term_sendkeys ( buf , "\<CR>" ) 939 940call StopVimInTerminal ( buf ) 941endfunc 942 943" Test scrolling multiple lines and stopping at non-zero skipcol. 944func Test_smoothscroll_multi_skipcol () 945CheckScreendump 946 947let lines =<< trim END 948setlocal cursorline scrolloff=0 smoothscroll 949call setline(1, repeat([''], 8)) 950call setline(3, repeat('a', 50)) 951call setline(4, repeat('a', 50)) 952call setline(7, 'bbb') 953call setline(8, 'ccc') 954redraw 955END 956call writefile ( lines , 'XSmoothMultiSkipcol' , 'D' ) 957let buf = RunVimInTerminal ( '-S XSmoothMultiSkipcol' , #{ rows : 10 , cols : 40 }) 958call VerifyScreenDump ( buf , 'Test_smooth_multi_skipcol_1' , {}) 959 960call term_sendkeys ( buf , "3\<C-E>" ) 961call VerifyScreenDump ( buf , 'Test_smooth_multi_skipcol_2' , {}) 962 963call term_sendkeys ( buf , "2\<C-E>" ) 964call VerifyScreenDump ( buf , 'Test_smooth_multi_skipcol_3' , {}) 965 966call StopVimInTerminal ( buf ) 967endfunc 968 969" this was dividing by zero bug in scroll_cursor_bot 970func Test_smoothscroll_zero_width_scroll_cursor_bot_noruler () 971CheckScreendump 972 973let lines =<< trim END 974set noruler 975silent normal yy 976silent normal 19p 977set cpoptions+=n 978vsplit 979vertical resize 0 980set foldcolumn=1 981set number 982set smoothscroll 983silent normal 20G 984END 985call writefile ( lines , 'XSmoothScrollZeroBot' , 'D' ) 986let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollZeroBot' , #{ rows : 19 }) 987call VerifyScreenDump ( buf , 'Test_smoothscroll_zero_bot' , {}) 988 989call StopVimInTerminal ( buf ) 990endfunc 991 992func Test_smoothscroll_zero_width_scroll_cursor_bot_ruler () 993CheckScreendump 994 995let lines =<< trim END 996set ruler 997silent normal yy 998silent normal 19p 999set cpoptions+=n 1000vsplit 1001vertical resize 0 1002set foldcolumn=1 1003set number 1004set smoothscroll 1005silent normal 20G 1006END 1007call writefile ( lines , 'XSmoothScrollZeroBot' , 'D' ) 1008let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollZeroBot' , #{ rows : 19 }) 1009call VerifyScreenDump ( buf , 'Test_smoothscroll_zero_bot_ruler' , {}) 1010 1011call StopVimInTerminal ( buf ) 1012endfunc 1013 1014" scroll_cursor_top() should reset skipcol when it changes topline 1015func Test_smoothscroll_cursor_top_noruler () 1016CheckScreendump 1017 1018let lines =<< trim END 1019set smoothscroll scrolloff=2 noruler 1020new | 11resize | wincmd j 1021call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4']) 1022exe "norm G3\<C-E>k" 1023END 1024call writefile ( lines , 'XSmoothScrollCursorTop' , 'D' ) 1025let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollCursorTop' , #{ rows : 12 , cols : 40 }) 1026call VerifyScreenDump ( buf , 'Test_smoothscroll_cursor_top' , {}) 1027 1028call StopVimInTerminal ( buf ) 1029endfunc 1030 1031func Test_smoothscroll_cursor_top_ruler () 1032CheckScreendump 1033 1034let lines =<< trim END 1035set smoothscroll scrolloff=2 ruler 1036new | 11resize | wincmd j 1037call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4']) 1038exe "norm G3\<C-E>k" 1039END 1040call writefile ( lines , 'XSmoothScrollCursorTop' , 'D' ) 1041let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollCursorTop' , #{ rows : 12 , cols : 40 }) 1042call VerifyScreenDump ( buf , 'Test_smoothscroll_cursor_ru_top' , {}) 1043 1044call StopVimInTerminal ( buf ) 1045endfunc 1046 1047" Division by zero, shouldn't crash 1048func Test_smoothscroll_crash () 1049CheckScreendump 1050 1051let lines =<< trim END 105220 new 1053vsp 1054put =repeat('aaaa', 20) 1055set nu fdc=1 smoothscroll cpo+=n 1056vert resize 0 1057exe "norm! 0\<c-e>" 1058END 1059call writefile ( lines , 'XSmoothScrollCrash' , 'D' ) 1060let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollCrash' , #{ rows : 12 , cols : 40 }) 1061call term_sendkeys ( buf , "2\<C-E>\<C-L>" ) 1062 1063call StopVimInTerminal ( buf ) 1064endfunc 1065 1066func Test_smoothscroll_insert_bottom_noruler () 1067CheckScreendump 1068 1069let lines =<< trim END 1070call setline(1, repeat([repeat('A very long line ...', 10)], 5)) 1071set wrap smoothscroll scrolloff=0 noruler 1072END 1073call writefile ( lines , 'XSmoothScrollInsertBottom' , 'D' ) 1074let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollInsertBottom' , #{ rows : 9 , cols : 40 }) 1075call term_sendkeys ( buf , "Go123456789\<CR>" ) 1076call VerifyScreenDump ( buf , 'Test_smoothscroll_insert_bottom' , {}) 1077 1078call StopVimInTerminal ( buf ) 1079endfunc 1080 1081func Test_smoothscroll_insert_bottom_ruler () 1082CheckScreendump 1083 1084let lines =<< trim END 1085call setline(1, repeat([repeat('A very long line ...', 10)], 5)) 1086set wrap smoothscroll scrolloff=0 ruler 1087END 1088call writefile ( lines , 'XSmoothScrollInsertBottom' , 'D' ) 1089let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollInsertBottom' , #{ rows : 9 , cols : 40 }) 1090call term_sendkeys ( buf , "Go123456789\<CR>" ) 1091call VerifyScreenDump ( buf , 'Test_smoothscroll_insert_bottom_ruler' , {}) 1092 1093call StopVimInTerminal ( buf ) 1094endfunc 1095 1096func Test_smoothscroll_in_qf_window_noruler () 1097CheckFeature quickfix 1098CheckScreendump 1099 1100let lines =<< trim END 1101set nocompatible display=lastline noruler 1102copen 5 1103setlocal number smoothscroll 1104let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10) 1105call setqflist(g:l, 'r') 1106normal! G 1107wincmd t 1108let g:l1 = [{'text': join(range(1000))}] 1109END 1110call writefile ( lines , 'XSmoothScrollInQfWindow' , 'D' ) 1111let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollInQfWindow' , #{ rows : 20 , cols : 60 }) 1112call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_1' , {}) 1113 1114call term_sendkeys ( buf , ":call setqflist([], 'r')\<CR>" ) 1115call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_2' , {}) 1116 1117call term_sendkeys ( buf , ":call setqflist(g:l, 'r')\<CR>" ) 1118call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_3' , {}) 1119 1120call term_sendkeys ( buf , ":call setqflist(g:l1, 'r')\<CR>" ) 1121call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_4' , {}) 1122 1123call term_sendkeys ( buf , "\<C-W>b$\<C-W>t" ) 1124call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_5' , {}) 1125 1126call term_sendkeys ( buf , ":call setqflist([], 'r')\<CR>" ) 1127call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_2' , {}) 1128 1129call term_sendkeys ( buf , ":call setqflist(g:l1, 'r')\<CR>" ) 1130call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_4' , {}) 1131 1132call term_sendkeys ( buf , "\<C-W>b$\<C-W>t" ) 1133call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_5' , {}) 1134 1135call term_sendkeys ( buf , ":call setqflist(g:l, 'r')\<CR>" ) 1136call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_3' , {}) 1137 1138call StopVimInTerminal ( buf ) 1139endfunc 1140 1141func Test_smoothscroll_in_qf_window_ruler () 1142CheckFeature quickfix 1143CheckScreendump 1144 1145let lines =<< trim END 1146set nocompatible display=lastline ruler 1147copen 5 1148setlocal number smoothscroll 1149let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10) 1150call setqflist(g:l, 'r') 1151normal! G 1152wincmd t 1153let g:l1 = [{'text': join(range(1000))}] 1154END 1155call writefile ( lines , 'XSmoothScrollInQfWindow' , 'D' ) 1156let buf = RunVimInTerminal ( '-u NONE -S XSmoothScrollInQfWindow' , #{ rows : 20 , cols : 60 }) 1157call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_1' , {}) 1158 1159call term_sendkeys ( buf , ":call setqflist([], 'r')\<CR>" ) 1160call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_2' , {}) 1161 1162call term_sendkeys ( buf , ":call setqflist(g:l, 'r')\<CR>" ) 1163call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_3' , {}) 1164 1165call term_sendkeys ( buf , ":call setqflist(g:l1, 'r')\<CR>" ) 1166call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_4' , {}) 1167 1168call term_sendkeys ( buf , "\<C-W>b$\<C-W>t" ) 1169call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_5' , {}) 1170 1171call term_sendkeys ( buf , ":call setqflist([], 'r')\<CR>" ) 1172call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_2' , {}) 1173 1174call term_sendkeys ( buf , ":call setqflist(g:l1, 'r')\<CR>" ) 1175call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_4' , {}) 1176 1177call term_sendkeys ( buf , "\<C-W>b$\<C-W>t" ) 1178call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_5' , {}) 1179 1180call term_sendkeys ( buf , ":call setqflist(g:l, 'r')\<CR>" ) 1181call VerifyScreenDump ( buf , 'Test_smoothscroll_in_qf_window_ru_3' , {}) 1182 1183call StopVimInTerminal ( buf ) 1184endfunc 1185 1186func Test_smoothscroll_in_zero_width_window () 1187set cpo += nnumber smoothscroll 1188set winwidth = 99999 winminwidth = 0 1189 1190vsplit 1191call assert_equal ( 0 , winwidth ( winnr ( '#' ))) 1192call win_execute ( win_getid ( winnr ( '#' )), "norm! \<C-Y>" ) 1193 1194only ! 1195set winwidth & winminwidth & 1196set cpo -= nnonumber nosmoothscroll 1197endfunc 1198 1199func Test_smoothscroll_textoff_small_winwidth () 1200set smoothscroll number 1201call setline ( 1 , 'llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch' ) 1202vsplit 1203 1204let textoff = getwininfo ( win_getid ())[ 0 ]. textoff 1205execute 'vertical resize' textoff + 1 1206redraw 1207call assert_equal ( 0 , winsaveview (). skipcol ) 1208execute "normal! 0\<C-E>" 1209redraw 1210call assert_equal ( 1 , winsaveview (). skipcol ) 1211execute 'vertical resize' textoff - 1 1212" This caused a signed integer overflow. 1213redraw 1214call assert_equal ( 1 , winsaveview (). skipcol ) 1215execute 'vertical resize' textoff 1216" This caused an infinite loop. 1217redraw 1218call assert_equal ( 1 , winsaveview (). skipcol ) 1219 1220 %bw ! 1221set smoothscroll & number & 1222endfunc 1223 1224func Test_smoothscroll_page () 1225call NewWindow ( 10 , 40 ) 1226setlocal smoothscroll 1227call setline ( 1 , 'abcde ' ->repeat ( 150 )) 1228 1229exe "norm! \<C-F>" 1230call assert_equal ( 400 , winsaveview (). skipcol ) 1231exe "norm! \<C-F>" 1232call assert_equal ( 800 , winsaveview (). skipcol ) 1233exe "norm! \<C-F>" 1234call assert_equal ( 880 , winsaveview (). skipcol ) 1235exe "norm! \<C-B>" 1236call assert_equal ( 480 , winsaveview (). skipcol ) 1237exe "norm! \<C-B>" 1238call assert_equal ( 80 , winsaveview (). skipcol ) 1239exe "norm! \<C-B>" 1240call assert_equal ( 0 , winsaveview (). skipcol ) 1241 1242" Half-page scrolling does not go beyond end of buffer and moves the cursor. 1243" Even with 'nostartofline', the correct amount of lines is scrolled. 1244setl nostartofline 1245exe "norm! 15|\<C-D>" 1246call assert_equal ( 200 , winsaveview (). skipcol ) 1247call assert_equal ( 215 , col ( '.' )) 1248exe "norm! \<C-D>" 1249call assert_equal ( 400 , winsaveview (). skipcol ) 1250call assert_equal ( 415 , col ( '.' )) 1251exe "norm! \<C-D>" 1252call assert_equal ( 520 , winsaveview (). skipcol ) 1253call assert_equal ( 615 , col ( '.' )) 1254exe "norm! \<C-D>" 1255call assert_equal ( 520 , winsaveview (). skipcol ) 1256call assert_equal ( 815 , col ( '.' )) 1257exe "norm! \<C-D>" 1258call assert_equal ( 520 , winsaveview (). skipcol ) 1259call assert_equal ( 895 , col ( '.' )) 1260exe "norm! \<C-U>" 1261call assert_equal ( 320 , winsaveview (). skipcol ) 1262call assert_equal ( 695 , col ( '.' )) 1263exe "norm! \<C-U>" 1264call assert_equal ( 120 , winsaveview (). skipcol ) 1265call assert_equal ( 495 , col ( '.' )) 1266exe "norm! \<C-U>" 1267call assert_equal ( 0 , winsaveview (). skipcol ) 1268call assert_equal ( 295 , col ( '.' )) 1269exe "norm! \<C-U>" 1270call assert_equal ( 0 , winsaveview (). skipcol ) 1271call assert_equal ( 95 , col ( '.' )) 1272exe "norm! \<C-U>" 1273call assert_equal ( 0 , winsaveview (). skipcol ) 1274call assert_equal ( 15 , col ( '.' )) 1275 1276bwipe ! 1277endfunc 1278 1279func Test_smoothscroll_next_topline () 1280call NewWindow ( 10 , 40 ) 1281setlocal smoothscroll 1282call setline ( 1 , [ 'abcde ' ->repeat ( 150 )] ->repeat ( 2 )) 1283 1284" Scrolling a screenline that causes the cursor to move to the next buffer 1285" line should not skip part of that line to bring the cursor into view. 1286exe "norm! 22\<C-E>" 1287call assert_equal ( 880 , winsaveview (). skipcol ) 1288exe "norm! \<C-E>" 1289redraw 1290call assert_equal ( 0 , winsaveview (). skipcol ) 1291 1292" Also when scrolling back. 1293exe "norm! G\<C-Y>" 1294redraw 1295call assert_equal ( 880 , winsaveview (). skipcol ) 1296 1297" Cursor in correct place when not in the first screenline of a buffer line. 1298exe "norm! gg4gj20\<C-D>\<C-D>" 1299redraw 1300call assert_equal ( 2 , line ( 'w0' )) 1301 1302" Cursor does not end up above topline, adjusting topline later. 1303setlocal nu cpo += n 1304exe "norm! G$g013\<C-Y>" 1305redraw 1306call assert_equal ( 2 , line ( '.' )) 1307call assert_equal ( 0 , winsaveview (). skipcol ) 1308 1309set cpo -= n 1310bwipe ! 1311endfunc 1312 1313func Test_smoothscroll_keep_skipcol () 1314call NewWindow ( 10 , 40 ) 1315setlocal smoothscroll 1316call setline ( 1 , [ 'abcde ' ->repeat ( 150 )] ->repeat ( 2 )) 1317 1318exe "norm! 10\<C-E>" 1319redraw 1320let skipcol = winsaveview (). skipcol 1321call assert_notequal ( 0 , skipcol ) 1322 1323" Changing the height of the window must not reset the scroll position. 1324resize -3 1325resize +3 1326redraw 1327call assert_equal ( skipcol , winsaveview (). skipcol ) 1328 1329" Using the autocommand window changes the height as well. 1330call bufload ( bufadd ( '' )) 1331redraw 1332call assert_equal ( skipcol , winsaveview (). skipcol ) 1333 1334bwipe ! 1335endfunc 1336 1337func Test_smoothscroll_cursor_back_in_line () 1338call NewWindow ( 10 , 40 ) 1339setlocal smoothscroll 1340call setline ( 1 , [ 'abcde ' ->repeat ( 150 )] ->repeat ( 2 )) 1341 1342exe "norm! 10\<C-E>" 1343redraw 1344call assert_equal ( 400 , winsaveview (). skipcol ) 1345 1346" Moving to an earlier column in the same line scrolls back only as far as 1347" needed, not all the way to the start of the line. 1348norm ! 240| 1349redraw 1350call assert_equal ( 200 , winsaveview (). skipcol ) 1351call assert_equal ( 1 , winline ()) 1352 1353bwipe ! 1354endfunc 1355 1356func Test_smoothscroll_squeezed_window () 1357setlocal smoothscroll 1358call setline ( 1 , [ repeat ( 'x' , 3000 )] + repeat ([ 'line' ], 10 )) 1359exe "norm! gg10\<C-E>" 1360redraw 1361let skipcol = winsaveview (). skipcol 1362call assert_notequal ( 0 , skipcol ) 1363let virtcol = virtcol ( '.' ) 1364 1365" Squeezing the window to one line and restoring it must not scroll back to 1366" the start of the line. 1367new 1368wincmd _ 1369close 1370redraw 1371call assert_notequal ( 0 , winsaveview (). skipcol ) 1372call assert_equal ( virtcol , virtcol ( '.' )) 1373 1374bwipe ! 1375endfunc 1376 1377func Test_smoothscroll_long_line_zb () 1378call NewWindow ( 10 , 40 ) 1379call setline ( 1 , 'abcde ' ->repeat ( 150 )) 1380 1381" Also works without 'smoothscroll' when last line of buffer doesn't fit. 1382" Used to set topline to buffer line count plus one, causing an empty screen. 1383norm zb 1384redraw 1385call assert_equal ( 1 , winsaveview (). topline ) 1386 1387" Moving cursor to bottom works on line that doesn't fit with 'smoothscroll'. 1388" Skipcol was adjusted later for cursor being on not visible part of line. 1389setlocal smoothscroll 1390norm zb 1391redraw 1392call assert_equal ( 520 , winsaveview (). skipcol ) 1393 1394bwipe ! 1395endfunc 1396 1397func Test_smooth_long_scrolloff_noruler () 1398CheckScreendump 1399 1400let lines =<< trim END 1401set smoothscroll scrolloff=3 1402set noruler 1403call setline(1, ['one', 'two long '->repeat(100), 'three', 'four', 'five', 'six']) 1404END 1405call writefile ( lines , 'XSmoothLongScrolloff' , 'D' ) 1406let buf = RunVimInTerminal ( '-u NONE -S XSmoothLongScrolloff' , #{ rows : 8 , cols : 40 }) 1407call term_sendkeys ( buf , ":norm j721|\<CR>" ) 1408call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_1' , {}) 1409 1410call term_sendkeys ( buf , "gj" ) 1411call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_2' , {}) 1412 1413call term_sendkeys ( buf , "gj" ) 1414call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_3' , {}) 1415 1416call term_sendkeys ( buf , "gj" ) 1417call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_4' , {}) 1418 1419call term_sendkeys ( buf , "gj" ) 1420call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_5' , {}) 1421 1422call term_sendkeys ( buf , "gj" ) 1423call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_6' , {}) 1424 1425call term_sendkeys ( buf , "gk" ) 1426call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_7' , {}) 1427 1428call StopVimInTerminal ( buf ) 1429endfunc 1430 1431func Test_smooth_long_scrolloff_ruler () 1432CheckScreendump 1433 1434let lines =<< trim END 1435set smoothscroll scrolloff=3 ruler 1436call setline(1, ['one', 'two long '->repeat(100), 'three', 'four', 'five', 'six']) 1437END 1438call writefile ( lines , 'XSmoothLongScrolloff' , 'D' ) 1439let buf = RunVimInTerminal ( '-u NONE -S XSmoothLongScrolloff' , #{ rows : 8 , cols : 40 }) 1440call term_sendkeys ( buf , ":norm j721|\<CR>" ) 1441call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_ru_1' , {}) 1442 1443call term_sendkeys ( buf , "gj" ) 1444call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_ru_2' , {}) 1445 1446call term_sendkeys ( buf , "gj" ) 1447call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_ru_3' , {}) 1448 1449call term_sendkeys ( buf , "gj" ) 1450call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_ru_4' , {}) 1451 1452call term_sendkeys ( buf , "gj" ) 1453call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_ru_5' , {}) 1454 1455call term_sendkeys ( buf , "gj" ) 1456call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_ru_6' , {}) 1457 1458call term_sendkeys ( buf , "gk" ) 1459call VerifyScreenDump ( buf , 'Test_smooth_long_scrolloff_ru_7' , {}) 1460 1461call StopVimInTerminal ( buf ) 1462endfunc 1463 1464func Test_smoothscroll_listchars_eol () 1465call NewWindow ( 10 , 40 ) 1466setlocal list listchars = eol:$scrolloff = 0 smoothscroll 1467call setline ( 1 , repeat ( '-' , 40 )) 1468call append ( 1 , repeat ([ 'foobar' ], 10 )) 1469 1470normal ! G 1471call assert_equal ( 2 , line ( 'w0' )) 1472call assert_equal ( 0 , winsaveview (). skipcol ) 1473 1474exe "normal! \<C-Y>" 1475call assert_equal ( 1 , line ( 'w0' )) 1476call assert_equal ( 40 , winsaveview (). skipcol ) 1477 1478exe "normal! \<C-Y>" 1479call assert_equal ( 1 , line ( 'w0' )) 1480call assert_equal ( 0 , winsaveview (). skipcol ) 1481 1482exe "normal! \<C-Y>" 1483call assert_equal ( 1 , line ( 'w0' )) 1484call assert_equal ( 0 , winsaveview (). skipcol ) 1485 1486exe "normal! \<C-E>" 1487call assert_equal ( 1 , line ( 'w0' )) 1488call assert_equal ( 40 , winsaveview (). skipcol ) 1489 1490exe "normal! \<C-E>" 1491call assert_equal ( 2 , line ( 'w0' )) 1492call assert_equal ( 0 , winsaveview (). skipcol ) 1493 1494for ve in [ '' , 'all' , 'onemore' ] 1495let & virtualedit = ve 1496normal ! gg 1497call assert_equal ( 1 , line ( 'w0' )) 1498call assert_equal ( 0 , winsaveview (). skipcol ) 1499 1500exe "normal! \<C-E>" 1501redraw " redrawing should not cause another scroll 1502call assert_equal ( 1 , line ( 'w0' )) 1503call assert_equal ( 40 , winsaveview (). skipcol ) 1504 1505exe "normal! \<C-E>" 1506redraw 1507call assert_equal ( 2 , line ( 'w0' )) 1508call assert_equal ( 0 , winsaveview (). skipcol ) 1509 1510if ve != 'all' 1511call assert_equal ([ 0 , 2 , 1 , 0 ], getpos ( '.' )) 1512endif 1513endfor 1514 1515set virtualedit & 1516bwipe ! 1517endfunc 1518 1519" scrolloffpad contract: 1520" - augment scrolloff only under EOF pressure (insufficient real lines below); 1521" - do not change explicit "z" viewport placement command semantics; 1522" - current scope is EOF-only, so BOF behavior remains unchanged. 1523func Test_scrolloffpad_zb_keeps_bottom_command_semantics () 1524new 1525resize 12 1526setlocal scrolloff = 10 1527call setline ( 1 , map ( range ( 1 , 300 ), 'printf("line %d", v:val)' )) 1528 1529setlocal scrolloffpad = 0 1530normal ! gg150Gzb 1531let baseline = [ line ( '.' ), line ( 'w$' ), winline ()] 1532 1533setlocal scrolloffpad = 1 1534normal ! gg150Gzb 1535call assert_equal ( baseline , [ line ( '.' ), line ( 'w$' ), winline ()]) 1536 1537bwipe ! 1538endfunc 1539 1540func Test_scrolloffpad_zminus_keeps_bottom_beginline_semantics () 1541new 1542resize 12 1543setlocal scrolloff = 10 1544call setline ( 1 , map ( range ( 1 , 300 ), 'printf(" line %d", v:val)' )) 1545 1546setlocal scrolloffpad = 0 1547normal ! gg150Gz- 1548let baseline = [ line ( '.' ), line ( 'w$' ), winline (), col ( '.' )] 1549call assert_equal ( match ( getline ( '.' ), '\S' ) + 1 , col ( '.' )) 1550 1551setlocal scrolloffpad = 1 1552normal ! gg150Gz- 1553call assert_equal ( baseline , [ line ( '.' ), line ( 'w$' ), winline (), col ( '.' )]) 1554call assert_equal ( match ( getline ( '.' ), '\S' ) + 1 , col ( '.' )) 1555 1556bwipe ! 1557endfunc 1558 1559func Test_scrolloffpad_zb_is_one_shot_then_scrolloff_reapplies () 1560new 1561resize 12 1562setlocal scrolloff = 10 1563call setline ( 1 , map ( range ( 1 , 300 ), 'printf("line %d", v:val)' )) 1564 1565let after_zb = {} 1566let after_j = {} 1567for sop in [ 0 , 1 ] 1568let & l: scrolloffpad = sop 1569normal ! gg150Gzb 1570let after_zb [ sop ] = [ line ( '.' ), line ( 'w$' ), winline (), winsaveview (). topline ] 1571 1572normal ! j 1573let after_j [ sop ] = [ line ( '.' ), line ( 'w$' ), winline (), winsaveview (). topline ] 1574call assert_notequal ( after_zb [ sop ][ 3 ], after_j [ sop ][ 3 ]) 1575call assert_true ( line ( '.' ) < line ( 'w$' )) 1576endfor 1577call assert_equal ( after_zb [ 0 ], after_zb [ 1 ]) 1578call assert_equal ( after_j [ 0 ], after_j [ 1 ]) 1579 1580bwipe ! 1581endfunc 1582 1583func Test_scrolloffpad_has_no_mid_buffer_effect () 1584new 1585resize 12 1586setlocal scrolloff = 10 scrolloffpad = 0 1587call setline ( 1 , map ( range ( 1 , 500 ), 'printf("line %d", v:val)' )) 1588 1589normal ! gg150G 1590let topline_without_pad = winsaveview (). topline 1591 1592setlocal scrolloffpad = 1 1593normal ! gg150G 1594let topline_with_pad = winsaveview (). topline 1595 1596call assert_equal ( topline_without_pad , topline_with_pad ) 1597 1598bwipe ! 1599endfunc 1600 1601func Test_scrolloffpad_changes_eof_pressure_only () 1602new 1603resize 12 1604setlocal scrolloff = 10 scrolloffpad = 0 1605call setline ( 1 , map ( range ( 1 , 200 ), 'printf("line %d", v:val)' )) 1606 1607normal ! ggG 1608let view_without_pad = winsaveview () 1609let cursor_without_pad = line ( '.' ) 1610let row_without_pad = winline () 1611 1612setlocal scrolloffpad = 1 1613normal ! ggG 1614let view_with_pad = winsaveview () 1615let row_with_pad = winline () 1616 1617call assert_equal ( line ( '$' ), line ( '.' )) 1618call assert_equal ( cursor_without_pad , line ( '.' )) 1619call assert_notequal ( view_without_pad . topline , view_with_pad . topline ) 1620call assert_true ( row_with_pad < row_without_pad ) 1621 1622bwipe ! 1623endfunc 1624 1625func Test_scrolloffpad_large_scrolloff_no_overflow () 1626new 1627resize 12 1628call setline ( 1 , map ( range ( 1 , 200 ), 'printf("line %d", v:val)' )) 1629setlocal scrolloff = 2147483647 scrolloffpad = 0 1630 1631normal ! ggG 1632let view_without_pad = winsaveview () 1633let row_without_pad = winline () 1634 1635setlocal scrolloffpad = 1 1636normal ! ggG 1637let view_with_pad = winsaveview () 1638let row_with_pad = winline () 1639 1640call assert_equal ( line ( '$' ), line ( '.' )) 1641call assert_notequal ( view_without_pad . topline , view_with_pad . topline ) 1642call assert_true ( row_with_pad < row_without_pad ) 1643 1644bwipe ! 1645endfunc 1646 1647func Test_scrolloffpad_boolean_gate_values () 1648new 1649resize 12 1650setlocal scrolloff = 10 1651call setline ( 1 , map ( range ( 1 , 200 ), 'printf("line %d", v:val)' )) 1652 1653let views = {} 1654let rows = {} 1655for sop in [ 0 , 1 , 2 ] 1656let & l: scrolloffpad = sop 1657normal ! ggG 1658let views [ sop ] = winsaveview () 1659let rows [ sop ] = winline () 1660call assert_equal ( line ( '$' ), line ( '.' )) 1661endfor 1662 1663call assert_equal ( views [ 1 ]. topline , views [ 2 ]. topline ) 1664call assert_equal ( rows [ 1 ], rows [ 2 ]) 1665call assert_notequal ( views [ 0 ]. topline , views [ 1 ]. topline ) 1666call assert_true ( rows [ 1 ] < rows [ 0 ]) 1667 1668bwipe ! 1669endfunc 1670 1671func Test_scrolloffpad_requires_scrolloff_nonzero () 1672new 1673resize 12 1674call setline ( 1 , map ( range ( 1 , 200 ), 'printf("line %d", v:val)' )) 1675 1676let states = {} 1677for so in [ 0 , 10 ] 1678let states [ so ] = {} 1679for sop in [ 0 , 1 ] 1680let & l: scrolloff = so 1681let & l: scrolloffpad = sop 1682normal ! ggG 1683let states [ so ][ sop ] = [ line ( '.' ), line ( 'w0' ), line ( 'w$' ), winline ()] 1684call assert_equal ( line ( '$' ), line ( '.' )) 1685endfor 1686endfor 1687 1688call assert_equal ( states [ 0 ][ 0 ], states [ 0 ][ 1 ]) 1689call assert_notequal ( states [ 10 ][ 0 ], states [ 10 ][ 1 ]) 1690call assert_true ( states [ 10 ][ 1 ][ 3 ] < states [ 10 ][ 0 ][ 3 ]) 1691 1692bwipe ! 1693endfunc 1694 1695func Test_scrolloffpad_search_to_eof () 1696new 1697resize 12 1698setlocal scrolloff = 10 1699call setline ( 1 , map ( range ( 1 , 200 ), 'printf("line %d", v:val)' )) 1700call setline ( line ( '$' ), 'EOF TARGET' ) 1701 1702let states = {} 1703for sop in [ 0 , 1 ] 1704let & l: scrolloffpad = sop 1705normal ! gg 1706call assert_true ( search ( 'EOF TARGET' ) > 0 ) 1707let states [ sop ] = [ line ( '.' ), line ( 'w0' ), line ( 'w$' ), winline ()] 1708call assert_equal ( line ( '$' ), line ( '.' )) 1709endfor 1710 1711call assert_notequal ( states [ 0 ], states [ 1 ]) 1712call assert_true ( states [ 1 ][ 3 ] < states [ 0 ][ 3 ]) 1713 1714bwipe ! 1715endfunc 1716 1717func Test_scrolloffpad_paging_to_eof () 1718new 1719resize 12 1720setlocal scrolloff = 10 1721call setline ( 1 , map ( range ( 1 , 240 ), 'printf("line %d", v:val)' )) 1722 1723let states = {} 1724for sop in [ 0 , 1 ] 1725let & l: scrolloffpad = sop 1726normal ! gg 1727 1728let prev = -1 1729for _ in range ( 1 , 200 ) 1730execute "normal! \<C-D>" 1731if line ( '.' ) == prev 1732break 1733endif 1734let prev = line ( '.' ) 1735endfor 1736 1737let states [ sop ] = [ line ( '.' ), line ( 'w0' ), line ( 'w$' ), winline ()] 1738call assert_equal ( line ( '$' ), line ( 'w$' )) 1739endfor 1740 1741call assert_notequal ( states [ 0 ], states [ 1 ]) 1742call assert_true ( states [ 1 ][ 3 ] < states [ 0 ][ 3 ]) 1743 1744bwipe ! 1745endfunc 1746 1747func Test_scrolloffpad_ctrl_d_at_eof () 1748new 1749setlocal scroll = 6 1750call setline ( 1 , map ( range ( 1 , 80 ), 'printf("line %d", v:val)' )) 1751 1752for height in [ 11 , 12 ] 1753execute 'resize ' .. height 1754for so in [ 1 , 999 ] 1755let & l: scrolloff = so 1756for sop in [ 0 , 1 ] 1757let & l: scrolloffpad = sop 1758for endcmd in [ 'ggG' , 'ggGzb' ] 1759let context = printf ( 'height=%d so=%d sop=%d %s' , 1760\ height , so , sop , endcmd ) 1761execute 'normal! ' .. endcmd 1762let view_before = winsaveview () 1763 1764call assert_beeps ( 'execute "normal! \<C-D>"' ) 1765call assert_equal ( view_before , winsaveview (), context ) 1766endfor 1767endfor 1768endfor 1769endfor 1770 1771bwipe ! 1772endfunc 1773 1774func Test_scrolloffpad_ctrl_e_at_eof () 1775new 1776call setline ( 1 , map ( range ( 1 , 80 ), 'printf("line %d", v:val)' )) 1777 1778for height in [ 11 , 12 ] 1779execute 'resize ' .. height 1780for so in [ 1 , 999 ] 1781let & l: scrolloff = so 1782for sop in [ 0 , 1 ] 1783let & l: scrolloffpad = sop 1784for endcmd in [ 'ggG' , 'ggGzb' ] 1785let context = printf ( 'height=%d so=%d sop=%d %s' , 1786\ height , so , sop , endcmd ) 1787execute 'normal! ' .. endcmd 1788let expected_view = winsaveview () 1789let expected_view . topline += 1 1790 1791execute "normal! \<C-E>" 1792call assert_equal ( expected_view , winsaveview (), context ) 1793endfor 1794endfor 1795endfor 1796endfor 1797 1798bwipe ! 1799endfunc 1800 1801func Test_scrolloffpad_autocmd_append_at_eof () 1802let states = {} 1803for sop in [ 0 , 1 ] 1804new 1805resize 12 1806setlocal scrolloff = 10 1807let & l: scrolloffpad = sop 1808call setline ( 1 , map ( range ( 1 , 120 ), 'printf("line %d", v:val)' )) 1809 1810let b: scrolloffpad_appended = 0 1811augroup ScrolloffpadAppendAtEof 1812autocmd ! 1813autocmd CursorMoved <buffer> if b: scrolloffpad_appended == 0 && line ( '.' ) == line ( '$' ) | call append ( '$' , 'appended' ) | let b: scrolloffpad_appended = 1 | endif 1814augroup END 1815 1816normal ! ggG 1817doautocmd <nomodeline> CursorMoved 1818let states [ sop ] = [ 1819\ line ( '.' ), 1820\ line ( '$' ), 1821\ line ( 'w0' ), 1822\ line ( 'w$' ), 1823\ winline (), 1824\ b: scrolloffpad_appended , 1825\ ] 1826 1827call assert_equal ( 1 , b: scrolloffpad_appended ) 1828call assert_equal ( states [ sop ][ 1 ] - 1 , states [ sop ][ 0 ]) 1829 1830augroup ScrolloffpadAppendAtEof 1831autocmd ! 1832augroup END 1833bwipe ! 1834endfor 1835 1836call assert_notequal ( states [ 0 ], states [ 1 ]) 1837call assert_true ( states [ 1 ][ 4 ] < states [ 0 ][ 4 ]) 1838 1839endfunc 1840 1841func Test_scrolloffpad_eof_no_reverse_scroll_on_j () 1842new 1843resize 20 1844setlocal scrolloff = 20 scrolloffpad = 1 1845call setline ( 1 , map ( range ( 1 , 80 ), 'printf("line %d", v:val)' )) 1846 1847normal ! gg 1848let prev_topline = winsaveview (). topline 1849for lnum in range ( 2 , line ( '$' )) 1850normal ! j 1851let cur_topline = winsaveview (). topline 1852call assert_true ( 1853\ cur_topline >= prev_topline , 1854\ printf ( 'topline moved backwards at line %d: %d -> %d' , 1855\ lnum , prev_topline , cur_topline )) 1856let prev_topline = cur_topline 1857endfor 1858 1859bwipe ! 1860endfunc 1861 1862func Test_scrolloffpad_bof_unchanged () 1863new 1864resize 12 1865setlocal scrolloff = 10 scrolloffpad = 0 1866call setline ( 1 , map ( range ( 1 , 200 ), 'printf("line %d", v:val)' )) 1867 1868normal ! Ggg 1869let view_without_pad = winsaveview () 1870let w0_without_pad = line ( 'w0' ) 1871 1872setlocal scrolloffpad = 1 1873normal ! Ggg 1874let view_with_pad = winsaveview () 1875let w0_with_pad = line ( 'w0' ) 1876 1877call assert_equal ( 1 , w0_without_pad ) 1878call assert_equal ( 1 , w0_with_pad ) 1879call assert_equal ( view_without_pad . topline , view_with_pad . topline ) 1880 1881bwipe ! 1882endfunc 1883 1884func Test_scrolloffpad_mouse_drag_uses_drag_scrolloff () 1885CheckFeature mouse 1886 1887let save_mouse = & mouse 1888set mouse = a 1889 1890new 1891resize 20 1892call setline ( 1 , map ( range ( 1 , 240 ), 'printf("line %d", v:val)' )) 1893setlocal scrolloff = 50 1894 1895let after_drag = {} 1896for sop in [ 0 , 1 ] 1897let & l: scrolloffpad = sop 1898normal ! gg160Gzt 1899normal ! v 1900call Ntest_setmouse ( 2 , 1 ) 1901call feedkeys ( "\<LeftMouse>" , 'xt' ) 1902call Ntest_setmouse ( 3 , 1 ) 1903call feedkeys ( "\<LeftDrag>" , 'xt' ) 1904let after_drag [ sop ] = [ winsaveview (). topline , line ( '.' ), winline ()] 1905call feedkeys ( "\<Esc>" , 'xt' ) 1906endfor 1907 1908call assert_equal ( after_drag [ 0 ], after_drag [ 1 ]) 1909 1910bwipe ! 1911let & mouse = save_mouse 1912endfunc 1913 1914func Test_scrolloffpad_basic () 1915CheckScreendump 1916CheckRunVimInTerminal 1917 1918let save_termwinsize = & termwinsize 1919set termwinsize = 1920 1921let lines =<< trim END 1922set scrolloff=10 1923set scrolloffpad=5 1924enew! 1925call setline(1, map(range(1, 100), 'printf("line %d", v:val)')) 1926normal! gg 1927END 1928call writefile ( lines , 'XScrolloffpadBasic' , 'D' ) 1929 1930let buf = RunVimInTerminal ( '-S XScrolloffpadBasic' , { 'rows' : 20 , 'cols' : 78 }) 1931 1932" Enabled: scrolloffpad > 0, expect EOF centering/padding 1933call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! G\<CR>" ) 1934call term_sendkeys ( buf , "\<C-L>" ) 1935call TermWait ( buf ) 1936call VerifyScreenDump ( buf , 'Test_scrolloffpad_basic_1' , {}) 1937 1938" Beginning-of-file is unchanged (Top) 1939call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! gg\<CR>" ) 1940call term_sendkeys ( buf , "\<C-L>" ) 1941call TermWait ( buf ) 1942call VerifyScreenDump ( buf , 'Test_scrolloffpad_basic_2' , {}) 1943 1944" Gating: disable scrolloffpad, then go to EOF again 1945" Expect normal EOF behavior (no extra centering/padding) 1946call term_sendkeys ( buf , "\<Esc>:\<C-U>set scrolloffpad=0\<CR>" ) 1947call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! G\<CR>" ) 1948call term_sendkeys ( buf , "\<C-L>" ) 1949call TermWait ( buf ) 1950call VerifyScreenDump ( buf , 'Test_scrolloffpad_basic_3' , {}) 1951 1952call StopVimInTerminal ( buf ) 1953let & termwinsize = save_termwinsize 1954endfunc 1955 1956func Test_scrolloffpad_smoothscroll () 1957CheckScreendump 1958CheckRunVimInTerminal 1959 1960let save_termwinsize = & termwinsize 1961set termwinsize = 1962 1963let lines =<< trim END 1964set smoothscroll scrolloff=10 scrolloffpad=1 1965enew! 1966call setline(1, map(range(1, 100), 'printf("line %d", v:val)')) 1967normal! gg 1968END 1969call writefile ( lines , 'XScrolloffpadSmoothscroll' , 'D' ) 1970 1971let buf = RunVimInTerminal ( '-S XScrolloffpadSmoothscroll' , #{ rows : 20 , cols : 78 }) 1972 1973call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! G\<CR>" ) 1974call term_sendkeys ( buf , "\<C-L>" ) 1975call TermWait ( buf ) 1976call VerifyScreenDump ( buf , 'Test_scrolloffpad_smoothscroll_1' , {}) 1977 1978call term_sendkeys ( buf , "\<Esc>:\<C-U>call setline(line('$'), repeat('LONG ', 30))\<CR>" ) 1979call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! 41|\<CR>" ) 1980call term_sendkeys ( buf , "\<C-L>" ) 1981call TermWait ( buf ) 1982call VerifyScreenDump ( buf , 'Test_scrolloffpad_smoothscroll_2' , {}) 1983 1984call StopVimInTerminal ( buf ) 1985let & termwinsize = save_termwinsize 1986endfunc 1987 1988func Test_scrolloffpad_insert_eof () 1989let save_so = & scrolloff 1990let save_sop = & scrolloffpad 1991 1992set scrolloff = 10 scrolloffpad = 1 1993enew ! 1994call setline ( 1 , map ( range ( 1 , 200 ), 'printf("line %d", v:val)' )) 1995normal ! G 1996 1997let topline_before = winsaveview (). topline 1998call feedkeys ( "i\<Esc>" , 'xt' ) 1999call assert_equal ( topline_before , winsaveview (). topline ) 2000 2001exe "normal! \<C-E>" 2002let topline_after = winsaveview (). topline 2003call feedkeys ( "i\<Esc>" , 'xt' ) 2004call assert_equal ( topline_after , winsaveview (). topline ) 2005 2006let & scrolloff = save_so 2007let & scrolloffpad = save_sop 2008bwipe ! 2009endfunc 2010 2011func Test_scrolloffpad_in_diff_mode () 2012CheckFeature diff 2013 2014let save_so = & scrolloff 2015let save_sop = & scrolloffpad 2016let save_splitright = & splitright 2017 2018set nosplitright 2019set scrolloff = 10 2020set scrolloffpad = 0 2021 2022enew 2023call setline ( 1 , map ( range ( 1 , 100 ), { _ , v -> 'line ' .. v })) 2024diffthis 2025 2026vnew 2027call setline ( 1 , map ( range ( 1 , 100 ), { _ , v -> 'line ' .. v })) 2028" Make buffers minimally different to avoid diff folding everything. 2029call setline ( 50 , 'DIFF LINE 50' ) 2030diffthis 2031 2032windo normal! zR 2033windo normal! gg 2034wincmd = 2035 2036let rows_without = [] 2037let rows_with = [] 2038let near_states = [] 2039let eof_states = [] 2040for sop in [ 0 , 1 ] 2041let & scrolloffpad = sop 2042 2043" Near EOF with real text visible in both windows. 2044windo normal! 99G 2045for w in range ( 1 , winnr ( '$' )) 2046execute w .. 'wincmd w' 2047let state = [ line ( '.' ), line ( 'w0' ), line ( 'w$' ), winline ()] 2048call assert_equal ( 99 , state [ 0 ]) 2049call assert_equal ( 100 , state [ 2 ]) 2050if sop == 0 2051call add ( near_states , state ) 2052endif 2053endfor 2054call assert_equal ( near_states [ 0 ], near_states [ 1 ]) 2055 2056" EOF in both windows: scrolloffpad should raise the cursor row. 2057windo normal! G 2058for w in range ( 1 , winnr ( '$' )) 2059execute w .. 'wincmd w' 2060let state = [ line ( '.' ), line ( 'w0' ), line ( 'w$' ), winline ()] 2061call assert_equal ( line ( '$' ), state [ 0 ]) 2062if sop == 0 2063call add ( eof_states , state ) 2064call add ( rows_without , state [ 3 ]) 2065else 2066call add ( rows_with , state [ 3 ]) 2067endif 2068endfor 2069call assert_equal ( eof_states [ 0 ], eof_states [ 1 ]) 2070endfor 2071 2072call assert_true ( rows_with [ 0 ] < rows_without [ 0 ]) 2073call assert_true ( rows_with [ 1 ] < rows_without [ 1 ]) 2074 2075windo diffoff 2076% bwipe ! 2077let & scrolloff = save_so 2078let & scrolloffpad = save_sop 2079let & splitright = save_splitright 2080endfunc 2081 2082func Test_scrolloffpad_diff_eof_filler_behavior () 2083CheckFeature diff 2084 2085let save_so = & scrolloff 2086let save_sop = & scrolloffpad 2087let save_diffopt = & diffopt 2088let save_splitright = & splitright 2089 2090set diffopt += filler 2091set scrolloff = 10 2092set scrolloffpad = 0 2093set nosplitright 2094 209520 new 2096call setline ( 1 , map ( range ( 1 , 100 ), { _ , v -> 'left ' .. v })) 2097diffthis 2098let short_wid = win_getid () 2099 2100vnew 2101call setline ( 1 , map ( range ( 1 , 120 ), { _ , v -> 'right ' .. v })) 2102diffthis 2103let long_wid = win_getid () 2104 2105call assert_true ( win_gotoid ( short_wid )) 2106let short_height = winheight ( 0 ) 2107call assert_true ( win_gotoid ( long_wid )) 2108let long_height = winheight ( 0 ) 2109call assert_equal ( short_height , long_height ) 2110call assert_equal ( 20 , short_height ) 2111 2112let ordered_diff_wids = [ long_wid , short_wid ] 2113let states = {} 2114for sop in [ 0 , 1 ] 2115execute 'set scrolloffpad=' .. sop 2116for wid in ordered_diff_wids 2117call assert_true ( win_gotoid ( wid )) 2118normal ! gg 2119endfor 2120for wid in ordered_diff_wids 2121call assert_true ( win_gotoid ( wid )) 2122normal ! G 2123endfor 2124 2125call assert_true ( win_gotoid ( short_wid )) 2126let short_view = winsaveview () 2127let short_state = [ 2128\ line ( '.' ), 2129\ line ( '$' ), 2130\ winline (), 2131\ short_view . topline , 2132\ short_view . topfill , 2133\ diff_filler ( line ( '$' ) + 1 ), 2134\ ] 2135call assert_equal ( short_state [ 1 ], short_state [ 0 ]) 2136call assert_true ( short_state [ 5 ] > 0 ) 2137 2138call assert_true ( win_gotoid ( long_wid )) 2139let long_view = winsaveview () 2140let long_state = [ 2141\ line ( '.' ), 2142\ line ( '$' ), 2143\ winline (), 2144\ long_view . topline , 2145\ long_view . topfill , 2146\ ] 2147call assert_true ( long_state [ 0 ] > 0 && long_state [ 0 ] <= long_state [ 1 ]) 2148call assert_equal ( short_state [ 0 ], long_state [ 0 ]) 2149 2150let states [ sop ] = [ short_state , long_state ] 2151endfor 2152 2153let short_without = states [ 0 ][ 0 ] 2154let short_with = states [ 1 ][ 0 ] 2155" Environment/layout can shift direction of movement; require only that 2156" scrolloffpad changes the short-window viewport state under EOF filler. 2157call assert_true ( short_with [ 2 ] != short_without [ 2 ] 2158\ || short_with [ 3 ] != short_without [ 3 ] 2159\ || short_with [ 4 ] != short_without [ 4 ]) 2160 2161windo diffoff 2162call assert_true ( win_gotoid ( short_wid )) 2163only ! 2164% bwipe ! 2165let & scrolloff = save_so 2166let & scrolloffpad = save_sop 2167let & diffopt = save_diffopt 2168let & splitright = save_splitright 2169endfunc 2170 2171func Test_scrolloffpad_with_folds () 2172CheckRunVimInTerminal 2173CheckFeature folding 2174let g: test_is_flaky = 1 2175 2176let save_termwinsize = & termwinsize 2177set termwinsize = 2178 2179let lines =<< trim END 2180set scrolloff=10 2181set scrolloffpad=1 2182 2183enew 2184call setline(1, map(range(1, 120), {_, v -> 'line ' . v})) 2185 2186" Create a large fold near the end of the file. 2187" Fold lines 60-110, leaving 111-120 visible after the fold. 2188set foldmethod=manual 2189set foldenable 2190normal! gg 2191normal! 60G 2192normal! zf50j 2193normal! gg 2194END 2195call writefile ( lines , 'XScrolloffpadFolds' , 'D' ) 2196 2197let buf = RunVimInTerminal ( '-S XScrolloffpadFolds' , #{ rows : 20 , cols : 78 }) 2198 2199" Case 1: Jump to end-of-file. 2200" With folds present, scrolloffpad should still keep the cursor positioned 2201" with padding below EOF. 2202call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! G\<CR>" ) 2203call term_sendkeys ( buf , "\<C-L>" ) 2204call WaitForAssert ({ -> assert_equal ( 'line 120' , trim ( term_getline ( buf , 10 )))}, 2205\ 1000 ) 2206call assert_equal ( 'line 111' , trim ( term_getline ( buf , 1 ))) 2207call assert_equal ( 'line 119' , trim ( term_getline ( buf , 9 ))) 2208call assert_equal ( '~' , trim ( term_getline ( buf , 11 ))) 2209call assert_match ( '120,1\s\+Bot' , term_getline ( buf , 20 )) 2210 2211" Case 2: Move to the folded line to ensure the fold is actually in view. 2212call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! 60G\<CR>" ) 2213call term_sendkeys ( buf , "\<C-L>" ) 2214call WaitForAssert ({ -> assert_match ( '^\s*+-- 51 lines: line 60--' , 2215\ term_getline ( buf , 10 ))}, 1000 ) 2216call assert_equal ( 'line 51' , trim ( term_getline ( buf , 1 ))) 2217call assert_equal ( 'line 59' , trim ( term_getline ( buf , 9 ))) 2218call assert_equal ( 'line 111' , trim ( term_getline ( buf , 11 ))) 2219call assert_equal ( 'line 119' , trim ( term_getline ( buf , 19 ))) 2220call assert_match ( '60,1\s\+98%' , term_getline ( buf , 20 )) 2221 2222" Case 3: Close the fold explicitly and go to EOF again. 2223" Behavior should remain stable with closed folds. 2224call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! zc\<CR>" ) 2225call term_sendkeys ( buf , "\<Esc>:\<C-U>normal! G\<CR>" ) 2226call term_sendkeys ( buf , "\<C-L>" ) 2227call WaitForAssert ({ -> assert_equal ( 'line 120' , trim ( term_getline ( buf , 10 )))}, 2228\ 1000 ) 2229call assert_equal ( 'line 111' , trim ( term_getline ( buf , 1 ))) 2230call assert_equal ( 'line 119' , trim ( term_getline ( buf , 9 ))) 2231call assert_equal ( '~' , trim ( term_getline ( buf , 11 ))) 2232call assert_match ( '120,1\s\+Bot' , term_getline ( buf , 20 )) 2233 2234call StopVimInTerminal ( buf ) 2235let & termwinsize = save_termwinsize 2236endfunc 2237 2238" Resizing to "textoff" after 'smoothscroll' skips part of a wrapped line must 2239" not crash. 2240func Test_smoothscroll_textoff_showbreak () 2241CheckOption smoothscroll 2242CheckRunVimInTerminal 2243 2244let donefile = 'XTest_crash_textoff_showbreak_done' 2245defer delete(donefile) 2246let lines =<< trim END 2247set noswapfile 2248 2249set scrolloff=0 2250set lines=12 columns=40 2251 2252call setline(1, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') 2253set number wrap smoothscroll showbreak=> 2254vsplit 2255 2256let textoff = getwininfo(win_getid())[0].textoff 2257execute "normal! 0\<C-E>" 2258redraw 2259execute 'vertical resize' textoff 2260redraw 2261call writefile(['done'], 'XTest_crash_textoff_showbreak_done') 2262END 2263call writefile ( lines , 'XTest_crash_textoff_showbreak' , 'D' ) 2264 2265let buf = 0 2266let buf = term_start ([ GetVimProg (), '--clean' ], #{ term_rows : 24 , term_cols : 80 }) 2267call TermWait ( buf , 200 ) 2268call term_sendkeys ( buf , ":source XTest_crash_textoff_showbreak\<CR>" ) 2269call WaitForAssert ({ -> assert_true ( filereadable ( donefile ))}) 2270let status = term_getstatus ( buf ) 2271call assert_equal ( 'running' , status ) 2272call assert_true ( filereadable ( donefile )) 2273call StopVimInTerminal ( buf ) 2274endfunc 2275 2276" comp_botline() reuses the line heights computed for the previous redraw. 2277" Changing an option that affects the displayed height of a line must 2278" invalidate that cache. Check that scrolling after such a change gives the 2279" same result as setting the option before scrolling. 2280func Test_botline_cache_invalidated_on_option_change () 2281" Resizing the height of a vertically split window pushes the reclaimed 2282" lines into 'cmdheight'; save and restore it so the following tests run 2283" with a full-height screen. 2284let save_cmdheight = & cmdheight 2285vnew 2286vertical resize 40 2287resize 10 2288setlocal scrolloff = 0 2289let lines = map ( range ( 1 , 400 ), { _ , v -> printf ( '%4d ' , v ) .. repeat ( 'word ' , 30 )}) 2290 2291for opt in [ 'number' , 'breakindent' , 'foldcolumn=4' , 'list' , 'nowrap' ] 2292" Reference: option set before scrolling, so no stale cache is possible. 2293call setline ( 1 , lines ) 2294setlocal wrap nonumber nobreakindent nolist foldcolumn = 0 2295exe 'setlocal ' .. opt 2296normal ! 120Gzt 2297redraw 2298let expected = getwininfo ( win_getid ())[ 0 ]. botline 2299 2300" Same option applied after scrolling, when the cache is populated. 2301setlocal wrap nonumber nobreakindent nolist foldcolumn = 0 2302normal ! 120Gzt 2303redraw 2304exe 'setlocal ' .. opt 2305redraw 2306call assert_equal ( expected , getwininfo ( win_getid ())[ 0 ]. botline , 'setlocal ' .. opt ) 2307endfor 2308 2309bwipe ! 2310let & cmdheight = save_cmdheight 2311endfunc 2312 2313" vim: shiftwidth=2 sts=2 expandtab