Skip to content

Commit

Permalink
feat: adds insert link selection mapping on ObsidianTags' callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoquec committed Sep 26, 2024
1 parent 14e0427 commit d23d9fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added "insert link" selection mapping in `ObsidianTags`' callback
- Added `opts.follow_img_func` option for customizing how to handle image paths.
- Added better handling for undefined template fields, which will now be prompted for.

Expand Down
1 change: 1 addition & 0 deletions lua/obsidian/commands/tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ local function gather_tag_picker_list(client, picker, tags)
callback = function(value)
util.open_buffer(value.path, { line = value.line, col = value.col })
end,
selection_mappings = picker:_tagged_note_selection_mappings(),
})
end)
end, { search = { sort = true } })
Expand Down
21 changes: 21 additions & 0 deletions lua/obsidian/pickers/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,27 @@ Picker._note_selection_mappings = function(self)
return mappings
end

--- Get selection mappings to use for `pick_tag()`'s callback note selection'.
---@return obsidian.PickerMappingTable
Picker._tagged_note_selection_mappings = function(self)
---@type obsidian.PickerMappingTable
local mappings = {}

if self.client.opts.picker.note_mappings and key_is_set(self.client.opts.picker.note_mappings.insert_link) then
mappings[self.client.opts.picker.note_mappings.insert_link] = {
desc = "insert link",
callback = function(value)
local note = Note.from_file(value.path)
local link = self.client:format_link(note, {})
vim.api.nvim_put({ link }, "", false, true)
self.client:update_ui()
end,
}
end

return mappings
end

--- Get selection mappings to use for `pick_tag()`.
---@return obsidian.PickerMappingTable
Picker._tag_selection_mappings = function(self)
Expand Down

0 comments on commit d23d9fd

Please sign in to comment.