Skip to content

Commit 45a93d9

Browse files
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 <[email protected]>
1 parent bd48816 commit 45a93d9

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lua/nvim-tree/actions/node/open-file.lua

+9-8
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ local function open_in_new_window(filename, mode)
333333

334334
local fname
335335
if M.relative_path then
336-
fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd())))
336+
fname = vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd()))
337337
else
338-
fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
338+
fname = vim.fn.fnameescape(filename)
339339
end
340340

341341
local command
@@ -372,35 +372,36 @@ end
372372
---@param mode string
373373
---@param filename string
374374
function M.fn(mode, filename)
375+
local fname = utils.escape_special_chars(filename)
375376
if type(mode) ~= "string" then
376377
mode = ""
377378
end
378379

379380
if mode == "tabnew" then
380-
return open_file_in_tab(filename)
381+
return open_file_in_tab(fname)
381382
end
382383

383384
if mode == "drop" then
384-
return drop(filename)
385+
return drop(fname)
385386
end
386387

387388
if mode == "tab_drop" then
388-
return tab_drop(filename)
389+
return tab_drop(fname)
389390
end
390391

391392
if mode == "edit_in_place" then
392-
return edit_in_current_buf(filename)
393+
return edit_in_current_buf(fname)
393394
end
394395

395-
local buf_loaded = is_already_loaded(filename)
396+
local buf_loaded = is_already_loaded(fname)
396397

397398
local found_win = utils.get_win_buf_from_path(filename)
398399
if found_win and (mode == "preview" or mode == "preview_no_picker") then
399400
return
400401
end
401402

402403
if not found_win then
403-
open_in_new_window(filename, mode)
404+
open_in_new_window(fname, mode)
404405
else
405406
vim.api.nvim_set_current_win(found_win)
406407
vim.bo.bufhidden = ""

lua/nvim-tree/utils.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function M.escape_special_chars(path)
290290
if path == nil then
291291
return path
292292
end
293-
return M.is_windows and path:gsub("%(", "\\("):gsub("%)", "\\)") or path
293+
return M.is_windows and path:gsub("\\", "/") or path
294294
end
295295

296296
--- Create empty sub-tables if not present

0 commit comments

Comments
 (0)