rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
3k stars 80 forks source link

Close a single notification using its id #75

Closed tvercruyssen closed 2 years ago

tvercruyssen commented 2 years ago

Their is a possibility to replace a notification and to dissmis all of them. But no function to dissmis a single notification using it's id/NotifyRecord. As a workaround you can replace a notification and set it's timeout to 0, but this seems less than ideal. I'm I missing a function here or has their simply never been a need to close a specfic notification.

rcarriga commented 2 years ago

Well the dismiss function is intended for users (i.e. person viewing the notification) while the returned record is intended for the caller of the notification.

You can set the on_open function for the notification which receives the window ID, store it somewhere and then call vim.api.nvim_win_close when you want. nvim-notify will handle a window closing gracefully.

tvercruyssen commented 2 years ago

That works perfectly, Thanks!

It seems I looked over the fact that on_open receives the window ID. Suppose I was looking for it in the wrong place as I didn't understand that the dismiss function was intended for users. Maybe drop a hint in the documentation that it is? It may just be me missreading misreading the docs.

Jeansidharta commented 1 year ago

Hey! I know this issue has been closed for a while, but I've been wondering if there could be a more intuitive or better documented solution for this? I was trying to make a loading notification, and took me quite a while to find this. Also, I think it's likely more people would have a need for such behavior.

I have a few ideas that could be done:

These are just a few ideas. I'd be willing to make a pull request for any of them, but I thought it'd be a better idea to discuss the best solution first

rcarriga commented 1 year ago

Using the id to close a notification is problematic because there is not a 1 to 1 relationship as notifications can be replaced over time, which I imagine would be a common use case for people looking to programmatically close a notification.

The wiki is open to edits if you'd like to an entry there :smile: