Skip to content

Commit 8124526

Browse files
committedMar 16, 2025
tidy up and change var name back
1 parent f059ec9 commit 8124526

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed
 

‎lua/orgmode/files/headline.lua

+24-20
Original file line numberDiff line numberDiff line change
@@ -904,52 +904,56 @@ function Headline:set_cookie(cookie, num, denum)
904904
end
905905

906906
function Headline:update_cookie()
907+
-- Update cookie state from a check box state change
908+
907909
-- Return early if the headline doesn't have a cookie
908910
local cookie = self:get_cookie()
909911
if not cookie then
910912
return self
911913
end
912914

913-
local num, denum = 0, 0
914-
-- Count checked boxes from all lists
915915
local section = self:node():parent()
916-
if section then
917-
local body = section:field('body')[1]
918-
if body then
919-
for node in body:iter_children() do
920-
if node:type() == 'list' then
921-
local boxes = self:child_checkboxes(node)
922-
denum = denum + #boxes
923-
local checked_boxes = vim.tbl_filter(function(box)
924-
return box:match('%[%w%]')
925-
end, boxes)
926-
num = num + #checked_boxes
927-
end
916+
if not section then
917+
return self
918+
end
919+
920+
-- Count checked boxes from all lists
921+
local num_checked_boxes, num_boxes = 0, 0
922+
local body = section:field('body')[1]
923+
if body then
924+
for node in body:iter_children() do
925+
if node:type() == 'list' then
926+
local boxes = self:child_checkboxes(node)
927+
num_boxes = num_boxes + #boxes
928+
local checked_boxes = vim.tbl_filter(function(box)
929+
return box:match('%[%w%]')
930+
end, boxes)
931+
num_checked_boxes = num_checked_boxes + #checked_boxes
928932
end
929933
end
930934
end
931935

932936
-- Update the cookie
933-
return self:set_cookie(cookie, num, denum)
937+
return self:set_cookie(cookie, num_checked_boxes, num_boxes)
934938
end
935939

936940
function Headline:update_todo_cookie()
937-
-- Count done children headlines
941+
-- Update cookie state from a TODO state change
942+
938943
-- Return early if the headline doesn't have a cookie
939944
local cookie = self:get_cookie()
940945
if not cookie then
941946
return self
942947
end
943-
local num, denum = 0, 0
948+
949+
-- Count done children headlines
944950
local children = self:get_child_headlines()
945951
local dones = vim.tbl_filter(function(h)
946952
return h:is_done()
947953
end, children)
948-
num = num + #dones
949-
denum = denum + #children
950954

951955
-- Update the cookie
952-
return self:set_cookie(cookie, num, denum)
956+
return self:set_cookie(cookie, #dones, #children)
953957
end
954958

955959
function Headline:update_parent_cookie()

0 commit comments

Comments
 (0)