Skip to content

Commit

Permalink
feat(layout): adds anchor_padding to the layout options layout(nvim-t…
Browse files Browse the repository at this point in the history
  • Loading branch information
Weyaaron committed Apr 7, 2024
1 parent 2015e38 commit ba64f0d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 9 additions & 0 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ append(
Default: { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }]]
)

append(
"anchor_padding",
5,
[[
Set amount of padding around the border of the windows. Negative Values
are not supported.
Default:1]]
)

append(
"get_status_text",
function(self, opts)
Expand Down
9 changes: 5 additions & 4 deletions lua/telescope/config/resolve.lua
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,21 @@ end
--- the picker will move to the corresponding edge/corner
--- e.g. "NW" -> "top left corner", "E" -> "right edge", "S" -> "bottom edge"
resolver.resolve_anchor_pos = function(anchor, p_width, p_height, max_columns, max_lines)
local anchor_padding = require("telescope.config").values.anchor_padding
anchor = anchor:upper()
local pos = { 0, 0 }
if anchor == "CENTER" then
return pos
end
if anchor:find "W" then
pos[1] = math.ceil((p_width - max_columns) / 2) + 1
pos[1] = math.ceil((p_width - max_columns) / 2) + anchor_padding
elseif anchor:find "E" then
pos[1] = math.ceil((max_columns - p_width) / 2) - 1
pos[1] = math.ceil((max_columns - p_width) / 2) - anchor_padding
end
if anchor:find "N" then
pos[2] = math.ceil((p_height - max_lines) / 2) + 1
pos[2] = math.ceil((p_height - max_lines) / 2) + anchor_padding
elseif anchor:find "S" then
pos[2] = math.ceil((max_lines - p_height) / 2) - 1
pos[2] = math.ceil((max_lines - p_height) / 2) - anchor_padding
end
return pos
end
Expand Down
1 change: 1 addition & 0 deletions lua/telescope/pickers/layout_strategies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ local shared_options = {
scroll_speed = "The number of lines to scroll through the previewer",
prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
anchor = { "Which edge/corner to pin the picker to", "See |resolver.resolve_anchor_pos()|" },
anchor_padding = { "Additional padding around borders", "Values should be a positive integer" },
}

-- Used for generating vim help documentation.
Expand Down

0 comments on commit ba64f0d

Please sign in to comment.