mirror of
https://github.com/zoriya/telescope.nvim.git
synced 2026-08-16 02:45:09 +00:00
wip: Modify action and action_set signatures
Now you can pass the entry that you want to take the action on for both actions and action sets. This is part 1 of being able to do things like taking actions on multiple entries, but only writing code for one :)
This commit is contained in:
+107
-91
@@ -5,6 +5,14 @@
|
||||
|
||||
---@brief [[
|
||||
--- Actions functions that are useful for people creating their own mappings.
|
||||
---
|
||||
--- All actions follow the same signature:
|
||||
--- function(prompt_bufnr, entry)
|
||||
---
|
||||
--- prompt_bufnr: The bufnr for the prompt
|
||||
--- entry: The entry to perform the action on.
|
||||
---
|
||||
---
|
||||
---@brief ]]
|
||||
|
||||
local a = vim.api
|
||||
@@ -27,44 +35,44 @@ local actions = setmetatable({}, {
|
||||
|
||||
--- Move the selection to the next entry
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.move_selection_next(prompt_bufnr)
|
||||
action_set.shift_selection(prompt_bufnr, 1)
|
||||
function actions.move_selection_next(prompt_bufnr, entry)
|
||||
action_set.shift_selection(prompt_bufnr, entry, 1)
|
||||
end
|
||||
|
||||
--- Move the selection to the previous entry
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.move_selection_previous(prompt_bufnr)
|
||||
action_set.shift_selection(prompt_bufnr, -1)
|
||||
function actions.move_selection_previous(prompt_bufnr, entry)
|
||||
action_set.shift_selection(prompt_bufnr, entry, -1)
|
||||
end
|
||||
|
||||
--- Move the selection to the entry that has a worse score
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.move_selection_worse(prompt_bufnr)
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
action_set.shift_selection(prompt_bufnr, p_scroller.worse(picker.sorting_strategy))
|
||||
function actions.move_selection_worse(prompt_bufnr, entry)
|
||||
local picker = action_state.get_current_picker()
|
||||
action_set.shift_selection(prompt_bufnr, entry, p_scroller.worse(picker.sorting_strategy))
|
||||
end
|
||||
|
||||
--- Move the selection to the entry that has a better score
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.move_selection_better(prompt_bufnr)
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
action_set.shift_selection(prompt_bufnr, p_scroller.better(picker.sorting_strategy))
|
||||
function actions.move_selection_better(prompt_bufnr, entry)
|
||||
local picker = action_state.get_current_picker()
|
||||
action_set.shift_selection(prompt_bufnr, entry, p_scroller.better(picker.sorting_strategy))
|
||||
end
|
||||
|
||||
--- Move to the top of the picker
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.move_to_top(prompt_bufnr)
|
||||
local current_picker = actions.get_current_picker(prompt_bufnr)
|
||||
current_picker:set_selection(p_scroller.top(current_picker.sorting_strategy,
|
||||
current_picker.max_results,
|
||||
current_picker.manager:num_results()
|
||||
local picker = action_state.get_current_picker()
|
||||
picker:set_selection(p_scroller.top(picker.sorting_strategy,
|
||||
picker.max_results,
|
||||
picker.manager:num_results()
|
||||
))
|
||||
end
|
||||
|
||||
--- Move to the middle of the picker
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.move_to_middle(prompt_bufnr)
|
||||
local current_picker = actions.get_current_picker(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker()
|
||||
current_picker:set_selection(p_scroller.middle(
|
||||
current_picker.sorting_strategy,
|
||||
current_picker.max_results,
|
||||
@@ -75,7 +83,7 @@ end
|
||||
--- Move to the bottom of the picker
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.move_to_bottom(prompt_bufnr)
|
||||
local current_picker = actions.get_current_picker(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker()
|
||||
current_picker:set_selection(p_scroller.bottom(current_picker.sorting_strategy,
|
||||
current_picker.max_results,
|
||||
current_picker.manager:num_results()
|
||||
@@ -85,80 +93,81 @@ end
|
||||
--- Add current entry to multi select
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.add_selection(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker()
|
||||
current_picker:add_selection(current_picker:get_selection_row())
|
||||
end
|
||||
|
||||
--- Remove current entry from multi select
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.remove_selection(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker()
|
||||
current_picker:remove_selection(current_picker:get_selection_row())
|
||||
end
|
||||
|
||||
--- Toggle current entry status for multi select
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function actions.toggle_selection(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker()
|
||||
current_picker:toggle_selection(current_picker:get_selection_row())
|
||||
end
|
||||
|
||||
function actions.preview_scrolling_up(prompt_bufnr)
|
||||
action_set.scroll_previewer(prompt_bufnr, -1)
|
||||
function actions.preview_scrolling_up(prompt_bufnr, entry)
|
||||
action_set.scroll_previewer(prompt_bufnr, entry, -1)
|
||||
end
|
||||
|
||||
function actions.preview_scrolling_down(prompt_bufnr)
|
||||
action_set.scroll_previewer(prompt_bufnr, 1)
|
||||
function actions.preview_scrolling_down(prompt_bufnr, entry)
|
||||
action_set.scroll_previewer(prompt_bufnr, entry, 1)
|
||||
end
|
||||
|
||||
function actions.center(_)
|
||||
vim.cmd(':normal! zz')
|
||||
end
|
||||
|
||||
--- THIS DOESNT ACTUALLY EXIST YET
|
||||
function actions.select_multi_default(prompt_bufnr)
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local picker = action_state.get_current_picker()
|
||||
local manager = picker.manager
|
||||
|
||||
for entry in manager:iter() do
|
||||
action_set.select(entry)
|
||||
action_set.select(prompt_bufnr, entry)
|
||||
end
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
end
|
||||
|
||||
function actions.select_default(prompt_bufnr)
|
||||
return action_set.select(prompt_bufnr, "default")
|
||||
function actions.select_default(prompt_bufnr, entry)
|
||||
return action_set.select(prompt_bufnr, entry, "default")
|
||||
end
|
||||
|
||||
function actions.select_horizontal(prompt_bufnr)
|
||||
return action_set.select(prompt_bufnr, "horizontal")
|
||||
function actions.select_horizontal(prompt_bufnr, entry)
|
||||
return action_set.select(prompt_bufnr, entry, "horizontal")
|
||||
end
|
||||
|
||||
function actions.select_vertical(prompt_bufnr)
|
||||
return action_set.select(prompt_bufnr, "vertical")
|
||||
function actions.select_vertical(prompt_bufnr, entry)
|
||||
return action_set.select(prompt_bufnr, entry, "vertical")
|
||||
end
|
||||
|
||||
function actions.select_tab(prompt_bufnr)
|
||||
return action_set.select(prompt_bufnr, "tab")
|
||||
function actions.select_tab(prompt_bufnr, entry)
|
||||
return action_set.select(prompt_bufnr, entry, "tab")
|
||||
end
|
||||
|
||||
-- TODO: consider adding float!
|
||||
-- https://github.com/nvim-telescope/telescope.nvim/issues/365
|
||||
|
||||
function actions.file_edit(prompt_bufnr)
|
||||
return action_set.edit(prompt_bufnr, "edit")
|
||||
function actions.file_edit(prompt_bufnr, entry)
|
||||
return action_set.edit(prompt_bufnr, entry, "edit")
|
||||
end
|
||||
|
||||
function actions.file_split(prompt_bufnr)
|
||||
return action_set.edit(prompt_bufnr, "new")
|
||||
function actions.file_split(prompt_bufnr, entry)
|
||||
return action_set.edit(prompt_bufnr, entry, "new")
|
||||
end
|
||||
|
||||
function actions.file_vsplit(prompt_bufnr)
|
||||
return action_set.edit(prompt_bufnr, "vnew")
|
||||
function actions.file_vsplit(prompt_bufnr, entry)
|
||||
return action_set.edit(prompt_bufnr, entry, "vnew")
|
||||
end
|
||||
|
||||
function actions.file_tab(prompt_bufnr)
|
||||
return action_set.edit(prompt_bufnr, "tabedit")
|
||||
function actions.file_tab(prompt_bufnr, entry)
|
||||
return action_set.edit(prompt_bufnr, entry, "tabedit")
|
||||
end
|
||||
|
||||
function actions.close_pum(_)
|
||||
@@ -168,8 +177,7 @@ function actions.close_pum(_)
|
||||
end
|
||||
|
||||
actions._close = function(prompt_bufnr, keepinsert)
|
||||
log.warn("Closing:", prompt_bufnr)
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local picker = action_state.get_current_picker()
|
||||
local prompt_win = state.get_status(prompt_bufnr).prompt_win
|
||||
local original_win_id = picker.original_win_id
|
||||
|
||||
@@ -202,30 +210,30 @@ actions.edit_command_line = function(prompt_bufnr, entry)
|
||||
a.nvim_feedkeys(a.nvim_replace_termcodes(":" .. entry.value , true, false, true), "t", true)
|
||||
end
|
||||
|
||||
actions.set_command_line = function(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry(prompt_bufnr)
|
||||
actions.set_command_line = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
vim.fn.histadd("cmd", entry.value)
|
||||
vim.cmd(entry.value)
|
||||
end
|
||||
|
||||
actions.edit_search_line = function(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry(prompt_bufnr)
|
||||
actions.edit_search_line = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
actions.close(prompt_bufnr)
|
||||
a.nvim_feedkeys(a.nvim_replace_termcodes("/" .. entry.value , true, false, true), "t", true)
|
||||
end
|
||||
|
||||
actions.set_search_line = function(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry(prompt_bufnr)
|
||||
actions.set_search_line = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
a.nvim_feedkeys(a.nvim_replace_termcodes("/" .. entry.value .. "<CR>", true, false, true), "t", true)
|
||||
end
|
||||
|
||||
actions.edit_register = function(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry(prompt_bufnr)
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
actions.edit_register = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
local picker = action_state.get_current_picker()
|
||||
|
||||
vim.fn.inputsave()
|
||||
local updated_value = vim.fn.input("Edit [" .. entry.value .. "] ❯ ", entry.content)
|
||||
@@ -245,8 +253,8 @@ actions.edit_register = function(prompt_bufnr)
|
||||
-- print(vim.inspect(picker.finder.results))
|
||||
end
|
||||
|
||||
actions.paste_register = function(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry(prompt_bufnr)
|
||||
actions.paste_register = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
|
||||
@@ -262,10 +270,10 @@ actions.paste_register = function(prompt_bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
actions.run_builtin = function(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry(prompt_bufnr)
|
||||
actions.run_builtin = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
actions._close(prompt_bufnr, true)
|
||||
actions._close(prompt_bufnr, true)
|
||||
require('telescope.builtin')[entry.text]()
|
||||
end
|
||||
|
||||
@@ -276,8 +284,8 @@ actions.insert_symbol = function(prompt_bufnr)
|
||||
end
|
||||
|
||||
-- TODO: Think about how to do this.
|
||||
actions.insert_value = function(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry(prompt_bufnr)
|
||||
actions.insert_value = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
vim.schedule(function()
|
||||
actions.close(prompt_bufnr)
|
||||
@@ -318,9 +326,10 @@ end
|
||||
|
||||
--- Checkout an existing git branch
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
actions.git_checkout = function(prompt_bufnr)
|
||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||
local selection = action_state.get_selected_entry()
|
||||
actions.git_checkout = function(prompt_bufnr, selection)
|
||||
selection = selection or action_state.get_selected_entry()
|
||||
|
||||
local cwd = action_state.get_current_picker().cwd
|
||||
actions.close(prompt_bufnr)
|
||||
local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', selection.value }, cwd)
|
||||
if ret == 0 then
|
||||
@@ -336,17 +345,18 @@ end
|
||||
|
||||
--- Tell git to track the currently selected remote branch in Telescope
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
actions.git_track_branch = function(prompt_bufnr)
|
||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||
local selection = action_state.get_selected_entry()
|
||||
actions.git_track_branch = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
local cwd = action_state.get_current_picker().cwd
|
||||
actions.close(prompt_bufnr)
|
||||
local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', '--track', selection.value }, cwd)
|
||||
local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', '--track', entry.value }, cwd)
|
||||
if ret == 0 then
|
||||
print("Tracking branch: " .. selection.value)
|
||||
print("Tracking branch: " .. entry.value)
|
||||
else
|
||||
print(string.format(
|
||||
'Error when tracking branch: %s. Git returned: "%s"',
|
||||
selection.value,
|
||||
entry.value,
|
||||
table.concat(stderr, ' ')
|
||||
))
|
||||
end
|
||||
@@ -355,21 +365,22 @@ end
|
||||
-- TODO: add this function header back once the treesitter max-query bug is resolved
|
||||
-- Delete the currently selected branch
|
||||
-- @param prompt_bufnr number: The prompt bufnr
|
||||
actions.git_delete_branch = function(prompt_bufnr)
|
||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||
local selection = action_state.get_selected_entry()
|
||||
actions.git_delete_branch = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
local confirmation = vim.fn.input('Do you really wanna delete branch ' .. selection.value .. '? [Y/n] ')
|
||||
local cwd = action_state.get_current_picker().cwd
|
||||
|
||||
local confirmation = vim.fn.input('Do you really wanna delete branch ' .. entry.value .. '? [Y/n] ')
|
||||
if confirmation ~= '' and string.lower(confirmation) ~= 'y' then return end
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
local _, ret, stderr = utils.get_os_command_output({ 'git', 'branch', '-D', selection.value }, cwd)
|
||||
local _, ret, stderr = utils.get_os_command_output({ 'git', 'branch', '-D', entry.value }, cwd)
|
||||
if ret == 0 then
|
||||
print("Deleted branch: " .. selection.value)
|
||||
print("Deleted branch: " .. entry.value)
|
||||
else
|
||||
print(string.format(
|
||||
'Error when deleting branch: %s. Git returned: "%s"',
|
||||
selection.value,
|
||||
entry.value,
|
||||
table.concat(stderr, ' ')
|
||||
))
|
||||
end
|
||||
@@ -378,21 +389,22 @@ end
|
||||
-- TODO: add this function header back once the treesitter max-query bug is resolved
|
||||
-- Rebase to selected git branch
|
||||
-- @param prompt_bufnr number: The prompt bufnr
|
||||
actions.git_rebase_branch = function(prompt_bufnr)
|
||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||
local selection = action_state.get_selected_entry()
|
||||
actions.git_rebase_branch = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
local confirmation = vim.fn.input('Do you really wanna rebase branch ' .. selection.value .. '? [Y/n] ')
|
||||
local cwd = action_state.get_current_picker().cwd
|
||||
|
||||
local confirmation = vim.fn.input('Do you really wanna rebase branch ' .. entry.value .. '? [Y/n] ')
|
||||
if confirmation ~= '' and string.lower(confirmation) ~= 'y' then return end
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
local _, ret, stderr = utils.get_os_command_output({ 'git', 'rebase', selection.value }, cwd)
|
||||
local _, ret, stderr = utils.get_os_command_output({ 'git', 'rebase', entry.value }, cwd)
|
||||
if ret == 0 then
|
||||
print("Rebased branch: " .. selection.value)
|
||||
print("Rebased branch: " .. entry.value)
|
||||
else
|
||||
print(string.format(
|
||||
'Error when rebasing branch: %s. Git returned: "%s"',
|
||||
selection.value,
|
||||
entry.value,
|
||||
table.concat(stderr, ' ')
|
||||
))
|
||||
end
|
||||
@@ -401,14 +413,14 @@ end
|
||||
-- TODO: add this function header back once the treesitter max-query bug is resolved
|
||||
-- Stage/unstage selected file
|
||||
-- @param prompt_bufnr number: The prompt bufnr
|
||||
actions.git_staging_toggle = function(prompt_bufnr)
|
||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||
local selection = action_state.get_selected_entry()
|
||||
actions.git_staging_toggle = function(prompt_bufnr, entry)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
if selection.status:sub(2) == ' ' then
|
||||
utils.get_os_command_output({ 'git', 'restore', '--staged', selection.value }, cwd)
|
||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||
if entry.status:sub(2) == ' ' then
|
||||
utils.get_os_command_output({ 'git', 'restore', '--staged', entry.value }, cwd)
|
||||
else
|
||||
utils.get_os_command_output({ 'git', 'add', selection.value }, cwd)
|
||||
utils.get_os_command_output({ 'git', 'add', entry.value }, cwd)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -449,6 +461,10 @@ local send_all_to_qf = function(prompt_bufnr, mode)
|
||||
vim.fn.setqflist(qf_entries, mode)
|
||||
end
|
||||
|
||||
--- TODO: These would be good candidates for thinking about how to add them
|
||||
--- one at a time OR with the list of items.
|
||||
---
|
||||
--- Very cool
|
||||
actions.send_selected_to_qflist = function(prompt_bufnr)
|
||||
send_selected_to_qf(prompt_bufnr, 'r')
|
||||
end
|
||||
@@ -466,7 +482,7 @@ actions.add_to_qflist = function(prompt_bufnr)
|
||||
end
|
||||
|
||||
local smart_send = function(prompt_bufnr, mode)
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local picker = action_state.get_current_picker()
|
||||
if table.getn(picker:get_multi_selection()) > 0 then
|
||||
send_selected_to_qf(prompt_bufnr, mode)
|
||||
else
|
||||
@@ -482,8 +498,8 @@ actions.smart_add_to_qflist = function(prompt_bufnr)
|
||||
smart_send(prompt_bufnr, 'a')
|
||||
end
|
||||
|
||||
actions.complete_tag = function(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
actions.complete_tag = function()
|
||||
local current_picker = action_state.get_current_picker()
|
||||
local tags = current_picker.sorter.tags
|
||||
local delimiter = current_picker.sorter._delimiter
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
--- a vertical split, etc. Instead of making users have to overwrite EACH
|
||||
--- of those every time they want to change this behavior, they can instead
|
||||
--- replace the `set` itself and then it will work great and they're done.
|
||||
---
|
||||
--- The first two arguments of all action sets are:
|
||||
--- function(prompt_bufnr, entry, ...)
|
||||
---
|
||||
---@brief ]]
|
||||
|
||||
local a = vim.api
|
||||
@@ -30,11 +34,11 @@ local action_set = setmetatable({}, {
|
||||
--- Handles not overflowing / underflowing the list.
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param change number: The amount to shift the selection by
|
||||
action_set.shift_selection = function(prompt_bufnr, change)
|
||||
action_set.shift_selection = function(prompt_bufnr, _, change)
|
||||
local count = vim.v.count
|
||||
count = count == 0 and 1 or count
|
||||
count = a.nvim_get_mode().mode == "n" and count or 1
|
||||
action_state.get_current_picker(prompt_bufnr):move_selection(change * count)
|
||||
action_state.get_current_picker():move_selection(change * count)
|
||||
end
|
||||
|
||||
--- Select the current entry. This is the action set to overwrite common
|
||||
@@ -44,8 +48,8 @@ end
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param type string: The type of selection to make
|
||||
-- Valid types include: "default", "horizontal", "vertical", "tabedit"
|
||||
action_set.select = function(prompt_bufnr, type)
|
||||
return action_set.edit(prompt_bufnr, action_state.select_key_to_edit_key(type))
|
||||
action_set.select = function(prompt_bufnr, entry, type)
|
||||
return action_set.edit(prompt_bufnr, entry, action_state.select_key_to_edit_key(type))
|
||||
end
|
||||
|
||||
local edit_buffer
|
||||
@@ -70,8 +74,8 @@ end
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param command string: The command to use to open the file.
|
||||
-- Valid commands include: "edit", "new", "vedit", "tabedit"
|
||||
action_set.edit = function(prompt_bufnr, command)
|
||||
local entry = action_state.get_selected_entry()
|
||||
action_set.edit = function(prompt_bufnr, entry, command)
|
||||
entry = entry or action_state.get_selected_entry()
|
||||
|
||||
if not entry then
|
||||
print("[telescope] Nothing currently selected")
|
||||
@@ -134,12 +138,12 @@ end
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param direction number: The direction of the scrolling
|
||||
-- Valid directions include: "1", "-1"
|
||||
action_set.scroll_previewer = function (prompt_bufnr, direction)
|
||||
action_set.scroll_previewer = function (prompt_bufnr, _, direction)
|
||||
local status = state.get_status(prompt_bufnr)
|
||||
local default_speed = vim.api.nvim_win_get_height(status.preview_win) / 2
|
||||
local speed = status.picker.layout_config.scroll_speed or default_speed
|
||||
|
||||
action_state.get_current_picker(prompt_bufnr).previewer:scroll_fn(math.floor(speed * direction))
|
||||
action_state.get_current_picker().previewer:scroll_fn(math.floor(speed * direction))
|
||||
end
|
||||
|
||||
-- ==================================================
|
||||
|
||||
@@ -21,9 +21,8 @@ function action_state.get_current_line()
|
||||
end
|
||||
|
||||
--- Gets the current picker
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
function action_state.get_current_picker(prompt_bufnr)
|
||||
return global_state.get_status(prompt_bufnr).picker
|
||||
function action_state.get_current_picker()
|
||||
return global_state.get_current_picker()
|
||||
end
|
||||
|
||||
local select_to_edit_map = {
|
||||
|
||||
@@ -228,6 +228,10 @@ mappings.execute_keymap = function(prompt_bufnr, keymap_identifier)
|
||||
)
|
||||
)
|
||||
|
||||
-- TODO(multi_action): Shoudl we just pass the entry here by default?
|
||||
-- Then we could remove all the cases where we're getting the entry in actions.
|
||||
-- ...
|
||||
-- Hmmm or we don't do that, so that it's not surprising?
|
||||
key_func(prompt_bufnr)
|
||||
end
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ function Picker:find()
|
||||
-- TODO: We need to center this and make it prettier...
|
||||
local prompt_win, prompt_opts = popup.create('', popup_opts.prompt)
|
||||
local prompt_bufnr = a.nvim_win_get_buf(prompt_win)
|
||||
a.nvim_buf_set_name(prompt_bufnr, self.prompt_title)
|
||||
a.nvim_win_set_option(prompt_win, 'winhl', 'Normal:TelescopeNormal')
|
||||
a.nvim_win_set_option(prompt_win, 'winblend', self.window.winblend)
|
||||
local prompt_border_win = prompt_opts.border and prompt_opts.border.win_id
|
||||
@@ -1044,7 +1045,7 @@ end
|
||||
|
||||
|
||||
function Picker:teardown()
|
||||
log.warn("CLEARING PICKER NOW")
|
||||
log.trace("Clearing picker now")
|
||||
|
||||
if self.sorter then
|
||||
self.sorter:_destroy()
|
||||
@@ -1057,9 +1058,6 @@ function Picker:teardown()
|
||||
for k, _ in pairs(self) do
|
||||
self[k] = nil
|
||||
end
|
||||
|
||||
collectgarbage()
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
pickers._Picker = Picker
|
||||
|
||||
Reference in New Issue
Block a user