From 39e26f97c5a3d19d7b99ea015c2bc03afd7f1810 Mon Sep 17 00:00:00 2001 From: metalinspired Date: Fri, 1 Nov 2024 09:08:30 +0100 Subject: [PATCH] Properly handle directory changes https://github.com/ThePrimeagen/harpoon/pull/614 --- lua/harpoon/init.lua | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lua/harpoon/init.lua b/lua/harpoon/init.lua index e34a7971..c9a06030 100644 --- a/lua/harpoon/init.lua +++ b/lua/harpoon/init.lua @@ -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