Skip to content

Commit

Permalink
refactor: use in-built autocmd registration functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
PriceHiller committed Jul 15, 2023
1 parent 920b347 commit 5884423
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lua/neogit/lib/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -574,20 +574,15 @@ function M:show()
},
}
end,
}

-- Closes the window if it loses focus and it is a floating buffer
if self.buffer.kind == "floating" then
vim.api.nvim_create_autocmd("WinLeave", {
callback = function(win)
if win.buf == self.buffer.handle then
autocmds = {
["WinLeave"] = function()
if self.buffer.kind == "floating" then
-- We pcall this because it's possible the window was closed by a command invocation, e.g. "cc" for commits
pcall(self.close)
pcall(self.close, self)
end
end,
once = true,
})
end
},
}
end

return M

0 comments on commit 5884423

Please sign in to comment.