Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(statistics cookie): count only TODO headlines #938

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lua/orgmode/files/headline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions tests/plenary/ui/mappings/todo_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading