Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lua/neo-tree/command/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ handle_reveal = function(args, state)
return
end

log.debug("Prompting for change cwd", args)
-- force was not specified and the file does not belong to cwd, so we need to ask the user
inputs.confirm("File not in cwd. Change cwd to " .. reveal_file_parent .. "?", function(response)
if response == true then
Expand Down
2 changes: 1 addition & 1 deletion lua/neo-tree/sources/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ M.get_path_to_reveal = function(include_terminals)
return abspath
end

return utils.path_join(vim.fn.getcwd(), utils.normalize_path(buf_relpath))
return utils.path_join(vim.fn.getcwd(), buf_relpath)
end

---@param source_name string
Expand Down
47 changes: 22 additions & 25 deletions lua/neo-tree/utils/_compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,41 +141,38 @@ local function path_resolve_dot(path)
return (is_path_absolute and "/" or "") .. table.concat(new_path_components, "/")
end

--- Expand tilde (~) character at the beginning of the path to the user's home directory.
---
--- @param path string Path to expand.
--- @param sep string|nil Path separator to use. Uses os_sep by default.
--- @return string Expanded path.
local function expand_home(path, sep)
sep = sep or require("neo-tree.utils").path_separator

if vim.startswith(path, "~") then
local home = uv.os_homedir() or "~" --- @type string

if home:sub(-1) == sep then
home = home:sub(1, -2)
end

path = home .. path:sub(2) --- @type string
end

return path
local user = uv.os_get_passwd().username
local path_segment_ends = { "/", "\\", "" }
---@param path string
---@param i integer
---@return boolean
local function path_segment_ends_at(path, i)
return vim.tbl_contains(path_segment_ends, path:sub(i, i))
end

--- Backporting vim.fs.normalize from neovim 0.11
--- A modified vim.fs.normalize from neovim 0.11, with proper home expansion
function compat.fs_normalize(path, opts)
opts = opts or {}

local win = opts.win == nil and require("neo-tree.utils").is_windows or not not opts.win
local os_sep_local = win and "\\" or "/"
local os_sep = win and "\\" or "/"

-- Empty path is already normalized
if path == "" then
return ""
end

-- Expand ~ to user's home directory
path = expand_home(path, os_sep_local)
if path:sub(1, 1) == "~" then
local home = uv.os_homedir() or "~" --- @type string
if home:sub(-1) == os_sep then
home = home:sub(1, -2)
end

if path_segment_ends_at(path, 2) then
path = home .. path:sub(2)
elseif vim.startswith(path, "~" .. user) and path_segment_ends_at(path, 2 + #user) then
path = home .. path:sub(#user + 2) --- @type string
end
end

-- Expand environment variables if `opts.expand_env` isn't `false`
if opts.expand_env == nil or opts.expand_env then
Expand All @@ -184,7 +181,7 @@ function compat.fs_normalize(path, opts)

if win then
-- Convert path separator to `/`
path = path:gsub(os_sep_local, "/")
path = path:gsub(os_sep, "/")
end

-- Check for double slashes at the start of the path because they have special meaning
Expand Down
5 changes: 1 addition & 4 deletions lua/neo-tree/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,7 @@ M.resolve_config_option = function(state, config_option, default_value)
end
end

local fs_normalize = vim.fs.normalize
if vim.fn.has("nvim-0.11") == 0 then
fs_normalize = compat.fs_normalize
end
local fs_normalize = compat.fs_normalize

---Normalize a path, to avoid errors when comparing paths.
---@param path string The path to be normalize.
Expand Down
Loading