refactor(diff): parse and reconcile markdown checkbox format
Problem: parse_buffer matched the old ' text' indent pattern and detected headers via '^%S'. Priority was read from a '[N] ' prefix. apply() never reconciled status changes written into the buffer. Solution: match '- [.] text' for tasks and '^## ' for headers. Extract state char to derive priority (! -> 1) and status (x -> done). apply() now reconciles status from the buffer, setting/clearing 'end' timestamps — enabling the oil-style edit-checkbox-then-:w workflow.
This commit is contained in:
parent
afb9e65f8d
commit
fe2ee47b5e
2 changed files with 45 additions and 37 deletions
|
|
@ -25,12 +25,12 @@ describe('diff', function()
|
|||
describe('parse_buffer', function()
|
||||
it('parses headers and tasks', function()
|
||||
local lines = {
|
||||
'School',
|
||||
'/1/ Do homework',
|
||||
'/2/ ! Read chapter 5',
|
||||
'## School',
|
||||
'/1/- [ ] Do homework',
|
||||
'/2/- [!] Read chapter 5',
|
||||
'',
|
||||
'Errands',
|
||||
'/3/ Buy groceries',
|
||||
'## Errands',
|
||||
'/3/- [ ] Buy groceries',
|
||||
}
|
||||
local result = diff.parse_buffer(lines)
|
||||
assert.are.equal(6, #result)
|
||||
|
|
@ -48,8 +48,8 @@ describe('diff', function()
|
|||
|
||||
it('handles new tasks without ids', function()
|
||||
local lines = {
|
||||
'Inbox',
|
||||
' New task here',
|
||||
'## Inbox',
|
||||
'- [ ] New task here',
|
||||
}
|
||||
local result = diff.parse_buffer(lines)
|
||||
assert.are.equal(2, #result)
|
||||
|
|
@ -62,9 +62,9 @@ describe('diff', function()
|
|||
describe('apply', function()
|
||||
it('creates new tasks from buffer lines', function()
|
||||
local lines = {
|
||||
'Inbox',
|
||||
' First task',
|
||||
' Second task',
|
||||
'## Inbox',
|
||||
'- [ ] First task',
|
||||
'- [ ] Second task',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
|
|
@ -80,8 +80,8 @@ describe('diff', function()
|
|||
store.add({ description = 'Delete me' })
|
||||
store.save()
|
||||
local lines = {
|
||||
'Inbox',
|
||||
'/1/ Keep me',
|
||||
'## Inbox',
|
||||
'/1/- [ ] Keep me',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
|
|
@ -97,8 +97,8 @@ describe('diff', function()
|
|||
store.add({ description = 'Original' })
|
||||
store.save()
|
||||
local lines = {
|
||||
'Inbox',
|
||||
'/1/ Renamed',
|
||||
'## Inbox',
|
||||
'/1/- [ ] Renamed',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
|
|
@ -111,9 +111,9 @@ describe('diff', function()
|
|||
store.add({ description = 'Original' })
|
||||
store.save()
|
||||
local lines = {
|
||||
'Inbox',
|
||||
'/1/ Original',
|
||||
'/1/ Copy of original',
|
||||
'## Inbox',
|
||||
'/1/- [ ] Original',
|
||||
'/1/- [ ] Copy of original',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
|
|
@ -126,8 +126,8 @@ describe('diff', function()
|
|||
store.add({ description = 'Moving task', category = 'Inbox' })
|
||||
store.save()
|
||||
local lines = {
|
||||
'Work',
|
||||
'/1/ Moving task',
|
||||
'## Work',
|
||||
'/1/- [ ] Moving task',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
|
|
@ -140,8 +140,8 @@ describe('diff', function()
|
|||
store.add({ description = 'Stable task', category = 'Inbox' })
|
||||
store.save()
|
||||
local lines = {
|
||||
'Inbox',
|
||||
'/1/ Stable task',
|
||||
'## Inbox',
|
||||
'/1/- [ ] Stable task',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
|
|
@ -158,8 +158,8 @@ describe('diff', function()
|
|||
store.add({ description = 'Pay bill', due = '2026-03-15' })
|
||||
store.save()
|
||||
local lines = {
|
||||
'Inbox',
|
||||
'/1/ Pay bill',
|
||||
'## Inbox',
|
||||
'/1/- [ ] Pay bill',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
|
|
@ -172,8 +172,8 @@ describe('diff', function()
|
|||
store.add({ description = 'Task name', priority = 1 })
|
||||
store.save()
|
||||
local lines = {
|
||||
'Inbox',
|
||||
'/1/ Task name',
|
||||
'## Inbox',
|
||||
'/1/- [ ] Task name',
|
||||
}
|
||||
diff.apply(lines)
|
||||
store.unload()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue