Skip to content

Commit

Permalink
feat(pickers): fully customizable layout
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Aug 30, 2023
1 parent 32e6792 commit 6b7c798
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 202 deletions.
8 changes: 4 additions & 4 deletions lua/telescope/actions/generate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
4 changes: 2 additions & 2 deletions lua/telescope/actions/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ 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
if picker.previewer and status.layout.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 status.layout.preview.winid then
picker.previewer = picker.hidden_previewer
picker.hidden_previewer = nil
else
Expand Down
8 changes: 4 additions & 4 deletions lua/telescope/actions/set.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ action_set.scroll_previewer = function(prompt_bufnr, direction)
local status = state.get_status(prompt_bufnr)

-- 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 status.layout.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.layaout.preview.winid) / 2
local speed = status.picker.layout_config.scroll_speed or default_speed

previewer:scroll_fn(math.floor(speed * direction))
Expand Down Expand Up @@ -270,12 +270,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)

Expand Down
4 changes: 2 additions & 2 deletions lua/telescope/builtin/__internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,8 @@ internal.colorscheme = function(opts)
preview_fn = function(_, entry, status)
if not deleted then
deleted = true
del_win(status.preview_win)
del_win(status.preview_border_win)
del_win(status.layout.preview.winid)
del_win(status.layout.preview.border.winid)
end
vim.cmd("colorscheme " .. entry.value)
end,
Expand Down
10 changes: 10 additions & 0 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ append(
Default: 'horizontal']]
)

append(
"create_layout",
nil,
[[
Configure the layout of Telescope pickers.
See |telescope.layout| for details.
Default: 'nil']]
)

append("layout_config", layout_config_defaults, layout_config_description)

append(
Expand Down
Loading

0 comments on commit 6b7c798

Please sign in to comment.