diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-03-24 14:53:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-24 14:53:20 +0800 |
commit | a72f338d76c871869712518df862c85d1df25f54 (patch) | |
tree | dca9871bc17e0315e94f4302f0409101c3c11228 /src/nvim/buffer.c | |
parent | ff82b2785f161fc14ff6bd8eae497f37ecd14564 (diff) | |
download | rneovim-a72f338d76c871869712518df862c85d1df25f54.tar.gz rneovim-a72f338d76c871869712518df862c85d1df25f54.tar.bz2 rneovim-a72f338d76c871869712518df862c85d1df25f54.zip |
fix(float): do not switch window before deleting last listed buffer (#17840)
Just allow close_windows() to close the current window instead.
This fixes wrong working directory or autocommands not being triggered.
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r-- | src/nvim/buffer.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 7fc880fb41..f200f16a5f 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1042,24 +1042,24 @@ static int empty_curbuf(int close_others, int forceit, int action) set_bufref(&bufref, buf); if (close_others) { + bool can_close_all_others = true; if (curwin->w_floating) { - bool can_close_all_others = false; + // Closing all other windows with this buffer may leave only floating windows. + can_close_all_others = false; for (win_T *wp = firstwin; !wp->w_floating; wp = wp->w_next) { if (wp->w_buffer != curbuf) { // Found another non-floating window with a different (probably unlisted) buffer. - // Closing all other windows with the this buffer is fine in this case. + // Closing all other windows with this buffer is fine in this case. can_close_all_others = true; break; } } - if (!can_close_all_others) { - // Closing all other windows with this buffer will close all non-floating windows. - // Move to a non-floating window then. - curwin = firstwin; - } } - // Close any other windows on this buffer, then make it empty. - close_windows(buf, true); + // If it is fine to close all other windows with this buffer, keep the current window and + // close any other windows with this buffer, then make it empty. + // Otherwise close_windows() will refuse to close the last non-floating window, so allow it + // to close the current window instead. + close_windows(buf, can_close_all_others); } setpcmark(); |