diff --git a/CHANGELOG.md b/CHANGELOG.md index b585ed0e2..e8b6bd310 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lua/obsidian/commands/tags.lua b/lua/obsidian/commands/tags.lua index 3fc0efaa3..ec97ee192 100644 --- a/lua/obsidian/commands/tags.lua +++ b/lua/obsidian/commands/tags.lua @@ -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 } }) diff --git a/lua/obsidian/pickers/picker.lua b/lua/obsidian/pickers/picker.lua index 0b4ab6b01..6178f1b91 100644 --- a/lua/obsidian/pickers/picker.lua +++ b/lua/obsidian/pickers/picker.lua @@ -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)