|
541 | 541 | ---@param opts { open_strategy: obsidian.config.OpenStrategy|? }|? |
542 | 542 | M.follow_link = function(link, opts) |
543 | 543 | opts = opts and opts or {} |
| 544 | + local Note = require "obsidian.note" |
544 | 545 |
|
545 | | - local location, _, link_type = util.parse_link(link, { |
| 546 | + local location, name, link_type = util.parse_link(link, { |
546 | 547 | include_naked_urls = true, |
547 | 548 | include_file_urls = true, |
548 | 549 | }) |
@@ -582,7 +583,26 @@ M.follow_link = function(link, opts) |
582 | 583 |
|
583 | 584 | local notes = search.resolve_note(location, {}) |
584 | 585 | if vim.tbl_isempty(notes) then |
585 | | - log.err "failed to resolve note" |
| 586 | + if M.confirm("Create new note '" .. location .. "'?") then |
| 587 | + ---@type string|?, string[] |
| 588 | + local id, aliases |
| 589 | + if name == location then |
| 590 | + aliases = {} |
| 591 | + else |
| 592 | + aliases = { name } |
| 593 | + id = location |
| 594 | + end |
| 595 | + |
| 596 | + local note = Note.create { title = name, id = id, aliases = aliases } |
| 597 | + return note:open { |
| 598 | + open_strategy = opts.open_strategy, |
| 599 | + callback = function(bufnr) |
| 600 | + note:write_to_buffer { bufnr = bufnr } |
| 601 | + end, |
| 602 | + } |
| 603 | + else |
| 604 | + return log.warn "Aborted" |
| 605 | + end |
586 | 606 | elseif #notes == 1 then |
587 | 607 | local note = notes[1] |
588 | 608 | jump_to_note(note, block_link, anchor_link) |
|
0 commit comments