feat: (wip) current_buffer strategy

This commit is contained in:
TJ DeVries
2020-09-15 13:10:34 -04:00
parent 5b4458ebea
commit 0ab858d9fe

View File

@@ -156,6 +156,62 @@ layout_strategies.flex = function(self, max_columns, max_lines, prompt_title)
end end
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" -- TODO: Add "flex"
-- If you don't have enough width, use the height one -- If you don't have enough width, use the height one
-- etc. -- etc.