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
|
||||
store.update(id, { status = 'pending', ['end'] = vim.NIL })
|
||||
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' })
|
||||
end
|
||||
store.save()
|
||||
|
|
@ -219,6 +233,8 @@ function M.add(text)
|
|||
description = description,
|
||||
category = metadata.cat,
|
||||
due = metadata.due,
|
||||
recur = metadata.rec,
|
||||
recur_mode = metadata.rec_mode,
|
||||
})
|
||||
store.save()
|
||||
local bufnr = buffer.bufnr()
|
||||
|
|
@ -320,6 +336,7 @@ end
|
|||
function M.show_help()
|
||||
local cfg = require('pending.config').get()
|
||||
local dk = cfg.date_syntax or 'due'
|
||||
local rk = cfg.recur_syntax or 'rec'
|
||||
local lines = {
|
||||
'pending.nvim keybindings',
|
||||
'',
|
||||
|
|
@ -344,14 +361,21 @@ function M.show_help()
|
|||
'Inline metadata (on new lines before :w):',
|
||||
' ' .. dk .. ':YYYY-MM-DD Set due date',
|
||||
' cat:Name Set category',
|
||||
' ' .. rk .. ':pattern Set recurrence',
|
||||
'',
|
||||
'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',
|
||||
'',
|
||||
'Highlights:',
|
||||
' PendingOverdue overdue tasks (red)',
|
||||
' PendingPriority [!] urgent tasks',
|
||||
'Recurrence patterns:',
|
||||
' daily, weekdays, weekly, biweekly',
|
||||
' 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',
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue