feat: add callback for handling buffer opening (#638)
This commit is contained in:
parent
200df01e4b
commit
dfb09e87bf
1 changed files with 14 additions and 9 deletions
|
|
@ -618,6 +618,7 @@ end
|
||||||
---@field split? "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
|
---@field split? "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
|
||||||
---@field tab? boolean Open the buffer in a new tab
|
---@field tab? boolean Open the buffer in a new tab
|
||||||
---@field close? boolean Close the original oil buffer once selection is made
|
---@field close? boolean Close the original oil buffer once selection is made
|
||||||
|
---@field handle_buffer_callback? fun(buf_id: integer) If defined, all other buffer related options here would be ignored. This callback allows you to take over the process of opening the buffer yourself.
|
||||||
|
|
||||||
---Select the entry under the cursor
|
---Select the entry under the cursor
|
||||||
---@param opts nil|oil.SelectOpts
|
---@param opts nil|oil.SelectOpts
|
||||||
|
|
@ -757,15 +758,19 @@ M.select = function(opts, callback)
|
||||||
elseif opts.split then
|
elseif opts.split then
|
||||||
cmd = "sbuffer"
|
cmd = "sbuffer"
|
||||||
end
|
end
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
if opts.handle_buffer_callback ~= nil then
|
||||||
local ok, err = pcall(vim.cmd, {
|
opts.handle_buffer_callback(filebufnr)
|
||||||
cmd = cmd,
|
else
|
||||||
args = { filebufnr },
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
mods = mods,
|
local ok, err = pcall(vim.cmd, {
|
||||||
})
|
cmd = cmd,
|
||||||
-- Ignore swapfile errors
|
args = { filebufnr },
|
||||||
if not ok and err and not err:match("^Vim:E325:") then
|
mods = mods,
|
||||||
vim.api.nvim_echo({ { err, "Error" } }, true, {})
|
})
|
||||||
|
-- Ignore swapfile errors
|
||||||
|
if not ok and err and not err:match("^Vim:E325:") then
|
||||||
|
vim.api.nvim_echo({ { err, "Error" } }, true, {})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
open_next_entry(cb)
|
open_next_entry(cb)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue