fix(window): close floats first when closing buffer in other tab (#20284)

This commit is contained in:
zeertzjq 2022-09-22 20:25:34 +08:00 committed by GitHub
parent a7f6f0e2dd
commit 2083c1771a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -2464,7 +2464,8 @@ void close_windows(buf_T *buf, bool keep_curwin)
for (tp = first_tabpage; tp != NULL; tp = nexttp) { for (tp = first_tabpage; tp != NULL; tp = nexttp) {
nexttp = tp->tp_next; nexttp = tp->tp_next;
if (tp != curtab) { if (tp != curtab) {
FOR_ALL_WINDOWS_IN_TAB(wp, tp) { // Start from tp_lastwin to close floating windows with the same buffer first.
for (win_T *wp = tp->tp_lastwin; wp != NULL; wp = wp->w_prev) {
if (wp->w_buffer == buf if (wp->w_buffer == buf
&& !(wp->w_closing || wp->w_buffer->b_locked > 0)) { && !(wp->w_closing || wp->w_buffer->b_locked > 0)) {
win_close_othertab(wp, false, tp); win_close_othertab(wp, false, tp);

View File

@ -596,6 +596,11 @@ describe('float window', function()
meths.buf_delete(old_buf, {force = true}) meths.buf_delete(old_buf, {force = true})
eq(old_win, curwin().id) eq(old_win, curwin().id)
end) end)
it('if called from non-floating window in another tabpage', function()
command('tab split')
eq(3, #meths.list_tabpages())
meths.buf_delete(old_buf, {force = true})
end)
it('if called from floating window with the same buffer', function() it('if called from floating window with the same buffer', function()
meths.set_current_win(same_buf_float) meths.set_current_win(same_buf_float)
command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()') command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')