added new action 'file_switch' (closes #301)

main
bhagwan 2 years ago
parent e3546e8272
commit 2d1862d034

@ -173,6 +173,32 @@ M.file_edit_or_qf = function(selected, opts)
end
end
M.file_switch = function(selected, opts)
local bufnr = nil
local entry = path.entry_to_file(selected[1])
local fullpath = entry.path
if not path.starts_with_separator(fullpath) then
fullpath = path.join({opts.cwd or vim.loop.cwd(), fullpath})
end
for _, b in ipairs(vim.api.nvim_list_bufs()) do
local bname = vim.api.nvim_buf_get_name(b)
if bname and bname == fullpath then
bufnr = b
break
end
end
if not bufnr then return false end
local is_term = utils.is_term_buffer(0)
if not is_term then vim.cmd("normal! m`") end
local winid = utils.winid_from_tab_buf(0, bufnr)
if winid then vim.api.nvim_set_current_win(winid) end
if entry.line>1 or entry.col>1 then
vim.api.nvim_win_set_cursor(0, {tonumber(entry.line), tonumber(entry.col)-1})
end
if not is_term then vim.cmd("norm! zvzz") end
return true
end
-- buffer actions
M.vimcmd_buf = function(vimcmd, selected, _)
for i = 1, #selected do

@ -725,6 +725,7 @@ M._action_to_helpstr = {
[actions.file_vsplit] = "file-vsplit",
[actions.file_tabedit] = "file-tabedit",
[actions.file_sel_to_qf] = "file-selection-to-qf",
[actions.file_switch] = "file-switch",
[actions.buf_edit] = "buffer-edit",
[actions.buf_split] = "buffer-split",
[actions.buf_vsplit] = "buffer-vsplit",

Loading…
Cancel
Save