Merge pull request #541 from abeldekat/harpoon2

fix: The name is ....... sometimes too broad for a buffer
This commit is contained in:
ThePrimeagen 2024-04-03 16:04:46 -06:00 committed by GitHub
commit 3d35250de8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,9 @@ local Path = require("plenary.path")
local function normalize_path(buf_name, root) local function normalize_path(buf_name, root)
return Path:new(buf_name):make_relative(root) return Path:new(buf_name):make_relative(root)
end end
local function to_exact_name(value)
return "^" .. value .. "$"
end
local M = {} local M = {}
local DEFAULT_LIST = "__harpoon_files" local DEFAULT_LIST = "__harpoon_files"
@ -102,11 +105,12 @@ function M.get_default_config()
return return
end end
local bufnr = vim.fn.bufnr(list_item.value) local bufnr = vim.fn.bufnr(to_exact_name(list_item.value))
local set_position = false local set_position = false
if bufnr == -1 then if bufnr == -1 then -- must create a buffer!
set_position = true set_position = true
bufnr = vim.fn.bufnr(list_item.value, true) -- bufnr = vim.fn.bufnr(list_item.value, true)
bufnr = vim.fn.bufadd(list_item.value)
end end
if not vim.api.nvim_buf_is_loaded(bufnr) then if not vim.api.nvim_buf_is_loaded(bufnr) then
vim.fn.bufload(bufnr) vim.fn.bufload(bufnr)