Skip to content

Commit a00ac1b

Browse files
feat(dates)!: Insert time stamp after cursor
Closes #489
1 parent 66591ca commit a00ac1b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lua/orgmode/org/mappings.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ end
984984
---@param inactive boolean
985985
function OrgMappings:org_time_stamp(inactive)
986986
local date = self:_get_date_under_cursor()
987+
987988
if date then
988989
return Calendar.new({ date = date }).open():next(function(new_date)
989990
if not new_date then
@@ -1002,8 +1003,9 @@ function OrgMappings:org_time_stamp(inactive)
10021003
local date_string = new_date:to_wrapped_string(not inactive)
10031004
if date_start then
10041005
date_string = '--' .. date_string
1006+
vim.cmd('norm!x')
10051007
end
1006-
vim.cmd(string.format('norm!i%s', date_string))
1008+
vim.cmd(string.format('norm!a%s', date_string))
10071009
end)
10081010
end
10091011

tests/plenary/ui/mappings/date_spec.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ describe('Date mappings', function()
292292
vim.cmd([[exe "norm \<S-UP>"]])
293293
assert.are.same('<' .. Date.today():add({ day = 1 }):to_string() .. '>', vim.fn.getline(7))
294294
-- make sure it updated back to todays date by opening the calendar and pressing . to go to today's date
295+
vim.fn.cursor(7, 1)
295296
vim.cmd('norm ,oi..')
296297
vim.cmd([[exe "norm \<CR>"]])
297298
assert.are.same('<' .. Date.today():to_string() .. '>', vim.fn.getline(7))
@@ -311,7 +312,7 @@ describe('Date mappings', function()
311312
vim.fn.cursor(7, 17)
312313
vim.cmd('norm ,oi.')
313314
vim.cmd([[exe "norm \<CR>"]])
314-
assert.are.same('<2021-09-16 Thu>--<' .. Date.today():to_string() .. '> ', vim.fn.getline(7))
315+
assert.are.same('<2021-09-16 Thu>--<' .. Date.today():to_string() .. '>', vim.fn.getline(7))
315316
end)
316317

317318
it('should insert plain inactive timestamp under cursor (org_time_stamp)', function()
@@ -334,6 +335,7 @@ describe('Date mappings', function()
334335
vim.cmd([[exe "norm \<S-UP>"]])
335336
assert.are.same('[' .. Date.today():add({ day = 1 }):to_string() .. ']', vim.fn.getline(7))
336337
-- make sure it updated back to todays date by opening the calendar and pressing . to go to today's date
338+
vim.fn.cursor(7, 1)
337339
vim.cmd('norm ,oi!.')
338340
vim.cmd([[exe "norm \<CR>"]])
339341
assert.are.same('[' .. Date.today():to_string() .. ']', vim.fn.getline(7))
@@ -353,6 +355,6 @@ describe('Date mappings', function()
353355
vim.fn.cursor(7, 17)
354356
vim.cmd('norm ,oi!')
355357
vim.cmd([[exe "norm \<CR>"]])
356-
assert.are.same('[2021-09-16 Thu]--[' .. Date.today():to_string() .. '] ', vim.fn.getline(7))
358+
assert.are.same('[2021-09-16 Thu]--[' .. Date.today():to_string() .. ']', vim.fn.getline(7))
357359
end)
358360
end)

0 commit comments

Comments
 (0)