Skip to content

Commit

Permalink
fix(toc): handle buf close
Browse files Browse the repository at this point in the history
  • Loading branch information
champignoom committed Dec 21, 2023
1 parent b6f5c8c commit 9c727b7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lua/neorg/modules/core/qol/toc/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ local function create_ui(tabpage, mode)

ui_data = {
buffer = ui_buffer,
tabpage = tabpage,
}

ui_data_of_tabpage[tabpage] = ui_data
Expand Down Expand Up @@ -421,18 +422,13 @@ module.on_event = function(event)
if vim.api.nvim_buf_is_loaded(ui_data.buffer) then
vim.api.nvim_buf_delete(ui_data.buffer, { force = true })
end
ui_data_of_tabpage[tabpage] = nil
end

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

vim.api.nvim_create_autocmd("WinClosed", {
buffer = ui_data.buffer,
once = true,
callback = close_buffer_callback,
})

do
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = "*.norg",
Expand Down Expand Up @@ -462,6 +458,10 @@ module.on_event = function(event)
callback = function(ev)
assert(ev.buf == ui_data.buffer)

if vim.fn.bufwinid(ui_data.norg_buffer) == -1 then
return
end

-- Ignore the first (fake) CursorMoved coming together with BufEnter of the ToC buffer
if ui_data.cursor_start_moving then
local location = get_target_location_under_cursor(ui_data)
Expand Down

0 comments on commit 9c727b7

Please sign in to comment.