Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lua/snacks/explorer/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
local uv = vim.uv or vim.loop

local function norm(path)
return svim.fs.normalize(path):gsub("/$", ""):gsub("^$", "/")
path = svim.fs.normalize(path)
-- keep trailing slash for Windows drive roots (D:/), otherwise
-- scandir("D:") resolves to the drive's current dir, not its root
if not path:match("^%a:/$") then
path = path:gsub("/$", "")
end
return path:gsub("^$", "/")
end

local function assert_dir(path)
Expand Down Expand Up @@ -77,9 +83,18 @@ end
---@param name string
---@param type string
function Tree:child(node, name, type)
-- skip empty segment from trailing slash (e.g. drive root "D:/")
if name == "" then
return node
end
if not node.children[name] then
local path = node.path .. "/" .. name
path = node == self.root and name or path
-- strip trailing slash from parent so drive roots don't double up ("D://name")
local base = node.path:gsub("/$", "")
local path = base .. "/" .. name
-- drive-letter root ("D:") keeps its trailing slash, so scandir hits the root
if node == self.root then
path = name:match("^%a:$") and (name .. "/") or name
end
node.children[name] = {
name = name,
path = path,
Expand Down