Skip to content

fix(#1545): dispatch Event.Resize on all window resizes, requires nvim 0.9+ #2238

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

Merged
merged 5 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local modified = require "nvim-tree.modified"
local keymap_legacy = require "nvim-tree.keymap-legacy"
local find_file = require "nvim-tree.actions.tree.find-file"
local open = require "nvim-tree.actions.tree.open"
local events = require "nvim-tree.events"

local _config = {}

Expand Down Expand Up @@ -337,6 +338,21 @@ local function setup_autocommands(opts)
end,
})
end

-- TODO #1545 remove similar check from view.resize
if vim.fn.has "nvim-0.9" == 1 then
create_nvim_tree_autocmd("WinResized", {
callback = function()
if vim.v.event and vim.v.event.windows then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it makes any difference but fallback receives an event afair.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the fallback in view.lua?

Sending multiple events would be undesirable...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the fallback in view.lua?

Sending multiple events would be undesirable...

No, meant that you should be able to do

callback = function(event)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, I'll give that a go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately no. The v:event data is still not passed to the callback. I hope they add that at some point...

for _, winid in ipairs(vim.v.event.windows) do
if vim.api.nvim_win_is_valid(winid) and utils.is_nvim_tree_buf(vim.api.nvim_win_get_buf(winid)) then
events._dispatch_on_tree_resize(vim.api.nvim_win_get_width(winid))
end
end
end
end,
})
end
end

local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ function M.is_nvim_tree_buf(bufnr)
if bufnr == nil then
bufnr = 0
end
if vim.fn.bufexists(bufnr) then
if vim.api.nvim_buf_is_valid(bufnr) then
local bufname = vim.api.nvim_buf_get_name(bufnr)
if vim.fn.fnamemodify(bufname, ":t"):match "^NvimTree_[0-9]+$" then
if vim.bo[bufnr].filetype == "NvimTree" then
Expand Down
6 changes: 5 additions & 1 deletion lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ function M.resize(size)
local new_size = get_width()
vim.api.nvim_win_set_width(M.get_winnr(), new_size)

events._dispatch_on_tree_resize(new_size)
-- TODO #1545 remove similar check from setup_autocommands
-- We let nvim handle sending resize events after 0.9
if vim.fn.has "nvim-0.9" == 0 then
events._dispatch_on_tree_resize(new_size)
end

if not M.View.preserve_window_proportions then
vim.cmd ":wincmd ="
Expand Down