nvim-tree / nvim-tree/nvim-tree.lua

Live Filter not working after 0a06f65bf06157972f20ca1dee03c97a0efcb188 for floating config

Open
#3,162 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug regression reproduced
Dominant language
Lua
Stars
8.6k
Forks
639
Avg merge
1d 14h
Merged PRs (30d)
2

Description

Description

After version 0a06f65bf06157972f20ca1dee03c97a0efcb188, when trying to filter for files, the floating window closes automatically. I noticed in this commit there's a lot of refactoring, haven't had time to look into it yet.

Neovim version
NVIM v0.11.2
Build type: Release
LuaJIT 2.1.1748459687
Operating system and version

MacOs 15.5

Windows variant

No response

nvim-tree version

0a06f65bf06157972f20ca1dee03c97a0efcb188

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
		},
		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.85 -- You can change this
	local WIDTH_RATIO = 0.79 -- You can change this too
	local floating = true

	local view = {
		-- relativenumber = false,
		-- width = 45,
		adaptive_size = true,
		side = "right",
	}
	if floating then
		view = {
			-- relativenumber = true,
			float = {
				enable = true,
				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
					local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get()
					return {
						border = "rounded",
						relative = "editor",
						row = center_y,
						col = center_x,
						width = window_w_int,
						height = window_h_int,
					}
				end,
			},
			width = function()
				return math.floor(vim.opt.columns:get() * WIDTH_RATIO)
			end,
		}
	end

	local tree_api = require("nvim-tree.api")

	require("nvim-tree").setup({
		on_attach = function(bufnr)
			local function opts(desc)
				return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
			end

			local map = vim.keymap.set
			map("n", "K", tree_api.node.show_info_popup, opts("Info"))
			map("n", "<C-t>", tree_api.node.open.tab, opts("Open: New Tab"))
			map("n", "<C-v>", tree_api.node.open.vertical, opts("Open: Vertical Split"))
			map("n", "<C-s>", tree_api.node.open.horizontal, opts("Open: Horizontal Split"))
			map("n", "<BS>", tree_api.node.navigate.parent_close, opts("Close Directory"))
			map("n", "<CR>", tree_api.node.open.edit, opts("Open"))
			map("n", ".", tree_api.node.run.cmd, opts("Run Command"))
			map("n", "a", tree_api.fs.create, opts("Create File Or Directory"))
			map("n", "bd", tree_api.marks.bulk.delete, opts("Delete Bookmarked"))
			map("n", "bD", tree_api.marks.bulk.trash, opts("Trash Bookmarked"))
			map("n", "bmv", tree_api.marks.bulk.move, opts("Move Bookmarked"))
			map("n", "B", tree_api.tree.toggle_no_buffer_filter, opts("Toggle Filter: No Buffer"))
			map("n", "y", tree_api.fs.copy.node, opts("Copy"))
			map("n", "d", tree_api.fs.remove, opts("Delete"))
			map("n", "D", tree_api.fs.trash, opts("Trash"))
			map("n", "E", tree_api.tree.expand_all, opts("Expand All"))
			map("n", "F", tree_api.live_filter.clear, opts("Live Filter: Clear"))
			map("n", "f", tree_api.live_filter.start, opts("Live Filter: Start"))
			map("n", "g?", tree_api.tree.toggle_help, opts("Help"))
			map("n", "H", tree_api.tree.toggle_hidden_filter, opts("Toggle Filter: Dotfiles"))
			map("n", "I", tree_api.tree.toggle_gitignore_filter, opts("Toggle Filter: Git Ignore"))
			map("n", "M", tree_api.tree.toggle_no_bookmark_filter, opts("Toggle Filter: No Bookmark"))
			map("n", "m", tree_api.marks.toggle, opts("Toggle Bookmark"))
			map("n", "p", tree_api.fs.paste, opts("Paste"))
			map("n", "P", tree_api.node.navigate.parent, opts("Parent Directory"))
			map("n", "q", tree_api.tree.close, opts("Close"))
			map("n", "r", tree_api.fs.rename_full, opts("Rename"))
			map("n", "R", tree_api.tree.reload, opts("Refresh"))
			map("n", "W", tree_api.tree.collapse_all, opts("Collapse"))
			map("n", "x", tree_api.fs.cut, opts("Cut"))
			map("n", "gc", tree_api.fs.copy.filename, opts("Copy Name"))
			map("n", "c", tree_api.fs.copy.relative_path, opts("Copy Relative Path"))
			map("n", "C", tree_api.fs.copy.absolute_path, opts("Copy Absolute Path"))
		end,
		disable_netrw = true,
		hijack_netrw = true,
		sort = {
			sorter = "case_sensitive",
		},
		view = view,
		renderer = {
			group_empty = true,
			indent_markers = { enable = true },
			highlight_git = true,
			root_folder_label = ":t",
		},
		actions = {
			change_dir = {
				enable = false,
				restrict_above_cwd = true,
			},
		},
		filters = {
			custom = { "node_modules", "^\\.git$", "^\\.github$" },
		},
		git = {
			enable = false,
		},
		update_focused_file = {
			enable = true,
		},
	})

	if floating then
		vim.api.nvim_create_augroup("NvimTreeResize", {
			clear = true,
		})
		vim.api.nvim_create_autocmd({ "VimResized" }, {
			group = "NvimTreeResize",
			callback = function()
				if require("nvim-tree.view").is_visible() then
					tree_api.tree.close()
					tree_api.tree.open()
				end
			end,
		})
	end
end

-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.
-- Requires diagnostics.enable = true in setup.
--[[
vim.api.nvim_create_autocmd("FileType", {
  pattern = "lua",
  callback = function()
    vim.lsp.start {
      name = "my-luals",
      cmd = { "lua-language-server" },
      root_dir = vim.loop.cwd(),
    }
  end,
})
]]
Steps to reproduce
  1. Use the config above
  2. Run :lua require('nvim-tree.api').tree.toggle()
  3. Press the f key to filter
Expected behavior

Should filter

Actual behavior

The floating window closes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the nvim-tree.api tree.toggle() and live_filter.start entry points, then inspect how the floating view is handled after the filter key is pressed. Reproduce the issue with the provided clean-room configuration and confirm that filtering keeps the floating window open.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.