Skip to content

Commit 624dab4

Browse files
authored
Merge pull request #16 from bosvik/main
Fix bug where ObsidianNewFromTemplate does not respect note_id_func
2 parents 87d7b4e + 4c2f1ce commit 624dab4

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
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Fixed an edge case with collecting backlinks.
2525
- Fixed typo in `ObsidianPasteImg`'s command description
2626
- Fixed the case when `opts.attachments` is `nil`.
27+
- Fixed bug where `ObsidianNewFromTemplate` did not respect `note_id_func`
2728

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

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

194195
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:
196+
195197
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:
196198
- Typical Obsidian-style wiki links, e.g. `[[My note#Heading 1]]`, `[[My note#Heading 1#Sub heading]]`, `[[My note#^block-123]]`.
197199
- Wiki links with a label, e.g. `[[my-note#heading-1|Heading 1 in My Note]]`.
@@ -200,7 +202,7 @@ There's a lot of new features and improvements here that I'm really excited abou
200202
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]]`.
201203

202204
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.
203-
3. 🔭 Improved picker integrations (especially for telescope), particular for the `:ObsidianTags` command. See https://github.com/epwalsh/obsidian.nvim/discussions/450 for a demo.
205+
3. 🔭 Improved picker integrations (especially for telescope), particular for the `:ObsidianTags` command. See <https://github.com/epwalsh/obsidian.nvim/discussions/450> for a demo.
204206

205207
Full changelog below 👇
206208

@@ -440,7 +442,7 @@ Minor internal improvements.
440442

441443
### Fixed
442444

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

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

@@ -470,7 +472,7 @@ Minor internal improvements.
470472
### Fixed
471473

472474
- Fixed a YAML parsing issue with unquoted URLs in an array item.
473-
- 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.
475+
- 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.
474476

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

@@ -800,6 +802,7 @@ Major internal refactoring to bring performance improvements through async execu
800802
- Added `mappings` configuration field.
801803
- Added `open_notes_in` configuration field
802804
- Added `backlinks` options to the config. The default is
805+
803806
```lua
804807
backlinks = {
805808
-- The default height of the backlinks pane.
@@ -901,7 +904,7 @@ Major internal refactoring to bring performance improvements through async execu
901904
### Added
902905

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

lua/obsidian/client.lua

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

18771877
if opts.template and util.buffer_is_empty(opts.bufnr) then
18781878
note = insert_template {
1879+
note = note,
18791880
template_name = opts.template,
18801881
client = self,
18811882
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)