Skip to content

[Floating] Cannot close last window #3187

@mrmerc

Description

@mrmerc

Description

nvim-tree throws an error Vim:E444: Cannot close last window while trying to delete currently open file when there are more than 2 open floating windows. I have the Snacks plugin which creates floating windows for vim.ui.input and vim.notify. So when I run delete file action, there are 3 open floating windows.

I believe this problem is related to the solution for this issue, where there is a limit on the number of open windows.

and #vim.api.nvim_list_wins() < 3 then

Neovim version

NVIM v0.11.3
Build type: Release
LuaJIT 2.1.1753364724

Operating system and version

macOS Sequoia 15.6 arm64

Windows variant

No response

nvim-tree version

tag: v1.14

Clean room replication

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
	require("packer").startup({
		{
			"wbthomason/packer.nvim",
			"nvim-tree/nvim-tree.lua",
			"nvim-tree/nvim-web-devicons",
			-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
			"folke/snacks.nvim",
		},
		config = {
			package_root = package_root,
			compile_path = install_path .. "/plugin/packer_compiled.lua",
			display = { non_interactive = true },
		},
	})
end
if vim.fn.isdirectory(install_path) == 0 then
	print("Installing nvim-tree and dependencies.")
	vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
	local HEIGHT_RATIO = 0.9
	local WIDTH_RATIO = 0.5

	require("nvim-tree").setup({
		actions = {
			open_file = {
				quit_on_open = true,
				window_picker = {
					enable = false,
				},
			},
		},
		view = {
			float = {
				enable = true,
				quit_on_focus_loss = false,
				open_win_config = function()
					local screen_w = vim.opt.columns:get()
					local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
					local window_w = screen_w * WIDTH_RATIO
					local window_h = screen_h * HEIGHT_RATIO
					local window_w_int = math.floor(window_w)
					local window_h_int = math.floor(window_h)
					local center_x = (screen_w - window_w) / 2
					return {
						border = "rounded",
						relative = "editor",
						row = 1,
						col = center_x,
						width = window_w_int,
						height = window_h_int,
					}
				end,
			},
		},
	})

	require("snacks").setup({
		notifier = {},
		input = {},
	})
end

Steps to reproduce

  1. :NvimTreeOpen
  2. create a file
  3. enter the file
  4. :NvimTreeOpen
  5. delete the file from the nvim-tree window using d key

Expected behavior

File deleted without the error

Actual behavior

Error executing vim.schedule lua callback: ...y/nvim-tree.lua/lua/nvim-tree/actions/fs/remove-file.lua:26: Vim:E444: Cannot close last window

stack traceback:
        [C]: in function 'nvim_win_close'
        ...y/nvim-tree.lua/lua/nvim-tree/actions/fs/remove-file.lua:26: in function 'close_windows'
        ...y/nvim-tree.lua/lua/nvim-tree/actions/fs/remove-file.lua:46: in function 'clear_buffer'
        ...y/nvim-tree.lua/lua/nvim-tree/actions/fs/remove-file.lua:117: in function 'remove'
        ...y/nvim-tree.lua/lua/nvim-tree/actions/fs/remove-file.lua:129: in function 'do_remove'
        ...y/nvim-tree.lua/lua/nvim-tree/actions/fs/remove-file.lua:153: in function 'callback'
        ...ocal/share/nvim/lazy/nvim-tree.lua/lua/nvim-tree/lib.lua:85: in function 'on_confirm'
        .../.local/share/nvim/lazy/snacks.nvim/lua/snacks/input.lua:130: in function <.../.local/share/nvim/lazy/snacks.nvim/lua/snacks/input
.lua:123>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions