fix: opening terminal buffers

Now when trying to open files and buffers it will use the `buffer`
command when there is an existing buffer with the same name. This will
allow us to open non file buffers like terminals and log buffers.

By using the `bufnr` function to get the existing buffers, it will also
work for buffers that have been renamed with `title` command

Ref: #31
This commit is contained in:
Ade Attwood 2023-04-25 19:46:44 +01:00
parent 2a72162150
commit 56dced41e0
2 changed files with 20 additions and 1 deletions

View file

@ -17,6 +17,13 @@ utils.command_map = {
[utils.actions.SPLIT] = "split",
}
utils.existing_command_map = {
[utils.actions.EDIT] = "buffer",
[utils.actions.CHECKPOINT] = "buffer",
[utils.actions.VSPLIT] = "vsplit | buffer",
[utils.actions.SPLIT] = "split | buffer",
}
utils.command_finder = function(command, min)
if min == nil then
min = 3
@ -72,7 +79,14 @@ utils.file_action = function()
return
end
local command = utils.command_map[action]
local buffer_number = vim.fn.bufnr(file)
local command
if buffer_number > -1 then
command = utils.existing_command_map[action]
else
command = utils.command_map[action]
end
if command == nil then
vim.api.nvim_err_writeln("[IVY] The file action is unable the handel the action " .. action)
return

View file

@ -75,6 +75,11 @@ mock.reset = function()
return lines
end,
},
fn = {
bufnr = function()
return -1
end,
},
schedule = function(callback)
callback()
end,