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 = {
|
local _config = {
|
||||||
descend_dir = {},
|
descend_dir = {},
|
||||||
switch_shortcut = "<leader>n",
|
|
||||||
open_in_new_tab = true
|
open_in_new_tab = true
|
||||||
}
|
}
|
||||||
|
|
||||||
local mapping = Extension_Map:new()
|
local mapping = Extension_Map:new()
|
||||||
|
|
||||||
local function open(filename)
|
local function open(filename)
|
||||||
if _config.open_in_new_tab then
|
|
||||||
vim.cmd("e " .. filename)
|
vim.cmd("e " .. filename)
|
||||||
else
|
|
||||||
vim.cmd("tabe " .. filename)
|
|
||||||
end
|
|
||||||
end
|
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 current_dir = vim.api.nvim_buf_get_name(0)
|
||||||
|
|
||||||
local file = nil
|
local file = nil
|
||||||
|
|
@ -52,7 +51,11 @@ function M.Switch()
|
||||||
local current_path = current_dir .. filename .. "." .. exts
|
local current_path = current_dir .. filename .. "." .. exts
|
||||||
|
|
||||||
if vim.fn.filereadable(current_path) > 0 then
|
if vim.fn.filereadable(current_path) > 0 then
|
||||||
|
if open_in_new_tab == true then
|
||||||
|
open_in_tab(current_path)
|
||||||
|
else
|
||||||
open(current_path)
|
open(current_path)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -61,6 +64,13 @@ function M.Switch()
|
||||||
end
|
end
|
||||||
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)
|
function M.setup(opts)
|
||||||
local options = opts or {}
|
local options = opts or {}
|
||||||
|
|
||||||
|
|
@ -79,8 +89,6 @@ function M.setup(opts)
|
||||||
if options.switch_shortcut ~= nil then
|
if options.switch_shortcut ~= nil then
|
||||||
_config.switch_shortcut = options.switch_shortcut
|
_config.switch_shortcut = options.switch_shortcut
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.keymap.set('n', _config.switch_shortcut, M.Switch)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user