Skip to content

Commit 2ba94c5

Browse files
author
Denzel
committed
check for valid window before resizing (#306)
when calling `notify` on a notification instance quickly after the window has been dismissed, the on_close callback was not yet called as it is handled asynchronously by vim-notify. Yet, the window is gone and its winID is not valid anymore. Since the on_open callback is also handled async, the winID has not been replaced by then. Skipping the resize should be fine as the new notification should be displayed with the correct size to begin with
1 parent 591ae37 commit 2ba94c5

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

lua/cmake-tools/notification.lua

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function Notification:notify(msg, level, opts)
7171
self.opts.title = "CMakeTools"
7272
self.opts.on_close = function(win)
7373
self.closed = true
74+
self.spinner_idx = 1
7475
if on_close then
7576
on_close(win)
7677
end
@@ -85,15 +86,18 @@ function Notification:notify(msg, level, opts)
8586

8687
render(self)
8788

88-
-- update the notification width when the message was updated
89-
local timeDigits = 8
90-
local headlineLength = (self.opts.icon and (#self.opts.icon + 1) or 0)
91-
+ #self.opts.title
92-
+ 3 -- padding between title and time
93-
+ timeDigits
94-
95-
if self.width then
96-
vim.api.nvim_win_set_width(self.win, math.max(#self.msg + 1, headlineLength))
89+
-- We have to check for a valid window here as it seems notify invokes the on_close callback async.
90+
-- Hence checking for self.win ~= nil does not work as it gets deleted too late
91+
if vim.api.nvim_win_is_valid(self.win) then
92+
if self.width then
93+
-- update the notification width when the message was updated
94+
local timeDigits = 8
95+
local headlineLength = (self.opts.icon and (#self.opts.icon + 1) or 0)
96+
+ #self.opts.title
97+
+ 3 -- padding between title and time
98+
+ timeDigits
99+
vim.api.nvim_win_set_width(self.win, math.max(#self.msg + 1, headlineLength))
100+
end
97101
end
98102
end
99103

0 commit comments

Comments
 (0)