Patch 8.2.5038
Problem: A finished terminal in a popup window does not show a scrollbar.
Solution: Show the scrollbar if the terminal job is finished. (closes
#10497)
Files: src/popupwin.c, src/testdir/test_popupwin.vim,
src/testdir/dumps/Test_popupwin_poptermscroll_1.dump,
src/testdir/dumps/Test_popupwin_poptermscroll_2.dump,
src/testdir/dumps/Test_popupwin_poptermscroll_3.dump
*** ../vim-8.2.5037/src/popupwin.c 2022-05-08 14:59:40.871968915 +0100
--- src/popupwin.c 2022-05-29 13:55:14.127990548 +0100
***************
*** 375,396 ****
void
popup_handle_scrollbar_click(win_T *wp, int row, int col)
{
- int height = popup_height(wp);
- int old_topline = wp->w_topline;
-
if (popup_is_in_scrollbar(wp, row, col))
{
if (row >= height / 2)
{
// Click in lower half, scroll down.
if (wp->w_topline < wp->w_buffer->b_ml.ml_line_count)
! ++wp->w_topline;
}
else if (wp->w_topline > 1)
// click on upper half, scroll up.
! --wp->w_topline;
! if (wp->w_topline != old_topline)
{
popup_set_firstline(wp);
redraw_win_later(wp, NOT_VALID);
}
--- 375,410 ----
void
popup_handle_scrollbar_click(win_T *wp, int row, int col)
{
if (popup_is_in_scrollbar(wp, row, col))
{
+ int height = popup_height(wp);
+ int new_topline = wp->w_topline;
+
if (row >= height / 2)
{
// Click in lower half, scroll down.
if (wp->w_topline < wp->w_buffer->b_ml.ml_line_count)
! ++new_topline;
}
else if (wp->w_topline > 1)
// click on upper half, scroll up.
! --new_topline;
! if (new_topline != wp->w_topline)
{
+ set_topline(wp, new_topline);
+ if (wp == curwin)
+ {
+ if (wp->w_cursor.lnum < wp->w_topline)
+ {
+ wp->w_cursor.lnum = wp->w_topline;
+ check_cursor();
+ }
+ else if (wp->w_cursor.lnum >= wp->w_botline)
+ {
+ wp->w_cursor.lnum = wp->w_botline - 1;
+ check_cursor();
+ }
+ }
popup_set_firstline(wp);
redraw_win_later(wp, NOT_VALID);
}
***************
*** 1419,1426 ****
wp->w_has_scrollbar = wp->w_want_scrollbar
&& (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count);
#ifdef FEAT_TERMINAL
! if (wp->w_buffer->b_term != NULL)
! // Terminal window never has a scrollbar, adjusts to window height.
wp->w_has_scrollbar = FALSE;
#endif
maxwidth_no_scrollbar = maxwidth;
--- 1433,1441 ----
wp->w_has_scrollbar = wp->w_want_scrollbar
&& (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count);
#ifdef FEAT_TERMINAL
! if (wp->w_buffer->b_term != NULL && !term_is_finished(wp->w_buffer))
! // Terminal window with running job never has a scrollbar, adjusts to
! // window height.
wp->w_has_scrollbar = FALSE;
#endif
maxwidth_no_scrollbar = maxwidth;
***************
*** 1587,1593 ****
// add a scrollbar.
wp->w_height = Rows - wp->w_winrow - extra_height;
#ifdef FEAT_TERMINAL
! if (wp->w_buffer->b_term == NULL)
#endif
{
wp->w_has_scrollbar = TRUE;
--- 1602,1608 ----
// add a scrollbar.
wp->w_height = Rows - wp->w_winrow - extra_height;
#ifdef FEAT_TERMINAL
! if (wp->w_buffer->b_term == NULL || term_is_finished(wp->w_buffer))
#endif
{
wp->w_has_scrollbar = TRUE;
*** ../vim-8.2.5037/src/testdir/test_popupwin.vim 2022-05-08 14:59:40.871968915 +0100
--- src/testdir/test_popupwin.vim 2022-05-29 14:11:07.722992373 +0100
***************
*** 2856,2862 ****
call assert_fails('call popup_create(termbuf2, #{})', 'E861:')
call term_sendkeys(termbuf2, "exit\<CR>")
! " Exiting shell closes popup window
call feedkeys("exit\<CR>", 'xt')
" Wait for shell to exit
call WaitForAssert({-> assert_equal("dead", job_status(term_getjob(termbuf)))})
--- 2856,2862 ----
call assert_fails('call popup_create(termbuf2, #{})', 'E861:')
call term_sendkeys(termbuf2, "exit\<CR>")
! " Exiting shell puts popup window in Terminal-Normal mode.
call feedkeys("exit\<CR>", 'xt')
" Wait for shell to exit
call WaitForAssert({-> assert_equal("dead", job_status(term_getjob(termbuf)))})
***************
*** 2866,2871 ****
--- 2866,2907 ----
call assert_equal(origwin, win_getid())
endfunc
+ func Test_popupwin_terminal_scrollbar()
+ CheckFeature terminal
+ CheckScreendump
+ CheckUnix
+
+ call writefile(range(50), 'Xtestfile')
+ let lines =<< trim END
+ vim9script
+
+ term_start(['cat', 'Xtestfile'], {hidden: true})
+ ->popup_create({
+ minwidth: 40,
+ maxwidth: 40,
+ minheight: 8,
+ maxheight: 8,
+ scrollbar: true,
+ border: []
+ })
+ END
+ call writefile(lines, 'Xpterm')
+ let buf = RunVimInTerminal('-S Xpterm', #{rows: 15})
+ call VerifyScreenDump(buf, 'Test_popupwin_poptermscroll_1', {})
+
+ " scroll to the middle
+ call term_sendkeys(buf, "50%")
+ call VerifyScreenDump(buf, 'Test_popupwin_poptermscroll_2', {})
+
+ " close the popupwin.
+ call term_sendkeys(buf, ":q\<CR>")
+ call VerifyScreenDump(buf, 'Test_popupwin_poptermscroll_3', {})
+
+ call StopVimInTerminal(buf)
+ call delete('Xtestfile')
+ call delete('Xpterm')
+ endfunc
+
func Test_popupwin_close_prevwin()
CheckFeature terminal
call Popupwin_close_prevwin()
*** ../vim-8.2.5037/src/testdir/dumps/Test_popupwin_poptermscroll_1.dump 2022-05-29 14:12:14.454939094 +0100
--- src/testdir/dumps/Test_popupwin_poptermscroll_1.dump 2022-05-29 14:08:52.147104198 +0100
***************
*** 0 ****
--- 1,15 ----
+ | +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @14|╔+0#0000001#ffd7ff255|═@40|╗| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|4|2| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|4|3| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|4@1| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|4|5| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|4|6| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|4|7| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|4|8| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255>4|9| @37| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|╚+0#0000001#ffd7ff255|═@40|╝| +0#4040ff13#ffffff0@15
+ |~| @73
+ |~| @73
+ | +0#0000000&@56|5|0|,|1| @9|B|o|t|
*** ../vim-8.2.5037/src/testdir/dumps/Test_popupwin_poptermscroll_2.dump 2022-05-29 14:12:14.458939091 +0100
--- src/testdir/dumps/Test_popupwin_poptermscroll_2.dump 2022-05-29 14:08:53.311103216 +0100
***************
*** 0 ****
--- 1,15 ----
+ | +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @14|╔+0#0000001#ffd7ff255|═@40|╗| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|2|1| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|2@1| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|2|3| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255>2|4| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|2|5| @37| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|2|6| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|2|7| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|║+0#0000001#ffd7ff255|2|8| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#4040ff13#ffffff0@15
+ |~| @14|╚+0#0000001#ffd7ff255|═@40|╝| +0#4040ff13#ffffff0@15
+ |~| @73
+ |~| @73
+ | +0#0000000&@56|2|5|,|1| @9|5|0|%|
*** ../vim-8.2.5037/src/testdir/dumps/Test_popupwin_poptermscroll_3.dump 2022-05-29 14:12:14.462939087 +0100
--- src/testdir/dumps/Test_popupwin_poptermscroll_3.dump 2022-05-29 14:08:54.471102237 +0100
***************
*** 0 ****
--- 1,15 ----
+ > +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |:+0#0000000&|q| @54|0|,|0|-|1| @8|A|l@1|
*** ../vim-8.2.5037/src/version.c 2022-05-28 14:25:32.127084455 +0100
--- src/version.c 2022-05-29 13:57:59.211764329 +0100
***************
*** 736,737 ****
--- 736,739 ----
{ /* Add new patch number below this line */
+ /**/
+ 5038,
/**/
--
Veni, Vidi, Video -- I came, I saw, I taped what I saw.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///