feat: action to open entry in new tab (#52)

This commit is contained in:
Steven Arcangeli 2023-01-28 16:19:45 -08:00
parent 0e53d40221
commit 48eec8b7ef
5 changed files with 23 additions and 3 deletions

View file

@ -30,6 +30,13 @@ M.select_split = {
end,
}
M.select_tab = {
desc = "Open the entry under the cursor in a new tab",
callback = function()
oil.select({ tab = true })
end,
}
M.preview = {
desc = "Open the entry under the cursor in a preview window, or close the preview window if already open",
callback = function()

View file

@ -37,6 +37,7 @@ local default_config = {
["<CR>"] = "actions.select",
["<C-s>"] = "actions.select_vsplit",
["<C-h>"] = "actions.select_split",
["<C-t>"] = "actions.select_tab",
["<C-p>"] = "actions.preview",
["<C-c>"] = "actions.close",
["<C-l>"] = "actions.refresh",

View file

@ -313,6 +313,7 @@ end
--- horizontal boolean Open the buffer in a horizontal split
--- split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
--- preview boolean Open the buffer in a preview window
--- tab boolean Open the buffer in a new tab
M.select = function(opts)
local cache = require("oil.cache")
opts = vim.tbl_extend("keep", opts or {}, {})
@ -322,6 +323,9 @@ M.select = function(opts)
if opts.preview and not opts.horizontal and opts.vertical == nil then
opts.vertical = true
end
if opts.tab and (opts.preview or opts.split) then
error("Cannot set preview or split when tab = true")
end
local util = require("oil.util")
if util.is_floating_win() and opts.preview then
vim.notify("oil preview doesn't work in a floating window", vim.log.levels.ERROR)
@ -405,7 +409,14 @@ M.select = function(opts)
if vim.tbl_isempty(mods) then
mods = nil
end
local cmd = opts.split and "split" or "edit"
local cmd
if opts.tab then
cmd = "tabedit"
elseif opts.split then
cmd = "split"
else
cmd = "edit"
end
vim.cmd({
cmd = cmd,
args = { url },