diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2021-07-09 20:45:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-09 20:45:29 +0200 |
| commit | 36996056272a7174868367acf1043cead333d115 (patch) | |
| tree | cd5a33dac60c9c5ee6ae17b6be2f51fa44b52562 /lua/telescope/actions/mt.lua | |
| parent | 385020eb232b48a5a3583f531ff27266fb06eec4 (diff) | |
feat: cycle prompt history (#521)
history is enabled on default but cycle_history_next and cycle_history_prev is not mapped yet
Example:
require('telescope').setup {
defaults = {
mappings = {
i = {
["<C-Down>"] = require('telescope.actions').cycle_history_next,
["<C-Up>"] = require('telescope.actions').cycle_history_prev,
}
}
}
}
For more information :help telescope.defaults.history
big thanks to clason and all other testers :)
Diffstat (limited to 'lua/telescope/actions/mt.lua')
| -rw-r--r-- | lua/telescope/actions/mt.lua | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lua/telescope/actions/mt.lua b/lua/telescope/actions/mt.lua index 5efeddf..7f233cf 100644 --- a/lua/telescope/actions/mt.lua +++ b/lua/telescope/actions/mt.lua @@ -19,6 +19,9 @@ action_mt.create = function(mod) __call = function(t, ...) local values = {} for _, action_name in ipairs(t) do + if t._static_pre[action_name] then + t._static_pre[action_name](...) + end if t._pre[action_name] then t._pre[action_name](...) end @@ -34,6 +37,9 @@ action_mt.create = function(mod) table.insert(values, res) end + if t._static_post[action_name] then + t._static_post[action_name](...) + end if t._post[action_name] then t._post[action_name](...) end @@ -55,8 +61,10 @@ action_mt.create = function(mod) return setmetatable(new_actions, getmetatable(lhs)) end, + _static_pre = {}, _pre = {}, _replacements = {}, + _static_post = {}, _post = {}, } @@ -119,8 +127,14 @@ action_mt.create = function(mod) return mt end -action_mt.transform = function(k, mt) - return setmetatable({k}, mt) +action_mt.transform = function(k, mt, mod, v) + local res = setmetatable({k}, mt) + if type(v) == "table" then + res._static_pre[k] = v.pre + res._static_post[k] = v.post + mod[k] = v.action + end + return res end action_mt.transform_mod = function(mod) @@ -130,8 +144,8 @@ action_mt.transform_mod = function(mod) -- This allows for custom errors, lookups, etc. local redirect = setmetatable({}, getmetatable(mod) or {}) - for k, _ in pairs(mod) do - redirect[k] = action_mt.transform(k, mt) + for k, v in pairs(mod) do + redirect[k] = action_mt.transform(k, mt, mod, v) end redirect._clear = mt.clear |
