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
This commit is contained in:
anott03
2021-01-27 11:22:11 -05:00
committed by GitHub
parent ccbb7f5638
commit 5995a8be8f
8 changed files with 52 additions and 59 deletions

View File

@@ -278,11 +278,11 @@ require('telescope').setup{
-- So, to not map "<C-n>", just put -- So, to not map "<C-n>", just put
["<c-x>"] = false, ["<c-x>"] = false,
-- Otherwise, just set the mapping to the function that you want it to be. -- Otherwise, just set the mapping to the function that you want it to be.
["<C-i>"] = actions.hselect, ["<C-i>"] = actions.goto_file_selection_split,
-- Add up multiple actions -- Add up multiple actions
["<CR>"] = actions.select + actions.center, ["<CR>"] = actions.goto_file_selection_edit + actions.center,
-- You can perform as many actions in a row as you like -- You can perform as many actions in a row as you like
["<CR>"] = actions.select + actions.center + my_cool_custom_action, ["<CR>"] = actions.goto_file_selection_edit + actions.center + my_cool_custom_action,
}, },
n = { n = {
["<esc>"] = actions.close ["<esc>"] = actions.close
@@ -303,7 +303,7 @@ local actions = require('telescope.actions')
require('telescope.builtin').fd({ -- or new custom picker's attach_mappings field: require('telescope.builtin').fd({ -- or new custom picker's attach_mappings field:
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
-- This will replace select no mather on which key it is mapped by default -- 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() local entry = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
print(vim.inspect(entry)) print(vim.inspect(entry))
@@ -311,17 +311,17 @@ require('telescope.builtin').fd({ -- or new custom picker's attach_mappings fiel
end) end)
-- You can also enhance an action with pre and post action which will run before of after an action -- 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() pre = function()
-- Will run before actions.hselect -- Will run before actions.goto_file_selection_split
end, end,
post = function() post = function()
-- Will run after actions.hselect -- Will run after actions.goto_file_selection_split
end, end,
}) })
-- Or replace for all commands: edit, new, vnew and tab -- 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 print(cmd) -- Will print edit, new, vnew or tab depending on your keystroke
end) end)
@@ -340,20 +340,20 @@ require('telescope.builtin').fd({ -- or new custom picker's attach_mappings fiel
<!-- sorter = sorters.fuzzy_with_index_bias(), --> <!-- sorter = sorters.fuzzy_with_index_bias(), -->
<!-- attach_mappings = function(prompt_bufnr) --> <!-- attach_mappings = function(prompt_bufnr) -->
<!-- -- This will replace select no mather on which key it is mapped by default --> <!-- -- 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() -->
<!-- -- Code here --> <!-- -- Code here -->
<!-- end) --> <!-- end) -->
<!-- -- You can also enhance an action with post and post action which will run before of after an action --> <!-- -- You can also enhance an action with post and post action which will run before of after an action -->
<!-- actions.hselect:enhance { --> <!-- actions.goto_file_selection_split:enhance { -->
<!-- pre = function() --> <!-- pre = function() -->
<!-- -- Will run before actions.hselect --> <!-- -- Will run before actions.goto_file_selection_split -->
<!-- end, --> <!-- end, -->
<!-- post = function() --> <!-- post = function() -->
<!-- -- Will run after actions.hselect --> <!-- -- Will run after actions.goto_file_selection_split -->
<!-- end, --> <!-- end, -->
<!-- } --> <!-- } -->
<!-- -- Or replace for all commands: edit, new, vnew and tab --> <!-- -- 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 --> <!-- print(cmd) -- Will print edit, new, vnew or tab depending on your keystroke -->
<!-- end) --> <!-- end) -->
<!-- return true --> <!-- return true -->

View File

