Skip to content

Commit 430514f

Browse files
committed
perf(#3253): move full-name setup_autocommands to main
1 parent 9184bb4 commit 430514f

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

lua/nvim-tree.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,24 @@ local function setup_autocommands()
110110
end,
111111
})
112112

113-
-- renderer.full name
114-
require("nvim-tree.renderer.components.full-name").setup_autocommands()
113+
if config.g.renderer.full_name then
114+
local group = vim.api.nvim_create_augroup("nvim_tree_floating_node", { clear = true })
115+
vim.api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, {
116+
group = group,
117+
pattern = { "NvimTree_*" },
118+
callback = function()
119+
require("nvim-tree.renderer.components.full-name").hide()
120+
end,
121+
})
122+
123+
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
124+
group = group,
125+
pattern = { "NvimTree_*" },
126+
callback = function()
127+
require("nvim-tree.renderer.components.full-name").show()
128+
end,
129+
})
130+
end
115131
end
116132

117133
---`require("nvim-tree").setup` must be called once to initialise nvim-tree.

lua/nvim-tree/renderer/components/full-name.lua

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ local M = {}
55

66
local utils = require("nvim-tree.utils")
77

8-
local function hide(win)
9-
if win then
10-
if vim.api.nvim_win_is_valid(win) then
11-
vim.api.nvim_win_close(win, true)
8+
function M.hide()
9+
if M.popup_win and utils.is_nvim_tree_buf(0) then
10+
if vim.api.nvim_win_is_valid(M.popup_win) then
11+
vim.api.nvim_win_close(M.popup_win, true)
1212
end
1313
end
1414
end
@@ -35,7 +35,11 @@ local function effective_win_width()
3535
return win_width - win_info[1].textoff
3636
end
3737

38-
local function show()
38+
function M.show()
39+
if not utils.is_nvim_tree_buf(0) then
40+
return
41+
end
42+
3943
local line_nr = vim.api.nvim_win_get_cursor(0)[1]
4044
if vim.wo.wrap then
4145
return
@@ -104,31 +108,4 @@ local function show()
104108
end)
105109
end
106110

107-
function M.setup_autocommands()
108-
if not config.g.renderer.full_name then
109-
return
110-
end
111-
112-
local group = vim.api.nvim_create_augroup("nvim_tree_floating_node", { clear = true })
113-
vim.api.nvim_create_autocmd({ "BufLeave", "CursorMoved" }, {
114-
group = group,
115-
pattern = { "NvimTree_*" },
116-
callback = function()
117-
if utils.is_nvim_tree_buf(0) then
118-
hide(M.popup_win)
119-
end
120-
end,
121-
})
122-
123-
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
124-
group = group,
125-
pattern = { "NvimTree_*" },
126-
callback = function()
127-
if utils.is_nvim_tree_buf(0) then
128-
show()
129-
end
130-
end,
131-
})
132-
end
133-
134111
return M

0 commit comments

Comments
 (0)