Skip to content

Commit

Permalink
fix: convert buffer name to posix when hijacking directory
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Apr 24, 2024
1 parent e8fe65b commit e90a243
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lua/oil/adapters/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ M.normalize_url = function(url, callback)
local is_directory
if stat then
is_directory = stat.type == "directory"
elseif vim.endswith(realpath, "/") then
elseif vim.endswith(realpath, "/") or (fs.is_windows and vim.endswith(realpath, "\\")) then
is_directory = true
else
local filetype = vim.filetype.match({ filename = vim.fs.basename(realpath) })
Expand Down
7 changes: 4 additions & 3 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ end
---@return boolean
local function maybe_hijack_directory_buffer(bufnr)
local config = require("oil.config")
local fs = require("oil.fs")
local util = require("oil.util")
if not config.default_file_explorer then
return false
Expand All @@ -684,10 +685,10 @@ local function maybe_hijack_directory_buffer(bufnr)
if util.parse_url(bufname) or vim.fn.isdirectory(bufname) == 0 then
return false
end
local replaced = util.rename_buffer(
bufnr,
util.addslash(config.adapter_to_scheme.files .. vim.fn.fnamemodify(bufname, ":p"))
local new_name = util.addslash(
config.adapter_to_scheme.files .. fs.os_to_posix_path(vim.fn.fnamemodify(bufname, ":p"))
)
local replaced = util.rename_buffer(bufnr, new_name)
return not replaced
end

Expand Down
2 changes: 1 addition & 1 deletion lua/oil/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ end
---@param path string
---@return string
M.addslash = function(path)
if not vim.endswith(path, "/") and not vim.endswith(path, "\\") then
if not vim.endswith(path, "/") then
return path .. "/"
else
return path
Expand Down

0 comments on commit e90a243

Please sign in to comment.