@@ -9,7 +9,10 @@ local M = {
99}
1010
1111local function close_windows (windows )
12- if view .View .float .enable and # vim .api .nvim_list_wins () == 1 then
12+ -- Prevent from closing when the win count equals 1 or 2,
13+ -- where the win to remove could be the last opened.
14+ -- For details see #2503.
15+ if view .View .float .enable and # vim .api .nvim_list_wins () < 3 then
1316 return
1417 end
1518
@@ -24,15 +27,15 @@ local function clear_buffer(absolute_path)
2427 local bufs = vim .fn .getbufinfo { bufloaded = 1 , buflisted = 1 }
2528 for _ , buf in pairs (bufs ) do
2629 if buf .name == absolute_path then
30+ local tree_winnr = vim .api .nvim_get_current_win ()
2731 if buf .hidden == 0 and (# bufs > 1 or view .View .float .enable ) then
28- local winnr = vim .api .nvim_get_current_win ()
2932 vim .api .nvim_set_current_win (buf .windows [1 ])
3033 vim .cmd " :bn"
31- if not view .View .float .enable then
32- vim .api .nvim_set_current_win (winnr )
33- end
3434 end
3535 vim .api .nvim_buf_delete (buf .bufnr , { force = true })
36+ if not view .View .float .quit_on_focus_loss then
37+ vim .api .nvim_set_current_win (tree_winnr )
38+ end
3639 if M .config .actions .remove_file .close_window then
3740 close_windows (buf .windows )
3841 end
0 commit comments