Skip to content

Commit 5438ee6

Browse files
committed
simplify split_path
1 parent 4cc6b1b commit 5438ee6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lua/neo-tree/utils/init.lua

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,17 +1123,13 @@ M.split_path = function(path)
11231123
if path == M.path_separator then
11241124
return nil, M.path_separator
11251125
end
1126-
local parts = M.split(path, M.path_separator)
1126+
local parts = vim.split(path, M.path_separator, { plain = true })
11271127
local name = table.remove(parts)
1128+
---@type string?
11281129
local parentPath = table.concat(parts, M.path_separator)
1129-
if M.is_windows then
1130-
if #parts == 1 then
1131-
parentPath = parentPath .. M.path_separator
1132-
elseif parentPath == "" then
1133-
return M.abspath_prefix(path), name
1134-
end
1135-
else
1136-
parentPath = M.path_separator .. parentPath
1130+
local prefix = M.abspath_prefix(path)
1131+
if #parentPath == 0 and prefix then
1132+
parentPath = prefix
11371133
end
11381134
return parentPath, name
11391135
end
@@ -1260,7 +1256,7 @@ end
12601256
---
12611257
---For Windows systems, this function handles punctuation characters that will
12621258
---be escaped, but may appear at the beginning of a path segment. For example,
1263-
---the path `C:\foo\(bar)\baz.txt` (where foo, (bar), and baz.txt are segments)
1259+
---the path `C:\foo\(bar\baz.txt` (where foo, (bar), and baz.txt are segments)
12641260
---will remain unchanged when escaped by `fnaemescape` on a Windows system.
12651261
---However, if that strig is used to edit a file with `:e`, `:b`, etc., the open
12661262
---parenthesis will be treated as an escaped character and the path separator will

0 commit comments

Comments
 (0)