patch 8.2.1406: popupwindow lacks scrollbar if no "maxheight" is used
Problem: Popupwindow lacks scrollbar if no "maxheight" is used.
Solution: Compute the max height depending on the position. (closes #6664)
diff --git a/src/testdir/dumps/Test_popupwin_toohigh_1.dump b/src/testdir/dumps/Test_popupwin_toohigh_1.dump
new file mode 100644
index 0000000..41dbd44
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_toohigh_1.dump
@@ -0,0 +1,10 @@
+|1+0&#ffffff0@9| @64
+|2@9| @64
+|3@8>3| @64
+|4@8|╔+0#0000001#ffd7ff255|═@8|╗| +0#0000000#ffffff0@54
+|5@8|║+0#0000001#ffd7ff255|o|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|6@8|║+0#0000001#ffd7ff255|t|w|o| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|7@8|║+0#0000001#ffd7ff255|t|h|r|e@1| @2| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|8@8|║+0#0000001#ffd7ff255|f|o|u|r| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|9@8|║+0#0000001#ffd7ff255|f|i|v|e| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+@9|╚+0#0000001#ffd7ff255|═@8|╝| +0#0000000#ffffff0@36|3|,|1|0| @9|T|o|p|
diff --git a/src/testdir/dumps/Test_popupwin_toohigh_2.dump b/src/testdir/dumps/Test_popupwin_toohigh_2.dump
new file mode 100644
index 0000000..911cc2f
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_toohigh_2.dump
@@ -0,0 +1,10 @@
+|1+0&#ffffff0@8|╔+0#0000001#ffd7ff255|═@8|╗| +0#0000000#ffffff0@54
+|2@8|║+0#0000001#ffd7ff255|o|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|3@8|║+0#0000001#ffd7ff255|t|w|o| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|4@8|║+0#0000001#ffd7ff255|t|h|r|e@1| @2| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|5@8|║+0#0000001#ffd7ff255|f|o|u|r| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|6@8|║+0#0000001#ffd7ff255|f|i|v|e| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@54
+|7@8|╚+0#0000001#ffd7ff255|═@8|╝| +0#0000000#ffffff0@54
+|8@8>8| @64
+|9@9| @64
+|:|c|a|l@1| |S|h|o|w|P|o|p|u|p|(|)| @39|8|,|1|0| @9|T|o|p|
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 30dfc66..c44c847 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -2144,6 +2144,36 @@
call delete('XtestPopupScroll')
endfunc
+func Test_popup_too_high_scrollbar()
+ CheckScreendump
+
+ let lines =<< trim END
+ call setline(1, range(1, 20)->map({i, v -> repeat(v, 10)}))
+ set scrolloff=0
+ func ShowPopup()
+ let winid = popup_atcursor(['one', 'two', 'three', 'four', 'five',
+ \ 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'], #{
+ \ minwidth: 8,
+ \ border: [],
+ \ })
+ endfunc
+ normal 3G$
+ call ShowPopup()
+ END
+ call writefile(lines, 'XtestPopupToohigh')
+ let buf = RunVimInTerminal('-S XtestPopupToohigh', #{rows: 10})
+ call VerifyScreenDump(buf, 'Test_popupwin_toohigh_1', {})
+
+ call term_sendkeys(buf, ":call popup_clear()\<CR>")
+ call term_sendkeys(buf, "8G$")
+ call term_sendkeys(buf, ":call ShowPopup()\<CR>")
+ call VerifyScreenDump(buf, 'Test_popupwin_toohigh_2', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+ call delete('XtestPopupToohigh')
+endfunc
+
func Test_popup_fitting_scrollbar()
" this was causing a crash, divide by zero
let winid = popup_create([