diff --git a/CHANGELOG.md b/CHANGELOG.md index b585ed0e2..c409b6cde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an edge case with collecting backlinks. - Fixed typo in `ObsidianPasteImg`'s command description - Fixed the case when `opts.attachments` is `nil`. +- Fixed bug where `ObsidianNewFromTemplate` did not respect `note_id_func` (#737) ## [v3.9.0](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.9.0) - 2024-07-11 diff --git a/lua/obsidian/client.lua b/lua/obsidian/client.lua index 00c09c77f..d0a14ddb7 100644 --- a/lua/obsidian/client.lua +++ b/lua/obsidian/client.lua @@ -1875,6 +1875,7 @@ Client.write_note_to_buffer = function(self, note, opts) if opts.template and util.buffer_is_empty(opts.bufnr) then note = insert_template { + note = note, template_name = opts.template, client = self, location = util.get_active_window_cursor_location(), diff --git a/lua/obsidian/templates.lua b/lua/obsidian/templates.lua index ac8a83f27..d7e9f3e7d 100644 --- a/lua/obsidian/templates.lua +++ b/lua/obsidian/templates.lua @@ -151,12 +151,14 @@ end ---Insert a template at the given location. --- ----@param opts { template_name: string|obsidian.Path, client: obsidian.Client, location: { [1]: integer, [2]: integer, [3]: integer, [4]: integer } } Options. +---@param opts { note: obsidian.Note|?, template_name: string|obsidian.Path, client: obsidian.Client, location: { [1]: integer, [2]: integer, [3]: integer, [4]: integer } } Options. --- ---@return obsidian.Note M.insert_template = function(opts) local buf, win, row, _ = unpack(opts.location) - local note = Note.from_buffer(buf) + if opts.note == nil then + opts.note = Note.from_buffer(buf) + end local template_path = resolve_template(opts.template_name, opts.client) @@ -165,7 +167,7 @@ M.insert_template = function(opts) if template_file then local lines = template_file:lines() for line in lines do - local new_lines = M.substitute_template_variables(line, opts.client, note) + local new_lines = M.substitute_template_variables(line, opts.client, opts.note) if string.find(new_lines, "[\r\n]") then local line_start = 1 for line_end in util.gfind(new_lines, "[\r\n]") do