Skip to content
Munif Tanjim edited this page Jun 22, 2023 · 1 revision

Unmount when focus moves outside

local popups = {
  a = Popup({ border = "single", enter = true }),
  b = Popup({ border = "single" }),
}

local layout = Layout(
  {
    relative = "editor",
    position = "50%",
    size = { height = 10, width = 60 },
  },
  Layout.Box({
    Layout.Box(popups.a, { grow = 1 }),
    Layout.Box(popups.b, { grow = 1 }),
  }, { dir = "row" })
)

for _, popup in pairs(popups) do
  popup:on("BufLeave", function()
    vim.schedule(function()
      local curr_bufnr = vim.api.nvim_get_current_buf()
      for _, p in pairs(popups) do
        if p.bufnr == curr_bufnr then
          return
        end
      end
      layout:unmount()
    end)
  end)
end
Clone this wiki locally