mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-13 17:40:25 +00:00
fix(nav-file): bufnr failure when trying to create the buffer
I'm not perfectly sure if this should be upstreamed, but seems like passing true to bufnr `create` argument now fails. This fixes this issue by adding a new buffer with bufadd when the buffer does not exist in the buffer list.
This commit is contained in:
parent
d3d3d22b62
commit
6138ff7096
@ -155,6 +155,15 @@ function M.on_menu_save()
|
|||||||
Marked.set_mark_list(get_menu_items())
|
Marked.set_mark_list(get_menu_items())
|
||||||
end
|
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)
|
function M.nav_file(id)
|
||||||
log.trace("nav_file(): Navigating to", id)
|
log.trace("nav_file(): Navigating to", id)
|
||||||
local idx = Marked.get_index_of(id)
|
local idx = Marked.get_index_of(id)
|
||||||
@ -168,7 +177,7 @@ function M.nav_file(id)
|
|||||||
if filename:sub(1, 1) ~= "/" then
|
if filename:sub(1, 1) ~= "/" then
|
||||||
filename = vim.loop.cwd() .. "/" .. mark.filename
|
filename = vim.loop.cwd() .. "/" .. mark.filename
|
||||||
end
|
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)
|
local set_row = not vim.api.nvim_buf_is_loaded(buf_id)
|
||||||
|
|
||||||
vim.api.nvim_set_current_buf(buf_id)
|
vim.api.nvim_set_current_buf(buf_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user