diff --git a/lua/todo/diff.lua b/lua/todo/diff.lua index 902c064..81ec9b4 100644 --- a/lua/todo/diff.lua +++ b/lua/todo/diff.lua @@ -26,36 +26,34 @@ function M.parse_buffer(lines) local current_category = nil for i, line in ipairs(lines) do + local id, body = line:match('^/(%d+)/( .+)$') + if not id then + body = line:match('^( .+)$') + end if line == '' then table.insert(result, { type = 'blank', lnum = i }) + elseif id or body then + local stripped = body:match('^ (.+)$') or body + local priority = 0 + if stripped:match('^! ') then + priority = 1 + stripped = stripped:sub(3) + end + local description, metadata = parse.body(stripped) + if description and description ~= '' then + table.insert(result, { + type = 'task', + id = id and tonumber(id) or nil, + description = description, + priority = priority, + category = metadata.cat or current_category or config.get().default_category, + due = metadata.due, + lnum = i, + }) + end elseif line:match('^%S') then current_category = line table.insert(result, { type = 'header', category = line, lnum = i }) - else - local id, body = line:match('^/(%d+)/( .+)$') - if not id then - body = line:match('^( .+)$') - end - if body then - local stripped = body:match('^ (.+)$') or body - local priority = 0 - if stripped:match('^! ') then - priority = 1 - stripped = stripped:sub(3) - end - local description, metadata = parse.body(stripped) - if description and description ~= '' then - table.insert(result, { - type = 'task', - id = id and tonumber(id) or nil, - description = description, - priority = priority, - category = metadata.cat or current_category or config.get().default_category, - due = metadata.due, - lnum = i, - }) - end - end end end diff --git a/spec/store_spec.lua b/spec/store_spec.lua index 588a3ec..3bd7e40 100644 --- a/spec/store_spec.lua +++ b/spec/store_spec.lua @@ -106,11 +106,11 @@ describe('store', function() it('updates fields and sets modified', function() store.load() local t = store.add({ description = 'Original' }) - local original_modified = t.modified + t.modified = '2025-01-01T00:00:00Z' store.update(t.id, { description = 'Updated' }) local updated = store.get(t.id) assert.are.equal('Updated', updated.description) - assert.is_not.equal(original_modified, updated.modified) + assert.is_not.equal('2025-01-01T00:00:00Z', updated.modified) end) it('sets end timestamp on completion', function()