Skip to content

Commit

Permalink
feat(pickers): custom results height for centered layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 committed Feb 25, 2024
1 parent 2360838 commit 2d97ff4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,7 @@ layout_strategies.center() *telescope.layout.center()*

`picker.layout_config` unique options:
- preview_cutoff: When lines are less than this value, the preview will be disabled
- results_height: Optional height specifically for results window


layout_strategies.cursor() *telescope.layout.cursor()*
Expand Down
12 changes: 12 additions & 0 deletions lua/telescope/pickers/layout_strategies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ layout_strategies.center = make_documented_layout(
"center",
vim.tbl_extend("error", shared_options, {
preview_cutoff = "When lines are less than this value, the preview will be disabled",
results_height = "Optional height specifically for results window",
}),
function(self, max_columns, max_lines, layout_config)
local initial_options = p_window.get_initial_window_options(self)
Expand Down Expand Up @@ -520,6 +521,17 @@ layout_strategies.center = make_documented_layout(
preview.line = preview.line + 1
end

-- set the height of the results window if specified
if layout_config.results_height then
local diff = results.height - resolve.resolve_height(layout_config.results_height)(self, max_columns, max_lines)
results.height = results.height - diff
results.line = results.line + diff
preview.height = preview.height + diff
if layout_config.prompt_position == "top" then
prompt.line = prompt.line + diff
end
end

return {
preview = self.previewer and preview.height > 0 and preview,
results = results,
Expand Down

0 comments on commit 2d97ff4

Please sign in to comment.