From 45a93d99794fff3064141d5b3a50db98ce352697 Mon Sep 17 00:00:00 2001 From: Zifan Zhu <55147873+dogeggz@users.noreply.github.com> Date: Sat, 14 Sep 2024 22:23:37 -0400 Subject: [PATCH] fix(#2862): windows path replaces backslashes with forward slashes (#2903) * Fix Winodws path issue by replacing backslashes with forward slashes * Fix #2862 (handle all filename-related tasks) * fix type mismatch --------- Co-authored-by: Alexander Courtis --- lua/nvim-tree/actions/node/open-file.lua | 17 +++++++++-------- lua/nvim-tree/utils.lua | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index c9bea9e1fb8..cb72df3a20e 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -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 @@ -372,27 +372,28 @@ 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 @@ -400,7 +401,7 @@ function M.fn(mode, filename) 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 = "" diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index 7da0a0c9cf5..b34518b14f8 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -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