From 5995a8be8faaa2c6e8693ca52f2320cb4a80e3fa Mon Sep 17 00:00:00 2001 From: anott03 Date: Wed, 27 Jan 2021 11:22:11 -0500 Subject: [PATCH] Undo #465 (#469) We have broke all extension that do some sort of goto_file_selection:replace Problem described here: https://github.com/nvim-telescope/telescope.nvim/pull/465#issuecomment-767831897 Possible solution: https://github.com/nvim-telescope/telescope.nvim/pull/465#issuecomment-767808213 --- README.md | 26 +++++++++++++------------- lua/telescope/actions/init.lua | 25 +++++++++---------------- lua/telescope/builtin/files.lua | 4 ++-- lua/telescope/builtin/git.lua | 6 +++--- lua/telescope/builtin/internal.lua | 30 +++++++++++++++--------------- lua/telescope/builtin/lsp.lua | 2 +- lua/telescope/config.lua | 2 +- lua/telescope/mappings.lua | 16 ++++++++-------- 8 files changed, 52 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 4f28634..1e89c5a 100644 --- a/README.md +++ b/README.md @@ -278,11 +278,11 @@ require('telescope').setup{ -- So, to not map "", just put [""] = false, -- Otherwise, just set the mapping to the function that you want it to be. - [""] = actions.hselect, + [""] = actions.goto_file_selection_split, -- Add up multiple actions - [""] = actions.select + actions.center, + [""] = actions.goto_file_selection_edit + actions.center, -- You can perform as many actions in a row as you like - [""] = actions.select + actions.center + my_cool_custom_action, + [""] = actions.goto_file_selection_edit + actions.center + my_cool_custom_action, }, n = { [""] = actions.close @@ -303,7 +303,7 @@ local actions = require('telescope.actions') require('telescope.builtin').fd({ -- or new custom picker's attach_mappings field: attach_mappings = function(prompt_bufnr) -- This will replace select no mather on which key it is mapped by default - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local entry = actions.get_selected_entry() actions.close(prompt_bufnr) print(vim.inspect(entry)) @@ -311,17 +311,17 @@ require('telescope.builtin').fd({ -- or new custom picker's attach_mappings fiel end) -- You can also enhance an action with pre and post action which will run before of after an action - actions.hselect:enhance ({ + actions.goto_file_selection_split:enhance ({ pre = function() - -- Will run before actions.hselect + -- Will run before actions.goto_file_selection_split end, post = function() - -- Will run after actions.hselect + -- Will run after actions.goto_file_selection_split end, }) -- Or replace for all commands: edit, new, vnew and tab - actions._select:replace(function(_, cmd) + actions._goto_file_selection:replace(function(_, cmd) print(cmd) -- Will print edit, new, vnew or tab depending on your keystroke end) @@ -340,20 +340,20 @@ require('telescope.builtin').fd({ -- or new custom picker's attach_mappings fiel - + - + - + - + - + diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 34cfede..50c7f37 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -66,7 +66,7 @@ function actions.preview_scrolling_down(prompt_bufnr) end -- TODO: It seems sometimes we get bad styling. -function actions._select(prompt_bufnr, command) +function actions._goto_file_selection(prompt_bufnr, command) local entry = actions.get_selected_entry(prompt_bufnr) if not entry then @@ -144,29 +144,22 @@ function actions.center(_) vim.cmd(':normal! zz') end -function actions.select(prompt_bufnr) - actions._select(prompt_bufnr, "edit") +function actions.goto_file_selection_edit(prompt_bufnr) + actions._goto_file_selection(prompt_bufnr, "edit") end -function actions.hselect(prompt_bufnr) - actions._select(prompt_bufnr, "new") +function actions.goto_file_selection_split(prompt_bufnr) + actions._goto_file_selection(prompt_bufnr, "new") end -function actions.vselect(prompt_bufnr) - actions._select(prompt_bufnr, "vnew") +function actions.goto_file_selection_vsplit(prompt_bufnr) + actions._goto_file_selection(prompt_bufnr, "vnew") end -function actions.tabselect(prompt_bufnr) - actions._select(prompt_bufnr, "tabedit") +function actions.goto_file_selection_tabedit(prompt_bufnr) + actions._goto_file_selection(prompt_bufnr, "tabedit") end --- aliases -actions._goto_file_selection = actions._select -actions.goto_file_selection_edit = actions.select -actions.goto_file_selection_split = actions.hselect -actions.goto_file_selection_vsplit = actions.vselect -actions.goto_file_selection_tabedit = actions.tabselect - function actions.close_pum(_) if 0 ~= vim.fn.pumvisible() then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, true, true), 'n', true) diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index cdb758a..b450eab 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -251,7 +251,7 @@ files.current_buffer_fuzzy_find = function(opts) }, sorter = conf.generic_sorter(opts), attach_mappings = function() - actions._select:enhance { + actions._goto_file_selection:enhance { post = function() local selection = actions.get_selected_entry() vim.api.nvim_win_set_cursor(0, {selection.lnum, 0}) @@ -287,7 +287,7 @@ files.tags = function(opts) previewer = previewers.ctags.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function() - actions._select:enhance { + actions._goto_file_selection:enhance { post = function() local selection = actions.get_selected_entry() diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index 2374a5d..a33e76b 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -47,7 +47,7 @@ git.commits = function(opts) previewer = previewers.git_commit_diff.new(opts), sorter = conf.file_sorter(opts), attach_mappings = function() - actions.select:replace(actions.git_checkout) + actions.goto_file_selection_edit:replace(actions.git_checkout) return true end }):find() @@ -67,7 +67,7 @@ git.bcommits = function(opts) previewer = previewers.git_commit_diff.new(opts), sorter = conf.file_sorter(opts), attach_mappings = function() - actions.select:replace(actions.git_checkout) + actions.goto_file_selection_edit:replace(actions.git_checkout) return true end }):find() @@ -107,7 +107,7 @@ git.branches = function(opts) previewer = previewers.git_branch_log.new(opts), sorter = conf.file_sorter(opts), attach_mappings = function() - actions.select:replace(actions.git_checkout) + actions.goto_file_selection_edit:replace(actions.git_checkout) return true end }):find() diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index d09f554..3c34b8b 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -47,7 +47,7 @@ internal.builtin = function(opts) previewer = previewers.builtin.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(_) - actions.select:replace(actions.run_builtin) + actions.goto_file_selection_edit:replace(actions.run_builtin) return true end }):find() @@ -82,7 +82,7 @@ internal.planets = function(opts) previewer = previewers.cat.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() actions.close(prompt_bufnr) @@ -137,7 +137,7 @@ internal.symbols = function(opts) }, sorter = conf.generic_sorter(opts), attach_mappings = function(_) - actions.select:replace(actions.insert_symbol) + actions.goto_file_selection_edit:replace(actions.insert_symbol) return true end }):find() @@ -168,7 +168,7 @@ internal.commands = function(opts) }, sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() actions.close(prompt_bufnr) local val = selection.value @@ -285,7 +285,7 @@ internal.vim_options = function(opts) -- previewer = previewers.help.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function() - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() local esc = "" @@ -411,7 +411,7 @@ internal.help_tags = function(opts) previewer = previewers.help.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions._select:replace(function(_, cmd) + actions._goto_file_selection:replace(function(_, cmd) local selection = actions.get_selected_entry() actions.close(prompt_bufnr) if cmd == 'edit' or cmd == 'new' then @@ -440,7 +440,7 @@ internal.man_pages = function(opts) previewer = previewers.man.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions._select:replace(function(_, cmd) + actions._goto_file_selection:replace(function(_, cmd) local selection = actions.get_selected_entry() actions.close(prompt_bufnr) @@ -483,7 +483,7 @@ internal.reloader = function(opts) sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() actions.close(prompt_bufnr) @@ -562,7 +562,7 @@ internal.colorscheme = function(opts) -- TODO: better preview? sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() actions.close(prompt_bufnr) @@ -614,7 +614,7 @@ internal.registers = function(opts) -- use levenshtein as n-gram doesn't support <2 char matches sorter = sorters.get_levenshtein_sorter(), attach_mappings = function(_, map) - actions.select:replace(actions.paste_register) + actions.goto_file_selection_edit:replace(actions.paste_register) map('i', '', actions.edit_register) return true @@ -653,7 +653,7 @@ internal.keymaps = function(opts) }, sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() vim.api.nvim_feedkeys( vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true), @@ -675,7 +675,7 @@ internal.filetypes = function(opts) }, sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() actions.close(prompt_bufnr) vim.cmd('setfiletype ' .. selection[1]) @@ -696,7 +696,7 @@ internal.highlights = function(opts) }, sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() actions.close(prompt_bufnr) vim.cmd('hi ' .. selection.value) @@ -787,7 +787,7 @@ internal.autocommands = function(opts) previewer = previewers.autocommands.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions._select:replace(function(_, vim_cmd) + actions._goto_file_selection:replace(function(_, vim_cmd) local selection = actions.get_selected_entry() actions.close(prompt_bufnr) vim.cmd(vim_cmd .. ' ' .. selection.value) @@ -811,7 +811,7 @@ internal.spell_suggest = function(opts) }, sorter = conf.generic_sorter(opts), attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() actions.close(prompt_bufnr) vim.cmd('normal! ciw' .. selection[1]) diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index 6c31839..4a373b1 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -116,7 +116,7 @@ lsp.code_actions = function(opts) end }, attach_mappings = function(prompt_bufnr) - actions.select:replace(function() + actions.goto_file_selection_edit:replace(function() local selection = actions.get_selected_entry() actions.close(prompt_bufnr) local val = selection.value diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 8af6b31..bfe8a6e 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -83,7 +83,7 @@ function config.set_defaults(defaults) -- Otherwise, just set the mapping to the function that you want it to be. -- -- ..., - -- [""] = actions.hselect + -- [""] = actions.goto_file_selection_split -- ..., -- set("mappings", {}) diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua index 38f238c..499be3e 100644 --- a/lua/telescope/mappings.lua +++ b/lua/telescope/mappings.lua @@ -16,10 +16,10 @@ mappings.default_mappings = config.values.default_mappings or { [""] = actions.move_selection_next, [""] = actions.move_selection_previous, - [""] = actions.select + actions.center, - [""] = actions.hselect, - [""] = actions.vselect, - [""] = actions.tabselect, + [""] = actions.goto_file_selection_edit + actions.center, + [""] = actions.goto_file_selection_split, + [""] = actions.goto_file_selection_vsplit, + [""] = actions.goto_file_selection_tabedit, [""] = actions.preview_scrolling_up, [""] = actions.preview_scrolling_down, @@ -30,10 +30,10 @@ mappings.default_mappings = config.values.default_mappings or { n = { [""] = actions.close, - [""] = actions.select + actions.center, - [""] = actions.hselect, - [""] = actions.vselect, - [""] = actions.tabselect, + [""] = actions.goto_file_selection_edit + actions.center, + [""] = actions.goto_file_selection_split, + [""] = actions.goto_file_selection_vsplit, + [""] = actions.goto_file_selection_tabedit, -- TODO: This would be weird if we switch the ordering. ["j"] = actions.move_selection_next,