From 7092ee17284e4a5f9de27b4f80dc226c5a378616 Mon Sep 17 00:00:00 2001 From: Freyskeyd Date: Fri, 22 Apr 2022 15:59:53 +0200 Subject: [PATCH] Added preview width and relative size Signed-off-by: Freyskeyd --- lua/symbols-outline/config.lua | 17 +++++++++++++++++ lua/symbols-outline/preview.lua | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lua/symbols-outline/config.lua b/lua/symbols-outline/config.lua index fe2a45f..c198c1e 100644 --- a/lua/symbols-outline/config.lua +++ b/lua/symbols-outline/config.lua @@ -9,6 +9,9 @@ M.defaults = { border = 'single', relative_width = true, width = 25, + preview_min_width = 100, + preview_width = 50, + relative_preview_width = true, auto_close = false, auto_preview = true, show_numbers = false, @@ -80,6 +83,20 @@ function M.get_window_width() 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() if M.options.position == 'left' then return 'topleft vs' diff --git a/lua/symbols-outline/preview.lua b/lua/symbols-outline/preview.lua index 04302d7..0c83422 100644 --- a/lua/symbols-outline/preview.lua +++ b/lua/symbols-outline/preview.lua @@ -29,7 +29,7 @@ end local function get_offset() local outline_winnr = main.state.outline_win - local width = 53 + local width = config.get_preview_width() + 6 local height = 0 if config.has_numbers() then @@ -41,6 +41,7 @@ local function get_offset() else width = vim.api.nvim_win_get_width(outline_winnr) + 1 end + return { height, width } end @@ -168,7 +169,7 @@ local function show_preview() local offsets = get_offset() state.preview_win = vim.api.nvim_open_win(state.preview_buf, false, { relative = 'win', - width = 50, + width = config.get_preview_width(), height = get_height(), bufpos = { 0, 0 }, row = offsets[1], @@ -194,7 +195,7 @@ local function show_hover() local height = get_height() state.hover_win = vim.api.nvim_open_win(state.hover_buf, false, { relative = 'win', - width = 50, + width = config.get_preview_width(), height = height, bufpos = { 0, 0 }, row = offsets[1] + height + 2,