aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-03-21 10:39:24 +0100
committerJustin M. Keyes <justinkz@gmail.com>2017-03-22 18:42:56 +0100
commit10f6624f65edbc8af84c9775e6712484be9c81a5 (patch)
treedffba08c6705c23a363742ec07352280e4f64711 /src/nvim/buffer.c
parent4a2e6f460d02762d211c0f92af305ef5290a667b (diff)
downloadrneovim-10f6624f65edbc8af84c9775e6712484be9c81a5.tar.gz
rneovim-10f6624f65edbc8af84c9775e6712484be9c81a5.tar.bz2
rneovim-10f6624f65edbc8af84c9775e6712484be9c81a5.zip
vim-patch:7.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/nvim/buffer.c')
-rw-r--r--src/nvim/buffer.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 5edc87eab1..7429e8628e 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -337,6 +337,10 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
bool del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE);
bool wipe_buf = (action == DOBUF_WIPE);
+ bool is_curwin = (curwin != NULL && curwin->w_buffer == buf);
+ win_T *the_curwin = curwin;
+ tabpage_T *the_curtab = curtab;
+
// Force unloading or deleting when 'bufhidden' says so, but not for terminal
// buffers.
// The caller must take care of NOT deleting/freeing when 'bufhidden' is
@@ -419,6 +423,16 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
if (aborting()) /* autocmds may abort script processing */
return;
}
+
+ // 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();
+ }
+
int nwindows = buf->b_nwindows;
/* decrease the link count from windows (unless not in any window) */