Skip to content

Commit

Permalink
fix: On close of TOC, only delete buffer if it exists (#978)
Browse files Browse the repository at this point in the history
fixes #977
  • Loading branch information
madskjeldgaard committed Jul 7, 2023
1 parent 4e6dbb1 commit 32bae17
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lua/neorg/modules/core/qol/toc/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,21 @@ module.on_event = function(event)
vim.api.nvim_win_set_option(window, "scrolloff", 999)
module.public.update_toc(namespace, toc_title, event.buffer, event.window, buffer, window)

vim.api.nvim_buf_set_keymap(buffer, "n", "q", "", {
callback = function()
local close_buffer_callback = function()
-- Check if buffer exists before deleting it
if vim.api.nvim_buf_is_loaded(buffer) then
vim.api.nvim_buf_delete(buffer, { force = true })
end,
end
end

vim.api.nvim_buf_set_keymap(buffer, "n", "q", "", {
callback = close_buffer_callback,
})

vim.api.nvim_create_autocmd("WinClosed", {
buffer = buffer,
once = true,
callback = function()
vim.api.nvim_buf_delete(buffer, { force = true })
end,
callback = close_buffer_callback,
})

do
Expand Down

0 comments on commit 32bae17

Please sign in to comment.