add is_windows flag for filename change

This commit is contained in:
ljie-PI 2024-10-21 15:16:57 +08:00
parent 2b110a6d0f
commit ada77cb7e9

View File

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