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

feat: add cursor layout #878

Merged
merged 18 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Allow preview width to be configured
  • Loading branch information
cbrunel authored and Luxed committed Jul 15, 2021
commit d002ef171a373647b02ea14520a175fb0406b4be
4 changes: 4 additions & 0 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ local layout_config_defaults = {
center = {
preview_cutoff = 40,
},

cursor = {
preview_cutoff = 40,
}
}

local layout_config_description = string.format([[
Expand Down
16 changes: 12 additions & 4 deletions lua/telescope/pickers/layout_strategies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ end)
--- └──────────────────────────────────────────────────┘
--- </pre>
layout_strategies.cursor = make_documented_layout("cursor", vim.tbl_extend("error", shared_options, {
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
Expand All @@ -433,11 +435,17 @@ layout_strategies.cursor = make_documented_layout("cursor", vim.tbl_extend("erro
results.height = height
preview.height = results.height + prompt.height + bs

-- If previewer is activated, it should take 2/3 of the space (width)
local width_left = self.previewer and math.floor(max_width / 3) or max_width
prompt.width = width_left
if self.previewer and max_columns >= layout_config.preview_cutoff then
preview.width = resolve.resolve_width(if_nil(layout_config.preview_width, function(_, cols)
-- By default, previewer takes 2/3 of the layout
return 2 * math.floor(max_width / 3)
end))(self, max_width, max_lines)
else
preview.width = 0
end

prompt.width = max_width - preview.width
results.width = prompt.width
preview.width = self.previewer and (2*width_left) or 0

local total_height = preview.height + (bs*2)
local total_width = prompt.width + (bs*2) + preview.width + bs
Expand Down