From d4d944d4915e0424b0d362dd0f3b5fbc3e7dd490 Mon Sep 17 00:00:00 2001 From: Jared Wyce Date: Sun, 19 Feb 2023 11:27:32 -0500 Subject: [PATCH 1/3] feat: custom action on select (see #16, #26) --- lua/telescope/_extensions/media_files.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/telescope/_extensions/media_files.lua b/lua/telescope/_extensions/media_files.lua index ad1a5ea..19d0080 100644 --- a/lua/telescope/_extensions/media_files.lua +++ b/lua/telescope/_extensions/media_files.lua @@ -90,7 +90,7 @@ function M.media_files(opts) local sourced_file = require('plenary.debug_utils').sourced_filepath() M.base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h:h") opts = opts or {} - opts.attach_mappings= function(prompt_bufnr,map) + opts.attach_mappings= opts.attach_mappings or function(prompt_bufnr,map) actions.select_default:replace(function() local entry = action_state.get_selected_entry() actions.close(prompt_bufnr) From 987c7facd592cc531406056e0a8664c0212d4766 Mon Sep 17 00:00:00 2001 From: Jared Wyce Date: Sun, 19 Feb 2023 11:32:38 -0500 Subject: [PATCH 2/3] try valid syntax --- lua/telescope/_extensions/media_files.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/telescope/_extensions/media_files.lua b/lua/telescope/_extensions/media_files.lua index 19d0080..b2819a4 100644 --- a/lua/telescope/_extensions/media_files.lua +++ b/lua/telescope/_extensions/media_files.lua @@ -90,7 +90,11 @@ function M.media_files(opts) local sourced_file = require('plenary.debug_utils').sourced_filepath() M.base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h:h") opts = opts or {} - opts.attach_mappings= opts.attach_mappings or function(prompt_bufnr,map) + opts.attach_mappings= function(prompt_bufnr,map) + if opts.attach_mappings then + opts.attach_mappings(prompt_bufnr, map) + return true + end actions.select_default:replace(function() local entry = action_state.get_selected_entry() actions.close(prompt_bufnr) From 7f54fbd5a80f8a455e50f27688b8ca4ff144ba6e Mon Sep 17 00:00:00 2001 From: Jared Wyce Date: Sun, 19 Feb 2023 11:34:15 -0500 Subject: [PATCH 3/3] attempt 3 --- lua/telescope/_extensions/media_files.lua | 24 +++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lua/telescope/_extensions/media_files.lua b/lua/telescope/_extensions/media_files.lua index b2819a4..44673d3 100644 --- a/lua/telescope/_extensions/media_files.lua +++ b/lua/telescope/_extensions/media_files.lua @@ -90,21 +90,19 @@ function M.media_files(opts) local sourced_file = require('plenary.debug_utils').sourced_filepath() M.base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h:h") opts = opts or {} - opts.attach_mappings= function(prompt_bufnr,map) - if opts.attach_mappings then - opts.attach_mappings(prompt_bufnr, map) + if not opts.attach_mappings then + opts.attach_mappings= function(prompt_bufnr,map) + actions.select_default:replace(function() + local entry = action_state.get_selected_entry() + actions.close(prompt_bufnr) + if entry[1] then + local filename = entry[1] + vim.fn.setreg(vim.v.register, filename) + vim.notify("The image path has been copied!") + end + end) return true end - actions.select_default:replace(function() - local entry = action_state.get_selected_entry() - actions.close(prompt_bufnr) - if entry[1] then - local filename = entry[1] - vim.fn.setreg(vim.v.register, filename) - vim.notify("The image path has been copied!") - end - end) - return true end opts.path_display = { "shorten" }