diff --git a/lua/orgmode/files/headline.lua b/lua/orgmode/files/headline.lua index 50470098e..45245f2cb 100644 --- a/lua/orgmode/files/headline.lua +++ b/lua/orgmode/files/headline.lua @@ -946,14 +946,19 @@ function Headline:update_todo_cookie() return self end - -- Count done children headlines + -- Count done children headlines and total children with TODO keywords local children = self:get_child_headlines() + local headlines_with_todo = vim.tbl_filter(function(h) + local todo, _, _ = h:get_todo() + return todo ~= nil + end, children) + local dones = vim.tbl_filter(function(h) return h:is_done() - end, children) + end, headlines_with_todo) -- Set the cookie - return self:_set_cookie(cookie, #dones, #children) + return self:_set_cookie(cookie, #dones, #headlines_with_todo) end function Headline:update_parent_cookie() diff --git a/tests/plenary/ui/mappings/todo_spec.lua b/tests/plenary/ui/mappings/todo_spec.lua index 856a50deb..0e025d5c8 100644 --- a/tests/plenary/ui/mappings/todo_spec.lua +++ b/tests/plenary/ui/mappings/todo_spec.lua @@ -430,4 +430,25 @@ describe('Todo mappings', function() '** TODO item', }, vim.api.nvim_buf_get_lines(0, 0, 6, false)) end) + it('should update headline cookies when children todo state changes', function() + helpers.create_file({ + '* Test orgmode [/]', + '** TODO item', + '** TODO item', + '** TODO item', + '** Non-todo item', + }) + vim.fn.cursor(4, 1) + local now = Date.now() + -- Changing to DONE and adding closed date + vim.cmd([[norm citd]]) + assert.are.same({ + '* Test orgmode [1/3]', + '** TODO item', + '** TODO item', + '** DONE item', + ' CLOSED: [' .. now:to_string() .. ']', + '** Non-todo item', + }, vim.api.nvim_buf_get_lines(0, 0, 6, false)) + end) end)