robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local n =require ( 'test.functional.testnvim' )() 2local t =require ( 'test.testutil' ) 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear =n . clear 7local exec =n . exec 8local feed =n . feed 9local assert_alive =n . assert_alive 10 11before_each ( clear ) 12 13describe ( 'smoothscroll' , function () 14local screen 15 16before_each ( function () 17screen =Screen . new ( 40 , 12 ) 18end ) 19 20-- oldtest: Test_CtrlE_CtrlY_stop_at_end() 21it ( 'disabled does not break <C-E> and <C-Y> stop at end' , function () 22exec ( [[ 23enew 24call setline(1, ['one', 'two']) 25set number 26]] ) 27feed ( '<C-Y>' ) 28screen : expect ( { any ='{8: 1 }^one' } ) 29feed ( '<C-E><C-E><C-E>' ) 30screen : expect ( { any ='{8: 2 }^two' } ) 31end ) 32 33-- oldtest: Test_smoothscroll_CtrlE_CtrlY() 34it ( 'works with <C-E> and <C-E>' , function () 35exec ( [[ 36call setline(1, [ 'line one', 'word '->repeat(20), 'line three', 'long word '->repeat(7), 'line', 'line', 'line', ]) 37set smoothscroll scrolloff=5 38:5 39]] ) 40local s1 =[[ 41word word word word word word word word |*2 42word word word word | 43line three | 44long word long word long word long word | 45long word long word long word | 46^line | 47line |*2 48{1:~ }|*2 49| 50]] 51local s2 =[[ 52{1:<<<}d word word word word word word word | 53word word word word | 54line three | 55long word long word long word long word | 56long word long word long word | 57^line | 58line |*2 59{1:~ }|*3 60| 61]] 62local s3 =[[ 63{1:<<<}d word word word | 64line three | 65long word long word long word long word | 66long word long word long word | 67^line | 68line |*2 69{1:~ }|*4 70| 71]] 72local s4 =[[ 73line three | 74long word long word long word long word | 75long word long word long word | 76line |*2 77^line | 78{1:~ }|*5 79| 80]] 81local s5 =[[ 82{1:<<<}d word word word | 83line three | 84long word long word long word long word | 85long word long word long word | 86line |*2 87^line | 88{1:~ }|*4 89| 90]] 91local s6 =[[ 92{1:<<<}d word word word word word word word | 93word word word word | 94line three | 95long word long word long word long word | 96long word long word long word | 97line |*2 98^line | 99{1:~ }|*3 100| 101]] 102local s7 =[[ 103word word word word word word word word |*2 104word word word word | 105line three | 106long word long word long word long word | 107long word long word long word | 108line |*2 109^line | 110{1:~ }|*2 111| 112]] 113local s8 =[[ 114line one | 115word word word word word word word word |*2 116word word word word | 117line three | 118long word long word long word long word | 119long word long word long word | 120line |*2 121^line | 122{1:~ }| 123| 124]] 125feed ( '<C-E>' ) 126screen : expect ( s1 ) 127feed ( '<C-E>' ) 128screen : expect ( s2 ) 129feed ( '<C-E>' ) 130screen : expect ( s3 ) 131feed ( '<C-E>' ) 132screen : expect ( s4 ) 133feed ( '<C-Y>' ) 134screen : expect ( s5 ) 135feed ( '<C-Y>' ) 136screen : expect ( s6 ) 137feed ( '<C-Y>' ) 138screen : expect ( s7 ) 139feed ( '<C-Y>' ) 140screen : expect ( s8 ) 141exec ( 'set foldmethod=indent' ) 142-- move the cursor so we can reuse the same dumps 143feed ( '5G<C-E>' ) 144screen : expect ( s1 ) 145feed ( '<C-E>' ) 146screen : expect ( s2 ) 147feed ( '7G<C-Y>' ) 148screen : expect ( s7 ) 149feed ( '<C-Y>' ) 150screen : expect ( s8 ) 151end ) 152 153-- oldtest: Test_smoothscroll_multibyte() 154it ( 'works with multibyte characters' , function () 155screen : try_resize ( 40 , 6 ) 156exec ( [[ 157set scrolloff=0 smoothscroll 158call setline(1, [repeat('ϛ', 45), repeat('2', 36)]) 159exe "normal G35l\<C-E>k" 160]] ) 161screen : expect ( [[ 162ϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛ^ϛϛϛϛϛ| 163ϛϛϛϛϛ | 164222222222222222222222222222222222222 | 165{1:~ }|*2 166| 167]] ) 168end ) 169 170-- oldtest: Test_smoothscroll_number() 171it ( "works 'number' and 'cpo'+=n" , function () 172exec ( [[ 173call setline(1, [ 'one ' .. 'word '->repeat(20), 'two ' .. 'long word '->repeat(7), 'line', 'line', 'line', ]) 174set smoothscroll scrolloff=5 175set splitkeep=topline 176set number cpo+=n 177:3 178func g:DoRel() 179set number relativenumber scrolloff=0 180:%del 181call setline(1, [ 'one', 'very long text '->repeat(12), 'three', ]) 182exe "normal 2Gzt\<C-E>" 183endfunc 184]] ) 185screen : expect ( [[ 186{8: 1 }one word word word word word word wo| 187rd word word word word word word word wo| 188rd word word word word word | 189{8: 2 }two long word long word long word lo| 190ng word long word long word long word | 191{8: 3 }^line | 192{8: 4 }line | 193{8: 5 }line | 194{1:~ }|*3 195| 196]] ) 197feed ( '<C-E>' ) 198screen : expect ( [[ 199{1:<<<}word word word word word word word wo| 200rd word word word word word | 201{8: 2 }two long word long word long word lo| 202ng word long word long word long word | 203{8: 3 }^line | 204{8: 4 }line | 205{8: 5 }line | 206{1:~ }|*4 207| 208]] ) 209feed ( '<C-E>' ) 210screen : expect ( [[ 211{1:<<<}word word word word word | 212{8: 2 }two long word long word long word lo| 213ng word long word long word long word | 214{8: 3 }^line | 215{8: 4 }line | 216{8: 5 }line | 217{1:~ }|*5 218| 219]] ) 220exec ( 'set cpo-=n' ) 221screen : expect ( [[ 222{1:<<<}{8: }d word word word word word word | 223{8: 2 }two long word long word long word lo| 224{8: }ng word long word long word long wor| 225{8: }d | 226{8: 3 }^line | 227{8: 4 }line | 228{8: 5 }line | 229{1:~ }|*4 230| 231]] ) 232feed ( '<C-Y>' ) 233screen : expect ( [[ 234{1:<<<}{8: }rd word word word word word word wor| 235{8: }d word word word word word word | 236{8: 2 }two long word long word long word lo| 237{8: }ng word long word long word long wor| 238{8: }d | 239{8: 3 }^line | 240{8: 4 }line | 241{8: 5 }line | 242{1:~ }|*3 243| 244]] ) 245feed ( '<C-Y>' ) 246screen : expect ( [[ 247{8: 1 }one word word word word word word wo| 248{8: }rd word word word word word word wor| 249{8: }d word word word word word word | 250{8: 2 }two long word long word long word lo| 251{8: }ng word long word long word long wor| 252{8: }d | 253{8: 3 }^line | 254{8: 4 }line | 255{8: 5 }line | 256{1:~ }|*2 257| 258]] ) 259exec ( 'botright split' ) 260feed ( 'gg' ) 261screen : expect ( [[ 262{8: 1 }one word word word word word word wo| 263{8: }rd word word word word word word wor| 264{8: }d word word word word word word | 265{8: 2 }two long word long word long word{1:@@@}| 266{2:[No Name] [+] }| 267{8: 1 }^one word word word word word word wo| 268{8: }rd word word word word word word wor| 269{8: }d word word word word word word | 270{8: 2 }two long word long word long word lo| 271{8: }ng word long word long word long {1:@@@}| 272{3:[No Name] [+] }| 273| 274]] ) 275 276feed ( '<C-E>' ) 277screen : expect ( [[ 278{8: 1 }one word word word word word word wo| 279{8: }rd word word word word word word wor| 280{8: }d word word word word word word | 281{8: 2 }two long word long word long word{1:@@@}| 282{2:[No Name] [+] }| 283{1:<<<}{8: }rd word word word word word word wor| 284{8: }d word word word word word word^ | 285{8: 2 }two long word long word long word lo| 286{8: }ng word long word long word long wor| 287{8: }d | 288{3:[No Name] [+] }| 289| 290]] ) 291 292feed ( '<C-E>' ) 293screen : expect ( [[ 294{8: 1 }one word word word word word word wo| 295{8: }rd word word word word word word wor| 296{8: }d word word word word word word | 297{8: 2 }two long word long word long word{1:@@@}| 298{2:[No Name] [+] }| 299{1:<<<}{8: }d word word word word word word^ | 300{8: 2 }two long word long word long word lo| 301{8: }ng word long word long word long wor| 302{8: }d | 303{8: 3 }line | 304{3:[No Name] [+] }| 305| 306]] ) 307exec ( 'close' ) 308exec ( 'call DoRel()' ) 309screen : expect ( [[ 310{8:2}{1:<<<}^ong text very long text very long te| 311{8: }xt very long text very long text ver| 312{8: }y long text very long text very long| 313{8: } text very long text very long text | 314{8: 1 }three | 315{1:~ }|*6 316--No lines in buffer-- | 317]] ) 318end ) 319 320-- oldtest: Test_smoothscroll_list() 321it ( 'works with list mode' , function () 322screen : try_resize ( 40 , 8 ) 323exec ( [[ 324set smoothscroll scrolloff=0 325set list 326call setline(1, [ 'one', 'very long text '->repeat(12), 'three', ]) 327exe "normal 2Gzt\<C-E>" 328]] ) 329screen : expect ( [[ 330{1:<<<}t very long text very long text very | 331^long text very long text very long text | 332very long text very long text very long | 333text very long text{1:-} | 334three | 335{1:~ }|*2 336| 337]] ) 338exec ( 'set listchars+=precedes:#' ) 339screen : expect ( [[ 340{1:#}ext very long text very long text very | 341^long text very long text very long text | 342very long text very long text very long | 343text very long text{1:-} | 344three | 345{1:~ }|*2 346| 347]] ) 348end ) 349 350-- oldtest: Test_smoothscroll_diff_mode() 351it ( 'works with diff mode' , function () 352screen : try_resize ( 40 , 8 ) 353exec ( [[ 354let text = 'just some text here' 355call setline(1, text) 356set smoothscroll 357diffthis 358new 359call setline(1, text) 360set smoothscroll 361diffthis 362]] ) 363 364screen : expect ( [[ 365{7:- }^just some text here | 366{1:~ }|*2 367{3:[No Name] [+] }| 368{7:- }just some text here | 369{1:~ }| 370{2:[No Name] [+] }| 371| 372]] ) 373feed ( '<C-Y>' ) 374screen : expect_unchanged () 375feed ( '<C-E>' ) 376screen : expect_unchanged () 377end ) 378 379-- oldtest: Test_smoothscroll_diff_change_line() 380it ( 'works in diff mode when changing line' , function () 381screen : try_resize ( 55 , 20 ) 382exec ( [[ 383set diffopt+=followwrap smoothscroll 384call setline(1, repeat(' abc', &columns)) 385call setline(2, 'bar') 386call setline(3, repeat(' abc', &columns)) 387vnew 388call setline(1, repeat(' abc', &columns)) 389call setline(2, 'foo') 390call setline(3, 'bar') 391call setline(4, repeat(' abc', &columns)) 392windo exe "normal! 2gg5\<C-E>" 393windo diffthis 394]] ) 395 396screen : expect ( [[ 397{1:<<<}bc abc abc abc abc abc a│{1:<<<}bc abc abc abc abc abc a| 398{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 399{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 400{7: } abc abc abc abc abc │{7: } abc abc abc abc abc | 401{7: }{22:foo }│{7: }{23:-------------------------}| 402{7: }bar │{7: }^bar | 403{7: } abc abc abc abc abc abc │{7: } abc abc abc abc abc abc | 404{7: }abc abc abc abc abc abc a│{7: }abc abc abc abc abc abc a| 405{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 406{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 407{7: } abc abc abc abc abc abc │{7: } abc abc abc abc abc abc | 408{7: }abc abc abc abc abc abc a│{7: }abc abc abc abc abc abc a| 409{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 410{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 411{7: } abc abc abc abc abc │{7: } abc abc abc abc abc | 412{1:~ }│{1:~ }|*3 413{2:[No Name] [+] }{3:[No Name] [+] }| 414| 415]] ) 416feed ( 'Abar' ) 417screen : expect ( [[ 418{1:<<<}bc abc abc abc abc abc a│{1:<<<}bc abc abc abc abc abc a| 419{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 420{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 421{7: } abc abc abc abc abc │{7: } abc abc abc abc abc | 422{7: }{22:foo }│{7: }{23:-------------------------}| 423{7: }bar │{7: }barbar^ | 424{7: } abc abc abc abc abc abc │{7: } abc abc abc abc abc abc | 425{7: }abc abc abc abc abc abc a│{7: }abc abc abc abc abc abc a| 426{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 427{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 428{7: } abc abc abc abc abc abc │{7: } abc abc abc abc abc abc | 429{7: }abc abc abc abc abc abc a│{7: }abc abc abc abc abc abc a| 430{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 431{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 432{7: } abc abc abc abc abc │{7: } abc abc abc abc abc | 433{1:~ }│{1:~ }|*3 434{2:[No Name] [+] }{3:[No Name] [+] }| 435{5:-- INSERT --} | 436]] ) 437feed ( '<Esc>' ) 438screen : expect ( [[ 439{1:<<<}bc abc abc abc abc abc a│{1:<<<}bc abc abc abc abc abc a| 440{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 441{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 442{7: } abc abc abc abc abc │{7: } abc abc abc abc abc | 443{7: }{22:foo }│{7: }{23:-------------------------}| 444{7: }{4:bar }│{7: }{4:bar}{27:ba^r}{4: }| 445{7: } abc abc abc abc abc abc │{7: } abc abc abc abc abc abc | 446{7: }abc abc abc abc abc abc a│{7: }abc abc abc abc abc abc a| 447{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 448{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 449{7: } abc abc abc abc abc abc │{7: } abc abc abc abc abc abc | 450{7: }abc abc abc abc abc abc a│{7: }abc abc abc abc abc abc a| 451{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 452{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 453{7: } abc abc abc abc abc │{7: } abc abc abc abc abc | 454{1:~ }│{1:~ }|*3 455{2:[No Name] [+] }{3:[No Name] [+] }| 456| 457]] ) 458feed ( 'yyp' ) 459screen : expect ( [[ 460{1:<<<}bc abc abc abc abc abc a│{1:<<<}bc abc abc abc abc abc a| 461{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 462{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 463{7: } abc abc abc abc abc │{7: } abc abc abc abc abc | 464{7: }{27:foo}{4: }│{7: }{27:barbar}{4: }| 465{7: }{4:bar }│{7: }{4:^bar}{27:bar}{4: }| 466{7: } abc abc abc abc abc abc │{7: } abc abc abc abc abc abc | 467{7: }abc abc abc abc abc abc a│{7: }abc abc abc abc abc abc a| 468{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 469{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 470{7: } abc abc abc abc abc abc │{7: } abc abc abc abc abc abc | 471{7: }abc abc abc abc abc abc a│{7: }abc abc abc abc abc abc a| 472{7: }bc abc abc abc abc abc ab│{7: }bc abc abc abc abc abc ab| 473{7: }c abc abc abc abc abc abc│{7: }c abc abc abc abc abc abc| 474{7: } abc abc abc abc abc │{7: } abc abc abc abc abc | 475{1:~ }│{1:~ }|*3 476{2:[No Name] [+] }{3:[No Name] [+] }| 477| 478]] ) 479end ) 480 481-- oldtest: Test_smoothscroll_wrap_scrolloff_zero() 482it ( "works with zero 'scrolloff'" , function () 483screen : try_resize ( 40 , 8 ) 484exec ( [[ 485call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) 486set smoothscroll scrolloff=0 display= 487:3 488]] ) 489screen : expect ( [[ 490{1:<<<}h some text with some text | 491Line with some text with some text with | 492some text with some text with some text | 493with some text with some text | 494^Line with some text with some text with | 495some text with some text with some text | 496with some text with some text | 497| 498]] ) 499feed ( 'j' ) 500screen : expect_unchanged () 501-- moving cursor down - whole bottom line shows 502feed ( '<C-E>j' ) 503screen : expect_unchanged () 504feed ( 'G' ) 505screen : expect_unchanged () 506feed ( '4<C-Y>G' ) 507screen : expect_unchanged () 508-- moving cursor up right after the <<< marker - no need to show whole line 509feed ( '2gj3l2k' ) 510screen : expect ( [[ 511{1:<<<}^h some text with some text | 512Line with some text with some text with | 513some text with some text with some text | 514with some text with some text | 515Line with some text with some text with | 516some text with some text with some text | 517with some text with some text | 518| 519]] ) 520-- moving cursor up where the <<< marker is - whole top line shows 521feed ( '2j02k' ) 522screen : expect ( [[ 523^Line with some text with some text with | 524some text with some text with some text | 525with some text with some text | 526Line with some text with some text with | 527some text with some text with some text | 528with some text with some text | 529{1:@ }| 530| 531]] ) 532end ) 533 534-- oldtest: Test_smoothscroll_wrap_long_line() 535it ( 'adjusts the cursor position in a long line' , function () 536screen : try_resize ( 40 , 6 ) 537exec ( [[ 538call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four']) 539set smoothscroll scrolloff=0 540normal 3G10|zt 541]] ) 542-- scrolling up, cursor moves screen line down 543screen : expect ( [[ 544Line with^ lots of text with lots of text| 545with lots of text with lots of text wit| 546h lots of text with lots of text with lo| 547ts of text with lots of text with lots o| 548f text with lots of text with lots of te| 549| 550]] ) 551feed ( '<C-E>' ) 552screen : expect ( [[ 553{1:<<<}th lot^s of text with lots of text wit| 554h lots of text with lots of text with lo| 555ts of text with lots of text with lots o| 556f text with lots of text with lots of te| 557xt with lots of text with lots of text w| 558| 559]] ) 560feed ( '5<C-E>' ) 561screen : expect ( [[ 562{1:<<<} lots ^of text with lots of text with | 563lots of text with lots of text with lots| 564of text with lots of text with lots of | 565text with lots of text with lots of text| 566with lots of text with lots of text wit| 567| 568]] ) 569-- scrolling down, cursor moves screen line up 570feed ( '5<C-Y>' ) 571screen : expect ( [[ 572{1:<<<}th lots of text with lots of text wit| 573h lots of text with lots of text with lo| 574ts of text with lots of text with lots o| 575f text with lots of text with lots of te| 576xt with l^ots of text with lots of text w| 577| 578]] ) 579feed ( '<C-Y>' ) 580screen : expect ( [[ 581Line with lots of text with lots of text| 582with lots of text with lots of text wit| 583h lots of text with lots of text with lo| 584ts of text with lots of text with lots o| 585f text wi^th lots of text with lots of te| 586| 587]] ) 588-- 'scrolloff' set to 1, scrolling up, cursor moves screen line down 589exec ( 'set scrolloff=1' ) 590feed ( '10|<C-E>' ) 591screen : expect ( [[ 592{1:<<<}th lots of text with lots of text wit| 593h lots of^ text with lots of text with lo| 594ts of text with lots of text with lots o| 595f text with lots of text with lots of te| 596xt with lots of text with lots of text w| 597| 598]] ) 599-- 'scrolloff' set to 1, scrolling down, cursor moves screen line up 600feed ( '<C-E>gjgj<C-Y>' ) 601screen : expect ( [[ 602{1:<<<}th lots of text with lots of text wit| 603h lots of text with lots of text with lo| 604ts of text with lots of text with lots o| 605f text wi^th lots of text with lots of te| 606xt with lots of text with lots of text w| 607| 608]] ) 609-- 'scrolloff' set to 2, scrolling up, cursor moves screen line down 610exec ( 'set scrolloff=2' ) 611feed ( '10|<C-E>' ) 612screen : expect ( [[ 613{1:<<<}th lots of text with lots of text wit| 614h lots of text with lots of text with lo| 615ts of tex^t with lots of text with lots o| 616f text with lots of text with lots of te| 617xt with lots of text with lots of text w| 618| 619]] ) 620-- 'scrolloff' set to 2, scrolling down, cursor moves screen line up 621feed ( '<C-E>gj<C-Y>' ) 622screen : expect_unchanged () 623-- 'scrolloff' set to 0, move cursor down one line. Cursor should move properly, 624-- and since this is a really long line, it will be put on top of the screen. 625exec ( 'set scrolloff=0' ) 626feed ( '0j' ) 627screen : expect ( [[ 628{1:<<<}th lots of text with lots of text wit| 629h lots of text with lots of text with lo| 630ts of text with lots of text with lots o| 631f text with lots of text end | 632^four | 633| 634]] ) 635-- Test zt/zz/zb that they work properly when a long line is above it 636feed ( 'zt' ) 637screen : expect ( [[ 638^four | 639{1:~ }|*4 640| 641]] ) 642feed ( 'zz' ) 643screen : expect ( [[ 644{1:<<<}of text with lots of text with lots o| 645f text with lots of text end | 646^four | 647{1:~ }|*2 648| 649]] ) 650feed ( 'zb' ) 651screen : expect ( [[ 652{1:<<<}th lots of text with lots of text wit| 653h lots of text with lots of text with lo| 654ts of text with lots of text with lots o| 655f text with lots of text end | 656^four | 657| 658]] ) 659-- Repeat the step and move the cursor down again. 660-- This time, use a shorter long line that is barely long enough to span more 661-- than one window. Note that the cursor is at the bottom this time because 662-- Vim prefers to do so if we are scrolling a few lines only. 663exec ( 664"call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])" 665) 666-- Currently visible lines were replaced, test that the lines and cursor 667-- are correctly displayed. 668screen : expect_unchanged () 669feed ( '3Gztj' ) 670screen : expect_unchanged () 671-- Repeat the step but this time start it when the line is smooth-scrolled by 672-- one line. This tests that the offset calculation is still correct and 673-- still end up scrolling down to the next line with cursor at bottom of 674-- screen. 675feed ( '3Gzt<C-E>j' ) 676screen : expect ( [[ 677{1:<<<}th lots of text with lots of text wit| 678h lots of text with lots of text with lo| 679ts of text with lots of text with lots o| 680f text with lots of text end | 681fou^r | 682| 683]] ) 684end ) 685 686-- oldtest: Test_smoothscroll_one_long_line() 687it ( 'scrolls correctly when moving the cursor' , function () 688screen : try_resize ( 40 , 6 ) 689exec ( [[ 690call setline(1, 'with lots of text '->repeat(7)) 691set smoothscroll scrolloff=0 692]] ) 693local s1 =[[ 694^with lots of text with lots of text with| 695lots of text with lots of text with lot| 696s of text with lots of text with lots of| 697text | 698{1:~ }| 699| 700]] 701screen : expect ( s1 ) 702feed ( '<C-E>' ) 703screen : expect ( [[ 704{1:<<<}ts of text with lots of text with lot| 705^s of text with lots of text with lots of| 706text | 707{1:~ }|*2 708| 709]] ) 710feed ( '0' ) 711screen : expect ( s1 ) 712end ) 713 714-- oldtest: Test_smoothscroll_long_line_showbreak() 715it ( 'cursor is not one screen line too far down' , function () 716screen : try_resize ( 40 , 6 ) 717-- a line that spans four screen lines 718exec ( "call setline(1, 'with lots of text in one line '->repeat(6))" ) 719exec ( 'set smoothscroll scrolloff=0 showbreak=+++\\ ' ) 720local s1 =[[ 721^with lots of text in one line with lots | 722{1:+++ }of text in one line with lots of tex| 723{1:+++ }t in one line with lots of text in o| 724{1:+++ }ne line with lots of text in one lin| 725{1:+++ }e with lots of text in one line | 726| 727]] 728screen : expect ( s1 ) 729feed ( '<C-E>' ) 730screen : expect ( [[ 731{1:+++ }^of text in one line with lots of tex| 732{1:+++ }t in one line with lots of text in o| 733{1:+++ }ne line with lots of text in one lin| 734{1:+++ }e with lots of text in one line | 735{1:~ }| 736| 737]] ) 738feed ( '0' ) 739screen : expect ( s1 ) 740end ) 741 742-- oldtest: Test_smoothscroll_marker_over_double_width_dump() 743it ( 'marker is drawn over double-width char correctly' , function () 744screen : try_resize ( 40 , 6 ) 745exec ( [[ 746call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10)) 747setlocal smoothscroll 748]] ) 749screen : expect ( [[ 750^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 751口口口口口口口口口口 | 752{1:~ }|*3 753| 754]] ) 755feed ( '<C-E>' ) 756screen : expect ( [[ 757{1:<<<} 口口口口口口口^口 | 758{1:~ }|*4 759| 760]] ) 761end ) 762 763-- oldtest: Test_smoothscroll_zero_width() 764it ( 'does not divide by zero with a narrow window' , function () 765screen : try_resize ( 12 , 2 ) 766exec ( [[ 767call setline(1, ['a'->repeat(100)]) 768set wrap smoothscroll number laststatus=0 769wincmd v 770wincmd v 771wincmd v 772wincmd v 773]] ) 774screen : expect ( [[ 775{8: 1^ }│{8: }│{8: }│{8: }│{8: }| 776| 777]] ) 778feed ( 'llllllllll<C-W>o' ) 779screen : expect ( [[ 780{1:<<<}{8: }aa^aaaaaa| 781| 782]] ) 783end ) 784 785-- oldtest: Test_smoothscroll_ins_lines() 786it ( 'does not unnecessarily insert lines' , function () 787screen : try_resize ( 40 , 6 ) 788exec ( [=[ 789set wrap smoothscroll scrolloff=0 conceallevel=2 concealcursor=nc 790call setline(1, [ 791\'line one' .. 'with lots of text in one line '->repeat(2), 792\'line two', 793\'line three', 794\'line four', 795\'line five' 796\]) 797]=] ) 798feed ( '<C-E>gjgk' ) 799screen : expect ( [[ 800{1:<<<}lots of text in one line^ | 801line two | 802line three | 803line four | 804line five | 805| 806]] ) 807end ) 808 809-- oldtest: Test_smoothscroll_cursormoved_line() 810it ( 'does not place the cursor in the command line' , function () 811screen : try_resize ( 40 , 6 ) 812exec ( [=[ 813set smoothscroll 814call setline(1, [ 815\'', 816\'_'->repeat(&lines * &columns), 817\(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2) 818\]) 819autocmd CursorMoved * eval [line('w0'), line('w$')] 820call search('xxx') 821]=] ) 822screen : expect ( [[ 823{1:<<<}_____________________________________| 824________________________________________| 825______________________________________^xx| 826x______________________________________x| 827xx | 828| 829]] ) 830end ) 831 832-- oldtest: Test_smoothscroll_eob() 833it ( 'does not scroll halfway at end of buffer' , function () 834screen : try_resize ( 40 , 10 ) 835exec ( [[ 836set smoothscroll 837call setline(1, ['']->repeat(100)) 838norm G 839]] ) 840-- does not scroll halfway when scrolling to end of buffer 841screen : expect ( [[ 842|*8 843^ | 844| 845]] ) 846exec ( "call setline(92, 'a'->repeat(100))" ) 847feed ( '<C-L><C-B>G' ) 848-- cursor is not placed below window 849screen : expect ( [[ 850{1:<<<}aaaaaaaaaaaaaaaaa | 851|*7 852^ | 853| 854]] ) 855end ) 856 857-- oldtest: Test_smoothscroll_incsearch() 858it ( 'does not reset skipcol when doing incremental search on the same word' , function () 859screen : try_resize ( 40 , 8 ) 860exec ( [[ 861set smoothscroll number scrolloff=0 incsearch 862call setline(1, repeat([''], 20)) 863call setline(11, repeat('a', 100)) 864call setline(14, 'bbbb') 865]] ) 866feed ( '/b' ) 867screen : expect ( [[ 868{1:<<<}{8: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa | 869{8: 12 } | 870{8: 13 } | 871{8: 14 }{2:b}{10:bbb} | 872{8: 15 } | 873{8: 16 } | 874{8: 17 } | 875/b^ | 876]] ) 877feed ( 'b' ) 878screen : expect ( [[ 879{1:<<<}{8: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa | 880{8: 12 } | 881{8: 13 } | 882{8: 14 }{2:bb}{10:bb} | 883{8: 15 } | 884{8: 16 } | 885{8: 17 } | 886/bb^ | 887]] ) 888feed ( 'b' ) 889screen : expect ( [[ 890{1:<<<}{8: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa | 891{8: 12 } | 892{8: 13 } | 893{8: 14 }{2:bbb}b | 894{8: 15 } | 895{8: 16 } | 896{8: 17 } | 897/bbb^ | 898]] ) 899feed ( 'b' ) 900screen : expect ( [[ 901{1:<<<}{8: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa | 902{8: 12 } | 903{8: 13 } | 904{8: 14 }{2:bbbb} | 905{8: 15 } | 906{8: 16 } | 907{8: 17 } | 908/bbbb^ | 909]] ) 910end ) 911 912-- oldtest: Test_smoothscroll_multi_skipcol() 913it ( 'scrolling multiple lines and stopping at non-zero skipcol' , function () 914screen : try_resize ( 40 , 10 ) 915exec ( [[ 916setlocal cursorline scrolloff=0 smoothscroll 917call setline(1, repeat([''], 8)) 918call setline(3, repeat('a', 50)) 919call setline(4, repeat('a', 50)) 920call setline(7, 'bbb') 921call setline(8, 'ccc') 922redraw 923]] ) 924screen : expect ( [[ 925{21:^ }| 926| 927aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 928aaaaaaaaaa | 929aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 930aaaaaaaaaa | 931|*2 932bbb | 933| 934]] ) 935feed ( '3<C-E>' ) 936screen : expect ( [[ 937{1:<<<}{21:aaaaaa^a }| 938aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 939aaaaaaaaaa | 940|*2 941bbb | 942ccc | 943{1:~ }|*2 944| 945]] ) 946feed ( '2<C-E>' ) 947screen : expect ( [[ 948{1:<<<}{21:aaaaaa^a }| 949|*2 950bbb | 951ccc | 952{1:~ }|*4 953| 954]] ) 955end ) 956 957-- oldtest: Test_smoothscroll_zero_width_scroll_cursor_bot() 958it ( 'does not divide by zero in zero-width window' , function () 959screen : try_resize ( 40 , 19 ) 960exec ( [[ 961silent normal yy 962silent normal 19p 963set cpoptions+=n 964vsplit 965vertical resize 0 966set foldcolumn=1 967set number 968set smoothscroll 969silent normal 20G 970]] ) 971screen : expect ( [[ 972{8: }│ | 973{1:@}│ |*15 974{1:^@}│ | 975{3:< }{2:[No Name] [+] }| 976| 977]] ) 978end ) 979 980-- oldtest: Test_smoothscroll_cursor_top() 981it ( 'resets skipcol when scrolling cursor to top' , function () 982screen : try_resize ( 40 , 12 ) 983exec ( [[ 984set smoothscroll scrolloff=2 985new | 11resize | wincmd j 986call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4']) 987exe "norm G3\<C-E>k" 988]] ) 989screen : expect ( [[ 990| 991{2:[No Name] }| 992line1 | 993line2 | 994^line3line3line3line3line3line3line3line3| 995line3line3line3line3line3line3line3line3| 996line3line3line3line3 | 997line4 | 998{1:~ }|*2 999{3:[No Name] [+] }| 1000| 1001]] ) 1002end ) 1003 1004-- oldtest: Test_smoothscroll_crash() 1005it ( 'does not crash with small window and cpo+=n' , function () 1006screen : try_resize ( 40 , 12 ) 1007exec ( [[ 100820 new 1009vsp 1010put =repeat('aaaa', 20) 1011set nu fdc=1 smoothscroll cpo+=n 1012vert resize 0 1013exe "norm! 0\<c-e>" 1014]] ) 1015feed ( '2<C-E>' ) 1016assert_alive () 1017end ) 1018 1019-- oldtest: Test_smoothscroll_insert_bottom() 1020it ( 'works in Insert mode at bottom of window' , function () 1021screen : try_resize ( 40 , 9 ) 1022exec ( [[ 1023call setline(1, repeat([repeat('A very long line ...', 10)], 5)) 1024set wrap smoothscroll scrolloff=0 1025]] ) 1026feed ( 'Go123456789<CR>' ) 1027screen : expect ( [[ 1028{1:<<<}ery long line ...A very long line ...| 1029A very long line ...A very long line ...|*5 1030123456789 | 1031^ | 1032{5:-- INSERT --} | 1033]] ) 1034end ) 1035 1036-- oldtest: Test_smoothscroll_in_qf_window() 1037it ( 'works in quickfix window when changing quickfix list' , function () 1038screen : try_resize ( 60 , 20 ) 1039exec ( [[ 1040set nocompatible display=lastline 1041copen 5 1042setlocal number smoothscroll 1043let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10) 1044call setqflist(g:l, 'r') 1045normal! G 1046wincmd t 1047let g:l1 = [{'text': join(range(1000))}] 1048]] ) 1049screen : expect ( [[ 1050^ | 1051{1:~ }|*11 1052{3:[No Name] }| 1053{1:<<<}{8: }21 22 23 24 25 26 27 28 29 | 1054{8: 10 }|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1055{8: }21 22 23 24 25 26 27 28 29 | 1056{8: 11 }|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1057{8: }21 22 23 24 25 26 27 28 29 | 1058{2:[Quickfix List] [-] }| 1059| 1060]] ) 1061 1062feed ( [[:call setqflist([], 'r')<CR>]] ) 1063local screen_empty =[[ 1064^ | 1065{1:~ }|*11 1066{3:[No Name] }| 1067{8: 1 } | 1068{1:~ }|*4 1069{2:[Quickfix List] [-] }| 1070:call setqflist([], 'r') | 1071]] 1072screen : expect ( screen_empty ) 1073 1074feed ( [[:call setqflist(g:l, 'r')<CR>]] ) 1075local screen_l_top =[[ 1076^ | 1077{1:~ }|*11 1078{3:[No Name] }| 1079{8: 1 }{10:|| foo }| 1080{8: 2 }|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1081{8: }21 22 23 24 25 26 27 28 29 | 1082{8: 3 }|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1083{8: }21 22 23 24 25 26 27 28 29 | 1084{2:[Quickfix List] [-] }| 1085:call setqflist(g:l, 'r') | 1086]] 1087screen : expect ( screen_l_top ) 1088 1089feed ( [[:call setqflist(g:l1, 'r')<CR>]] ) 1090local screen_l1_top =[[ 1091^ | 1092{1:~ }|*11 1093{3:[No Name] }| 1094{8: 1 }{10:|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 }| 1095{8: }{10:21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39}| 1096{8: }{10: 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 5}| 1097{8: }{10:8 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 }| 1098{8: }{10:77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95}| 1099{2:[Quickfix List] [-] }| 1100:call setqflist(g:l1, 'r') | 1101]] 1102screen : expect ( screen_l1_top ) 1103 1104feed ( '<C-W>b$<C-W>t' ) 1105local screen_l1_bot =[[ 1106^ | 1107{1:~ }|*11 1108{3:[No Name] }| 1109{1:<<<}{8: }{10: 937 938 939 940 941 942 943 944 945 946 947 948 949 950}| 1110{8: }{10: 951 952 953 954 955 956 957 958 959 960 961 962 963 964}| 1111{8: }{10: 965 966 967 968 969 970 971 972 973 974 975 976 977 978}| 1112{8: }{10: 979 980 981 982 983 984 985 986 987 988 989 990 991 992}| 1113{8: }{10: 993 994 995 996 997 998 999 }| 1114{2:[Quickfix List] [-] }| 1115:call setqflist(g:l1, 'r') | 1116]] 1117screen : expect ( screen_l1_bot ) 1118 1119feed ( [[:call setqflist([], 'r')<CR>]] ) 1120screen : expect ( screen_empty ) 1121 1122feed ( [[:call setqflist(g:l1, 'r')<CR>]] ) 1123screen : expect ( screen_l1_top ) 1124 1125feed ( '<C-W>b$<C-W>t' ) 1126screen : expect ( screen_l1_bot ) 1127 1128feed ( [[:call setqflist(g:l, 'r')<CR>]] ) 1129screen : expect ( screen_l_top ) 1130end ) 1131 1132-- oldtest: Test_smoothscroll_textoff_showbreak() 1133it ( 'does not crash when resizing to textoff with showbreak' , function () 1134exec ( [[ 1135set noswapfile scrolloff=0 1136 1137call setline(1, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') 1138set number wrap smoothscroll showbreak=> 1139vsplit 1140 1141let textoff = getwininfo(win_getid())[0].textoff 1142execute "normal! 0\<C-E>" 1143redraw 1144execute 'vertical resize' textoff 1145redraw 1146]] ) 1147assert_alive () 1148end ) 1149 1150it ( 'works with virt_lines above and below' , function () 1151screen : try_resize ( 55 , 7 ) 1152exec ( [=[ 1153call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(3)) 1154set smoothscroll 1155let ns = nvim_create_namespace('') 1156call nvim_buf_set_extmark(0, ns, 0, 0, {'virt_lines':[[['virt_below1']]]}) 1157call nvim_buf_set_extmark(0, ns, 1, 0, {'virt_lines':[[['virt_above1']]],'virt_lines_above':1}) 1158call nvim_buf_set_extmark(0, ns, 1, 0, {'virt_lines':[[['virt_below2']]]}) 1159call nvim_buf_set_extmark(0, ns, 2, 0, {'virt_lines':[[['virt_above2']]],'virt_lines_above':1}) 1160norm ggL 1161]=] ) 1162screen : expect ( [[ 1163Line with some text with some text with some text with | 1164some text with some text with some text with some text | 1165virt_below1 | 1166virt_above1 | 1167^Line with some text with some text with some text with | 1168some text with some text with some text with some text | 1169| 1170]] ) 1171feed ( '<C-E>' ) 1172screen : expect ( [[ 1173{1:<<<}e text with some text with some text with some text | 1174virt_below1 | 1175virt_above1 | 1176^Line with some text with some text with some text with | 1177some text with some text with some text with some text | 1178virt_below2 | 1179| 1180]] ) 1181feed ( '<C-E>' ) 1182screen : expect ( [[ 1183virt_below1 | 1184virt_above1 | 1185^Line with some text with some text with some text with | 1186some text with some text with some text with some text | 1187virt_below2 | 1188virt_above2 | 1189| 1190]] ) 1191feed ( '<C-E>' ) 1192screen : expect ( [[ 1193virt_above1 | 1194^Line with some text with some text with some text with | 1195some text with some text with some text with some text | 1196virt_below2 | 1197virt_above2 | 1198Line with some text with some text with some text wi{1:@@@}| 1199| 1200]] ) 1201feed ( '<C-E>' ) 1202screen : expect ( [[ 1203^Line with some text with some text with some text with | 1204some text with some text with some text with some text | 1205virt_below2 | 1206virt_above2 | 1207Line with some text with some text with some text with | 1208some text with some text with some text with some text | 1209| 1210]] ) 1211feed ( '<C-E>' ) 1212screen : expect ( [[ 1213{1:<<<}e text with some text with some text with some tex^t | 1214virt_below2 | 1215virt_above2 | 1216Line with some text with some text with some text with | 1217some text with some text with some text with some text | 1218{1:~ }| 1219| 1220]] ) 1221end ) 1222 1223it ( '<<< marker shows with tabline, winbar and splits' , function () 1224screen : try_resize ( 40 , 12 ) 1225screen : add_extra_attr_ids { 1226[ 100 ] ={ foreground =Screen . colors . Magenta1 , bold =true } , 1227} 1228exec ( [[ 1229call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) 1230set smoothscroll scrolloff=0 1231norm sj 1232]] ) 1233screen : expect ( [[ 1234{1:<<<}e text with some text with some text | 1235with some text with some text | 1236Line with some text with some text with | 1237some text with some text with some text | 1238with some text with some text | 1239{2:[No Name] [+] }| 1240{1:<<<}e text with some text with some text | 1241^with some text with some text | 1242Line with some text with some text with | 1243some text with some text with some te{1:@@@}| 1244{3:[No Name] [+] }| 1245| 1246]] ) 1247exec ( 'set showtabline=2' ) 1248screen : expect ( [[ 1249{5: }{100:2}{5:+ [No Name] }{2: }| 1250{1:<<<}e text with some text with some text | 1251with some text with some text | 1252Line with some text with some text with | 1253some text with some text with some text | 1254with some text with some text | 1255{2:[No Name] [+] }| 1256{1:<<<}e text with some text with some text | 1257^with some text with some text | 1258Line with some text with some text wi{1:@@@}| 1259{3:[No Name] [+] }| 1260| 1261]] ) 1262exec ( 'set winbar=winbar' ) 1263feed ( '<C-w>k' ) 1264screen : expect ( [[ 1265{5: }{100:2}{5:+ [No Name] }{2: }| 1266{5:winbar }| 1267{1:<<<}e text with some text with some text | 1268^with some text with some text | 1269Line with some text with some text with | 1270some text with some text with some te{1:@@@}| 1271{3:[No Name] [+] }| 1272{5:winbar }| 1273{1:<<<}e text with some text with some text | 1274with some text with some text | 1275{2:[No Name] [+] }| 1276| 1277]] ) 1278end ) 1279 1280it ( 'works with very long line' , function () 1281exec ( [[ 1282edit test/functional/fixtures/bigfile_oneline.txt 1283setlocal smoothscroll number 1284]] ) 1285screen : expect ( [[ 1286{8: 1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;| 1287{8: }; 0001;<control>;Cc;0;BN;;;;;N;START| 1288{8: } OF HEADING;;;; 0002;<control>;Cc;0;| 1289{8: }BN;;;;;N;START OF TEXT;;;; 0003;<con| 1290{8: }trol>;Cc;0;BN;;;;;N;END OF TEXT;;;; | 1291{8: }0004;<control>;Cc;0;BN;;;;;N;END OF | 1292{8: }TRANSMISSION;;;; 0005;<control>;Cc;0| 1293{8: };BN;;;;;N;ENQUIRY;;;; 0006;<control>| 1294{8: };Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; 0007;| 1295{8: }<control>;Cc;0;BN;;;;;N;BELL;;;; 000| 1296{8: }8;<control>;Cc;0;BN;;;;;N;BACKSPACE;| 1297| 1298]] ) 1299feed ( 'j' ) 1300screen : expect ( [[ 1301{1:<<<}{8: }CJK COMPATIBILITY IDEOGRAPH-2F91F;Lo| 1302{8: };0;L;243AB;;;;N;;;;; 2F920;CJK COMPA| 1303{8: }TIBILITY IDEOGRAPH-2F920;Lo;0;L;7228| 1304{8: };;;;N;;;;; 2F921;CJK COMPATIBILITY I| 1305{8: }DEOGRAPH-2F921;Lo;0;L;7235;;;;N;;;;;| 1306{8: } 2F922;CJK COMPATIBILITY IDEOGRAPH-2| 1307{8: }F922;Lo;0;L;7250;;;;N;;;;; | 1308{8: 2 }^2F923;CJK COMPATIBILITY IDEOGRAPH-2F| 1309{8: }923;Lo;0;L;24608;;;;N;;;;; | 1310{8: 3 }2F924;CJK COMPATIBILITY IDEOGRAPH-2F| 1311{8: }924;Lo;0;L;7280;;;;N;;;;; | 1312| 1313]] ) 1314end ) 1315 1316it ( 'works with very long line and scrolloff' , function () 1317screen : try_resize ( 40 , 8 ) 1318exec ( [[ 1319set smoothscroll scrolloff=3 1320call setline(1, ['one', 'two long '->repeat(100), 'three', 'four', 'five', 'six']) 1321]] ) 1322feed ( ':norm j721|<CR>' ) 1323screen : expect ( [[ 1324{1:<<<}two long two long two long two long t| 1325wo long two long two long two long two l| 1326ong two long two long two long two long | 1327^two long two long two long two long two | 1328long two long two long two long two long| 1329two long two long two long two long two| 1330long two long two long two long two lon| 1331:norm j721| | 1332]] ) 1333feed ( 'gj' ) 1334screen : expect ( [[ 1335{1:<<<}two long two long two long two long t| 1336wo long two long two long two long two l| 1337ong two long two long two long two long | 1338two long two long two long two long two | 1339^long two long two long two long two long| 1340two long two long two long two long two| 1341long two long two long two long two lon| 1342:norm j721| | 1343]] ) 1344feed ( 'gj' ) 1345screen : expect ( [[ 1346{1:<<<}long two long two long two long two l| 1347ong two long two long two long two long | 1348two long two long two long two long two | 1349long two long two long two long two long| 1350^ two long two long two long two long two| 1351long two long two long two long two lon| 1352g two long two long | 1353:norm j721| | 1354]] ) 1355feed ( 'gj' ) 1356screen : expect ( [[ 1357{1:<<<}long two long two long two long two l| 1358ong two long two long two long two long | 1359two long two long two long two long two | 1360long two long two long two long two long| 1361two long two long two long two long two| 1362^ long two long two long two long two lon| 1363g two long two long | 1364:norm j721| | 1365]] ) 1366feed ( 'gj' ) 1367screen : expect ( [[ 1368{1:<<<}long two long two long two long two l| 1369ong two long two long two long two long | 1370two long two long two long two long two | 1371long two long two long two long two long| 1372two long two long two long two long two| 1373long two long two long two long two lon| 1374^g two long two long | 1375:norm j721| | 1376]] ) 1377feed ( 'gj' ) 1378screen : expect ( [[ 1379{1:<<<} long two long two long two long two | 1380long two long two long two long two long| 1381two long two long two long two long two| 1382long two long two long two long two lon| 1383g two long two long | 1384^three | 1385four | 1386:norm j721| | 1387]] ) 1388feed ( 'gk' ) 1389screen : expect ( [[ 1390{1:<<<}long two long two long two long two l| 1391ong two long two long two long two long | 1392two long two long two long two long two | 1393long two long two long two long two long| 1394two long two long two long two long two| 1395long two long two long two long two lon| 1396^g two long two long | 1397:norm j721| | 1398]] ) 1399end ) 1400end ) 1401 1402describe ( 'scrolloffpad' , function () 1403local screen 1404 1405before_each ( function () 1406screen =Screen . new ( 78 , 20 ) 1407end ) 1408 1409-- oldtest: Test_scrolloffpad_basic() 1410it ( 'works' , function () 1411exec ( [[ 1412set scrolloff=10 1413set scrolloffpad=5 1414enew! 1415call setline(1, map(range(1, 100), 'printf("line %d", v:val)')) 1416normal! gg 1417]] ) 1418 1419-- Enabled: scrolloffpad > 0, expect EOF centering/padding 1420exec ( 'normal! G' ) 1421screen : expect ( [[ 1422line 91 | 1423line 92 | 1424line 93 | 1425line 94 | 1426line 95 | 1427line 96 | 1428line 97 | 1429line 98 | 1430line 99 | 1431^line 100 | 1432{1:~ }|*9 1433| 1434]] ) 1435 1436-- Beginning-of-file is unchanged (Top) 1437exec ( 'normal! gg' ) 1438screen : expect ( [[ 1439^line 1 | 1440line 2 | 1441line 3 | 1442line 4 | 1443line 5 | 1444line 6 | 1445line 7 | 1446line 8 | 1447line 9 | 1448line 10 | 1449line 11 | 1450line 12 | 1451line 13 | 1452line 14 | 1453line 15 | 1454line 16 | 1455line 17 | 1456line 18 | 1457line 19 | 1458| 1459]] ) 1460 1461-- Gating: disable scrolloffpad, then go to EOF again 1462-- Expect normal EOF behavior (no extra centering/padding) 1463exec ( 'set scrolloffpad=0' ) 1464exec ( 'normal! G' ) 1465screen : expect ( [[ 1466line 82 | 1467line 83 | 1468line 84 | 1469line 85 | 1470line 86 | 1471line 87 | 1472line 88 | 1473line 89 | 1474line 90 | 1475line 91 | 1476line 92 | 1477line 93 | 1478line 94 | 1479line 95 | 1480line 96 | 1481line 97 | 1482line 98 | 1483line 99 | 1484^line 100 | 1485| 1486]] ) 1487end ) 1488 1489-- oldtest: Test_scrolloffpad_smoothscroll() 1490it ( 'works with smoothscroll' , function () 1491exec ( [[ 1492set smoothscroll scrolloff=10 scrolloffpad=1 1493enew! 1494call setline(1, map(range(1, 100), 'printf("line %d", v:val)')) 1495normal! gg 1496]] ) 1497 1498exec ( 'normal! G' ) 1499screen : expect ( [[ 1500line 91 | 1501line 92 | 1502line 93 | 1503line 94 | 1504line 95 | 1505line 96 | 1506line 97 | 1507line 98 | 1508line 99 | 1509^line 100 | 1510{1:~ }|*9 1511| 1512]] ) 1513 1514exec ( [[call setline(line('$'), repeat('LONG ', 30))]] ) 1515exec ( 'normal! 41|' ) 1516screen : expect ( [[ 1517line 92 | 1518line 93 | 1519line 94 | 1520line 95 | 1521line 96 | 1522line 97 | 1523line 98 | 1524line 99 | 1525LONG LONG LONG LONG LONG LONG LONG LONG ^LONG LONG LONG LONG LONG LONG LONG LON| 1526G LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG | 1527{1:~ }|*9 1528| 1529]] ) 1530end ) 1531 1532-- oldtest: Test_scrolloffpad_with_folds() 1533it ( 'works with folds' , function () 1534exec ( [[ 1535set scrolloff=10 1536set scrolloffpad=1 1537 1538enew 1539call setline(1, map(range(1, 120), {_, v -> 'line ' . v})) 1540 1541" Create a large fold near the end of the file. 1542" Fold lines 60-110, leaving 111-120 visible after the fold. 1543set foldmethod=manual 1544set foldenable 1545normal! gg 1546normal! 60G 1547normal! zf50j 1548normal! gg 1549]] ) 1550 1551-- Case 1: Jump to end-of-file 1552-- With folds present, scrolloffpad should still 1553-- keep the cursor positioned with padding below EOF 1554exec ( 'normal! G' ) 1555local s1 =[[ 1556line 111 | 1557line 112 | 1558line 113 | 1559line 114 | 1560line 115 | 1561line 116 | 1562line 117 | 1563line 118 | 1564line 119 | 1565^line 120 | 1566{1:~ }|*9 1567| 1568]] 1569screen : expect ( s1 ) 1570 1571-- Case 2: Move to the folded line to ensure the fold is actually in view 1572exec ( 'normal! 60G' ) 1573screen : expect ( [[ 1574line 51 | 1575line 52 | 1576line 53 | 1577line 54 | 1578line 55 | 1579line 56 | 1580line 57 | 1581line 58 | 1582line 59 | 1583{13:^+-- 51 lines: line 60·························································}| 1584line 111 | 1585line 112 | 1586line 113 | 1587line 114 | 1588line 115 | 1589line 116 | 1590line 117 | 1591line 118 | 1592line 119 | 1593| 1594]] ) 1595 1596-- Case 3: Close the fold explicitly and go to EOF again 1597-- Behavior should remain stable with closed folds 1598exec ( 'normal! zc' ) 1599exec ( 'normal! G' ) 1600screen : expect ( s1 ) 1601end ) 1602 1603it ( "uses the target window's value, not the current window's" , function () 1604exec ( [[ 1605set scrolloff=10 scrolloffpad=0 1606enew! 1607call setline(1, map(range(1, 100), 'printf("line %d", v:val)')) 1608split 1609setlocal scrolloffpad=5 1610normal! G 1611wincmd j 1612silent 1,60d 1613]] ) 1614-- The upper window turned 'scrolloffpad' on for itself, so its own value 1615-- decides how far its cursor is padded from the end of the buffer, even 1616-- though the current window leaves the option at the global 0. 1617t . eq ( 36 , n . fn . line ( 'w0' , n . fn . win_getid ( 1 ))) 1618end ) 1619end ) 1620 1621describe ( 'scroll_cursor_halfway()' , function () 1622local screen 1623 1624before_each ( function () 1625screen =Screen . new ( 40 , 12 ) 1626end ) 1627 1628it ( 'weighs lines by their screen height' , function () 1629exec ( [[ 1630set nosmoothscroll scrolloff=0 1631call setline(1, map(range(1, 20), '"short " .. v:val')) 1632call append(20, 'CURSOR') 1633call append(21, map(range(1, 8), 'repeat("x", 200)')) 1634]] ) 1635feed ( '21Gzz' ) 1636-- The lines below the cursor wrap to five rows each, so only one of them 1637-- fits under the cursor once it sits on row 6 of this 11 row window. 1638screen : expect ( [[ 1639short 16 | 1640short 17 | 1641short 18 | 1642short 19 | 1643short 20 | 1644^CURSOR | 1645xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|*5 1646| 1647]] ) 1648end ) 1649end )