diff --git a/lua/dotvim/extra/obsidian/telescope.lua b/lua/dotvim/extra/obsidian/telescope.lua index e83178ef..d5131d5c 100644 --- a/lua/dotvim/extra/obsidian/telescope.lua +++ b/lua/dotvim/extra/obsidian/telescope.lua @@ -174,9 +174,31 @@ function M.find_notes_tags(opts, next_opts) local finders = require("telescope.finders") local action_state = require("telescope.actions.state") local actions = require("telescope.actions") + local previewers = require("telescope.previewers.buffer_previewer") opts = opts or {} + local previewer = previewers.new_buffer_previewer { + title = "Tag Preview", + dyn_title = function(_, entry) + return ("󰓼 %s %d"):format(entry.value.tag, #entry.value.notes) + end, + get_buffer_by_name = function(_, entry) + return entry.value.tag + end, + define_preview = function(self, entry, _) + ---@type dotvim.extra.obsidian.ObsidianNote[] + local notes = entry.value.notes + local lines = {} + for _, note in ipairs(notes) do + table.insert(lines, ("- %s"):format(note:title())) + end + + vim.api.nvim_buf_set_option(self.state.bufnr, "filetype", "markdown") + vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines) + end, + } + pickers .new(opts, { prompt_title = "Obsidian Tags", @@ -185,7 +207,7 @@ function M.find_notes_tags(opts, next_opts) results = values, entry_maker = tag_entry_maker(opts), }, - previewer = false, + previewer = previewer, attach_mappings = function(bufnr, map) map("i", "", function() local entry = action_state.get_selected_entry()