summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-08-27 22:55:44 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-08-27 22:55:44 -0400
commit4100795d0ca64b2afd073e90435374a16f3ae962 (patch)
tree1965e78b562b113f3df4e561171cc130433cf7d4 /lua
parentbb446421c5e97310fc0823c157d94cef624688bb (diff)
slightly better small screen UX
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/mappings.lua5
-rw-r--r--lua/telescope/pickers.lua18
-rw-r--r--lua/telescope/previewers.lua7
3 files changed, 24 insertions, 6 deletions
diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua
index 1e79900..264a2d3 100644
--- a/lua/telescope/mappings.lua
+++ b/lua/telescope/mappings.lua
@@ -52,7 +52,8 @@ keymap["control-p"] = function(prompt_bufnr, _)
end
keymap["enter"] = function(prompt_bufnr, results_bufnr)
- local entry = state.get_status(prompt_bufnr).picker:get_selection()
+ local picker = state.get_status(prompt_bufnr).picker
+ local entry = picker:get_selection()
if not entry then
print("[telescope] Nothing currently selected")
@@ -72,6 +73,8 @@ keymap["enter"] = function(prompt_bufnr, results_bufnr)
vim.cmd(string.format([[bdelete! %s]], prompt_bufnr))
+ a.nvim_set_current_win(picker.original_win_id or 0)
+
local bufnr = vim.fn.bufnr(filename, true)
a.nvim_set_current_buf(bufnr)
a.nvim_buf_set_option(bufnr, 'buflisted', true)
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 9973c8e..8adde83 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -51,9 +51,12 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
enter = true
}
+ -- TODO: Test with 120 width terminal
+
local width_padding = 10
if max_columns < 150 then
- preview.width = 60
+ width_padding = 5
+ preview.width = math.floor(max_columns * 0.4)
elseif max_columns < 200 then
preview.width = 80
else
@@ -64,7 +67,13 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
results.width = other_width
prompt.width = other_width
- results.height = 25
+ local base_height
+ if max_lines < 40 then
+ base_height = math.floor(max_lines * 0.5)
+ else
+ base_height = math.floor(max_lines * 0.8)
+ end
+ results.height = base_height
results.minheight = results.height
prompt.height = 1
prompt.minheight = prompt.height
@@ -76,7 +85,8 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
prompt.col = width_padding
preview.col = results.col + results.width + 2
- local height_padding = math.floor(0.95 * max_lines)
+ -- TODO: Center this in the page a bit better.
+ local height_padding = math.max(math.floor(0.95 * max_lines), 2)
results.line = max_lines - height_padding
prompt.line = results.line + results.height + 2
preview.line = results.line
@@ -97,6 +107,8 @@ function Picker:find(opts)
local sorter = opts.sorter
local prompt_string = opts.prompt
+ self.original_win_id = a.nvim_get_current_win()
+
-- Create three windows:
-- 1. Prompt window
-- 2. Options window
diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua
index 8d1a1e1..5082b1a 100644
--- a/lua/telescope/previewers.lua
+++ b/lua/telescope/previewers.lua
@@ -5,6 +5,9 @@ local previewers = {}
local Previewer = {}
Previewer.__index = Previewer
+local bat_options = "--style=grid --paging=always --wrap=never"
+-- --terminal-width=%s
+
function Previewer:new(opts)
opts = opts or {}
@@ -122,7 +125,7 @@ previewers.vimgrep = previewers.new {
setup = function()
local command_string = "cat %s"
if vim.fn.executable("bat") then
- command_string = "bat %s --style=grid --paging=always --highlight-line %s -r %s:%s"
+ command_string = "bat %s --highlight-line %s -r %s:%s" .. bat_options
end
return {
@@ -160,7 +163,7 @@ previewers.qflist = previewers.new {
setup = function()
local command_string = "cat %s"
if vim.fn.executable("bat") then
- command_string = "bat %s --style=grid --paging=always --highlight-line %s -r %s:%s"
+ command_string = "bat %s --highlight-line %s -r %s:%s"
end
return {