Added preview width and relative size

Signed-off-by: Freyskeyd <simon.paitrault@gmail.com>
This commit is contained in:
Freyskeyd
2022-04-22 15:59:53 +02:00
parent 15ae99c273
commit 7092ee1728
2 changed files with 21 additions and 3 deletions

View File

@@ -9,6 +9,9 @@ M.defaults = {
border = 'single', border = 'single',
relative_width = true, relative_width = true,
width = 25, width = 25,
preview_min_width = 100,
preview_width = 50,
relative_preview_width = true,
auto_close = false, auto_close = false,
auto_preview = true, auto_preview = true,
show_numbers = false, show_numbers = false,
@@ -80,6 +83,20 @@ function M.get_window_width()
end end
end end
function M.get_preview_width()
if M.options.relative_preview_width then
local relative_width = math.ceil(vim.o.columns * (M.options.preview_width / 100))
if relative_width < M.options.preview_min_width then
return M.options.preview_min_width
else
return relative_width
end
else
return M.options.preview_width
end
end
function M.get_split_command() function M.get_split_command()
if M.options.position == 'left' then if M.options.position == 'left' then
return 'topleft vs' return 'topleft vs'

View File

@@ -29,7 +29,7 @@ end
local function get_offset() local function get_offset()
local outline_winnr = main.state.outline_win local outline_winnr = main.state.outline_win
local width = 53 local width = config.get_preview_width() + 6
local height = 0 local height = 0
if config.has_numbers() then if config.has_numbers() then
@@ -41,6 +41,7 @@ local function get_offset()
else else
width = vim.api.nvim_win_get_width(outline_winnr) + 1 width = vim.api.nvim_win_get_width(outline_winnr) + 1
end end
return { height, width } return { height, width }
end end
@@ -168,7 +169,7 @@ local function show_preview()
local offsets = get_offset() local offsets = get_offset()
state.preview_win = vim.api.nvim_open_win(state.preview_buf, false, { state.preview_win = vim.api.nvim_open_win(state.preview_buf, false, {
relative = 'win', relative = 'win',
width = 50, width = config.get_preview_width(),
height = get_height(), height = get_height(),
bufpos = { 0, 0 }, bufpos = { 0, 0 },
row = offsets[1], row = offsets[1],
@@ -194,7 +195,7 @@ local function show_hover()
local height = get_height() local height = get_height()
state.hover_win = vim.api.nvim_open_win(state.hover_buf, false, { state.hover_win = vim.api.nvim_open_win(state.hover_buf, false, {
relative = 'win', relative = 'win',
width = 50, width = config.get_preview_width(),
height = height, height = height,
bufpos = { 0, 0 }, bufpos = { 0, 0 },
row = offsets[1] + height + 2, row = offsets[1] + height + 2,