fix: Dropdown theme positioning #96

fix: Dropdown theme positioning
This commit is contained in:
Dave Lage
2020-09-18 02:26:13 -04:00
committed by GitHub
2 changed files with 22 additions and 25 deletions

View File

@@ -292,7 +292,7 @@ Common groups of settings can be setup to allow for themes. We have some built i
### Dropdown ### Dropdown
![Dropdown layout](https://i.imgur.com/bQKiEkh.png) ![Dropdown layout](https://i.imgur.com/S3DE30I.png)
```vim ```vim
nnoremap <Leader>f :lua require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({}))<cr> nnoremap <Leader>f :lua require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({}))<cr>

View File

@@ -112,19 +112,24 @@ layout_strategies.horizontal = function(self, max_columns, max_lines, prompt_tit
end end
--[[ --[[
+-----------------+ +--------------+
| Prompt | | Preview |
+-----------------+ +--------------+
| Result | | Prompt |
| Result | +--------------+
| Result | | Result |
+-----------------+ | Result |
| Result |
+--------------+
--]] --]]
-- Check if there are any borders. Right now it's a little raw as -- Check if there are any borders. Right now it's a little raw as
-- there are a few things that contribute to the border -- there are a few things that contribute to the border
local is_borderless = function(opts) local is_borderless = function(opts)
if opts.window.border == false then return true else return false end return opts.window.border == false
end end
layout_strategies.center = function(self, columns, lines, prompt_title) layout_strategies.center = function(self, columns, lines, prompt_title)
@@ -133,18 +138,9 @@ layout_strategies.center = function(self, columns, lines, prompt_title)
local results = initial_options.results local results = initial_options.results
local prompt = initial_options.prompt local prompt = initial_options.prompt
local max_results = self.max_results or 15 local max_results = 15
local width = resolve.resolve_width(function(self, max_columns) local width = resolve.resolve_width(self.window.width)(self, columns)
local width_opts = resolve.win_option(self.window.width)
if width_opts.preview > max_columns then
return max_columns
end
return width_opts.preview
end)(self, columns)
-- All width's will likely result in the same width. Can be more specific with inquiry.
local max_width = (width > columns and columns or width) local max_width = (width > columns and columns or width)
prompt.height = 1 prompt.height = 1
@@ -154,9 +150,11 @@ layout_strategies.center = function(self, columns, lines, prompt_title)
results.width = max_width results.width = max_width
preview.width = max_width preview.width = max_width
local bs = 1 -- border size -- border size
local bs = 1
if is_borderless(self) then bs = 0 end if is_borderless(self) then
bs = 0
end
prompt.line = (lines / 2) - ((max_results + (bs * 2)) / 2) prompt.line = (lines / 2) - ((max_results + (bs * 2)) / 2)
results.line = prompt.line + prompt.height + (bs * 2) results.line = prompt.line + prompt.height + (bs * 2)
@@ -168,8 +166,7 @@ layout_strategies.center = function(self, columns, lines, prompt_title)
preview.height = 0 preview.height = 0
end end
-- Get left column, after centering, appling the width, and the border size results.col = math.ceil((columns / 2) - (width / 2) - bs)
results.col = (columns / 2) - (width / 2) + (bs * 2)
prompt.col = results.col prompt.col = results.col
preview.col = results.col preview.col = results.col