feat: action to open entry in new tab (#52)
This commit is contained in:
parent
0e53d40221
commit
48eec8b7ef
5 changed files with 23 additions and 3 deletions
|
|
@ -30,6 +30,13 @@ M.select_split = {
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
M.select_tab = {
|
||||||
|
desc = "Open the entry under the cursor in a new tab",
|
||||||
|
callback = function()
|
||||||
|
oil.select({ tab = true })
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
M.preview = {
|
M.preview = {
|
||||||
desc = "Open the entry under the cursor in a preview window, or close the preview window if already open",
|
desc = "Open the entry under the cursor in a preview window, or close the preview window if already open",
|
||||||
callback = function()
|
callback = function()
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ local default_config = {
|
||||||
["<CR>"] = "actions.select",
|
["<CR>"] = "actions.select",
|
||||||
["<C-s>"] = "actions.select_vsplit",
|
["<C-s>"] = "actions.select_vsplit",
|
||||||
["<C-h>"] = "actions.select_split",
|
["<C-h>"] = "actions.select_split",
|
||||||
|
["<C-t>"] = "actions.select_tab",
|
||||||
["<C-p>"] = "actions.preview",
|
["<C-p>"] = "actions.preview",
|
||||||
["<C-c>"] = "actions.close",
|
["<C-c>"] = "actions.close",
|
||||||
["<C-l>"] = "actions.refresh",
|
["<C-l>"] = "actions.refresh",
|
||||||
|
|
|
||||||
|
|
@ -313,6 +313,7 @@ end
|
||||||
--- horizontal boolean Open the buffer in a horizontal split
|
--- horizontal boolean Open the buffer in a horizontal split
|
||||||
--- split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
|
--- split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
|
||||||
--- preview boolean Open the buffer in a preview window
|
--- preview boolean Open the buffer in a preview window
|
||||||
|
--- tab boolean Open the buffer in a new tab
|
||||||
M.select = function(opts)
|
M.select = function(opts)
|
||||||
local cache = require("oil.cache")
|
local cache = require("oil.cache")
|
||||||
opts = vim.tbl_extend("keep", opts or {}, {})
|
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
|
if opts.preview and not opts.horizontal and opts.vertical == nil then
|
||||||
opts.vertical = true
|
opts.vertical = true
|
||||||
end
|
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")
|
local util = require("oil.util")
|
||||||
if util.is_floating_win() and opts.preview then
|
if util.is_floating_win() and opts.preview then
|
||||||
vim.notify("oil preview doesn't work in a floating window", vim.log.levels.ERROR)
|
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
|
if vim.tbl_isempty(mods) then
|
||||||
mods = nil
|
mods = nil
|
||||||
end
|
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({
|
vim.cmd({
|
||||||
cmd = cmd,
|
cmd = cmd,
|
||||||
args = { url },
|
args = { url },
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ a.describe("Alternate buffer", function()
|
||||||
oil.open_float()
|
oil.open_float()
|
||||||
test_util.wait_for_autocmd("BufReadPost")
|
test_util.wait_for_autocmd("BufReadPost")
|
||||||
-- This is lazy, but testing the actual select logic is more difficult. We can simply
|
-- This is lazy, but testing the actual select logic is more difficult. We can simply
|
||||||
-- replicated it by closing the current window and then doing the edit
|
-- replicate it by closing the current window and then doing the edit
|
||||||
vim.api.nvim_win_close(0, true)
|
vim.api.nvim_win_close(0, true)
|
||||||
vim.cmd.edit({ args = { "bar" } })
|
vim.cmd.edit({ args = { "bar" } })
|
||||||
assert.equals("foo", vim.fn.expand("#"))
|
assert.equals("foo", vim.fn.expand("#"))
|
||||||
|
|
@ -88,7 +88,7 @@ a.describe("Alternate buffer", function()
|
||||||
oil.open_float()
|
oil.open_float()
|
||||||
test_util.wait_for_autocmd("BufReadPost")
|
test_util.wait_for_autocmd("BufReadPost")
|
||||||
-- This is lazy, but testing the actual select logic is more difficult. We can simply
|
-- This is lazy, but testing the actual select logic is more difficult. We can simply
|
||||||
-- replicated it by closing the current window and then doing the edit
|
-- replicate it by closing the current window and then doing the edit
|
||||||
vim.api.nvim_win_close(0, true)
|
vim.api.nvim_win_close(0, true)
|
||||||
vim.cmd.edit({ args = { "bar" } })
|
vim.cmd.edit({ args = { "bar" } })
|
||||||
assert.equals("foo", vim.fn.expand("#"))
|
assert.equals("foo", vim.fn.expand("#"))
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ describe("url", function()
|
||||||
it("get_url_for_path", function()
|
it("get_url_for_path", function()
|
||||||
local cases = {
|
local cases = {
|
||||||
{ "", "oil://" .. util.addslash(vim.fn.getcwd()) },
|
{ "", "oil://" .. util.addslash(vim.fn.getcwd()) },
|
||||||
|
{ "term://~/oil.nvim//52953:/bin/bash", "oil://" .. vim.loop.os_homedir() .. "/oil.nvim/" },
|
||||||
{ "/foo/bar.txt", "oil:///foo/", "bar.txt" },
|
{ "/foo/bar.txt", "oil:///foo/", "bar.txt" },
|
||||||
{ "oil:///foo/bar.txt", "oil:///foo/", "bar.txt" },
|
{ "oil:///foo/bar.txt", "oil:///foo/", "bar.txt" },
|
||||||
{ "oil:///", "oil:///" },
|
{ "oil:///", "oil:///" },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue