fix: command modifiers for :Oil (#691)

* Support command mods `:belowright hor 10Oil`
* Fix `:tab Oil` only work on the first tab
This commit is contained in:
phanium 2025-12-01 06:01:40 +08:00 committed by GitHub
parent b9ab05fe5a
commit cbcb3f997f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1128,9 +1128,9 @@ M.setup = function(opts)
config.setup(opts) config.setup(opts)
set_colors() set_colors()
vim.api.nvim_create_user_command("Oil", function(args) local callback = function(args)
local util = require("oil.util") local util = require("oil.util")
if args.smods.tab == 1 then if args.smods.tab > 0 then
vim.cmd.tabnew() vim.cmd.tabnew()
end end
local float = false local float = false
@ -1163,11 +1163,11 @@ M.setup = function(opts)
end end
end end
if not float and (args.smods.vertical or args.smods.split ~= "") then if not float and (args.smods.vertical or args.smods.horizontal or args.smods.split ~= "") then
if args.smods.vertical then if args.smods.vertical then
vim.cmd.vsplit({ mods = { split = args.smods.split } }) vim.cmd.vsplit({ mods = { split = args.smods.split }, range = { args.count } })
else else
vim.cmd.split({ mods = { split = args.smods.split } }) vim.cmd.split({ mods = { split = args.smods.split }, range = { args.count } })
end end
end end
@ -1183,7 +1183,12 @@ M.setup = function(opts)
open_opts.preview = {} open_opts.preview = {}
end end
M[method](path, open_opts) M[method](path, open_opts)
end, { desc = "Open oil file browser on a directory", nargs = "*", complete = "dir" }) end
vim.api.nvim_create_user_command(
"Oil",
callback,
{ desc = "Open oil file browser on a directory", nargs = "*", complete = "dir", count = true }
)
local aug = vim.api.nvim_create_augroup("Oil", {}) local aug = vim.api.nvim_create_augroup("Oil", {})
if config.default_file_explorer then if config.default_file_explorer then