comparison src/testdir/test_popupwin.vim @ 16896:52fc577a087d v8.1.1449

patch 8.1.1449: popup text truncated at end of screen commit https://github.com/vim/vim/commit/042fb4b449bb5d8494698803e766dfd288b458cf Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 2 14:49:56 2019 +0200 patch 8.1.1449: popup text truncated at end of screen Problem: Popup text truncated at end of screen. Solution: Move popup left if needed. Add the "fixed" property to disable that. (Ben Jackson , closes #4466)
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 Jun 2019 15:00:06 +0200
parents 236c182c6300
children 16fd1bb2e675
comparison
equal deleted inserted replaced
16895:44f703825130 16896:52fc577a087d
420 \ 'minheight': 11, 420 \ 'minheight': 11,
421 \ 'maxwidth': 20, 421 \ 'maxwidth': 20,
422 \ 'maxheight': 21, 422 \ 'maxheight': 21,
423 \ 'zindex': 100, 423 \ 'zindex': 100,
424 \ 'time': 5000, 424 \ 'time': 5000,
425 \ 'fixed': 1
425 \}) 426 \})
426 redraw 427 redraw
427 let res = popup_getoptions(winid) 428 let res = popup_getoptions(winid)
428 call assert_equal(2, res.line) 429 call assert_equal(2, res.line)
429 call assert_equal(3, res.col) 430 call assert_equal(3, res.col)
430 call assert_equal(10, res.minwidth) 431 call assert_equal(10, res.minwidth)
431 call assert_equal(11, res.minheight) 432 call assert_equal(11, res.minheight)
432 call assert_equal(20, res.maxwidth) 433 call assert_equal(20, res.maxwidth)
433 call assert_equal(21, res.maxheight) 434 call assert_equal(21, res.maxheight)
434 call assert_equal(100, res.zindex) 435 call assert_equal(100, res.zindex)
436 call assert_equal(1, res.fixed)
435 if has('timers') 437 if has('timers')
436 call assert_equal(5000, res.time) 438 call assert_equal(5000, res.time)
437 endif 439 endif
438 call popup_close(winid) 440 call popup_close(winid)
439 441
445 call assert_equal(0, res.minwidth) 447 call assert_equal(0, res.minwidth)
446 call assert_equal(0, res.minheight) 448 call assert_equal(0, res.minheight)
447 call assert_equal(0, res.maxwidth) 449 call assert_equal(0, res.maxwidth)
448 call assert_equal(0, res.maxheight) 450 call assert_equal(0, res.maxheight)
449 call assert_equal(50, res.zindex) 451 call assert_equal(50, res.zindex)
452 call assert_equal(0, res.fixed)
450 if has('timers') 453 if has('timers')
451 call assert_equal(0, res.time) 454 call assert_equal(0, res.time)
452 endif 455 endif
453 call popup_close(winid) 456 call popup_close(winid)
454 call assert_equal({}, popup_getoptions(winid)) 457 call assert_equal({}, popup_getoptions(winid))
645 648
646 " clean up 649 " clean up
647 call StopVimInTerminal(buf) 650 call StopVimInTerminal(buf)
648 call delete('XtestPopupBehind') 651 call delete('XtestPopupBehind')
649 endfunc 652 endfunc
653
654 func s:VerifyPosition( p, msg, line, col, width, height )
655 call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' )
656 call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' )
657 call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' )
658 call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' )
659 endfunc
660
661 func Test_popup_position_adjust()
662 " Anything placed past 2 cells from of the right of the screen is moved to the
663 " left.
664 "
665 " When wrapping is disabled, we also shift to the left to display on the
666 " screen, unless fixed is set.
667
668 " Entries for cases which don't vary based on wrapping.
669 " Format is per tests described below
670 let both_wrap_tests = [
671 \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ],
672 \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ],
673 \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ],
674 \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ],
675 \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ],
676 \
677 \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ],
678 \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ],
679 \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ],
680 \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ],
681 \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ],
682 \
683 \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ],
684 \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
685 \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
686 \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
687 \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ],
688 \ ]
689
690 " these test groups are dicts with:
691 " - comment: something to identify the group of tests by
692 " - options: dict of options to merge with the row/col in tests
693 " - tests: list of cases. Each one is a list with elements:
694 " - text
695 " - row
696 " - col
697 " - expected row
698 " - expected col
699 " - expected width
700 " - expected height
701 let tests = [
702 \ {
703 \ 'comment': 'left-aligned with wrapping',
704 \ 'options': {
705 \ 'wrap': 1,
706 \ 'pos': 'botleft',
707 \ },
708 \ 'tests': both_wrap_tests + [
709 \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ],
710 \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ],
711 \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ],
712 \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ],
713 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
714 \ ],
715 \ },
716 \ {
717 \ 'comment': 'left aligned without wrapping',
718 \ 'options': {
719 \ 'wrap': 0,
720 \ 'pos': 'botleft',
721 \ },
722 \ 'tests': both_wrap_tests + [
723 \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ],
724 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ],
725 \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ],
726 \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ],
727 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
728 \ ],
729 \ },
730 \ {
731 \ 'comment': 'left aligned with fixed position',
732 \ 'options': {
733 \ 'wrap': 0,
734 \ 'fixed': 1,
735 \ 'pos': 'botleft',
736 \ },
737 \ 'tests': both_wrap_tests + [
738 \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ],
739 \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ],
740 \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ],
741 \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ],
742 \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ],
743 \ ],
744 \ },
745 \ ]
746
747 for test_group in tests
748 for test in test_group.tests
749 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
750 let options = {
751 \ 'line': line,
752 \ 'col': col,
753 \ }
754 call extend( options, test_group.options )
755
756 let p = popup_create( text, options )
757
758 let msg = string( extend( options, { 'text': text } ) )
759 call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height )
760 call popup_close( p )
761 endfor
762 endfor
763
764 popupclear
765 %bwipe!
766 endfunc
767
768 function Test_adjust_left_past_screen_width()
769 " width of screen
770 let X = join(map(range(&columns), {->'X'}), '')
771
772 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
773 call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 )
774
775 redraw
776 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
777 call assert_equal(X, line)
778
779 call popup_close( p )
780 redraw
781
782 " Same if placed on the right hand side
783 let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } )
784 call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 )
785
786 redraw
787 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
788 call assert_equal(X, line)
789
790 call popup_close( p )
791 redraw
792
793 " Extend so > window width
794 let X .= 'x'
795
796 let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } )
797 call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 )
798
799 redraw
800 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
801 call assert_equal(X[ : -2 ], line)
802
803 call popup_close( p )
804 redraw
805
806 " Shifted then truncated (the x is not visible)
807 let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } )
808 call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 )
809
810 redraw
811 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
812 call assert_equal(X[ : -2 ], line)
813
814 call popup_close( p )
815 redraw
816
817 " Not shifted, just truncated
818 let p = popup_create( X,
819 \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } )
820 call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
821
822 redraw
823 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
824 let e_line = ' ' . X[ 1 : -2 ]
825 call assert_equal(e_line, line)
826
827 call popup_close( p )
828 redraw
829
830 popupclear
831 %bwipe!
832 endfunction