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
This commit is contained in:
Ali Almohaya 2022-10-16 04:17:17 +03:00 committed by GitHub
parent c446527056
commit c995ce0878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -167,9 +167,9 @@ end
-- This is only to avoid the BufEnter for nvim-tree to trigger
-- which would cause find-file to run on an invalid file.
local function set_current_win_no_autocmd(winid)
local function set_current_win_no_autocmd(winid, autocmd)
local eventignore = vim.opt.eventignore:get()
vim.opt.eventignore:append "BufEnter"
vim.opt.eventignore:append(autocmd)
api.nvim_set_current_win(winid)
vim.opt.eventignore = eventignore
end
@ -211,7 +211,15 @@ local function open_in_new_window(filename, mode, win_ids)
cmd = string.format("edit %s", fname)
end
set_current_win_no_autocmd(target_winid)
if mode == "preview" and view.View.float.enable then
-- ignore "WinLeave" autocmd on preview
-- because the registered "WinLeave"
-- will kill the floating window immediately
set_current_win_no_autocmd(target_winid, { "WinLeave", "BufEnter" })
else
set_current_win_no_autocmd(target_winid, { "BufEnter" })
end
pcall(vim.cmd, cmd)
lib.set_target_win()
end