summaryrefslogtreecommitdiff
path: root/lua/telescope/actions/generate.lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2022-07-01 23:29:24 +0200
committerGitHub <noreply@github.com>2022-07-01 23:29:24 +0200
commit7df95f9b208ba7228a25e7f75fb4cc02d6604cce (patch)
treee4933fb547bc886f27f06011a6c4780facfd7642 /lua/telescope/actions/generate.lua
parent1aa74b231c6f93152c4ac51549a0563dca9b4453 (diff)
parente778abfdb457cc47ca47ce9b76905e043e87e598 (diff)
Merge pull request #1945 from nvim-telescope/dev
full changelog `:help telescope.changelog-1945`
Diffstat (limited to 'lua/telescope/actions/generate.lua')
-rw-r--r--lua/telescope/actions/generate.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/lua/telescope/actions/generate.lua b/lua/telescope/actions/generate.lua
index 2069b03..703c83d 100644
--- a/lua/telescope/actions/generate.lua
+++ b/lua/telescope/actions/generate.lua
@@ -24,6 +24,10 @@
---@brief ]]
local actions = require "telescope.actions"
+local config = require "telescope.config"
+local action_state = require "telescope.actions.state"
+local finders = require "telescope.finders"
+
local action_generate = {}
--- Display the keymaps of registered actions similar to which-key.nvim.<br>
@@ -54,4 +58,56 @@ action_generate.which_key = function(opts)
end
end
+action_generate.refine = function(prompt_bufnr, opts)
+ opts = opts or {}
+ opts.prompt_to_prefix = vim.F.if_nil(opts.prompt_to_prefix, false)
+ opts.prefix_hl_group = vim.F.if_nil(opts.prompt_hl_group, "TelescopePromptPrefix")
+ opts.prompt_prefix = vim.F.if_nil(opts.promt_prefix, config.values.prompt_prefix)
+ opts.reset_multi_selection = vim.F.if_nil(opts.reset_multi_selection, false)
+ opts.reset_prompt = vim.F.if_nil(opts.reset_prompt, true)
+ opts.sorter = vim.F.if_nil(opts.sorter, config.values.generic_sorter {})
+
+ local current_picker = action_state.get_current_picker(prompt_bufnr)
+
+ -- title
+ if opts.prompt_title then
+ current_picker.prompt_border:change_title(opts.prompt_title)
+ end
+
+ if opts.results_title then
+ current_picker.results_border:change_title(opts.results_title)
+ end
+
+ local results = {}
+ for entry in current_picker.manager:iter() do
+ table.insert(results, entry)
+ end
+
+ -- if opts.sorter == false, keep older sorter
+ if opts.sorter then
+ current_picker.sorter:_destroy()
+ current_picker.sorter = opts.sorter
+ current_picker.sorter:_init()
+ end
+
+ local new_finder = finders.new_table {
+ results = results,
+ entry_maker = function(x)
+ return x
+ end,
+ }
+
+ if not opts.reset_multi_selection and action_state.get_current_line() ~= "" then
+ opts.multi = current_picker._multi
+ end
+
+ if opts.prompt_to_prefix then
+ local prompt = action_state.get_current_line()
+ local current_prefix = current_picker.prompt_prefix
+ local suffix = current_prefix ~= opts.prompt_prefix and current_prefix or ""
+ opts.new_prefix = suffix .. prompt .. " " .. opts.prompt_prefix
+ end
+ current_picker:refresh(new_finder, opts)
+end
+
return action_generate