Skip to content

Commit

Permalink
possible fix: hoping to address #566 #567
Browse files Browse the repository at this point in the history
  • Loading branch information
theprimeagen committed Apr 9, 2024
1 parent da326d0 commit d345631
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 5 additions & 7 deletions lua/harpoon/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ function M.get_default_config()
---@return HarpoonListItem
create_list_item = function(config, name)
name = name
-- TODO: should we do path normalization???
-- i know i have seen sometimes it becoming an absolute
-- path, if that is the case we can use the context to
-- store the bufname and then have value be the normalized
-- value
or normalize_path(
vim.api.nvim_buf_get_name(
vim.api.nvim_get_current_buf()
Expand Down Expand Up @@ -224,8 +219,11 @@ function M.get_default_config()
---@param list HarpoonList
BufLeave = function(arg, list)
local bufnr = arg.buf
local bufname = vim.api.nvim_buf_get_name(bufnr)
local item = list:get_by_display(bufname)
local bufname = normalize_path(
vim.api.nvim_buf_get_name(bufnr),
list.config.get_root_dir()
)
local item = list:get_by_value(bufname)

if item then
local pos = vim.api.nvim_win_get_cursor(0)
Expand Down
12 changes: 9 additions & 3 deletions lua/harpoon/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,15 @@ function HarpoonList:get(index)
return self.items[index]
end

function HarpoonList:get_by_display(name)
local displayed = self:display()
local index = index_of(displayed, #displayed, name)
function HarpoonList:get_by_value(value)

This comment has been minimized.

Copy link
@cuiko

cuiko Apr 12, 2024

I think this is a break change, My code is using get_by_display.

local index = index_of(self.items, self._length, value, {
equals = function(element, item)
if item == nil then
return false
end
return element == item.value
end,
})
if index == -1 then
return nil
end
Expand Down

0 comments on commit d345631

Please sign in to comment.