From fe25e93336b6a71b3cb3d7fd53ab6e4cb4a125c1 Mon Sep 17 00:00:00 2001 From: Ben Lubas <56943754+benlubas@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:58:28 -0500 Subject: [PATCH] feat: undojoin timestamp updates (#1272) --- .../modules/core/esupports/metagen/module.lua | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lua/neorg/modules/core/esupports/metagen/module.lua b/lua/neorg/modules/core/esupports/metagen/module.lua index 8ad5fd3fb..6df791be2 100644 --- a/lua/neorg/modules/core/esupports/metagen/module.lua +++ b/lua/neorg/modules/core/esupports/metagen/module.lua @@ -141,14 +141,20 @@ module.config.public = { -- Timezone information in the timestamps -- - "utc" the timestamp is in UTC+0 - -- - "local" the timestmap is in the local timezone + -- - "local" the timestamp is in the local timezone -- - "implicit-local" like "local", but the timezone information is omitted from the timestamp timezone = "local", + + -- Whether or not to call :h :undojoin just before changing the timestamp in `update_metadata` + -- This will make your undo key undo the last change before writing the file in addition to the + -- timestamp change. This will move your cursor to the top of the file. + undojoin_updates = false, } module.private = { buffers = {}, listen_event = "none", + skip_next_update = false, } ---@class core.esupports.metagen @@ -203,6 +209,11 @@ module.public = { } end, + --- Skip the next call to update_metadata + skip_next_update = function() + module.private.skip_next_update = true + end, + ---@class core.esupports.metagen.metadata ---@field title? function|string the title of the note ---@field description? function|string the description of the note @@ -261,8 +272,12 @@ module.public = { end, update_metadata = function(buf) - local present = module.public.is_metadata_present(buf) + if module.private.skip_next_update then + module.private.skip_next_update = false + return + end + local present = module.public.is_metadata_present(buf) if not present then return end @@ -324,6 +339,9 @@ module.public = { if date ~= current_date then local range = module.required["core.integrations.treesitter"].get_node_range(node) + if module.config.public.undojoin_updates then + vim.cmd.undojoin() + end vim.api.nvim_buf_set_text( buf, range.row_start,