From acf1a58632e5400ca6e1af9c057a82dd3a77dbea Mon Sep 17 00:00:00 2001 From: NStefan002 Date: Wed, 17 Jan 2024 02:34:02 +0100 Subject: [PATCH 1/2] fix(buffer): close the harpoon window when opening netrw inside it --- lua/harpoon/buffer.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/harpoon/buffer.lua b/lua/harpoon/buffer.lua index 0a5576ee..9984e3a5 100644 --- a/lua/harpoon/buffer.lua +++ b/lua/harpoon/buffer.lua @@ -81,6 +81,24 @@ function M.setup_autocmds_and_keymaps(bufnr) require("harpoon").ui:toggle_quick_menu() end, }) + + vim.api.nvim_create_autocmd("FileType", { + group = HarpoonGroup, + pattern = "*", + callback = function(ev) + vim.schedule(function() + local ui = require("harpoon").ui + if + not ui.closing + and ev.buf ~= ui.bufnr + and ui.win_id == vim.api.nvim_get_current_win() + then + require("harpoon").logger:log("toggle by FileType") + ui:toggle_quick_menu() + end + end) + end, + }) end ---@param bufnr number From c65a7235092ba5ff92b33abe4c5955ef097f415f Mon Sep 17 00:00:00 2001 From: NStefan002 Date: Wed, 17 Jan 2024 18:58:49 +0100 Subject: [PATCH 2/2] fix(buffer): check if the buffer that triggered autocmd is in the harpoon window --- lua/harpoon/buffer.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lua/harpoon/buffer.lua b/lua/harpoon/buffer.lua index 9984e3a5..6a6dfcbd 100644 --- a/lua/harpoon/buffer.lua +++ b/lua/harpoon/buffer.lua @@ -88,11 +88,12 @@ function M.setup_autocmds_and_keymaps(bufnr) callback = function(ev) vim.schedule(function() local ui = require("harpoon").ui - if - not ui.closing - and ev.buf ~= ui.bufnr - and ui.win_id == vim.api.nvim_get_current_win() - then + local current_win = vim.api.nvim_get_current_win() + local current_win_buf = vim.api.nvim_win_get_buf(current_win) + if ui.win_id ~= current_win or ev.buf ~= current_win_buf then + return + end + if not ui.closing and ev.buf ~= ui.bufnr then require("harpoon").logger:log("toggle by FileType") ui:toggle_quick_menu() end