Skip to content

Commit fe25e93

Browse files
authored
feat: undojoin timestamp updates (#1272)
1 parent d97e3c8 commit fe25e93

File tree

1 file changed

+20
-2
lines changed
  • lua/neorg/modules/core/esupports/metagen

1 file changed

+20
-2
lines changed

lua/neorg/modules/core/esupports/metagen/module.lua

+20-2
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,20 @@ module.config.public = {
141141

142142
-- Timezone information in the timestamps
143143
-- - "utc" the timestamp is in UTC+0
144-
-- - "local" the timestmap is in the local timezone
144+
-- - "local" the timestamp is in the local timezone
145145
-- - "implicit-local" like "local", but the timezone information is omitted from the timestamp
146146
timezone = "local",
147+
148+
-- Whether or not to call :h :undojoin just before changing the timestamp in `update_metadata`
149+
-- This will make your undo key undo the last change before writing the file in addition to the
150+
-- timestamp change. This will move your cursor to the top of the file.
151+
undojoin_updates = false,
147152
}
148153

149154
module.private = {
150155
buffers = {},
151156
listen_event = "none",
157+
skip_next_update = false,
152158
}
153159

154160
---@class core.esupports.metagen
@@ -203,6 +209,11 @@ module.public = {
203209
}
204210
end,
205211

212+
--- Skip the next call to update_metadata
213+
skip_next_update = function()
214+
module.private.skip_next_update = true
215+
end,
216+
206217
---@class core.esupports.metagen.metadata
207218
---@field title? function|string the title of the note
208219
---@field description? function|string the description of the note
@@ -261,8 +272,12 @@ module.public = {
261272
end,
262273

263274
update_metadata = function(buf)
264-
local present = module.public.is_metadata_present(buf)
275+
if module.private.skip_next_update then
276+
module.private.skip_next_update = false
277+
return
278+
end
265279

280+
local present = module.public.is_metadata_present(buf)
266281
if not present then
267282
return
268283
end
@@ -324,6 +339,9 @@ module.public = {
324339
if date ~= current_date then
325340
local range = module.required["core.integrations.treesitter"].get_node_range(node)
326341

342+
if module.config.public.undojoin_updates then
343+
vim.cmd.undojoin()
344+
end
327345
vim.api.nvim_buf_set_text(
328346
buf,
329347
range.row_start,

0 commit comments

Comments
 (0)