Skip to content

Commit 83de79f

Browse files
DenzellceWolf
authored andcommitted
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 83de79f

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

lua/cmake-tools/notification.lua

Lines changed: 10 additions & 8 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,14 +86,15 @@ 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
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.closed would not work as it gets set too late
91+
if vim.api.nvim_win_is_valid(self.win) and self.width then
92+
-- update the notification width when the message was updated
93+
local timeDigits = 8
94+
local headlineLength = (self.opts.icon and (#self.opts.icon + 1) or 0)
95+
+ #self.opts.title
96+
+ 3 -- padding between title and time
97+
+ timeDigits
9698
vim.api.nvim_win_set_width(self.win, math.max(#self.msg + 1, headlineLength))
9799
end
98100
end

0 commit comments

Comments
 (0)