fix(#2961): windows: escape brackets and parentheses when opening file (#2962)

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

This reverts commit 45a93d9979.

* fix the case when '()' and '[]' are both in file path

* remove debug messages

* remove unnecessary comments

* add is_windows feature flag when normalizing path

* add is_windows flag for filename change

* Revert "add is_windows flag for filename change"

This reverts commit ada77cb7e9.

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Jie Liu
2024-10-25 08:11:21 +08:00
committed by GitHub
parent 9b82ff9bba
commit 63c7ad9037
2 changed files with 36 additions and 13 deletions

View File

@@ -331,9 +331,9 @@ local function open_in_new_window(filename, mode)
local fname
if M.relative_path then
fname = vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd()))
fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd())))
else
fname = vim.fn.fnameescape(filename)
fname = utils.escape_special_chars(vim.fn.fnameescape(filename))
end
local command
@@ -370,28 +370,27 @@ 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(fname)
return open_file_in_tab(filename)
end
if mode == "drop" then
return drop(fname)
return drop(filename)
end
if mode == "tab_drop" then
return tab_drop(fname)
return tab_drop(filename)
end
if mode == "edit_in_place" then
return edit_in_current_buf(fname)
return edit_in_current_buf(filename)
end
local buf_loaded = is_already_loaded(fname)
local buf_loaded = is_already_loaded(filename)
local found_win = utils.get_win_buf_from_path(filename)
if found_win and (mode == "preview" or mode == "preview_no_picker") then
@@ -399,7 +398,7 @@ function M.fn(mode, filename)
end
if not found_win then
open_in_new_window(fname, mode)
open_in_new_window(filename, mode)
else
vim.api.nvim_set_current_win(found_win)
vim.bo.bufhidden = ""