feat(init): spawn next task on recurring task completion
Problem: completing a recurring task does not create the next occurrence, and :Pending add does not pass recurrence fields. Solution: in toggle_complete(), detect recurrence and spawn a new pending task with the next due date. Wire rec/rec_mode through the add() command path.
This commit is contained in:
parent
597ec6bb2a
commit
b08d01fe78
1 changed files with 28 additions and 4 deletions
|
|
@ -127,6 +127,20 @@ function M.toggle_complete()
|
||||||
if task.status == 'done' then
|
if task.status == 'done' then
|
||||||
store.update(id, { status = 'pending', ['end'] = vim.NIL })
|
store.update(id, { status = 'pending', ['end'] = vim.NIL })
|
||||||
else
|
else
|
||||||
|
if task.recur and task.due then
|
||||||
|
local recur = require('pending.recur')
|
||||||
|
local mode = task.recur_mode or 'scheduled'
|
||||||
|
local base = mode == 'completion' and os.date('%Y-%m-%d') --[[@as string]] or task.due
|
||||||
|
local next_date = recur.next_due(base, task.recur, mode)
|
||||||
|
store.add({
|
||||||
|
description = task.description,
|
||||||
|
category = task.category,
|
||||||
|
priority = task.priority,
|
||||||
|
due = next_date,
|
||||||
|
recur = task.recur,
|
||||||
|
recur_mode = task.recur_mode,
|
||||||
|
})
|
||||||
|
end
|
||||||
store.update(id, { status = 'done' })
|
store.update(id, { status = 'done' })
|
||||||
end
|
end
|
||||||
store.save()
|
store.save()
|
||||||
|
|
@ -219,6 +233,8 @@ function M.add(text)
|
||||||
description = description,
|
description = description,
|
||||||
category = metadata.cat,
|
category = metadata.cat,
|
||||||
due = metadata.due,
|
due = metadata.due,
|
||||||
|
recur = metadata.rec,
|
||||||
|
recur_mode = metadata.rec_mode,
|
||||||
})
|
})
|
||||||
store.save()
|
store.save()
|
||||||
local bufnr = buffer.bufnr()
|
local bufnr = buffer.bufnr()
|
||||||
|
|
@ -320,6 +336,7 @@ end
|
||||||
function M.show_help()
|
function M.show_help()
|
||||||
local cfg = require('pending.config').get()
|
local cfg = require('pending.config').get()
|
||||||
local dk = cfg.date_syntax or 'due'
|
local dk = cfg.date_syntax or 'due'
|
||||||
|
local rk = cfg.recur_syntax or 'rec'
|
||||||
local lines = {
|
local lines = {
|
||||||
'pending.nvim keybindings',
|
'pending.nvim keybindings',
|
||||||
'',
|
'',
|
||||||
|
|
@ -344,14 +361,21 @@ function M.show_help()
|
||||||
'Inline metadata (on new lines before :w):',
|
'Inline metadata (on new lines before :w):',
|
||||||
' ' .. dk .. ':YYYY-MM-DD Set due date',
|
' ' .. dk .. ':YYYY-MM-DD Set due date',
|
||||||
' cat:Name Set category',
|
' cat:Name Set category',
|
||||||
|
' ' .. rk .. ':pattern Set recurrence',
|
||||||
'',
|
'',
|
||||||
'Due date input:',
|
'Due date input:',
|
||||||
' today, tomorrow, +Nd, mon-sun',
|
' today, tomorrow, yesterday, +Nd, +Nw, +Nm',
|
||||||
|
' -Nd, -Nw, mon-sun, jan-dec, 1st-31st',
|
||||||
|
' eod, eow, eom, eoq, eoy, sow, som, soq, soy',
|
||||||
|
' later, someday',
|
||||||
' Empty input clears due date',
|
' Empty input clears due date',
|
||||||
'',
|
'',
|
||||||
'Highlights:',
|
'Recurrence patterns:',
|
||||||
' PendingOverdue overdue tasks (red)',
|
' daily, weekdays, weekly, biweekly',
|
||||||
' PendingPriority [!] urgent tasks',
|
' monthly, quarterly, yearly, Nd, Nw, Nm, Ny',
|
||||||
|
' Prefix ! for completion-based (e.g. !weekly)',
|
||||||
|
'',
|
||||||
|
'Completion: <C-x><C-o> after due:, cat:, rec:',
|
||||||
'',
|
'',
|
||||||
'Press q or <Esc> to close',
|
'Press q or <Esc> to close',
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue