@@ -615,4 +615,132 @@ func Test_window_prevwin()
615615 delfunc Fun_RenewFile
616616endfunc
617617
618+ func Test_relative_cursor_position_in_one_line_window ()
619+ new
620+ only
621+ call setline (1 , range (1 , 10000 ))
622+ normal 50 %
623+ let lnum = getcurpos ()[1 ]
624+ split
625+ split
626+ " make third window take as many lines as possible, other windows will
627+ " become one line
628+ 3 wincmd w
629+ for i in range (1 , &lines - 6 )
630+ wincmd +
631+ redraw !
632+ endfor
633+
634+ " first and second window should show cursor line
635+ let wininfo = getwininfo ()
636+ call assert_equal (lnum, wininfo[0 ].topline)
637+ call assert_equal (lnum, wininfo[1 ].topline)
638+
639+ only !
640+ bwipe!
641+ endfunc
642+
643+ func Test_relative_cursor_position_after_move_and_resize ()
644+ let so_save = &so
645+ set so = 0
646+ enew
647+ call setline (1 , range (1 , 10000 ))
648+ normal 50 %
649+ split
650+ 1 wincmd w
651+ " Move cursor to first line in window
652+ normal H
653+ redraw !
654+ " Reduce window height to two lines
655+ let height = winheight (0 )
656+ while winheight (0 ) > 2
657+ wincmd -
658+ redraw !
659+ endwhile
660+ " move cursor to second/last line in window
661+ normal j
662+ " restore previous height
663+ while winheight (0 ) < height
664+ wincmd +
665+ redraw !
666+ endwhile
667+ " make window two lines again
668+ while winheight (0 ) > 2
669+ wincmd -
670+ redraw !
671+ endwhile
672+
673+ " cursor should be at bottom line
674+ let info = getwininfo (win_getid ())[0 ]
675+ call assert_equal (info.topline + 1 , getcurpos ()[1 ])
676+
677+ only !
678+ bwipe!
679+ let &so = so_save
680+ endfunc
681+
682+ func Test_relative_cursor_position_after_resize ()
683+ let so_save = &so
684+ set so = 0
685+ enew
686+ call setline (1 , range (1 , 10000 ))
687+ normal 50 %
688+ split
689+ 1 wincmd w
690+ let winid1 = win_getid ()
691+ let info = getwininfo (winid1)[0 ]
692+ " Move cursor to second line in window
693+ exe " normal " . (info.topline + 1 ) . " G"
694+ redraw !
695+ let lnum = getcurpos ()[1 ]
696+
697+ " Make the window only two lines high, cursor should end up in top line
698+ 2 wincmd w
699+ exe (info.height - 2 ) . " wincmd +"
700+ redraw !
701+ let info = getwininfo (winid1)[0 ]
702+ call assert_equal (lnum, info.topline)
703+
704+ only !
705+ bwipe!
706+ let &so = so_save
707+ endfunc
708+
709+ func Test_relative_cursor_second_line_after_resize ()
710+ let so_save = &so
711+ set so = 0
712+ enew
713+ call setline (1 , range (1 , 10000 ))
714+ normal 50 %
715+ split
716+ 1 wincmd w
717+ let winid1 = win_getid ()
718+ let info = getwininfo (winid1)[0 ]
719+
720+ " Make the window only two lines high
721+ 2 wincmd _
722+
723+ " Move cursor to second line in window
724+ normal H
725+ normal j
726+
727+ " Make window size bigger, then back to 2 lines
728+ for i in range (1 , 10 )
729+ wincmd +
730+ redraw !
731+ endfor
732+ for i in range (1 , 10 )
733+ wincmd -
734+ redraw !
735+ endfor
736+
737+ " cursor should end up in bottom line
738+ let info = getwininfo (winid1)[0 ]
739+ call assert_equal (info.topline + 1 , getcurpos ()[1 ])
740+
741+ only !
742+ bwipe!
743+ let &so = so_save
744+ endfunc
745+
618746" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments