From 0ab858d9fedf962abca2237c6de1344780e46b45 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 15 Sep 2020 13:10:34 -0400 Subject: [PATCH] feat: (wip) current_buffer strategy --- lua/telescope/pickers/layout_strategies.lua | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua index 6397254..b8fe6d1 100644 --- a/lua/telescope/pickers/layout_strategies.lua +++ b/lua/telescope/pickers/layout_strategies.lua @@ -156,6 +156,62 @@ layout_strategies.flex = function(self, max_columns, max_lines, prompt_title) end end +layout_strategies.current_buffer = function(self, _, _, prompt_title) + local initial_options = self:_get_initial_window_options(prompt_title) + + local window_width = vim.api.nvim_win_get_width(0) + local window_height = vim.api.nvim_win_get_height(0) + + local preview = initial_options.preview + local results = initial_options.results + local prompt = initial_options.prompt + + local width_padding = 2 + local width = window_width - width_padding * 2 + if not self.previewer then + preview.width = 0 + else + preview.width = width + end + results.width = width + prompt.width = width + + -- Height + local height_padding = 3 + + results.height = 10 + prompt.height = 1 + + -- The last 2 * 2 is for the extra borders + if self.previewer then + preview.height = window_height - results.height - prompt.height - 2 * 2 - height_padding * 2 + else + results.height = window_height - prompt.height - 2 - height_padding * 2 + end + + + local win_position = vim.api.nvim_win_get_position(0) + + local line = win_position[1] + if self.previewer then + preview.line = height_padding + line + results.line = preview.line + preview.height + 2 + prompt.line = results.line + results.height + 2 + else + results.line = height_padding + line + prompt.line = results.line + results.height + 2 + end + + local col = win_position[2] + width_padding + preview.col, results.col, prompt.col = col, col, col + + return { + preview = preview.width > 0 and preview, + results = results, + prompt = prompt, + } +end + -- TODO: Add "flex" -- If you don't have enough width, use the height one -- etc.