From d20be453a82b7fc6e54c8424133218b4032962a7 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 27 Aug 2020 23:41:17 -0400 Subject: [PATCH] feat: default cut off for preview --- lua/telescope/pickers.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index b9f0010..3b70235 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -44,7 +44,7 @@ function Picker:new(opts) }, Picker) end -function Picker:get_window_options(max_columns, max_lines, prompt_title) +function Picker:get_window_options(max_columns, max_lines, prompt_title, find_options) local preview = { border = {}, enter = false, @@ -63,7 +63,7 @@ function Picker:get_window_options(max_columns, max_lines, prompt_title) -- TODO: Test with 120 width terminal local width_padding = 10 - if not self.previewer then + if not self.previewer or max_columns < find_options.preview_cutoff then preview.width = 0 elseif max_columns < 150 then width_padding = 5 @@ -107,15 +107,20 @@ function Picker:get_window_options(max_columns, max_lines, prompt_title) preview.line = results.line return { - preview = self.previewer and preview, + preview = preview.width > 0 and preview, results = results, prompt = prompt, } end +-- opts.preview_cutoff = 120 function Picker:find(opts) opts = opts or {} + if opts.preview_cutoff == nil then + opts.preview_cutoff = 120 + end + local finder = opts.finder assert(finder, "Finder is required to do picking") @@ -128,7 +133,7 @@ function Picker:find(opts) -- 1. Prompt window -- 2. Options window -- 3. Preview window - local popup_opts = self:get_window_options(vim.o.columns, vim.o.lines, prompt_string) + local popup_opts = self:get_window_options(vim.o.columns, vim.o.lines, prompt_string, opts) -- TODO: Add back the borders after fixing some stuff in popup.nvim local results_win, results_opts = popup.create('', popup_opts.results)