diff --git a/lua/pending/init.lua b/lua/pending/init.lua index a10d72d..06c722c 100644 --- a/lua/pending/init.lua +++ b/lua/pending/init.lua @@ -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()