Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: undojoin timestamp updates #1272

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lua/neorg/modules/core/esupports/metagen/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading