fix(parse): skip forge refs in right-to-left metadata scan
Problem: `parse.body()` scans tokens right-to-left and breaks on the first non-metadata token. Forge refs like `gl:a/b#12` halted the scan, preventing metadata tokens to their left (e.g. `due:tomorrow`) from being parsed. Additionally, `diff.parse_buffer()` ignored `metadata.priority` from `+!!` tokens and only used checkbox-derived priority, and priority updates between two non-zero values were silently skipped. Solution: Recognize forge ref tokens via `forge.parse_ref()` during the right-to-left scan and skip past them, re-appending them to the description so `forge.find_refs()` still works. Prefer `metadata.priority` over checkbox priority in `parse_buffer()`, and simplify the priority update condition to catch all value changes.
This commit is contained in:
parent
b131d6d391
commit
fb76359579
4 changed files with 74 additions and 5 deletions
|
|
@ -379,5 +379,41 @@ describe('diff', function()
|
|||
local task = s:get(1)
|
||||
assert.are.equal(0, task.priority)
|
||||
end)
|
||||
|
||||
it('sets priority from +!! token', function()
|
||||
local lines = {
|
||||
'# Inbox',
|
||||
'- [ ] Pay bills +!!',
|
||||
}
|
||||
diff.apply(lines, s)
|
||||
s:load()
|
||||
local task = s:get(1)
|
||||
assert.are.equal(2, task.priority)
|
||||
end)
|
||||
|
||||
it('updates priority between non-zero values', function()
|
||||
s:add({ description = 'Task name', priority = 2 })
|
||||
s:save()
|
||||
local lines = {
|
||||
'# Inbox',
|
||||
'/1/- [!] Task name',
|
||||
}
|
||||
diff.apply(lines, s)
|
||||
s:load()
|
||||
local task = s:get(1)
|
||||
assert.are.equal(1, task.priority)
|
||||
end)
|
||||
|
||||
it('parses metadata with forge ref on same line', function()
|
||||
local lines = {
|
||||
'# Inbox',
|
||||
'- [ ] Fix bug due:2026-03-15 gh:user/repo#42',
|
||||
}
|
||||
diff.apply(lines, s)
|
||||
s:load()
|
||||
local task = s:get(1)
|
||||
assert.are.equal('2026-03-15', task.due)
|
||||
assert.is_not_nil(task._extra._forge_ref)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue