Skip to content

Commit 4c2f1ce

Browse files
committed
Fix bug where ObsidianNewFromTemplate does not respect note_id_func
1 parent bacd8b2 commit 4c2f1ce

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Fixed an edge case with collecting backlinks.
2424
- Fixed typo in `ObsidianPasteImg`'s command description
2525
- Fixed the case when `opts.attachments` is `nil`.
26+
- Fixed bug where `ObsidianNewFromTemplate` did not respect `note_id_func`
2627

2728
## [v3.9.0](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.9.0) - 2024-07-11
2829

@@ -191,6 +192,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
191192
## [v3.7.0](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.0) - 2024-03-08
192193

193194
There's a lot of new features and improvements here that I'm really excited about 🥳 They've improved my workflow a ton and I hope they do for you too. To highlight the 3 biggest additions:
195+
194196
1. 🔗 Full support for header anchor links and block links! That means both for following links and completion of links. Various forms of anchor/block links are support. Here are a few examples:
195197
- Typical Obsidian-style wiki links, e.g. `[[My note#Heading 1]]`, `[[My note#Heading 1#Sub heading]]`, `[[My note#^block-123]]`.
196198
- Wiki links with a label, e.g. `[[my-note#heading-1|Heading 1 in My Note]]`.
@@ -199,7 +201,7 @@ There's a lot of new features and improvements here that I'm really excited abou
199201
We also support links to headers within the same note, like for a table of contents, e.g. `[[#Heading 1]]`, `[[#heading-1|Heading]]`, `[[#^block-1]]`.
200202

201203
2. 📲 A basic callback system to let you easily customize obisidian.nvim's behavior even more. There are currently 4 events: `post_setup`, `enter_note`, `pre_write_note`, and `post_set_workspace`. You can define a function for each of these in your config.
202-
3. 🔭 Improved picker integrations (especially for telescope), particular for the `:ObsidianTags` command. See https://github.com/epwalsh/obsidian.nvim/discussions/450 for a demo.
204+
3. 🔭 Improved picker integrations (especially for telescope), particular for the `:ObsidianTags` command. See <https://github.com/epwalsh/obsidian.nvim/discussions/450> for a demo.
203205

204206
Full changelog below 👇
205207

@@ -439,7 +441,7 @@ Minor internal improvements.
439441

440442
### Fixed
441443

442-
- Fixed parsing header with trailing whitespace (https://github.com/epwalsh/obsidian.nvim/issues/341#issuecomment-1925445271).
444+
- Fixed parsing header with trailing whitespace (<https://github.com/epwalsh/obsidian.nvim/issues/341#issuecomment-1925445271>).
443445

444446
## [v2.9.0](https://github.com/epwalsh/obsidian.nvim/releases/tag/v2.9.0) - 2024-01-31
445447

@@ -469,7 +471,7 @@ Minor internal improvements.
469471
### Fixed
470472

471473
- Fixed a YAML parsing issue with unquoted URLs in an array item.
472-
- Fixed an issue on Windows when cloning a template into a new note. The root cause was this bug in plenary: https://github.com/nvim-lua/plenary.nvim/issues/489. We've added a work-around.
474+
- Fixed an issue on Windows when cloning a template into a new note. The root cause was this bug in plenary: <https://github.com/nvim-lua/plenary.nvim/issues/489>. We've added a work-around.
473475

474476
## [v2.7.1](https://github.com/epwalsh/obsidian.nvim/releases/tag/v2.7.1) - 2024-01-23
475477

@@ -799,6 +801,7 @@ Major internal refactoring to bring performance improvements through async execu
799801
- Added `mappings` configuration field.
800802
- Added `open_notes_in` configuration field
801803
- Added `backlinks` options to the config. The default is
804+
802805
```lua
803806
backlinks = {
804807
-- The default height of the backlinks pane.
@@ -900,7 +903,7 @@ Major internal refactoring to bring performance improvements through async execu
900903
### Added
901904

902905
- Added support for [fzf-lua](https://github.com/ibhagwan/fzf-lua) as one of the possible fallbacks for the `:ObsidianQuickSwitch` command.
903-
- Added `:ObsidianQuickSwitch` to fuzzy-find a note by name in telescope/fzf _a la_ <C-O> in Obsidian.
906+
- Added `:ObsidianQuickSwitch` to fuzzy-find a note by name in telescope/fzf *a la* <C-O> in Obsidian.
904907
- Added support for [fzf-lua](https://github.com/ibhagwan/fzf-lua) as one of the possible fallbacks for the `:ObsidianSearch` command.
905908
- Added `:ObsidianFollowLink` and companion function `util.cursor_on_markdown_link`
906909
- Added `:ObsidianLink` and `:ObsidianLinkNew` commands.

lua/obsidian/client.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,7 @@ Client.write_note_to_buffer = function(self, note, opts)
18751875

18761876
if opts.template and util.buffer_is_empty(opts.bufnr) then
18771877
note = insert_template {
1878+
note = note,
18781879
template_name = opts.template,
18791880
client = self,
18801881
location = util.get_active_window_cursor_location(),

lua/obsidian/templates.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ end
151151

152152
---Insert a template at the given location.
153153
---
154-
---@param opts { template_name: string|obsidian.Path, client: obsidian.Client, location: { [1]: integer, [2]: integer, [3]: integer, [4]: integer } } Options.
154+
---@param opts { note: obsidian.Note|?, template_name: string|obsidian.Path, client: obsidian.Client, location: { [1]: integer, [2]: integer, [3]: integer, [4]: integer } } Options.
155155
---
156156
---@return obsidian.Note
157157
M.insert_template = function(opts)
158158
local buf, win, row, _ = unpack(opts.location)
159-
local note = Note.from_buffer(buf)
159+
if opts.note == nil then
160+
opts.note = Note.from_buffer(buf)
161+
end
160162

161163
local template_path = resolve_template(opts.template_name, opts.client)
162164

@@ -165,7 +167,7 @@ M.insert_template = function(opts)
165167
if template_file then
166168
local lines = template_file:lines()
167169
for line in lines do
168-
local new_lines = M.substitute_template_variables(line, opts.client, note)
170+
local new_lines = M.substitute_template_variables(line, opts.client, opts.note)
169171
if string.find(new_lines, "[\r\n]") then
170172
local line_start = 1
171173
for line_end in util.gfind(new_lines, "[\r\n]") do

0 commit comments

Comments
 (0)