Skip to content

Commit

Permalink
fix: make notify work when wiping all buffers with %bw (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
folke authored Jan 16, 2023
1 parent b005821 commit cf66cd8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
4 changes: 4 additions & 0 deletions lua/notify/service/buffer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ function NotificationBuf:buffer()
return self._buffer
end

function NotificationBuf:is_valid()
return self._buffer and vim.api.nvim_buf_is_valid(self._buffer)
end

function NotificationBuf:level()
return self._notif.level
end
Expand Down
2 changes: 1 addition & 1 deletion lua/notify/service/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end

function NotificationService:replace(id, notif)
local existing = self._buffers[id]
if not existing then
if not (existing and existing:is_valid()) then
vim.notify("No matching notification found to replace")
return
end
Expand Down
65 changes: 35 additions & 30 deletions lua/notify/windows/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,34 @@ function WindowAnimator:push_pending(queue)
while not queue:is_empty() do
---@type NotificationBuf
local notif_buf = queue:peek()
local windows = vim.tbl_keys(self.win_stages)
local win_opts = self.stages[1]({
message = self:_get_dimensions(notif_buf),
open_windows = windows,
})
if not win_opts then
return
end
local opacity = util.pop(win_opts, "opacity")
if opacity then
notif_buf.highlights:set_opacity(opacity)
if not notif_buf:is_valid() then
queue:pop()
else
local windows = vim.tbl_keys(self.win_stages)
local win_opts = self.stages[1]({
message = self:_get_dimensions(notif_buf),
open_windows = windows,
})
if not win_opts then
return
end
local opacity = util.pop(win_opts, "opacity")
if opacity then
notif_buf.highlights:set_opacity(opacity)
end
win_opts.noautocmd = true
local win = util.open_win(notif_buf, false, win_opts)
vim.fn.setwinvar(
win,
"&winhl",
"Normal:" .. notif_buf.highlights.body .. ",FloatBorder:" .. notif_buf.highlights.border
)
self.win_stages[win] = 2
self.win_states[win] = {}
self.notif_bufs[win] = notif_buf
queue:pop()
notif_buf:open(win)
end
win_opts.noautocmd = true
local win = util.open_win(notif_buf, false, win_opts)
vim.fn.setwinvar(
win,
"&winhl",
"Normal:" .. notif_buf.highlights.body .. ",FloatBorder:" .. notif_buf.highlights.border
)
self.win_stages[win] = 2
self.win_states[win] = {}
self.notif_bufs[win] = notif_buf
queue:pop()
notif_buf:open(win)
end
end

Expand Down Expand Up @@ -273,13 +277,14 @@ function WindowAnimator:_apply_win_state(win, win_state)
if win_state.opacity then
win_updated = true
local notif_buf = self.notif_bufs[win]
notif_buf.highlights:set_opacity(win_state.opacity.position)

vim.fn.setwinvar(
win,
"&winhl",
"Normal:" .. notif_buf.highlights.body .. ",FloatBorder:" .. notif_buf.highlights.border
)
if notif_buf:is_valid() then
notif_buf.highlights:set_opacity(win_state.opacity.position)
vim.fn.setwinvar(
win,
"&winhl",
"Normal:" .. notif_buf.highlights.body .. ",FloatBorder:" .. notif_buf.highlights.border
)
end
end
local exists, conf = util.get_win_config(win)
local new_conf = {}
Expand Down

0 comments on commit cf66cd8

Please sign in to comment.