Skip to content

Commit ad0f1b4

Browse files
author
neo451
committed
fix: incorrect fallback for resolve note
1 parent 6463065 commit ad0f1b4

File tree

7 files changed

+55
-58
lines changed

7 files changed

+55
-58
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Fixed incorrect call signature for `options.callbacks.post_set_workspace`
13+
- Fixed incorrect fallback for `resolve_note`.
1314

1415
## [v3.13.0](https://github.com/obsidian-nvim/obsidian.nvim/releases/tag/v3.13.0) - 2025-07-28
1516

@@ -350,7 +351,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
350351
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:
351352

352353
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:
353-
354354
- Typical Obsidian-style wiki links, e.g. `[[My note#Heading 1]]`, `[[My note#Heading 1#Sub heading]]`, `[[My note#^block-123]]`.
355355
- Wiki links with a label, e.g. `[[my-note#heading-1|Heading 1 in My Note]]`.
356356
- Markdown links, e.g. `[Heading 1 in My Note](my-note.md#heading-1)`.

lua/obsidian/api.lua

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -612,64 +612,56 @@ M.follow_link = function(link, opts)
612612
opts = opts and opts or {}
613613
local Note = require "obsidian.note"
614614

615-
search.resolve_link_async(link, function(result)
616-
if not result then
615+
---@param res obsidian.ResolveLinkResult
616+
local function follow_link(res)
617+
if res.url ~= nil then
618+
Obsidian.opts.follow_url_func(res.url)
617619
return
618620
end
619621

620-
---@param res obsidian.ResolveLinkResult
621-
local function follow_link(res)
622-
if res.url ~= nil then
623-
Obsidian.opts.follow_url_func(res.url)
624-
return
625-
end
626-
627-
if util.is_img(res.location) then
628-
local path = Obsidian.dir / res.location
629-
Obsidian.opts.follow_img_func(tostring(path))
630-
return
631-
end
622+
if util.is_img(res.location) then
623+
local path = Obsidian.dir / res.location
624+
Obsidian.opts.follow_img_func(tostring(path))
625+
return
626+
end
632627

633-
if res.note ~= nil then
634-
-- Go to resolved note.
635-
return res.note:open { line = res.line, col = res.col, open_strategy = opts.open_strategy }
636-
end
628+
if res.note ~= nil then
629+
-- Go to resolved note.
630+
return res.note:open { line = res.line, col = res.col, open_strategy = opts.open_strategy }
631+
end
637632

638-
if res.link_type == search.RefTypes.Wiki or res.link_type == search.RefTypes.WikiWithAlias then
639-
-- Prompt to create a new note.
640-
if M.confirm("Create new note '" .. res.location .. "'?") then
641-
-- Create a new note.
642-
---@type string|?, string[]
643-
local id, aliases
644-
if res.name == res.location then
645-
aliases = {}
646-
else
647-
aliases = { res.name }
648-
id = res.location
649-
end
650-
651-
local note = Note.create { title = res.name, id = id, aliases = aliases }
652-
return note:open {
653-
open_strategy = opts.open_strategy,
654-
callback = function(bufnr)
655-
note:write_to_buffer { bufnr = bufnr }
656-
end,
657-
}
633+
if res.link_type == search.RefTypes.Wiki or res.link_type == search.RefTypes.WikiWithAlias then
634+
-- Prompt to create a new note.
635+
if M.confirm("Create new note '" .. res.location .. "'?") then
636+
-- Create a new note.
637+
---@type string|?, string[]
638+
local id, aliases
639+
if res.name == res.location then
640+
aliases = {}
658641
else
659-
log.warn "Aborted"
660-
return
642+
aliases = { res.name }
643+
id = res.location
661644
end
662-
end
663645

664-
return log.err("Failed to resolve file '" .. res.location .. "'")
646+
local note = Note.create { title = res.name, id = id, aliases = aliases }
647+
return note:open {
648+
open_strategy = opts.open_strategy,
649+
callback = function(bufnr)
650+
note:write_to_buffer { bufnr = bufnr }
651+
end,
652+
}
653+
else
654+
log.warn "Aborted"
655+
return
656+
end
665657
end
666658

667-
-- if #results == 1 then
668-
return vim.schedule(function()
669-
follow_link(result)
670-
end)
671-
end, { pick = true })
659+
return log.err("Failed to resolve file '" .. res.location .. "'")
660+
end
661+
662+
search.resolve_link_async(link, vim.schedule_wrap(follow_link), { pick = true })
672663
end
664+
673665
--------------------------
674666
---- Mapping functions ---
675667
--------------------------

lua/obsidian/commands/backlinks.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ return function(client)
9494

9595
search.resolve_note_async(location, function(note)
9696
if not note then
97-
log.err("No notes matching '%s'", location)
98-
return
97+
return log.err("No notes matching '%s'", location)
9998
else
10099
return collect_backlinks(client, picker, note, opts)
101100
end

lua/obsidian/commands/link.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local log = require "obsidian.log"
66
return function(_, data)
77
local viz = api.get_visual_selection()
88
if not viz then
9-
log.err "ObsidianLink must be called with visual selection"
9+
log.err "`Obsidian link` must be called with visual selection"
1010
return
1111
elseif #viz.lines ~= 1 then
1212
log.err "Only in-line visual selections allowed"
@@ -16,11 +16,11 @@ return function(_, data)
1616
local line = assert(viz.lines[1])
1717

1818
---@type string
19-
local search_term
19+
local query
2020
if data.args ~= nil and string.len(data.args) > 0 then
21-
search_term = data.args
21+
query = data.args
2222
else
23-
search_term = viz.selection
23+
query = viz.selection
2424
end
2525

2626
---@param note obsidian.Note
@@ -32,7 +32,10 @@ return function(_, data)
3232
require("obsidian.ui").update(0)
3333
end
3434

35-
search.resolve_note_async(search_term, function(note)
35+
search.resolve_note_async(query, function(note)
36+
if not note then
37+
return log.err("No notes matching '%s'", query)
38+
end
3639
vim.schedule(function()
3740
insert_ref(note)
3841
end)

lua/obsidian/commands/quick_switch.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ return function(_, data)
1313
picker:find_notes()
1414
else
1515
search.resolve_note_async(data.args, function(note)
16+
if not note then
17+
return log.err("No notes matching '%s'", data.args)
18+
end
1619
note:open()
1720
end)
1821
end

lua/obsidian/path.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ end
1010

1111
---@param path table
1212
---@param k string
13-
---@param factory fun(obsidian.Path): any
13+
---@param factory fun(path: obsidian.Path): any
1414
local function cached_get(path, k, factory)
1515
local cache_key = "__" .. k
1616
local v = rawget(path, cache_key)

lua/obsidian/search.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ end
736736
--- Resolve a note, opens a picker to choose a single note when there are multiple matches.
737737
---
738738
---@param query string
739-
---@param callback fun(obsidian.Note)
739+
---@param callback fun(note: obsidian.Note|nil)
740740
---@param opts { notes: obsidian.note.LoadOpts|?, prompt_title: string|?, pick: boolean }|?
741741
---
742742
---@return obsidian.Note|?
@@ -746,7 +746,7 @@ M.resolve_note_async = function(query, callback, opts)
746746

747747
_resolve_note_async(query, function(notes)
748748
if #notes == 0 then
749-
return log.err("No notes matching '%s'", query)
749+
return callback()
750750
elseif #notes == 1 then
751751
return callback(notes[1])
752752
end

0 commit comments

Comments
 (0)