summaryrefslogtreecommitdiff
path: root/lua/telescope/pickers
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-09-15 13:10:34 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-09-15 13:10:34 -0400
commit0ab858d9fedf962abca2237c6de1344780e46b45 (patch)
treef2fd0672a7efd22cbd98330ce587042d9688c84b /lua/telescope/pickers
parent5b4458ebea9874bb5c44fdd9b933b584dcb09752 (diff)
feat: (wip) current_buffer strategy
Diffstat (limited to 'lua/telescope/pickers')
-rw-r--r--lua/telescope/pickers/layout_strategies.lua56
1 files changed, 56 insertions, 0 deletions
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.