fix: move to actions.select as default action (#465)

This commit is contained in:
anott03
2021-01-25 13:20:01 -05:00
committed by GitHub
parent 5bf9e14f10
commit ccbb7f5638
8 changed files with 61 additions and 54 deletions

View File

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

View File

@@ -66,7 +66,7 @@ function actions.preview_scrolling_down(prompt_bufnr)
end
-- TODO: It seems sometimes we get bad styling.
function actions._goto_file_selection(prompt_bufnr, command)
function actions._select(prompt_bufnr, command)
local entry = actions.get_selected_entry(prompt_bufnr)
if not entry then
@@ -144,22 +144,29 @@ function actions.center(_)
vim.cmd(':normal! zz')
end
function actions.goto_file_selection_edit(prompt_bufnr)
actions._goto_file_selection(prompt_bufnr, "edit")
function actions.select(prompt_bufnr)
actions._select(prompt_bufnr, "edit")
end
function actions.goto_file_selection_split(prompt_bufnr)
actions._goto_file_selection(prompt_bufnr, "new")
function actions.hselect(prompt_bufnr)
actions._select(prompt_bufnr, "new")
end
function actions.goto_file_selection_vsplit(prompt_bufnr)
actions._goto_file_selection(prompt_bufnr, "vnew")
function actions.vselect(prompt_bufnr)
actions._select(prompt_bufnr, "vnew")
end
function actions.goto_file_selection_tabedit(prompt_bufnr)
actions._goto_file_selection(prompt_bufnr, "tabedit")
function actions.tabselect(prompt_bufnr)
actions._select(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("<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),
attach_mappings = function()
actions._goto_file_selection:enhance {
actions._select: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._goto_file_selection:enhance {
actions._select:enhance {
post = function()
local selection = actions.get_selected_entry()

View File

@@ -47,7 +47,7 @@ git.commits = function(opts)
previewer = previewers.git_commit_diff.new(opts),
sorter = conf.file_sorter(opts),
attach_mappings = function()
actions.goto_file_selection_edit:replace(actions.git_checkout)
actions.select: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.goto_file_selection_edit:replace(actions.git_checkout)
actions.select: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.goto_file_selection_edit:replace(actions.git_checkout)
actions.select:replace(actions.git_checkout)
return true
end
}):find()

View File

@@ -47,7 +47,7 @@ internal.builtin = function(opts)
previewer = previewers.builtin.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(_)
actions.goto_file_selection_edit:replace(actions.run_builtin)
actions.select: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.goto_file_selection_edit:replace(function()
actions.select: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.goto_file_selection_edit:replace(actions.insert_symbol)
actions.select: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.goto_file_selection_edit:replace(function()
actions.select: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.goto_file_selection_edit:replace(function()
actions.select: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._goto_file_selection:replace(function(_, cmd)
actions._select: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._goto_file_selection:replace(function(_, cmd)
actions._select: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.goto_file_selection_edit:replace(function()
actions.select: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.goto_file_selection_edit:replace(function()
actions.select: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.goto_file_selection_edit:replace(actions.paste_register)
actions.select:replace(actions.paste_register)
map('i', '<C-e>', actions.edit_register)
return true
@@ -653,7 +653,7 @@ internal.keymaps = function(opts)
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.goto_file_selection_edit:replace(function()
actions.select: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.goto_file_selection_edit:replace(function()
actions.select: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.goto_file_selection_edit:replace(function()
actions.select: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._goto_file_selection:replace(function(_, vim_cmd)
actions._select: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.goto_file_selection_edit:replace(function()
actions.select:replace(function()
local selection = actions.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('normal! ciw' .. selection[1])

View File

@@ -116,7 +116,7 @@ lsp.code_actions = function(opts)
end
},
attach_mappings = function(prompt_bufnr)
actions.goto_file_selection_edit:replace(function()
actions.select:replace(function()
local selection = actions.get_selected_entry()
actions.close(prompt_bufnr)
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.
--
-- ...,
-- ["<C-i>"] = actions.goto_file_selection_split
-- ["<C-i>"] = actions.hselect
-- ...,
--
set("mappings", {})

View File

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