Skip to content

Commit 1872b04

Browse files
authored
Merge branch 'master' into 2746-float-window-for-full-filenames-has-wrong-bg
2 parents 56ba24b + bd54d1d commit 1872b04

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

lua/nvim-tree.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ local function setup_autocommands(opts)
242242
pattern = "*",
243243
---@param ev vim.api.keyset.create_autocmd.callback_args
244244
callback = function(ev)
245+
if not vim.api.nvim_buf_is_valid(ev.buf) then
246+
return
247+
end
245248
if vim.api.nvim_get_option_value("filetype", { buf = ev.buf }) == "NvimTree" then
246249
require("nvim-tree.events")._dispatch_on_tree_close()
247250
end

lua/nvim-tree/renderer/builder.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ end
135135
function Builder:format_line(indent_markers, arrows, icon, name, node)
136136
local added_len = 0
137137
local function add_to_end(t1, t2)
138-
if not t2 then
138+
if not t2 or vim.tbl_isempty(t2) then
139139
return
140140
end
141141
for _, v in ipairs(t2) do

lua/nvim-tree/utils.lua

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,51 @@ function M.rename_loaded_buffers(old_path, new_path)
303303
end
304304
end
305305

306+
local is_windows_drive = function(path)
307+
return (M.is_windows) and (path:match("^%a:\\$") ~= nil)
308+
end
309+
306310
---@param path string path to file or directory
307311
---@return boolean
308312
function M.file_exists(path)
309-
local _, error = vim.loop.fs_stat(path)
310-
return error == nil
313+
if not (M.is_windows or M.is_wsl) then
314+
local _, error = vim.loop.fs_stat(path)
315+
return error == nil
316+
end
317+
318+
-- Windows is case-insensetive, but case-preserving
319+
-- If a file's name is being changed into itself
320+
-- with different casing, windows will falsely
321+
-- report that file is already existing, so a hand-rolled
322+
-- implementation of checking for existance is needed.
323+
-- Same holds for WSL, since it can sometimes
324+
-- access Windows files directly.
325+
-- For more details see (#3117).
326+
327+
if is_windows_drive(path) then
328+
return vim.fn.isdirectory(path) == 1
329+
end
330+
331+
local parent = vim.fn.fnamemodify(path, ":h")
332+
local filename = vim.fn.fnamemodify(path, ":t")
333+
334+
local handle = vim.loop.fs_scandir(parent)
335+
if not handle then
336+
-- File can not exist if its parent directory does not exist
337+
return false
338+
end
339+
340+
while true do
341+
local name, _ = vim.loop.fs_scandir_next(handle)
342+
if not name then
343+
break
344+
end
345+
if name == filename then
346+
return true
347+
end
348+
end
349+
350+
return false
311351
end
312352

313353
---@param path string

0 commit comments

Comments
 (0)