diff options
| author | Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> | 2021-11-13 11:15:07 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-13 11:15:07 +0000 |
| commit | bf77c5d2fab49cf932c9ebfc98be3b7ce2ac3bad (patch) | |
| tree | 1a568b4e3d177dca703faa978262fd31deaea765 /lua/telescope/actions/set.lua | |
| parent | 3d45c6c55537c8c95a6b2ea8653f5a491131def7 (diff) | |
feat: results scrolling actions (#1436)
Diffstat (limited to 'lua/telescope/actions/set.lua')
| -rw-r--r-- | lua/telescope/actions/set.lua | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lua/telescope/actions/set.lua b/lua/telescope/actions/set.lua index 320addd..b7170db 100644 --- a/lua/telescope/actions/set.lua +++ b/lua/telescope/actions/set.lua @@ -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. -- ================================================== |
