Skip to content

Commit 7dddda0

Browse files
committed
fix: fs clear window, rename echo_warning -> warn
also fix renaming and add an event blocker to avoid running many events at the same time
1 parent 5ba3e6b commit 7dddda0

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

lua/nvim-tree.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ local keypress_funcs = {
114114
elseif _config.is_unix then
115115
_config.system_open.cmd = 'xdg-open'
116116
else
117-
require'nvim-tree.utils'.echo_warning("Cannot open file with system application. Unrecognized platform.")
117+
require'nvim-tree.utils'.warn("Cannot open file with system application. Unrecognized platform.")
118118
return
119119
end
120120
end
@@ -454,7 +454,7 @@ function M.setup(conf)
454454
_config.open_on_setup = opts.open_on_setup
455455
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup
456456
if type(opts.update_to_buf_dir) == "boolean" then
457-
utils.echo_warning("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir")
457+
utils.warn("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir")
458458
_config.update_to_buf_dir = {
459459
enable = opts.update_to_buf_dir,
460460
auto_open = opts.update_to_buf_dir,
@@ -464,7 +464,7 @@ function M.setup(conf)
464464
end
465465

466466
if opts.lsp_diagnostics ~= nil then
467-
utils.echo_warning("setup.lsp_diagnostics has been removed, see :help nvim-tree.diagnostics")
467+
utils.warn("setup.lsp_diagnostics has been removed, see :help nvim-tree.diagnostics")
468468
end
469469

470470
require'nvim-tree.colors'.setup()

lua/nvim-tree/fs.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ local function clear_buffer(absolute_path)
113113
api.nvim_set_current_win(winnr)
114114
end
115115
vim.api.nvim_buf_delete(buf.bufnr, {})
116+
if buf.windows[1] then
117+
vim.api.nvim_win_close(buf.windows[1], true)
118+
end
116119
return
117120
end
118121
end
@@ -289,7 +292,13 @@ function M.rename(with_sub)
289292
local abs_path = with_sub and node.absolute_path:sub(0, namelen * (-1) -1) or node.absolute_path
290293
local new_name = vim.fn.input("Rename " ..node.name.. " to ", abs_path)
291294
utils.clear_prompt()
292-
if not new_name or #new_name == 0 then return end
295+
if not new_name or #new_name == 0 then
296+
return
297+
end
298+
if luv.fs_access(new_name, 'R') then
299+
utils.warn("Cannot rename: file already exists")
300+
return
301+
end
293302

294303
local success = luv.fs_rename(node.absolute_path, new_name)
295304
if not success then

lua/nvim-tree/lib.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,20 @@ local function refresh_nodes(node, projects)
150150
end
151151
end
152152

153+
local event_running = false
153154
function M.refresh_tree()
154-
if not M.Tree.cwd or vim.v.exiting ~= vim.NIL then
155+
if event_running or not M.Tree.cwd or vim.v.exiting ~= vim.NIL then
155156
return
156157
end
158+
event_running = true
157159

158160
git.reload(function(projects)
159161
refresh_nodes(M.Tree, projects)
160162
if view.win_open() then
161163
M.redraw()
162164
end
163165
diagnostics.update()
166+
event_running = false
164167
end)
165168
end
166169

@@ -179,17 +182,16 @@ local function reload_node_status(parent_node, projects)
179182
end
180183
end
181184

182-
local running_reload = false
183185
function M.reload_git()
184-
if not git.config.enable or running_reload then
186+
if not git.config.enable or event_running then
185187
return
186188
end
187-
running_reload = true
189+
event_running = true
188190

189191
git.reload(function(projects)
190-
running_reload = false
191192
reload_node_status(M.Tree, projects)
192193
M.redraw()
194+
event_running = false
193195
end)
194196
end
195197

lua/nvim-tree/populate.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ local function should_group(cwd, dirs, files, links)
9797
end
9898

9999
local function node_comparator(a, b)
100+
if not (a and b) then
101+
return true
102+
end
100103
if a.entries and not b.entries then
101104
return true
102105
elseif not a.entries and b.entries then
@@ -122,12 +125,6 @@ local function should_ignore(path)
122125
return false
123126
end
124127

125-
-- if vim.g.nvim_tree_gitignore == 1 then
126-
-- if git.should_gitignore(path) then
127-
-- return true
128-
-- end
129-
-- end
130-
131128
local relpath = utils.path_relative(path, vim.loop.cwd())
132129
if M.ignore_list[relpath] == true or M.ignore_list[basename] == true then
133130
return true

lua/nvim-tree/renderer/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ if vim.g.nvim_tree_git_hl == 1 then
163163
local icons = git_hl[git_status]
164164

165165
if icons == nil then
166-
utils.echo_warning('Unrecognized git state "'..git_status..'". Please open up an issue on https://github.com/kyazdani42/nvim-tree.lua/issues with this message.')
166+
utils.warn('Unrecognized git state "'..git_status..'". Please open up an issue on https://github.com/kyazdani42/nvim-tree.lua/issues with this message.')
167167
icons = git_hl.dirty
168168
end
169169

@@ -239,7 +239,7 @@ if icon_state.show_git_icon then
239239
local icons = git_icon_state[git_status]
240240
if not icons then
241241
if vim.g.nvim_tree_git_hl ~= 1 then
242-
utils.echo_warning('Unrecognized git state "'..git_status..'". Please open up an issue on https://github.com/kyazdani42/nvim-tree.lua/issues with this message.')
242+
utils.warn('Unrecognized git state "'..git_status..'". Please open up an issue on https://github.com/kyazdani42/nvim-tree.lua/issues with this message.')
243243
end
244244
icons = git_icon_state.dirty
245245
end

lua/nvim-tree/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function M.path_to_matching_str(path)
66
return path:gsub('(%-)', '(%%-)'):gsub('(%.)', '(%%.)'):gsub('(%_)', '(%%_)')
77
end
88

9-
function M.echo_warning(msg)
9+
function M.warn(msg)
1010
api.nvim_command('echohl WarningMsg')
1111
api.nvim_command("echom '[NvimTree] "..msg:gsub("'", "''").."'")
1212
api.nvim_command('echohl None')

plugin/nvim-tree-startup.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ end, out_config)
3434

3535
if #x > 0 then
3636
local msg = "Following options were moved to setup (:help nvim-tree.setup): "
37-
require'nvim-tree.utils'.echo_warning(msg..table.concat(x, ", "))
37+
require'nvim-tree.utils'.warn(msg..table.concat(x, ", "))
3838
end

0 commit comments

Comments
 (0)