File tree Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,11 @@ function Headline:remove_closed_date()
121
121
end
122
122
123
123
function Headline :cookie ()
124
- return self :parse (' %[%d?/%d?%]' )
124
+ local cookie = self :parse (' %[%d?/%d?%]' )
125
+ if cookie then
126
+ return cookie
127
+ end
128
+ return self :parse (' %[%d?%d?%d?%%%]' )
125
129
end
126
130
127
131
-- @return tsnode, string
Original file line number Diff line number Diff line change @@ -23,7 +23,9 @@ function List:parent_cookie()
23
23
local content = top_item :field (' contents' )[1 ]
24
24
-- The cookie should be the last thing on the line
25
25
local cookie_node = content :named_child (content :named_child_count () - 1 )
26
- if query .get_node_text (cookie_node , 0 ):match (' %[%d?/%d?%]' ) then
26
+
27
+ local text = query .get_node_text (cookie_node , 0 )
28
+ if text :match (' %[%d?/%d?%]' ) or text :match (' %[%d?%d?%d?%%%]' ) then
27
29
return cookie_node
28
30
end
29
31
end
@@ -42,7 +44,12 @@ function List:update_parent_cookie()
42
44
local checked_boxes = vim .tbl_filter (function (box )
43
45
return box :match (' %[%w%]' )
44
46
end , checkboxes )
45
- local new_status = (' [%d/%d]' ):format (# checked_boxes , # checkboxes )
47
+ local new_status
48
+ if query .get_node_text (parent_cookie , 0 ):find (' %%' ) then
49
+ new_status = (' [%d%%]' ):format ((# checked_boxes /# checkboxes ) * 100 )
50
+ else
51
+ new_status = (' [%d/%d]' ):format (# checked_boxes , # checkboxes )
52
+ end
46
53
tree_utils .set_node_text (parent_cookie , new_status )
47
54
end
48
55
Original file line number Diff line number Diff line change 1
1
local ts_utils = require (' nvim-treesitter.ts_utils' )
2
2
local config = require (' orgmode.config' )
3
+ local query = vim .treesitter .query
3
4
local M = {}
4
5
5
6
function M .current_node ()
Original file line number Diff line number Diff line change @@ -1618,4 +1618,27 @@ describe('Mappings', function()
1618
1618
vim .cmd ([[ exe "norm \<C-space>"]] )
1619
1619
assert .are .same (' - Test orgmode [1/2]' , vim .fn .getline (1 ))
1620
1620
end )
1621
+
1622
+ it (' should update the checklist cookies with a percentage within a headline' , function ()
1623
+ helpers .load_file_content ({
1624
+ ' * Test orgmode [%]' ,
1625
+ ' - [ ] checkbox item' ,
1626
+ ' - [ ] checkbox item' ,
1627
+ })
1628
+ vim .fn .cursor (2 , 1 )
1629
+ vim .cmd ([[ exe "norm \<C-space>"]] )
1630
+ assert .are .same (' * Test orgmode [50%]' , vim .fn .getline (1 ))
1631
+ end )
1632
+
1633
+ it (' should update the checklist cookies with a percentage within a nested list' , function ()
1634
+ helpers .load_file_content ({
1635
+ ' - Test orgmode [%]' ,
1636
+ ' - [ ] checkbox item' ,
1637
+ ' - [ ] checkbox item' ,
1638
+ ' - [ ] checkbox item' ,
1639
+ })
1640
+ vim .fn .cursor (2 , 1 )
1641
+ vim .cmd ([[ exe "norm \<C-space>"]] )
1642
+ assert .are .same (' - Test orgmode [33%]' , vim .fn .getline (1 ))
1643
+ end )
1621
1644
end )
You can’t perform that action at this time.
0 commit comments