patch 8.1.2265: when popup with "botleft" does not fit it flips incorrectly
Problem: When popup with "botleft" does not fit it flips incorrectly.
Solution: Only flip when there is more space on the other side. Add the
"posinvert" option to disable flipping and do it in both
directions if enabled. (closes #5151)
diff --git a/src/testdir/dumps/Test_popupwin_nospace.dump b/src/testdir/dumps/Test_popupwin_nospace.dump
new file mode 100644
index 0000000..f062a68
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_nospace.dump
@@ -0,0 +1,12 @@
+|-+0&#ffffff0|╔+0#0000001#ffd7ff255|═@2|╗|-+0#0000000#ffffff0@1|╔+0#0000001#ffd7ff255|═@2|╗|-+0#0000000#ffffff0@8|╔+0#0000001#ffd7ff255|═@2|╗|-+0#0000000#ffffff0@32| @14
+|-|║+0#0000001#ffd7ff255|o|n|e|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255|o|n|e|║|-+0#0000000#ffffff0@8|║+0#0000001#ffd7ff255|a@2|║|-+0#0000000#ffffff0@32| @14
+|-|║+0#0000001#ffd7ff255|t|w|o|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255|t|w|o|║|-+0#0000000#ffffff0@8|║+0#0000001#ffd7ff255|b@2|║|-+0#0000000#ffffff0@15|╔+0#0000001#ffd7ff255|═@2|╗|-+0#0000000#ffffff0@11| @14
+|-|╚+0#0000001#ffd7ff255|═@2|╝|-+0#0000000#ffffff0@1|╚+0#0000001#ffd7ff255|═@2|╝|-+0#0000000#ffffff0@8|║+0#0000001#ffd7ff255|c@2|║|-+0#0000000#ffffff0@15|║+0#0000001#ffd7ff255|o|n|e|║|-+0#0000000#ffffff0@11| @14
+|-|@|-@5|#|-@5|%|-@5|║+0#0000001#ffd7ff255|d@2|║|-+0#0000000#ffffff0@15|║+0#0000001#ffd7ff255|t|w|o|║|-+0#0000000#ffffff0@1>*|-@8| @14
+|-@14|╔+0#0000001#ffd7ff255|═@2|╗|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255|e@2|║|-+0#0000000#ffffff0@15|║+0#0000001#ffd7ff255|t|e@1|║|-+0#0000000#ffffff0@1|╔+0#0000001#ffd7ff255|═@2|╗|-+0#0000000#ffffff0@4| @14
+|-@14|║+0#0000001#ffd7ff255|o|n|e|║|-+0#0000000#ffffff0@1|╚+0#0000001#ffd7ff255|═@2|╝|-+0#0000000#ffffff0@15|╚+0#0000001#ffd7ff255|═@2|╝|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255|a@2|║|-+0#0000000#ffffff0@4| @14
+|-@14|║+0#0000001#ffd7ff255|t|w|o|║|-+0#0000000#ffffff0@1|*|-@5|@|-@5|#|-@5|%|-@5|║+0#0000001#ffd7ff255|b@2|║|-+0#0000000#ffffff0@4| @14
+|-@14|║+0#0000001#ffd7ff255|t|e@1|║|-+0#0000000#ffffff0@8|╔+0#0000001#ffd7ff255|═@2|╗|-+0#0000000#ffffff0@1|╔+0#0000001#ffd7ff255|═@2|╗|-+0#0000000#ffffff0@8|║+0#0000001#ffd7ff255|c@2|║|-+0#0000000#ffffff0@4| @14
+|-@14|╚+0#0000001#ffd7ff255|═@2|╝|-+0#0000000#ffffff0@8|║+0#0000001#ffd7ff255|o|n|e|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255|o|n|e|║|-+0#0000000#ffffff0@8|║+0#0000001#ffd7ff255|d@2|║|-+0#0000000#ffffff0@4| @14
+|-@28|║+0#0000001#ffd7ff255|t|w|o|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255|t|w|o|║|-+0#0000000#ffffff0@8|║+0#0000001#ffd7ff255|e@2|║|-+0#0000000#ffffff0@4| @14
+@29|╚+0#0000001#ffd7ff255|═@2|╝| +0#0000000#ffffff0@1|║+0#0000001#ffd7ff255|t|e@1|║| +0#0000000#ffffff0@8|║+0#0000001#ffd7ff255|f@2|║| +0#0000000#ffffff0@1|5|,|5|1| @9|T|o|p|
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index e38b721..0a45df4 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -323,6 +323,98 @@
call delete('XtestPopupCorners')
endfunc
+func Test_popup_nospace()
+ CheckScreendump
+
+ let lines =<< trim END
+ call setline(1, repeat([repeat('-', 60)], 15))
+ set so=0
+
+ " cursor in a line in top half, using "botleft" with popup that
+ " does fit
+ normal 5G2|r@
+ let winid1 = popup_create(['one', 'two'], #{
+ \ line: 'cursor-1',
+ \ col: 'cursor',
+ \ pos: 'botleft',
+ \ border: [],
+ \ })
+ " cursor in a line in top half, using "botleft" with popup that
+ " doesn't fit: gets truncated
+ normal 5G9|r#
+ let winid1 = popup_create(['one', 'two', 'tee'], #{
+ \ line: 'cursor-1',
+ \ col: 'cursor',
+ \ pos: 'botleft',
+ \ posinvert: 0,
+ \ border: [],
+ \ })
+ " cursor in a line in top half, using "botleft" with popup that
+ " doesn't fit and 'posinvert' set: flips to below.
+ normal 5G16|r%
+ let winid1 = popup_create(['one', 'two', 'tee'], #{
+ \ line: 'cursor-1',
+ \ col: 'cursor',
+ \ pos: 'botleft',
+ \ border: [],
+ \ })
+ " cursor in a line in bottom half, using "botleft" with popup that
+ " doesn't fit: does not flip.
+ normal 8G23|r*
+ let winid1 = popup_create(['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], #{
+ \ line: 'cursor-1',
+ \ col: 'cursor',
+ \ pos: 'botleft',
+ \ border: [],
+ \ })
+
+ " cursor in a line in bottom half, using "topleft" with popup that
+ " does fit
+ normal 8G30|r@
+ let winid1 = popup_create(['one', 'two'], #{
+ \ line: 'cursor+1',
+ \ col: 'cursor',
+ \ pos: 'topleft',
+ \ border: [],
+ \ })
+ " cursor in a line in top half, using "topleft" with popup that
+ " doesn't fit: truncated
+ normal 8G37|r#
+ let winid1 = popup_create(['one', 'two', 'tee'], #{
+ \ line: 'cursor+1',
+ \ col: 'cursor',
+ \ pos: 'topleft',
+ \ posinvert: 0,
+ \ border: [],
+ \ })
+ " cursor in a line in top half, using "topleft" with popup that
+ " doesn't fit and "posinvert" set: flips to below.
+ normal 8G44|r%
+ let winid1 = popup_create(['one', 'two', 'tee'], #{
+ \ line: 'cursor+1',
+ \ col: 'cursor',
+ \ pos: 'topleft',
+ \ border: [],
+ \ })
+ " cursor in a line in top half, using "topleft" with popup that
+ " doesn't fit: does not flip.
+ normal 5G51|r*
+ let winid1 = popup_create(['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], #{
+ \ line: 'cursor+1',
+ \ col: 'cursor',
+ \ pos: 'topleft',
+ \ border: [],
+ \ })
+ END
+ call writefile(lines, 'XtestPopupNospace')
+ let buf = RunVimInTerminal('-S XtestPopupNospace', #{rows: 12})
+ call VerifyScreenDump(buf, 'Test_popupwin_nospace', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+ call delete('XtestPopupNospace')
+endfunc
+
func Test_popup_firstline()
CheckScreendump
@@ -586,6 +678,7 @@
\], #{
\ line: 1,
\ col: 10,
+ \ posinvert: 0,
\ wrap: 0,
\ fixed: 1,
\ zindex: 90,
@@ -604,6 +697,7 @@
\], #{
\ line: 7,
\ col: 10,
+ \ posinvert: 0,
\ wrap: 0,
\ fixed: 1,
\ close: 'button',