summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-09-04 21:33:09 +0200
committerBram Moolenaar <Bram@vim.org>2016-09-04 21:33:09 +0200
commitf9e687e0681a250e1549ab27b6c7ef2c500395e3 (patch)
treedf8b0ef0bc7020120472d3f1752d27ff8e869f73 /src
parentc8fe338d64cc6183c03d4c12b1e036a7745e2932 (diff)
patch 7.4.2328v7.4.2328
Problem: Crash when BufWinLeave autocmd goes to another tab page. (Hirohito Higashi) Solution: Make close_buffer() go back to the right window.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c18
-rw-r--r--src/testdir/test_autocmd.vim10
-rw-r--r--src/version.c2
3 files changed, 30 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 6489168214..ac37685aa6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -450,6 +450,11 @@ close_buffer(
int is_curbuf;
int nwindows;
bufref_T bufref;
+# ifdef FEAT_WINDOWS
+ int is_curwin = (curwin!= NULL && curwin->w_buffer == buf);
+ win_T *the_curwin = curwin;
+ tabpage_T *the_curtab = curtab;
+# endif
#endif
int unload_buf = (action != 0);
int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE);
@@ -544,6 +549,19 @@ aucmd_abort:
return;
# endif
}
+
+# ifdef FEAT_WINDOWS
+ /* If the buffer was in curwin and the window has changed, go back to that
+ * window, if it still exists. This avoids that ":edit x" triggering a
+ * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */
+ if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
+ {
+ block_autocmds();
+ goto_tabpage_win(the_curtab, the_curwin);
+ unblock_autocmds();
+ }
+# endif
+
nwindows = buf->b_nwindows;
#endif
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 43aa8d48dd..c029ca1bd6 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -83,6 +83,16 @@ function Test_autocmd_bufunload_with_tabnext()
quit
endfunc
+function Test_autocmd_bufwinleave_with_tabfirst()
+ tabedit
+ augroup sample
+ autocmd!
+ autocmd BufWinLeave <buffer> tabfirst
+ augroup END
+ call setline(1, ['a', 'b', 'c'])
+ edit! a.txt
+endfunc
+
" SEGV occurs in older versions. (At least 7.4.2321 or older)
function Test_autocmd_bufunload_avoiding_SEGV_01()
split aa.txt
diff --git a/src/version.c b/src/version.c
index 4ab697b9ba..89e5f9509c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2328,
+/**/
2327,
/**/
2326,