Skip to content

Commit

Permalink
Merge pull request ThePrimeagen#186 from kyazdani42/fix/nav-file/bufn…
Browse files Browse the repository at this point in the history
…r-failure

fix(nav-file): bufnr failure when trying to create the buffer
  • Loading branch information
ThePrimeagen authored Aug 10, 2022
2 parents d3d3d22 + 6138ff7 commit 16482f5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/harpoon/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 16482f5

Please sign in to comment.