Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pickers): custom results height for centered layout #2911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2289,6 +2289,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