diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-09-12 23:15:07 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-09-12 23:15:10 -0400 |
| commit | ebd090c0fe8a3f5acff0897d8724ac0f281db9d2 (patch) | |
| tree | 92ceb719c0f6a02ce55dcc2be79d58327323de3a /lua/telescope | |
| parent | a2acd607b023ab93a611677e0a3a07331f05a28d (diff) | |
wip: some more musings on resolving height and width
Diffstat (limited to 'lua/telescope')
| -rw-r--r-- | lua/telescope/config/resolve.lua | 40 | ||||
| -rw-r--r-- | lua/telescope/pickers.lua | 5 |
2 files changed, 34 insertions, 11 deletions
diff --git a/lua/telescope/config/resolve.lua b/lua/telescope/config/resolve.lua index 5aa9c84..b00d66c 100644 --- a/lua/telescope/config/resolve.lua +++ b/lua/telescope/config/resolve.lua @@ -87,21 +87,41 @@ local get_default = require('telescope.utils').get_default local resolver = {} -local percentage_resolver = function(selector, percentage) - assert(percentage <= 1) - assert(percentage >= 0) +local _resolve_map = { + -- Percentages + [function(val) return type(val) == 'number' and val > 0 and val <= 1 end] = function(selector, val) + return function(...) + 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, + +} - return function(...) - return percentage * select(selector, ...) +resolver.resolve_height = function(val) + for k, v in pairs(_resolve_map) do + if k(val) then + return v(3, val) + end end -end -resolver.resolve_percentage_height = function(percentage) - return percentage_resolver(3, percentage) + error('invalid configuration option for height:' .. tostring(val)) end -resolver.resolve_percentage_width = function(percentage) - return percentage_resolver(2, percentage) +resolver.resolve_width = function(val) + 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 --- Win option always returns a table with preview, results, and prompt. diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 8ce8587..4336558 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -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, 'winhl', 'Normal:TelescopeNormal') - pcall(a.nvim_buf_set_option, prompt_bufnr, 'filetype', 'TelescopePrompt') -- a.nvim_buf_set_option(prompt_bufnr, 'buftype', 'prompt') -- vim.fn.prompt_setprompt(prompt_bufnr, prompt_string) @@ -311,6 +310,7 @@ function Picker:find() local displayed_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.max_results, vim.schedule_wrap(function(index, entry) @@ -471,6 +471,9 @@ function Picker:find() 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 vim.api.nvim_buf_set_lines(prompt_bufnr, 0, 1, false, {self.default_text}) end |
