feat(init): allow :Pending done with no args to use cursor line

Problem: `:Pending done` required an explicit task ID, making it
awkward to mark the current task done while inside the pending buffer.

Solution: When called with no ID, `M.done()` reads the cursor row from
`buffer.meta()` to resolve the task ID, erroring if the cursor is not
on a saved task line.
This commit is contained in:
Barrett Ruth 2026-03-06 11:35:45 -05:00
parent b8ca31aa86
commit 39b54fbc50

View file

@ -430,13 +430,28 @@ function M.toggle_complete()
end
end
---@param id_str string
---@param id_str? string
---@return nil
function M.done(id_str)
local id = tonumber(id_str)
if not id then
log.error('Invalid task ID: ' .. tostring(id_str))
return
local id
if not id_str or id_str == '' then
local row = vim.api.nvim_win_get_cursor(0)[1]
local meta = buffer.meta()
if not meta[row] or meta[row].type ~= 'task' then
log.error('Cursor is not on a task line.')
return
end
id = meta[row].id
if not id then
log.error('Task has no ID — save the buffer first.')
return
end
else
id = tonumber(id_str)
if not id then
log.error('Invalid task ID: ' .. tostring(id_str))
return
end
end
local s = get_store()
s:load()