diff options
| author | Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> | 2021-12-10 19:08:24 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-10 19:08:24 +0000 |
| commit | 5f37fbfa837dfee7ecd30f388b271f4a71c0a9e0 (patch) | |
| tree | d7623b89980c808f33347cbfa396ef8d6315989c /lua/telescope/config | |
| parent | 5e5351ef13dc1f225b3e51a66d54854bfe91d2cb (diff) | |
feat: layout `anchor` (#1582)
* feat: add `anchor` option to some `layout_strategies`
* tests: improve tests for `resolve_height/width`
Diffstat (limited to 'lua/telescope/config')
| -rw-r--r-- | lua/telescope/config/resolve.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lua/telescope/config/resolve.lua b/lua/telescope/config/resolve.lua index 9875565..3b47025 100644 --- a/lua/telescope/config/resolve.lua +++ b/lua/telescope/config/resolve.lua @@ -213,6 +213,35 @@ resolver.resolve_width = function(val) error("invalid configuration option for width:" .. tostring(val)) end +--- Calculates the adjustment required to move the picker from the middle of the screen to +--- an edge or corner. <br> +--- The `anchor` can be any of the following strings: +--- - "", "CENTER", "NW", "N", "NE", "E", "SE", "S", "SW", "W" +--- The anchors have the following meanings: +--- - "" or "CENTER":<br> +--- the picker will remain in the middle of the screen. +--- - Compass directions:<br> +--- 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) + 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 + elseif anchor:find "E" then + pos[1] = math.ceil((max_columns - p_width) / 2) - 1 + end + if anchor:find "N" then + pos[2] = math.ceil((p_height - max_lines) / 2) + 1 + elseif anchor:find "S" then + pos[2] = math.ceil((max_lines - p_height) / 2) - 1 + end + return pos +end + -- Win option always returns a table with preview, results, and prompt. -- It handles many different ways. Some examples are as follows: -- |
