Merge pull request #186 from kyazdani42/fix/nav-file/bufnr-failure

fix(nav-file): bufnr failure when trying to create the buffer
This commit is contained in:
ThePrimeagen 2022-08-09 20:35:54 -06:00 committed by GitHub
commit 16482f5ba6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -155,6 +155,15 @@ function M.on_menu_save()
Marked.set_mark_list(get_menu_items())
end
local function get_or_create_buffer(filename)
local buf_exists = vim.fn.bufexists(filename) ~= 0
if buf_exists then
return vim.fn.bufnr(filename)
end
return vim.fn.bufadd(filename)
end
function M.nav_file(id)
log.trace("nav_file(): Navigating to", id)
local idx = Marked.get_index_of(id)
@ -168,7 +177,7 @@ function M.nav_file(id)
if filename:sub(1, 1) ~= "/" then
filename = vim.loop.cwd() .. "/" .. mark.filename
end
local buf_id = vim.fn.bufnr(filename, true)
local buf_id = get_or_create_buffer(filename)
local set_row = not vim.api.nvim_buf_is_loaded(buf_id)
vim.api.nvim_set_current_buf(buf_id)