@@ -66,7 +66,7 @@ function actions.preview_scrolling_down(prompt_bufnr)
end end
-- TODO: It seems sometimes we get bad styling. -- 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) local entry = actions.get_selected_entry(prompt_bufnr)
if not entry then if not entry then
@@ -144,29 +144,22 @@ function actions.center(_)
vim.cmd(':normal! zz') vim.cmd(':normal! zz')
end end
function actions.select(prompt_bufnr) function actions.goto_file_selection_edit(prompt_bufnr)
actions._select(prompt_bufnr, "edit") actions._goto_file_selection(prompt_bufnr, "edit")
end end
function actions.hselect(prompt_bufnr) function actions.goto_file_selection_split(prompt_bufnr)
actions._select(prompt_bufnr, "new") actions._goto_file_selection(prompt_bufnr, "new")
end end
function actions.vselect(prompt_bufnr) function actions.goto_file_selection_vsplit(prompt_bufnr)
actions._select(prompt_bufnr, "vnew") actions._goto_file_selection(prompt_bufnr, "vnew")
end end
function actions.tabselect(prompt_bufnr) function actions.goto_file_selection_tabedit(prompt_bufnr)
actions._select(prompt_bufnr, "tabedit") actions._goto_file_selection(prompt_bufnr, "tabedit")
end 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(_) function actions.close_pum(_)
if 0 ~= vim.fn.pumvisible() then if 0 ~= vim.fn.pumvisible() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<c-y>", true, true, true), 'n', true) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<c-y>", true, true, true), 'n', true)

View File

@@ -251,7 +251,7 @@ files.current_buffer_fuzzy_find = function(opts)
}, },
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function() attach_mappings = function()
actions._select:enhance { actions._goto_file_selection:enhance {
post = function() post = function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
vim.api.nvim_win_set_cursor(0, {selection.lnum, 0}) vim.api.nvim_win_set_cursor(0, {selection.lnum, 0})
@@ -287,7 +287,7 @@ files.tags = function(opts)
previewer = previewers.ctags.new(opts), previewer = previewers.ctags.new(opts),
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function() attach_mappings = function()
actions._select:enhance { actions._goto_file_selection:enhance {
post = function() post = function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()

View File

@@ -47,7 +47,7 @@ git.commits = function(opts)
previewer = previewers.git_commit_diff.new(opts), previewer = previewers.git_commit_diff.new(opts),
sorter = conf.file_sorter(opts), sorter = conf.file_sorter(opts),
attach_mappings = function() attach_mappings = function()
actions.select:replace(actions.git_checkout) actions.goto_file_selection_edit:replace(actions.git_checkout)
return true return true
end end
}):find() }):find()
@@ -67,7 +67,7 @@ git.bcommits = function(opts)
previewer = previewers.git_commit_diff.new(opts), previewer = previewers.git_commit_diff.new(opts),
sorter = conf.file_sorter(opts), sorter = conf.file_sorter(opts),
attach_mappings = function() attach_mappings = function()
actions.select:replace(actions.git_checkout) actions.goto_file_selection_edit:replace(actions.git_checkout)
return true return true
end end
}):find() }):find()
@@ -107,7 +107,7 @@ git.branches = function(opts)
previewer = previewers.git_branch_log.new(opts), previewer = previewers.git_branch_log.new(opts),
sorter = conf.file_sorter(opts), sorter = conf.file_sorter(opts),
attach_mappings = function() attach_mappings = function()
actions.select:replace(actions.git_checkout) actions.goto_file_selection_edit:replace(actions.git_checkout)
return true return true
end end
}):find() }):find()

View File

