From 930e87f464d48237d73e39555ebccec4af46f470 Mon Sep 17 00:00:00 2001 From: Fidel Yin Date: Thu, 26 Feb 2026 19:40:40 -0500 Subject: [PATCH] fix(#3187): prevent closing the last non-floating window when deleting files --- lua/nvim-tree/actions/fs/remove-file.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index a22aad3a8ed..5810e3d1e5d 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -14,11 +14,18 @@ local M = { ---@param windows integer[] local function close_windows(windows) - -- Prevent from closing when the win count equals 1 or 2, - -- where the win to remove could be the last opened. - -- For details see #2503. - if view.View.float.enable and #vim.api.nvim_list_wins() < 3 then - return + -- When floating, prevent closing the last non-floating window. + -- For details see #2503, #3187. + if view.View.float.enable then + local non_float_count = 0 + for _, win in ipairs(vim.api.nvim_list_wins()) do + if vim.api.nvim_win_get_config(win).relative == "" then + non_float_count = non_float_count + 1 + end + end + if non_float_count <= 1 then + return + end end for _, window in ipairs(windows) do