comparison src/testdir/test_window_cmd.vim @ 15977:7fbdceabad64 v8.1.0994

patch 8.1.0994: relative cursor position is not calculated correctly commit https://github.com/vim/vim/commit/8fcb60f961bdd134599fb016c6537fd496e800f5 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 4 13:18:30 2019 +0100 patch 8.1.0994: relative cursor position is not calculated correctly Problem: Relative cursor position is not calculated correctly. Solution: Always set topline, also when window is one line only. (Robert Webb) Add more info to getwininfo() for testing.
author Bram Moolenaar <Bram@vim.org>
date Mon, 04 Mar 2019 13:30:08 +0100
parents 63b02fcf1361
children 243cdc183ec9
comparison
equal deleted inserted replaced
15976:50aa746472f6 15977:7fbdceabad64
613 call delete('tmp.txt') 613 call delete('tmp.txt')
614 set hidden&vim autoread&vim 614 set hidden&vim autoread&vim
615 delfunc Fun_RenewFile 615 delfunc Fun_RenewFile
616 endfunc 616 endfunc
617 617
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 3wincmd 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 1wincmd 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 1wincmd 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 2wincmd 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 1wincmd w
717 let winid1 = win_getid()
718 let info = getwininfo(winid1)[0]
719
720 " Make the window only two lines high
721 2wincmd _
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
618 " vim: shiftwidth=2 sts=2 expandtab 746 " vim: shiftwidth=2 sts=2 expandtab