@@ -47,7 +47,7 @@ internal.builtin = function(opts)
previewer = previewers.builtin.new(opts), previewer = previewers.builtin.new(opts),
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(_) attach_mappings = function(_)
actions.select:replace(actions.run_builtin) actions.goto_file_selection_edit:replace(actions.run_builtin)
return true return true
end end
}):find() }):find()
@@ -82,7 +82,7 @@ internal.planets = function(opts)
previewer = previewers.cat.new(opts), previewer = previewers.cat.new(opts),
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
@@ -137,7 +137,7 @@ internal.symbols = function(opts)
}, },
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(_) attach_mappings = function(_)
actions.select:replace(actions.insert_symbol) actions.goto_file_selection_edit:replace(actions.insert_symbol)
return true return true
end end
}):find() }):find()
@@ -168,7 +168,7 @@ internal.commands = function(opts)
}, },
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
local val = selection.value local val = selection.value
@@ -285,7 +285,7 @@ internal.vim_options = function(opts)
-- previewer = previewers.help.new(opts), -- previewer = previewers.help.new(opts),
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function() attach_mappings = function()
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
local esc = "" local esc = ""
@@ -411,7 +411,7 @@ internal.help_tags = function(opts)
previewer = previewers.help.new(opts), previewer = previewers.help.new(opts),
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions._select:replace(function(_, cmd) actions._goto_file_selection:replace(function(_, cmd)
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
if cmd == 'edit' or cmd == 'new' then if cmd == 'edit' or cmd == 'new' then
@@ -440,7 +440,7 @@ internal.man_pages = function(opts)
previewer = previewers.man.new(opts), previewer = previewers.man.new(opts),
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions._select:replace(function(_, cmd) actions._goto_file_selection:replace(function(_, cmd)
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
@@ -483,7 +483,7 @@ internal.reloader = function(opts)
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
@@ -562,7 +562,7 @@ internal.colorscheme = function(opts)
-- TODO: better preview? -- TODO: better preview?
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
@@ -614,7 +614,7 @@ internal.registers = function(opts)
-- use levenshtein as n-gram doesn't support <2 char matches -- use levenshtein as n-gram doesn't support <2 char matches
sorter = sorters.get_levenshtein_sorter(), sorter = sorters.get_levenshtein_sorter(),
attach_mappings = function(_, map) attach_mappings = function(_, map)
actions.select:replace(actions.paste_register) actions.goto_file_selection_edit:replace(actions.paste_register)
map('i', '<C-e>', actions.edit_register) map('i', '<C-e>', actions.edit_register)
return true return true
@@ -653,7 +653,7 @@ internal.keymaps = function(opts)
}, },
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
vim.api.nvim_feedkeys( vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true), vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true),
@@ -675,7 +675,7 @@ internal.filetypes = function(opts)
}, },
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
vim.cmd('setfiletype ' .. selection[1]) vim.cmd('setfiletype ' .. selection[1])
@@ -696,7 +696,7 @@ internal.highlights = function(opts)
}, },
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
vim.cmd('hi ' .. selection.value) vim.cmd('hi ' .. selection.value)
@@ -787,7 +787,7 @@ internal.autocommands = function(opts)
previewer = previewers.autocommands.new(opts), previewer = previewers.autocommands.new(opts),
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) 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() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
vim.cmd(vim_cmd .. ' ' .. selection.value) vim.cmd(vim_cmd .. ' ' .. selection.value)
@@ -811,7 +811,7 @@ internal.spell_suggest = function(opts)
}, },
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
vim.cmd('normal! ciw' .. selection[1]) vim.cmd('normal! ciw' .. selection[1])

View File

@@ -116,7 +116,7 @@ lsp.code_actions = function(opts)
end end
}, },
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select:replace(function() actions.goto_file_selection_edit:replace(function()
local selection = actions.get_selected_entry() local selection = actions.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
local val = selection.value local val = selection.value

View File

@@ -83,7 +83,7 @@ function config.set_defaults(defaults)
-- Otherwise, just set the mapping to the function that you want it to be. -- Otherwise, just set the mapping to the function that you want it to be.
-- --
-- ..., -- ...,
-- ["<C-i>"] = actions.hselect -- ["<C-i>"] = actions.goto_file_selection_split
-- ..., -- ...,
-- --
set("mappings", {}) set("mappings", {})

View File

@@ -16,10 +16,10 @@ mappings.default_mappings = config.values.default_mappings or {
["<Down>"] = actions.move_selection_next, ["<Down>"] = actions.move_selection_next,
["<Up>"] = actions.move_selection_previous, ["<Up>"] = actions.move_selection_previous,
["<CR>"] = actions.select + actions.center, ["<CR>"] = actions.goto_file_selection_edit + actions.center,
["<C-x>"] = actions.hselect, ["<C-x>"] = actions.goto_file_selection_split,
["<C-v>"] = actions.vselect, ["<C-v>"] = actions.goto_file_selection_vsplit,
["<C-t>"] = actions.tabselect, ["<C-t>"] = actions.goto_file_selection_tabedit,
["<C-u>"] = actions.preview_scrolling_up, ["<C-u>"] = actions.preview_scrolling_up,
["<C-d>"] = actions.preview_scrolling_down, ["<C-d>"] = actions.preview_scrolling_down,
@@ -30,10 +30,10 @@ mappings.default_mappings = config.values.default_mappings or {
n = { n = {
["<esc>"] = actions.close, ["<esc>"] = actions.close,
["<CR>"] = actions.select + actions.center, ["<CR>"] = actions.goto_file_selection_edit + actions.center,
["<C-x>"] = actions.hselect, ["<C-x>"] = actions.goto_file_selection_split,
["<C-v>"] = actions.vselect, ["<C-v>"] = actions.goto_file_selection_vsplit,
["<C-t>"] = actions.tabselect, ["<C-t>"] = actions.goto_file_selection_tabedit,
-- TODO: This would be weird if we switch the ordering. -- TODO: This would be weird if we switch the ordering.
["j"] = actions.move_selection_next, ["j"] = actions.move_selection_next,