Skip to content

fix(#2862): windows path replaces backslashes with forward slashes #2903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 15, 2024
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
17 changes: 9 additions & 8 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ local function open_in_new_window(filename, mode)

local fname
if M.relative_path then
fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd())))
fname = vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd()))
else
fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
fname = vim.fn.fnameescape(filename)
end

local command
Expand Down Expand Up @@ -372,35 +372,36 @@ end
---@param mode string
---@param filename string
function M.fn(mode, filename)
local fname = utils.escape_special_chars(filename)
if type(mode) ~= "string" then
mode = ""
end

if mode == "tabnew" then
return open_file_in_tab(filename)
return open_file_in_tab(fname)
end

if mode == "drop" then
return drop(filename)
return drop(fname)
end

if mode == "tab_drop" then
return tab_drop(filename)
return tab_drop(fname)
end

if mode == "edit_in_place" then
return edit_in_current_buf(filename)
return edit_in_current_buf(fname)
end

local buf_loaded = is_already_loaded(filename)
local buf_loaded = is_already_loaded(fname)

local found_win = utils.get_win_buf_from_path(filename)
if found_win and (mode == "preview" or mode == "preview_no_picker") then
return
end

if not found_win then
open_in_new_window(filename, mode)
open_in_new_window(fname, mode)
else
vim.api.nvim_set_current_win(found_win)
vim.bo.bufhidden = ""
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function M.escape_special_chars(path)
if path == nil then
return path
end
return M.is_windows and path:gsub("%(", "\\("):gsub("%)", "\\)") or path
return M.is_windows and path:gsub("\\", "/") or path
end

--- Create empty sub-tables if not present
Expand Down
Loading