feat(buffer): persist fold state across sessions (#94)

Problem: folded category headers are lost when Neovim exits because
`_fold_state` only lives in memory. Users must re-fold categories
every session.

Solution: store folded category names in the JSON data file as a
top-level `folded_categories` field. On first render, `restore_folds`
seeds from the store instead of the empty in-memory state. Folds are
persisted on `M.close()` and `VimLeavePre`.
This commit is contained in:
Barrett Ruth 2026-03-07 20:18:34 -05:00
parent 61eeed58f7
commit 22d0b4a3d4
4 changed files with 121 additions and 1 deletions

View file

@ -268,6 +268,18 @@ function M._setup_autocmds(bufnr)
end
end,
})
vim.api.nvim_create_autocmd('VimLeavePre', {
group = group,
callback = function()
local bnr = buffer.bufnr()
log.debug(('VimLeavePre: bufnr=%s valid=%s'):format(
tostring(bnr), tostring(bnr and vim.api.nvim_buf_is_valid(bnr))))
if bnr and vim.api.nvim_buf_is_valid(bnr) then
buffer.persist_folds()
get_store():save()
end
end,
})
end
---@param bufnr integer