feat: center layout mirror option (#1577)

This commit is contained in:
Luke Kershaw
2021-12-10 10:48:14 +00:00
committed by GitHub
parent 991d0127f0
commit 80cdb00b22
2 changed files with 22 additions and 18 deletions

View File

@@ -186,6 +186,7 @@ local shared_options = {
height = { "How tall to make Telescope's entire layout", "See |resolver.resolve_height()|" },
mirror = "Flip the location of the results/prompt and preview windows",
scroll_speed = "The number of lines to scroll through the previewer",
prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
}
-- Used for generating vim help documentation.
@@ -287,7 +288,6 @@ layout_strategies.horizontal = make_documented_layout(
vim.tbl_extend("error", shared_options, {
preview_width = { "Change the width of Telescope's preview window", "See |resolver.resolve_width()|" },
preview_cutoff = "When columns are less than this value, the preview will be disabled",
prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
}),
function(self, max_columns, max_lines, layout_config)
local initial_options = p_window.get_initial_window_options(self)
@@ -412,7 +412,6 @@ 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",
prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
}),
function(self, max_columns, max_lines, layout_config)
local initial_options = p_window.get_initial_window_options(self)
@@ -448,7 +447,7 @@ layout_strategies.center = make_documented_layout(
prompt.height = 1
results.height = height - prompt.height - h_space
local topline = (max_lines / 2) - ((results.height + (2 * bs)) / 2) + 1
local topline = math.floor((max_lines / 2) - ((results.height + (2 * bs)) / 2) + 1)
-- Align the prompt and results so halfway up the screen is
-- in the middle of this combined block
if layout_config.prompt_position == "top" then
@@ -464,11 +463,15 @@ layout_strategies.center = make_documented_layout(
error(string.format("Unknown prompt_position: %s\n%s", self.window.prompt_position, vim.inspect(layout_config)))
end
preview.line = 2
if self.previewer and max_lines >= layout_config.preview_cutoff then
preview.height = math.floor(topline - (3 + bs))
if not layout_config.mirror then
preview.line = 1 + bs
preview.height = topline - (2 * bs + 2)
else
preview.line = topline + (results.height + (2 * bs + 2))
preview.height = max_lines - preview.line + (1 - bs)
end
if not (self.previewer and max_lines >= layout_config.preview_cutoff) then
preview.height = 0
end
@@ -617,7 +620,6 @@ layout_strategies.vertical = make_documented_layout(
vim.tbl_extend("error", shared_options, {
preview_cutoff = "When lines are less than this value, the preview will be disabled",
preview_height = { "Change the height of Telescope's preview window", "See |resolver.resolve_height()|" },
prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
}),
function(self, max_columns, max_lines, layout_config)
local initial_options = p_window.get_initial_window_options(self)
@@ -792,7 +794,6 @@ layout_strategies.bottom_pane = make_documented_layout(
vim.tbl_extend("error", shared_options, {
preview_width = { "Change the width of Telescope's preview window", "See |resolver.resolve_width()|" },
preview_cutoff = "When columns are less than this value, the preview will be disabled",
prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
}),
function(self, max_columns, max_lines, layout_config)
local initial_options = p_window.get_initial_window_options(self)