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

@@ -75,12 +75,12 @@ action_generate.refine = function(prompt_bufnr, opts)
end
-- title
if opts.prompt_title and current_picker.prompt_border then
current_picker.prompt_border:change_title(opts.prompt_title)
if opts.prompt_title and current_picker.layout.prompt.border then
current_picker.layout.prompt.border:change_title(opts.prompt_title)
end
if opts.results_title and current_picker.results_border then
current_picker.results_border:change_title(opts.results_title)
if opts.results_title and current_picker.layout.results.border then
current_picker.layout.results.border:change_title(opts.results_title)
end
local results = {}

View File

@@ -26,10 +26,11 @@ action_layout.toggle_preview = function(prompt_bufnr)
local picker = action_state.get_current_picker(prompt_bufnr)
local status = state.get_status(picker.prompt_bufnr)
if picker.previewer and status.preview_win then
local preview_winid = status.layout.preview and status.layout.preview.winid
if picker.previewer and preview_winid then
picker.hidden_previewer = picker.previewer
picker.previewer = nil
elseif picker.hidden_previewer and not status.preview_win then
elseif picker.hidden_previewer and not preview_winid then
picker.previewer = picker.hidden_previewer
picker.hidden_previewer = nil
else

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)