-
-
Notifications
You must be signed in to change notification settings - Fork 626
fix: preview on floating window #1648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: preview on floating window #1648
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ummmm, after some digging I found out that I have update_focused_file = {
enable = true,
}, in my config file, when removing it the issue you faced occurs, I'm checking... You can try this config with my branch and vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup({
{
"wbthomason/packer.nvim",
{
"almo7aya/nvim-tree.lua",
branch = "fix/preview_action_on_floating_windows",
},
"kyazdani42/nvim-web-devicons",
-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
},
config = {
package_root = package_root,
compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true },
},
})
end
if vim.fn.isdirectory(install_path) == 0 then
print("Installing nvim-tree and dependencies.")
vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true
-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
require("nvim-tree").setup({
update_focused_file = {
enable = true,
},
view = {
float = {
enable = true,
},
},
})
end
vim.api.nvim_set_keymap("n", "<Space>e", "<cmd>:NvimTreeToggle<CR>", {})
|
That works as expected. |
seems like if opts.update_focused_file.enable then
create_nvim_tree_autocmd("BufEnter", {
callback = function()
M.find_file(false)
end,
})
end has something todo with this, removing Edit: adding require("nvim-tree.renderer").draw() fixes the issue for |
Cursory investigation: It seems that the tree window is being closed during the preview action: https://github.com/Almo7aya/nvim-tree.lua/blob/79f631bc1d52b387f4ae59fad1291d894afa97f5/lua/nvim-tree/actions/node/open-file.lua#L134 Rather than being reactive to the closed window in |
After a deep debugging session, I discovered that we have an option called if opts.view.float.enable and opts.view.float.quit_on_focus_loss then
create_nvim_tree_autocmd("WinLeave", { pattern = "NvimTree_*", callback = view.close })
end so ignoring this autocmd on preview fixes the issue use this config to test all the cases vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup({
{
"wbthomason/packer.nvim",
{
"almo7aya/nvim-tree.lua",
branch = "fix/preview_action_on_floating_windows",
},
"kyazdani42/nvim-web-devicons",
-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
},
config = {
package_root = package_root,
compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true },
},
})
end
if vim.fn.isdirectory(install_path) == 0 then
print("Installing nvim-tree and dependencies.")
vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true
-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
require("nvim-tree").setup({
actions = {
open_file = {
quit_on_open = true,
},
},
update_focused_file = {
enable = true,
},
view = {
float = {
enable = true,
quit_on_focus_loss = true,
},
},
})
end
vim.api.nvim_set_keymap("n", "<Space>e", "<cmd>:NvimTreeToggle<CR>", {})
|
Still blank after preview. The floating window is definitely still being closed. This can be validated via The next call to if mode == "preview" then
-- ignore "WinLeave" autocmd on preview
-- because the registered "WinLeave"
-- will kill the floating window immediately
set_current_win_no_autocmd(api.nvim_get_current_win(), "WinLeave")
else
set_current_win_no_autocmd(target_winid)
end Unfortunately there is another WinLeave event fired after |
I was calling |
Nice work. I'm out of time today, I'll take it for a drive tomorrow. |
@@ -209,7 +209,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" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct, however is only desirable for floating windows. There may be (future) WinLeave events in the non-floating case that we still wish to receive.
- Please change to
if mode == "preview" and view float is set then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested OK with open-file changes only:
- float enabled
- float disabled
- filter visible
- quit_on_focus_lost disabled
Thank you so much for this fix! |
fixes #1643
My changes prevent nvim-tree from using already closed window, usually when using floating window mode.
More details in the issue #1643