Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check if tabline is present when calculating certain layouts #1027

Merged
merged 4 commits into from
Jul 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 49 additions & 13 deletions lua/telescope/pickers/layout_strategies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ local get_border_size = function(opts)
return 1
end

local calc_tabline = function(max_lines)
local tbln = (vim.o.showtabline == 2)
or (vim.o.showtabline == 1 and #vim.api.nvim_list_tabpages() > 1)
if tbln then
max_lines = max_lines - 1
end
return max_lines, tbln
end

local layout_strategies = {}
layout_strategies._configurations = {}

Expand Down Expand Up @@ -245,11 +254,15 @@ layout_strategies.horizontal = make_documented_layout('horizontal', vim.tbl_exte
preview_cutoff = "When columns are less than this value, the preview will be disabled",
prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
}), function(self, max_columns, max_lines, layout_config)

local initial_options = p_window.get_initial_window_options(self)
local preview = initial_options.preview
local results = initial_options.results
local prompt = initial_options.prompt

local tbln
max_lines, tbln = calc_tabline(max_lines)

local width_opt = layout_config.width
local picker_width = resolve.resolve_width(width_opt)(self, max_columns, max_lines)
local width_padding = math.floor((max_columns - picker_width)/2)
Expand Down Expand Up @@ -306,11 +319,17 @@ layout_strategies.horizontal = make_documented_layout('horizontal', vim.tbl_exte
error("Unknown prompt_position: " .. tostring(self.window.prompt_position) .. "\n" .. vim.inspect(layout_config))
end

if tbln then
prompt.line = prompt.line + 1
results.line = results.line + 1
preview.line = preview.line + 1
end

return {
preview = self.previewer and preview.width > 0 and preview,
results = results,
prompt = prompt
}
}
end)

--- Centered layout with a combined block of the prompt
Expand Down Expand Up @@ -342,11 +361,15 @@ end)
layout_strategies.center = make_documented_layout("center", vim.tbl_extend("error", shared_options, {
preview_cutoff = "When lines are less than this value, the preview will be disabled",
}), function(self, max_columns, max_lines,layout_config)

local initial_options = p_window.get_initial_window_options(self)
local preview = initial_options.preview
local results = initial_options.results
local prompt = initial_options.prompt

local tbln
max_lines, tbln = calc_tabline(max_lines)

-- This sets the width for the whole layout
local width_opt = layout_config.width
local width = resolve.resolve_width(width_opt)(self, max_columns, max_lines)
Expand Down Expand Up @@ -384,6 +407,12 @@ layout_strategies.center = make_documented_layout("center", vim.tbl_extend("erro
prompt.col = results.col
preview.col = results.col

if tbln then
prompt.line = prompt.line + 1
results.line = results.line + 1
preview.line = preview.line + 1
end

return {
preview = self.previewer and preview.height > 0 and preview,
results = results,
Expand Down Expand Up @@ -416,6 +445,7 @@ layout_strategies.cursor = make_documented_layout("cursor", vim.tbl_extend("erro
preview_width = { "Change the width of Telescope's preview window", "See |resolver.resolve_width()|", },
preview_cutoff = "When columns are less than this value, the preview will be disabled",
}), function(self, max_columns, max_lines, layout_config)

local initial_options = p_window.get_initial_window_options(self)
local preview = initial_options.preview
local results = initial_options.results
Expand Down Expand Up @@ -512,11 +542,15 @@ layout_strategies.vertical = make_documented_layout("vertical", vim.tbl_extend("
preview_height = { "Change the height of Telescope's preview window", "See |resolver.resolve_height()|" },
prompt_position = { "(unimplemented, but we plan on supporting)" },
}), function(self, max_columns, max_lines, layout_config)

local initial_options = p_window.get_initial_window_options(self)
local preview = initial_options.preview
local results = initial_options.results
local prompt = initial_options.prompt

local tbln
max_lines, tbln = calc_tabline(max_lines)

local width_opt = layout_config.width
local picker_width = resolve.resolve_width(width_opt)(self,max_columns,max_lines)
local width_padding = math.floor((max_columns - picker_width)/2)
Expand Down Expand Up @@ -548,19 +582,21 @@ layout_strategies.vertical = make_documented_layout("vertical", vim.tbl_extend("

results.col, preview.col, prompt.col = width_padding, width_padding, width_padding

if self.previewer then
if not layout_config.mirror then
preview.line = height_padding
results.line = preview.line + preview.height + 2
prompt.line = results.line + results.height + 2
else
prompt.line = height_padding
results.line = prompt.line + prompt.height + 2
preview.line = results.line + results.height + 2
end
else
results.line = height_padding
if not layout_config.mirror then
preview.line = height_padding
results.line = (preview.height == 0) and preview.line
or preview.line + preview.height + 2
prompt.line = results.line + results.height + 2
else
prompt.line = height_padding
results.line = prompt.line + prompt.height + 2
preview.line = results.line + results.height + 2
end

if tbln then
prompt.line = prompt.line + 1
results.line = results.line + 1
preview.line = preview.line + 1
end

return {
Expand Down