Add choice for opening in file or current buffer
This commit is contained in:
parent
f17f0a80c6
commit
39cc0a16b7
|
|
@ -5,21 +5,20 @@ local Path = require"SpecSwitcher.path"
|
|||
|
||||
local _config = {
|
||||
descend_dir = {},
|
||||
switch_shortcut = "<leader>n",
|
||||
open_in_new_tab = true
|
||||
}
|
||||
|
||||
local mapping = Extension_Map:new()
|
||||
|
||||
local function open(filename)
|
||||
if _config.open_in_new_tab then
|
||||
vim.cmd("e " .. filename)
|
||||
else
|
||||
vim.cmd("tabe " .. filename)
|
||||
end
|
||||
vim.cmd("e " .. filename)
|
||||
end
|
||||
|
||||
function M.Switch()
|
||||
local function open_in_tab(filename)
|
||||
vim.cmd("tabe " .. filename)
|
||||
end
|
||||
|
||||
function M.Switch(open_in_new_tab)
|
||||
local current_dir = vim.api.nvim_buf_get_name(0)
|
||||
|
||||
local file = nil
|
||||
|
|
@ -52,7 +51,11 @@ function M.Switch()
|
|||
local current_path = current_dir .. filename .. "." .. exts
|
||||
|
||||
if vim.fn.filereadable(current_path) > 0 then
|
||||
open(current_path)
|
||||
if open_in_new_tab == true then
|
||||
open_in_tab(current_path)
|
||||
else
|
||||
open(current_path)
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
|
@ -61,6 +64,13 @@ function M.Switch()
|
|||
end
|
||||
end
|
||||
|
||||
function M.Switch_Open(open_in_new_tab)
|
||||
local tab = open_in_new_tab
|
||||
return function()
|
||||
M.Switch(tab)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
local options = opts or {}
|
||||
|
||||
|
|
@ -79,8 +89,6 @@ function M.setup(opts)
|
|||
if options.switch_shortcut ~= nil then
|
||||
_config.switch_shortcut = options.switch_shortcut
|
||||
end
|
||||
|
||||
vim.keymap.set('n', _config.switch_shortcut, M.Switch)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user