fix: correct buffer parser and timestamp test
Problem: parse_buffer classified /id/-prefixed task lines as headers because '/' matches the '^%S' header pattern. Store timestamp test was flaky when add and update ran within the same second. Solution: check for task line patterns (id prefix or 2-space indent) before falling through to the header branch. Backdate the initial modified timestamp in the store update test.
This commit is contained in:
parent
6cb5ae9dda
commit
edd16f6ecf
2 changed files with 25 additions and 27 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue