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/init.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/init.lua')
| -rw-r--r-- | lua/telescope/actions/init.lua | 84 |
1 files changed, 72 insertions, 12 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index bf45bb3..8ca96c7 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -196,21 +196,53 @@ function actions.center(_) vim.cmd(':normal! zz') end -function actions.select_default(prompt_bufnr) - return action_set.select(prompt_bufnr, "default") -end +actions.select_default = { + pre = function(prompt_bufnr) + action_state.get_current_history():append( + action_state.get_current_line(), + action_state.get_current_picker(prompt_bufnr) + ) + end, + action = function(prompt_bufnr) + return action_set.select(prompt_bufnr, "default") + end +} -function actions.select_horizontal(prompt_bufnr) - return action_set.select(prompt_bufnr, "horizontal") -end +actions.select_horizontal = { + pre = function(prompt_bufnr) + action_state.get_current_history():append( + action_state.get_current_line(), + action_state.get_current_picker(prompt_bufnr) + ) + end, + action = function(prompt_bufnr) + return action_set.select(prompt_bufnr, "horizontal") + end +} -function actions.select_vertical(prompt_bufnr) - return action_set.select(prompt_bufnr, "vertical") -end +actions.select_vertical = { + pre = function(prompt_bufnr) + action_state.get_current_history():append( + action_state.get_current_line(), + action_state.get_current_picker(prompt_bufnr) + ) + end, + action = function(prompt_bufnr) + return action_set.select(prompt_bufnr, "vertical") + end +} -function actions.select_tab(prompt_bufnr) - return action_set.select(prompt_bufnr, "tab") -end +actions.select_tab = { + pre = function(prompt_bufnr) + action_state.get_current_history():append( + action_state.get_current_line(), + action_state.get_current_picker(prompt_bufnr) + ) + end, + action = function(prompt_bufnr) + return action_set.select(prompt_bufnr, "tab") + end +} -- TODO: consider adding float! -- https://github.com/nvim-telescope/telescope.nvim/issues/365 @@ -238,6 +270,7 @@ function actions.close_pum(_) end actions._close = function(prompt_bufnr, keepinsert) + action_state.get_current_history():reset() local picker = action_state.get_current_picker(prompt_bufnr) local prompt_win = state.get_status(prompt_bufnr).prompt_win local original_win_id = picker.original_win_id @@ -695,6 +728,33 @@ actions.complete_tag = function(prompt_bufnr) end +actions.cycle_history_next = function(prompt_bufnr) + local history = action_state.get_current_history() + local current_picker = actions.get_current_picker(prompt_bufnr) + local line = action_state.get_current_line() + + local entry = history:get_next(line, current_picker) + if entry == false then return end + + current_picker:reset_prompt() + if entry ~= nil then + current_picker:set_prompt(entry) + end +end + +actions.cycle_history_prev = function(prompt_bufnr) + local history = action_state.get_current_history() + local current_picker = actions.get_current_picker(prompt_bufnr) + local line = action_state.get_current_line() + + local entry = history:get_prev(line, current_picker) + if entry == false then return end + if entry ~= nil then + current_picker:reset_prompt() + current_picker:set_prompt(entry) + end +end + --- Open the quickfix list actions.open_qflist = function(_) vim.cmd [[copen]] |
