summaryrefslogtreecommitdiff
path: root/lua/telescope/pickers/layout_strategies.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2021-05-15 12:02:14 -0700
committerGitHub <noreply@github.com>2021-05-15 15:02:14 -0400
commit4da66dab44f37d0de4b88cedf9e114c5b0855c20 (patch)
treeea0179d0d0c8be5e716ce70d6dab14aa4fc4fcac /lua/telescope/pickers/layout_strategies.lua
parentb78d4ef10c72597c322baaa3830c760a26734b21 (diff)
feat: add ivy-style layout strategy (#771)
* feat: add new layout strategy * [docgen] Update doc/telescope.txt skip-checks: true Co-authored-by: Github Actions <actions@github>
Diffstat (limited to 'lua/telescope/pickers/layout_strategies.lua')
-rw-r--r--lua/telescope/pickers/layout_strategies.lua102
1 files changed, 67 insertions, 35 deletions
diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua
index b4c9fda..21994b3 100644
--- a/lua/telescope/pickers/layout_strategies.lua
+++ b/lua/telescope/pickers/layout_strategies.lua
@@ -61,38 +61,7 @@
local config = require('telescope.config')
local resolve = require("telescope.config.resolve")
-local function get_initial_window_options(picker)
- local popup_border = resolve.win_option(picker.window.border)
- local popup_borderchars = resolve.win_option(picker.window.borderchars)
-
- local preview = {
- title = picker.preview_title,
- border = popup_border.preview,
- borderchars = popup_borderchars.preview,
- enter = false,
- highlight = false
- }
-
- local results = {
- title = picker.results_title,
- border = popup_border.results,
- borderchars = popup_borderchars.results,
- enter = false,
- }
-
- local prompt = {
- title = picker.prompt_title,
- border = popup_border.prompt,
- borderchars = popup_borderchars.prompt,
- enter = true
- }
-
- return {
- preview = preview,
- results = results,
- prompt = prompt,
- }
-end
+local p_window = require('telescope.pickers.window')
-- Check if there are any borders. Right now it's a little raw as
@@ -139,7 +108,7 @@ layout_strategies.horizontal = function(self, max_columns, max_lines)
scroll_speed = "The speed when scrolling through the previewer",
})
- local initial_options = get_initial_window_options(self)
+ 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
@@ -237,7 +206,7 @@ end
--- +--------------+
--- </pre>
layout_strategies.center = function(self, columns, lines)
- local initial_options = get_initial_window_options(self)
+ 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
@@ -307,7 +276,7 @@ layout_strategies.vertical = function(self, max_columns, max_lines)
scroll_speed = "The speed when scrolling through the previewer",
})
- local initial_options = get_initial_window_options(self)
+ 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
@@ -447,4 +416,67 @@ layout_strategies.current_buffer = function(self, _, _)
}
end
+layout_strategies.bottom_pane = function(self, max_columns, max_lines)
+ local layout_config = validate_layout_config(self.layout_config or {}, {
+ height = "The height of the layout",
+ })
+
+ local initial_options = p_window.get_initial_window_options(self)
+ local results = initial_options.results
+ local prompt = initial_options.prompt
+ local preview = initial_options.preview
+
+ local result_height = layout_config.height or 25
+
+ local prompt_width = max_columns
+ local col = 0
+
+ local has_border = not not self.window.border
+ if has_border then
+ col = 1
+ prompt_width = prompt_width - 2
+ end
+
+ local result_width
+ if self.previewer then
+ result_width = math.floor(prompt_width / 2)
+
+ local base_col = result_width + 1
+ if has_border then
+ preview = vim.tbl_deep_extend("force", {
+ col = base_col + 2,
+ line = max_lines - result_height + 1,
+ width = prompt_width - result_width - 2,
+ height = result_height - 1,
+ }, preview)
+ else
+ preview = vim.tbl_deep_extend("force", {
+ col = base_col,
+ line = max_lines - result_height,
+ width = prompt_width - result_width,
+ height = result_height,
+ }, preview)
+ end
+ else
+ preview = nil
+ result_width = prompt_width
+ end
+
+ return {
+ preview = preview,
+ prompt = vim.tbl_deep_extend("force", prompt, {
+ line = max_lines - result_height - 1,
+ col = col,
+ height = 1,
+ width = prompt_width,
+ }),
+ results = vim.tbl_deep_extend("force", results, {
+ line = max_lines - result_height,
+ col = col,
+ height = result_height,
+ width = result_width,
+ }),
+ }
+end
+
return layout_strategies