feat(buffer): persist fold state across sessions
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:
parent
26d43688d0
commit
5a4cc7f8a1
4 changed files with 121 additions and 1 deletions
|
|
@ -214,6 +214,35 @@ describe('store', function()
|
|||
end)
|
||||
end)
|
||||
|
||||
describe('folded_categories', function()
|
||||
it('defaults to empty table when missing from JSON', function()
|
||||
local path = tmpdir .. '/tasks.json'
|
||||
local f = io.open(path, 'w')
|
||||
f:write(vim.json.encode({
|
||||
version = 1,
|
||||
next_id = 1,
|
||||
tasks = {},
|
||||
}))
|
||||
f:close()
|
||||
s:load()
|
||||
assert.are.same({}, s:get_folded_categories())
|
||||
end)
|
||||
|
||||
it('round-trips folded categories through save and load', function()
|
||||
s:set_folded_categories({ 'Work', 'Home' })
|
||||
s:save()
|
||||
s:load()
|
||||
assert.are.same({ 'Work', 'Home' }, s:get_folded_categories())
|
||||
end)
|
||||
|
||||
it('persists empty list', function()
|
||||
s:set_folded_categories({})
|
||||
s:save()
|
||||
s:load()
|
||||
assert.are.same({}, s:get_folded_categories())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('active_tasks', function()
|
||||
it('excludes deleted tasks', function()
|
||||
s:add({ description = 'Active' })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue