summaryrefslogtreecommitdiff
path: root/lua/telescope/pickers.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2021-02-22 11:30:57 -0500
committerGitHub <noreply@github.com>2021-02-22 11:30:57 -0500
commitd7c02e3b52b5a13265e071d0de2d6a989110a515 (patch)
tree165f83bac6ffbb8594f6afb53905bc7bc64a4359 /lua/telescope/pickers.lua
parent1c5e42a6a5a6d29be8fbf8dcefb0d8da535eac9a (diff)
feat: Action improvements (#472)
* feat: replace_map * feat: Add action_set and action_state * fix: Move all actions.get_ to action_state.get_ * fix: replace all internal references of _goto_file_selection_edit * feat: add some docs * fix: lint * feat: actions.select * remove mentions and usage of goto_file_selection APIs * feat: special case attach_mappings to be overridable and defaultable * Having goto_file_selection mappings will cause a error as well as replacing deprecated goto_file_selection methodes For config and replacing use this instead: - actions.select_default - actions.select_horizonal - actions.select_vertical - actions.select_tab Only replacing: - actions.set.edit -- for replacing all select functions * adds actions.state.select_key_to_edit_key Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
Diffstat (limited to 'lua/telescope/pickers.lua')
-rw-r--r--lua/telescope/pickers.lua49
1 files changed, 29 insertions, 20 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 007df7a..5462559 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -4,6 +4,7 @@ local popup = require('popup')
require('telescope')
local actions = require('telescope.actions')
+local action_set = require('telescope.actions.set')
local config = require('telescope.config')
local debounce = require('telescope.debounce')
local resolve = require('telescope.config.resolve')
@@ -21,25 +22,6 @@ local EntryManager = require('telescope.entry_manager')
local get_default = utils.get_default
--- TODO: Make this work with deep extend I think.
-local extend = function(opts, defaults)
- local result = {}
-
- for k, v in pairs(opts or {}) do
- assert(type(k) == 'string', "Should be string, opts")
- result[k] = v
- end
-
- for k, v in pairs(defaults or {}) do
- if result[k] == nil then
- assert(type(k) == 'string', "Should be string, defaults")
- result[k] = v
- end
- end
-
- return result
-end
-
local ns_telescope_matching = a.nvim_create_namespace('telescope_matching')
local ns_telescope_prompt = a.nvim_create_namespace('telescope_prompt')
local ns_telescope_prompt_prefix = a.nvim_create_namespace('telescope_prompt_prefix')
@@ -62,7 +44,10 @@ function Picker:new(opts)
end
-- Reset actions for any replaced / enhanced actions.
+ -- TODO: Think about how we could remember to NOT have to do this...
+ -- I almost forgot once already, cause I'm not smart enough to always do it.
actions._clear()
+ action_set._clear()
local layout_strategy = get_default(opts.layout_strategy, config.values.layout_strategy)
@@ -1016,7 +1001,31 @@ end
pickers.new = function(opts, defaults)
- return Picker:new(extend(opts, defaults))
+ local result = {}
+
+ for k, v in pairs(opts or {}) do
+ assert(type(k) == 'string', "Should be string, opts")
+ result[k] = v
+ end
+
+ for k, v in pairs(defaults or {}) do
+ if result[k] == nil then
+ assert(type(k) == 'string', "Should be string, defaults")
+ result[k] = v
+ else
+ -- For attach mappings, we want people to be able to pass in another function
+ -- and apply their mappings after we've applied our defaults.
+ if k == 'attach_mappings' then
+ local opt_value = result[k]
+ result[k] = function(...)
+ v(...)
+ return opt_value(...)
+ end
+ end
+ end
+ end
+
+ return Picker:new(result)
end
function pickers.on_close_prompt(prompt_bufnr)