Skip to content

Commit 5db7eec

Browse files
committed
patch 8.1.0243: using :term ++close ++hidden closes a window
Problem: Using :term ++close ++hidden closes a window. (Marcin Szamotulski) Solution: Don't close the window if only using it temporarily for unloading the terminal buffer. (closes #3287)
1 parent 02ab977 commit 5db7eec

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/terminal.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2818,11 +2818,17 @@ term_after_channel_closed(term_T *term)
28182818
if (term->tl_finish == TL_FINISH_CLOSE)
28192819
{
28202820
aco_save_T aco;
2821+
int do_set_w_closing = term->tl_buffer->b_nwindows == 0;
28212822

2822-
/* ++close or term_finish == "close" */
2823+
// ++close or term_finish == "close"
28232824
ch_log(NULL, "terminal job finished, closing window");
28242825
aucmd_prepbuf(&aco, term->tl_buffer);
2826+
// Avoid closing the window if we temporarily use it.
2827+
if (do_set_w_closing)
2828+
curwin->w_closing = TRUE;
28252829
do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE);
2830+
if (do_set_w_closing)
2831+
curwin->w_closing = FALSE;
28262832
aucmd_restbuf(&aco);
28272833
return TRUE;
28282834
}

src/testdir/test_terminal.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,3 +1621,15 @@ func Test_terminal_hidden()
16211621
call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))})
16221622
bwipe!
16231623
endfunc
1624+
1625+
func Test_terminal_hidden_and_close()
1626+
if !has('unix')
1627+
return
1628+
endif
1629+
call assert_equal(1, winnr('$'))
1630+
term ++hidden ++close ls
1631+
let bnr = bufnr('$')
1632+
call assert_equal('terminal', getbufvar(bnr, '&buftype'))
1633+
call WaitForAssert({-> assert_false(bufexists(bnr))})
1634+
call assert_equal(1, winnr('$'))
1635+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static char *(features[]) =
794794

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
243,
797799
/**/
798800
242,
799801
/**/

0 commit comments

Comments
 (0)