slightly better small screen UX
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user