From 2cb2b23c6d06e1437192aca79e2445bf76a4ac9b Mon Sep 17 00:00:00 2001 From: ray-x Date: Wed, 8 Sep 2021 08:38:07 +1000 Subject: [PATCH] Add split options when open preview file --- README.md | 2 ++ lua/navigator/gui.lua | 6 ++++-- lua/navigator/util.lua | 11 +++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8ac84d0..c82406a 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,8 @@ require'navigator'.setup({ | n | \j | move cursor to preview (windows move to bottom view point)| | n | \k | move cursor to list (windows move to up view point)| | i/n | \ | open preview file in nvim/Apply action| +| n | \ | open preview file in nvim with vsplit| +| n | \ | open preview file in nvim with split| | n | \ | open preview file in nvim/Apply action| | i/n | \ | previous page in listview| | i/n | \ | next page in listview| diff --git a/lua/navigator/gui.lua b/lua/navigator/gui.lua index 13e6769..ea53c2c 100644 --- a/lua/navigator/gui.lua +++ b/lua/navigator/gui.lua @@ -178,10 +178,12 @@ function M.new_list_view(opts) -- data = display_data, data = data, border = border, - on_confirm = opts.on_confirm or function(item) + on_confirm = opts.on_confirm or function(item, split_opts) + log(split_opts) + split_opts = split_opts or {} if item.filename ~= nil then log("openfile ", item.filename, item.lnum, item.col) - util.open_file_at(item.filename, item.lnum, item.col) + util.open_file_at(item.filename, item.lnum, item.col, split_opts.split) end end, transparency = transparency, diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index 0f4efe2..04472df 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -282,8 +282,15 @@ M.open_file = function(filename) vim.api.nvim_command(string.format("e! %s", filename)) end -M.open_file_at = function(filename, line, col) - vim.api.nvim_command(string.format("e! +%s %s", line, filename)) +M.open_file_at = function(filename, line, col, split) + if split == nil then + -- code + vim.api.nvim_command(string.format("e! +%s %s", line, filename)) + elseif split == 'v' then + vim.api.nvim_command(string.format("vsp! +%s %s", line, filename)) + elseif split == 's' then + vim.api.nvim_command(string.format("sp! +%s %s", line, filename)) + end -- vim.api.nvim_command(string.format("e! %s", filename)) col = col or 1 vim.fn.cursor(line, col)