Skip to content

Commit c995ce0

Browse files
authored
fix(#1643): preview on floating window (#1648)
* fix: preview on floating window * chore: redrawing the tree after setting current win * chore: ignore winleave autocmd on preview action * fix: typo in comment * chore: call correct window id * chore: revert changes in focus method * chore: check if float window is enabled before ignoring WinLeave
1 parent c446527 commit c995ce0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ end
167167

168168
-- This is only to avoid the BufEnter for nvim-tree to trigger
169169
-- which would cause find-file to run on an invalid file.
170-
local function set_current_win_no_autocmd(winid)
170+
local function set_current_win_no_autocmd(winid, autocmd)
171171
local eventignore = vim.opt.eventignore:get()
172-
vim.opt.eventignore:append "BufEnter"
172+
vim.opt.eventignore:append(autocmd)
173173
api.nvim_set_current_win(winid)
174174
vim.opt.eventignore = eventignore
175175
end
@@ -211,7 +211,15 @@ local function open_in_new_window(filename, mode, win_ids)
211211
cmd = string.format("edit %s", fname)
212212
end
213213

214-
set_current_win_no_autocmd(target_winid)
214+
if mode == "preview" and view.View.float.enable then
215+
-- ignore "WinLeave" autocmd on preview
216+
-- because the registered "WinLeave"
217+
-- will kill the floating window immediately
218+
set_current_win_no_autocmd(target_winid, { "WinLeave", "BufEnter" })
219+
else
220+
set_current_win_no_autocmd(target_winid, { "BufEnter" })
221+
end
222+
215223
pcall(vim.cmd, cmd)
216224
lib.set_target_win()
217225
end

0 commit comments

Comments
 (0)