Skip to content

Commit 0345117

Browse files
authored
fix(#1545): dispatch Event.Resize on all window resizes, requires nvim 0.9+ (#2238)
1 parent 8d82c4d commit 0345117

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lua/nvim-tree.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local modified = require "nvim-tree.modified"
1515
local keymap_legacy = require "nvim-tree.keymap-legacy"
1616
local find_file = require "nvim-tree.actions.tree.find-file"
1717
local open = require "nvim-tree.actions.tree.open"
18+
local events = require "nvim-tree.events"
1819

1920
local _config = {}
2021

@@ -337,6 +338,21 @@ local function setup_autocommands(opts)
337338
end,
338339
})
339340
end
341+
342+
-- TODO #1545 remove similar check from view.resize
343+
if vim.fn.has "nvim-0.9" == 1 then
344+
create_nvim_tree_autocmd("WinResized", {
345+
callback = function()
346+
if vim.v.event and vim.v.event.windows then
347+
for _, winid in ipairs(vim.v.event.windows) do
348+
if vim.api.nvim_win_is_valid(winid) and utils.is_nvim_tree_buf(vim.api.nvim_win_get_buf(winid)) then
349+
events._dispatch_on_tree_resize(vim.api.nvim_win_get_width(winid))
350+
end
351+
end
352+
end
353+
end,
354+
})
355+
end
340356
end
341357

342358
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS

lua/nvim-tree/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ function M.is_nvim_tree_buf(bufnr)
434434
if bufnr == nil then
435435
bufnr = 0
436436
end
437-
if vim.fn.bufexists(bufnr) then
437+
if vim.api.nvim_buf_is_valid(bufnr) then
438438
local bufname = vim.api.nvim_buf_get_name(bufnr)
439439
if vim.fn.fnamemodify(bufname, ":t"):match "^NvimTree_[0-9]+$" then
440440
if vim.bo[bufnr].filetype == "NvimTree" then

lua/nvim-tree/view.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ function M.resize(size)
330330
local new_size = get_width()
331331
vim.api.nvim_win_set_width(M.get_winnr(), new_size)
332332

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

335339
if not M.View.preserve_window_proportions then
336340
vim.cmd ":wincmd ="

0 commit comments

Comments
 (0)