diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-09-10 21:21:14 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-09-11 00:14:40 -0400 |
| commit | fe387d10db66dc9b33388f05fadabbdc9b31c28b (patch) | |
| tree | e178ea08415c1d0a9387daeb0ee12b5feb10b51c /lua/telescope/pickers | |
| parent | 769f5934f00a49097fec227adbdef62a34d71109 (diff) | |
feat: add top down prompt position
Diffstat (limited to 'lua/telescope/pickers')
| -rw-r--r-- | lua/telescope/pickers/config_collapse.lua | 51 | ||||
| -rw-r--r-- | lua/telescope/pickers/layout_strategies.lua | 15 |
2 files changed, 63 insertions, 3 deletions
diff --git a/lua/telescope/pickers/config_collapse.lua b/lua/telescope/pickers/config_collapse.lua new file mode 100644 index 0000000..286d484 --- /dev/null +++ b/lua/telescope/pickers/config_collapse.lua @@ -0,0 +1,51 @@ + +--[[ + +Ultimately boils down to getting `height` and `width` for: +- prompt +- preview +- results + +No matter what you do, I will not make prompt have more than one line (atm) + +Result of `resolve` should be a table with: + +{ + preview = { + get_width = function(self, max_columns, max_lines) end + get_height = function(self, max_columns, max_lines) end + }, + + result = { + get_width = function(self, max_columns, max_lines) end + get_height = function(self, max_columns, max_lines) end + }, + + prompt = { + get_width = function(self, max_columns, max_lines) return 1end + get_height = function(self, max_columns, max_lines) end + }, +} + +--]] + +local resolver = {} + +local percentage_resolver = function(selector, percentage) + assert(percentage <= 1) + assert(percentage >= 0) + + return function(...) + return percentage * select(selector, ...) + end +end + +resolver.resolve_percentage_height = function(percentage) + return percentage_resolver(3, percentage) +end + +resolver.resolve_percentage_width = function(percentage) + return percentage_resolver(2, percentage) +end + +return resolver diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua index f47fb99..77cb3ab 100644 --- a/lua/telescope/pickers/layout_strategies.lua +++ b/lua/telescope/pickers/layout_strategies.lua @@ -64,9 +64,18 @@ layout_strategies.horizontal = function(self, max_columns, max_lines, prompt_tit -- TODO: Center this in the page a bit better. local height_padding = math.max(math.floor(0.95 * max_lines), 2) - results.line = max_lines - height_padding - prompt.line = results.line + results.height + 2 - preview.line = results.line + + if self.window.prompt_position == "top" then + prompt.line = max_lines - height_padding + results.line = prompt.line + 3 + preview.line = prompt.line + elseif self.window.prompt_position == "bottom" then + results.line = max_lines - height_padding + prompt.line = results.line + results.height + 2 + preview.line = results.line + else + error("Unknown prompt_position: " .. self.window.prompt_position) + end return { preview = preview.width > 0 and preview, |
