Skip to content

Commit 667ffd7

Browse files
Fix adding closed date to a headline plan that is not of a specific type. Closes #309
1 parent fafeba0 commit 667ffd7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lua/orgmode/treesitter/headline.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ function Headline:add_closed_date()
185185
string.format('%s%s', indent, closed_text),
186186
})
187187
end
188-
local last_child = dates['DEADLINE'] or dates['SCHEDULED']
188+
local keys = vim.tbl_keys(dates)
189+
local last_child = dates['DEADLINE'] or dates['SCHEDULED'] or dates[keys[#keys]]
189190
local ptext = query.get_node_text(last_child, 0)
190191
local text = ptext .. ' ' .. closed_text
191192
tree_utils.set_node_text(last_child, text)

tests/plenary/ui/mappings/todo_spec.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,19 @@ describe('Todo mappings', function()
114114
vim.cmd('norm ciT')
115115
assert.are.same('* test TODO', vim.fn.getline(1))
116116
end)
117+
118+
it('Should properly add closed date when plan date is not of specific type', function()
119+
helpers.load_file_content({
120+
'#TITLE: Test',
121+
'',
122+
'* TODO Test orgmode',
123+
' <2021-07-21 Wed 22:02>',
124+
})
125+
vim.fn.cursor({ 3, 1 })
126+
vim.cmd([[norm cit]])
127+
assert.are.same({
128+
'* DONE Test orgmode',
129+
' <2021-07-21 Wed 22:02> CLOSED: [' .. Date.now():to_string() .. ']',
130+
}, vim.api.nvim_buf_get_lines(0, 2, 4, false))
131+
end)
117132
end)

0 commit comments

Comments
 (0)