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 :)
This commit is contained in:
Simon Hauser
2021-07-09 20:45:29 +02:00
committed by GitHub
parent 385020eb23
commit 3699605627
9 changed files with 1098 additions and 625 deletions

View File

@@ -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