From 7cfddbfd93a1fbd4bc7158ec66cbc5d43cd93567 Mon Sep 17 00:00:00 2001 From: max397574 <81827001+max397574@users.noreply.github.com> Date: Sun, 28 Nov 2021 18:32:50 +0100 Subject: [PATCH] feat: add `preview width` option for `bottom_pane` layout (#1505) * feat(layout_strategies): started adding preview width for bottom pane * fix(bottom_pane preview_width): fixed some values and added defualt * fix(config): better default for preview cutoff * fix(layout): removed unnecessary variable value --- lua/telescope/config.lua | 1 + lua/telescope/pickers/layout_strategies.lua | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index a57ec7f..ccce136 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -108,6 +108,7 @@ local layout_config_defaults = { bottom_pane = { height = 25, prompt_position = "top", + preview_cutoff = 120, }, } diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua index 271fc72..706c3e7 100644 --- a/lua/telescope/pickers/layout_strategies.lua +++ b/lua/telescope/pickers/layout_strategies.lua @@ -778,6 +778,7 @@ end) layout_strategies.bottom_pane = make_documented_layout( "bottom_pane", vim.tbl_extend("error", shared_options, { + preview_width = { "Change the width of Telescope's preview window", "See |resolver.resolve_width()|" }, prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" }, }), function(self, max_columns, max_lines, layout_config) @@ -806,13 +807,20 @@ layout_strategies.bottom_pane = make_documented_layout( results.height = height - prompt.height - (2 * bs) preview.height = results.height - bs + local width + -- Width prompt.width = max_columns - 2 * bs - -- TODO(l-kershaw): add a preview_cutoff option - if self.previewer then - -- TODO(l-kershaw): make configurable - results.width = math.floor(max_columns / 2) - 2 * bs - preview.width = max_columns - results.width - 4 * bs + local w_space + if self.previewer and max_columns >= layout_config.preview_cutoff then + -- Cap over/undersized width (with preview) + width, w_space = calc_size_and_spacing(max_columns, max_columns, bs, 2, 4, 0) + + preview.width = resolve.resolve_width(if_nil(layout_config.preview_width, function(_, _) + -- By default, previewer takes 1/2 of the layout + return math.floor(width / 2) + end))(self, width, max_lines) + results.width = width - preview.width - w_space else results.width = prompt.width preview.width = 0