feat: results scrolling actions (#1436)
This commit is contained in:
@@ -2190,7 +2190,20 @@ action_set.edit({prompt_bufnr}, {command}) *action_set.edit()*
|
||||
|
||||
|
||||
action_set.scroll_previewer({prompt_bufnr}, {direction}) *action_set.scroll_previewer()*
|
||||
Scrolls the previewer up or down
|
||||
Scrolls the previewer up or down. Defaults to a half page scroll, but can
|
||||
be overridden using the `scroll_speed` option in `layout_config`. See
|
||||
|telescope.layout| for more details.
|
||||
|
||||
|
||||
Parameters: ~
|
||||
{prompt_bufnr} (number) The prompt bufnr
|
||||
{direction} (number) The direction of the scrolling
|
||||
|
||||
|
||||
action_set.scroll_results({prompt_bufnr}, {direction}) *action_set.scroll_results()*
|
||||
Scrolls the results up or down. Defaults to a half page scroll, but can be
|
||||
overridden using the `scroll_speed` option in `layout_config`. See
|
||||
|telescope.layout| for more details.
|
||||
|
||||
|
||||
Parameters: ~
|
||||
|
||||
@@ -152,6 +152,14 @@ function actions.preview_scrolling_down(prompt_bufnr)
|
||||
action_set.scroll_previewer(prompt_bufnr, 1)
|
||||
end
|
||||
|
||||
function actions.results_scrolling_up(prompt_bufnr)
|
||||
action_set.scroll_results(prompt_bufnr, -1)
|
||||
end
|
||||
|
||||
function actions.results_scrolling_down(prompt_bufnr)
|
||||
action_set.scroll_results(prompt_bufnr, 1)
|
||||
end
|
||||
|
||||
function actions.center(_)
|
||||
vim.cmd ":normal! zz"
|
||||
end
|
||||
|
||||
@@ -143,7 +143,9 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
end
|
||||
end
|
||||
|
||||
--- Scrolls the previewer up or down
|
||||
--- Scrolls the previewer up or down.
|
||||
--- Defaults to a half page scroll, but can be overridden using the `scroll_speed`
|
||||
--- option in `layout_config`. See |telescope.layout| for more details.
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param direction number: The direction of the scrolling
|
||||
-- Valid directions include: "1", "-1"
|
||||
@@ -162,6 +164,26 @@ action_set.scroll_previewer = function(prompt_bufnr, direction)
|
||||
previewer:scroll_fn(math.floor(speed * direction))
|
||||
end
|
||||
|
||||
--- Scrolls the results up or down.
|
||||
--- Defaults to a half page scroll, but can be overridden using the `scroll_speed`
|
||||
--- option in `layout_config`. See |telescope.layout| for more details.
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param direction number: The direction of the scrolling
|
||||
-- Valid directions include: "1", "-1"
|
||||
action_set.scroll_results = function(prompt_bufnr, direction)
|
||||
local status = state.get_status(prompt_bufnr)
|
||||
local default_speed = vim.api.nvim_win_get_height(status.results_win) / 2
|
||||
local speed = status.picker.layout_config.scroll_speed or default_speed
|
||||
|
||||
local input = direction > 0 and [[]] or [[]]
|
||||
|
||||
vim.api.nvim_win_call(status.results_win, function()
|
||||
vim.cmd([[normal! ]] .. math.floor(speed) .. input)
|
||||
end)
|
||||
|
||||
action_set.shift_selection(prompt_bufnr, math.floor(speed) * direction)
|
||||
end
|
||||
|
||||
-- ==================================================
|
||||
-- Transforms modules and sets the corect metatables.
|
||||
-- ==================================================
|
||||
|
||||
@@ -25,6 +25,9 @@ mappings.default_mappings = config.values.default_mappings
|
||||
["<C-u>"] = actions.preview_scrolling_up,
|
||||
["<C-d>"] = actions.preview_scrolling_down,
|
||||
|
||||
["<PageUp>"] = actions.results_scrolling_up,
|
||||
["<PageDown>"] = actions.results_scrolling_down,
|
||||
|
||||
["<Tab>"] = actions.toggle_selection + actions.move_selection_worse,
|
||||
["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better,
|
||||
["<C-q>"] = actions.send_to_qflist + actions.open_qflist,
|
||||
@@ -59,6 +62,10 @@ mappings.default_mappings = config.values.default_mappings
|
||||
|
||||
["<C-u>"] = actions.preview_scrolling_up,
|
||||
["<C-d>"] = actions.preview_scrolling_down,
|
||||
|
||||
["<PageUp>"] = actions.results_scrolling_up,
|
||||
["<PageDown>"] = actions.results_scrolling_down,
|
||||
|
||||
["?"] = actions.which_key,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user