nvim-tree-preview.lua icon indicating copy to clipboard operation
nvim-tree-preview.lua copied to clipboard

Preview remains open sometimes

Open idr4n opened this issue 6 months ago • 0 comments

Hi,

I noticed that if I open and focus the preview (even if I focus back on nvim-tree), and then close nvim-tree, the preview remains open and focused. I think this is not the desired behavior. This does not happen if I just open the preview and close nvim-tree without ever focusing the preview; in that case, the preview gets closed together with nvim-tree, which I think is the desired behavior.

When we had focusable = false, the behavior was that if we opened the preview, focused it, focused back on nvim-tree, and closed nvim-tree, then the preview was closed as well (desired behavior). However, if the preview was focused, it would remain open after closing nvim-tree (maybe not the desired behavior).

If we add tostring(tree.win) to the autocmd pattern for WinClosed, I think we get the desired behavior: the preview is closed after closing nvim-tree, regardless of whether the preview is focused. The autocmd in Preview:setup_autocmds would be:

vim.api.nvim_create_autocmd('WinClosed', {
  group = self.augroup,
  pattern = { tostring(tree.win), tostring(self.preview_win) }, -- <-- additional pattern tostring(tree.win)
  once = true,
  callback = function()
    self:close { focus_tree = false, unwatch = true }
  end,
})

Let me know what you think and whether you can reproduce the same behavior. Hopefully, I explained myself clearly above 😅

Thanks in advance!

idr4n avatar Jul 14 '25 03:07 idr4n