diff options
-rw-r--r-- | src/buffer.c | 11 | ||||
-rw-r--r-- | src/proto/window.pro | 1 | ||||
-rw-r--r-- | src/testdir/test_autocmd.vim | 12 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/window.c | 6 |
5 files changed, 31 insertions, 1 deletions
diff --git a/src/buffer.c b/src/buffer.c index b17ae16521..8d62e64368 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1790,6 +1790,7 @@ set_curbuf(buf_T *buf, int action) bufref_T newbufref; bufref_T prevbufref; int valid; + int last_winid = get_last_winid(); setpcmark(); if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) @@ -1818,7 +1819,11 @@ set_curbuf(buf_T *buf, int action) if (prevbuf == curwin->w_buffer) reset_synblock(curwin); #endif - if (unload) + // autocommands may have opened a new window + // with prevbuf, grr + if (unload || + (last_winid != get_last_winid() && + strchr((char *)"wdu", prevbuf->b_p_bh[0]) != NULL)) close_windows(prevbuf, FALSE); #if defined(FEAT_EVAL) if (bufref_valid(&prevbufref) && !aborting()) @@ -1854,6 +1859,10 @@ set_curbuf(buf_T *buf, int action) #endif ) || curwin->w_buffer == NULL) { + // autocommands changed curbuf and we will move to another + // buffer soon, so decrement curbuf->b_nwindows + if (curbuf != NULL && prevbuf != curbuf) + curbuf->b_nwindows--; // If the buffer is not valid but curwin->w_buffer is NULL we must // enter some buffer. Using the last one is hopefully OK. if (!valid) diff --git a/src/proto/window.pro b/src/proto/window.pro index a91a51190b..e5c03969fb 100644 --- a/src/proto/window.pro +++ b/src/proto/window.pro @@ -96,4 +96,5 @@ int win_hasvertsplit(void); int get_win_number(win_T *wp, win_T *first_win); int get_tab_number(tabpage_T *tp); char *check_colorcolumn(win_T *wp); +int get_last_winid(void); /* vim: set ft=c : */ diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index 90dc3c1d32..f4e3c15a61 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -4441,4 +4441,16 @@ func Test_autocmd_invalidates_undo_on_textchanged() call StopVimInTerminal(buf) endfunc +func Test_autocmd_creates_new_buffer_on_bufleave() + e a.txt + e b.txt + setlocal bufhidden=wipe + autocmd BufLeave <buffer> diffsplit c.txt + bn + call assert_equal(1, winnr('$')) + call assert_equal('a.txt', bufname('%')) + bw a.txt + bw c.txt +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index c6c536ab19..cc2d412471 100644 --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 143, +/**/ 142, /**/ 141, diff --git a/src/window.c b/src/window.c index 7123780c52..bda24fc4e5 100644 --- a/src/window.c +++ b/src/window.c @@ -7941,3 +7941,9 @@ skip: return NULL; // no error } #endif + + int +get_last_winid(void) +{ + return last_win_id; +} |