mirror of
https://github.com/zoriya/telescope.nvim.git
synced 2026-08-16 02:45:09 +00:00
feat: add top down prompt position
This commit is contained in:
@@ -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
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user