feat(pickers): fully customizable layout (#2572)

This commit is contained in:
Munif Tanjim
2023-09-27 12:34:22 +06:00
committed by GitHub
parent 5c91b855b8
commit 84d53dfdbe
15 changed files with 648 additions and 201 deletions

View File

@@ -230,12 +230,13 @@ action_set.scroll_previewer = function(prompt_bufnr, direction)
local previewer = action_state.get_current_picker(prompt_bufnr).previewer
local status = state.get_status(prompt_bufnr)
local preview_winid = status.layout.preview and status.layout.preview.winid
-- Check if we actually have a previewer and a preview window
if type(previewer) ~= "table" or previewer.scroll_fn == nil or status.preview_win == nil then
if type(previewer) ~= "table" or previewer.scroll_fn == nil or preview_winid == nil then
return
end
local default_speed = vim.api.nvim_win_get_height(status.preview_win) / 2
local default_speed = vim.api.nvim_win_get_height(status.layout.preview.winid) / 2
local speed = status.picker.layout_config.scroll_speed or default_speed
previewer:scroll_fn(math.floor(speed * direction))
@@ -270,12 +271,12 @@ end
-- 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 default_speed = vim.api.nvim_win_get_height(status.layout.results.winid) / 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.api.nvim_win_call(status.layout.results.winid, function()
vim.cmd([[normal! ]] .. math.floor(speed) .. input)
end)