wip: some more musings on resolving height and width
This commit is contained in:
@@ -87,21 +87,41 @@ local get_default = require('telescope.utils').get_default
|
|||||||
|
|
||||||
local resolver = {}
|
local resolver = {}
|
||||||
|
|
||||||
local percentage_resolver = function(selector, percentage)
|
local _resolve_map = {
|
||||||
assert(percentage <= 1)
|
-- Percentages
|
||||||
assert(percentage >= 0)
|
[function(val) return type(val) == 'number' and val > 0 and val <= 1 end] = function(selector, val)
|
||||||
|
|
||||||
return function(...)
|
return function(...)
|
||||||
return percentage * select(selector, ...)
|
return math.floor(val * select(selector, ...))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
-- Numbers
|
||||||
|
[function(val) return type(val) == 'number' and val > 1 end] = function(selector, val)
|
||||||
|
return function(...)
|
||||||
|
return math.min(val, select(selector, ...))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
resolver.resolve_height = function(val)
|
||||||
|
for k, v in pairs(_resolve_map) do
|
||||||
|
if k(val) then
|
||||||
|
return v(3, val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resolver.resolve_percentage_height = function(percentage)
|
error('invalid configuration option for height:' .. tostring(val))
|
||||||
return percentage_resolver(3, percentage)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
resolver.resolve_percentage_width = function(percentage)
|
resolver.resolve_width = function(val)
|
||||||
return percentage_resolver(2, percentage)
|
for k, v in pairs(_resolve_map) do
|
||||||
|
if k(val) then
|
||||||
|
return v(2, val)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
error('invalid configuration option for height:' .. tostring(val))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Win option always returns a table with preview, results, and prompt.
|
--- Win option always returns a table with preview, results, and prompt.
|
||||||
|
|||||||
@@ -288,7 +288,6 @@ function Picker:find()
|
|||||||
a.nvim_win_set_option(prompt_win, 'winblend', self.window.winblend)
|
a.nvim_win_set_option(prompt_win, 'winblend', self.window.winblend)
|
||||||
|
|
||||||
a.nvim_win_set_option(prompt_win, 'winhl', 'Normal:TelescopeNormal')
|
a.nvim_win_set_option(prompt_win, 'winhl', 'Normal:TelescopeNormal')
|
||||||
pcall(a.nvim_buf_set_option, prompt_bufnr, 'filetype', 'TelescopePrompt')
|
|
||||||
|
|
||||||
-- a.nvim_buf_set_option(prompt_bufnr, 'buftype', 'prompt')
|
-- a.nvim_buf_set_option(prompt_bufnr, 'buftype', 'prompt')
|
||||||
-- vim.fn.prompt_setprompt(prompt_bufnr, prompt_string)
|
-- vim.fn.prompt_setprompt(prompt_bufnr, prompt_string)
|
||||||
@@ -311,6 +310,7 @@ function Picker:find()
|
|||||||
local displayed_amount = 0
|
local displayed_amount = 0
|
||||||
local displayed_fn_amount = 0
|
local displayed_fn_amount = 0
|
||||||
|
|
||||||
|
-- TODO: Entry manager should have a "bulk" setter. This can prevent a lot of redraws from display
|
||||||
self.manager = pickers.entry_manager(
|
self.manager = pickers.entry_manager(
|
||||||
self.max_results,
|
self.max_results,
|
||||||
vim.schedule_wrap(function(index, entry)
|
vim.schedule_wrap(function(index, entry)
|
||||||
@@ -471,6 +471,9 @@ function Picker:find()
|
|||||||
|
|
||||||
mappings.apply_keymap(prompt_bufnr, self.attach_mappings, default_mappings)
|
mappings.apply_keymap(prompt_bufnr, self.attach_mappings, default_mappings)
|
||||||
|
|
||||||
|
-- Do filetype last, so that users can register at the last second.
|
||||||
|
pcall(a.nvim_buf_set_option, prompt_bufnr, 'filetype', 'TelescopePrompt')
|
||||||
|
|
||||||
if self.default_text then
|
if self.default_text then
|
||||||
vim.api.nvim_buf_set_lines(prompt_bufnr, 0, 1, false, {self.default_text})
|
vim.api.nvim_buf_set_lines(prompt_bufnr, 0, 1, false, {self.default_text})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ eq('a', opt.preview)
|
|||||||
eq('b', opt.prompt)
|
eq('b', opt.prompt)
|
||||||
eq('c', opt.results)
|
eq('c', opt.results)
|
||||||
|
|
||||||
|
|
||||||
|
eq(10, resolve.resolve_height(0.1)(nil, 24, 100))
|
||||||
|
eq(2, resolve.resolve_width(0.1)(nil, 24, 100))
|
||||||
|
|
||||||
|
eq(10, resolve.resolve_width(10)(nil, 24, 100))
|
||||||
|
eq(24, resolve.resolve_width(50)(nil, 24, 100))
|
||||||
|
|
||||||
-- local true_table = {true}
|
-- local true_table = {true}
|
||||||
-- opt = resolve.win_option(some_specified, 'a')
|
-- opt = resolve.win_option(some_specified, 'a')
|
||||||
-- eq('a', opt.preview)
|
-- eq('a', opt.preview)
|
||||||
|
|||||||
Reference in New Issue
Block a user