Skip to content

Commit

Permalink
Properly handle directory changes
Browse files Browse the repository at this point in the history
  • Loading branch information
metalinspired committed Nov 1, 2024
1 parent 901daa7 commit 39e26f9
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions lua/harpoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,29 @@ function Harpoon.setup(self, partial_config)
---TODO: should we go through every seen list and update its config?

if self.hooks_setup == false then
vim.api.nvim_create_autocmd({ "BufLeave", "VimLeavePre" }, {
group = HarpoonGroup,
pattern = "*",
callback = function(ev)
self:_for_each_list(function(list, config)
local fn = config[ev.event]
if fn ~= nil then
fn(ev, list)
vim.api.nvim_create_autocmd(
{ "BufLeave", "VimLeavePre", "DirChanged" },
{
group = HarpoonGroup,
pattern = "*",
callback = function(ev)
if ev.event == "DirChanged" then
self.data = Data.Data:new(self.config)
self.lists = {}
end

if ev.event == "VimLeavePre" then
self:sync()
end
end)
end,
})
self:_for_each_list(function(list, config)
local fn = config[ev.event]
if fn ~= nil then
fn(ev, list)
end

if ev.event == "VimLeavePre" then
self:sync()
end
end)
end,
}
)

self.hooks_setup = true
end
Expand Down

0 comments on commit 39e26f9

Please sign in to comment.