Merge upstream PR 130 (preview width control)

simrat39/symbols-outline.nvim#130
This commit is contained in:
hedy
2023-11-08 14:23:38 +08:00
2 changed files with 26 additions and 10 deletions

View File

@@ -32,7 +32,7 @@ M.defaults = {
preview_window = {
auto_preview = false,
width = 50,
min_width = 100,
min_width = 50,
relative_width = true,
bg_hl = 'Pmenu',
border = 'single',
@@ -132,6 +132,20 @@ function M.get_window_width()
end
end
function M.get_preview_width()
if M.o.preview_window.relative_width then
local relative_width = math.ceil(vim.o.columns * (M.o.preview_window.width / 100))
if relative_width < M.o.preview_window.min_width then
return M.o.preview_window.min_width
else
return relative_width
end
else
return M.o.preview_window.width
end
end
function M.get_split_command()
if M.o.outline_window.position == 'left' then
return 'topleft vs'

View File

@@ -26,12 +26,14 @@ end
M.has_code_win = has_code_win
local function get_offset()
local function get_width_offset()
---@type integer
local outline_winnr = so.view.winnr
local width = 53
local height = 0
local width = cfg.get_preview_width() + 3
local has_numbers = vim.api.nvim_win_get_option(outline_winnr, "number")
has_numbers = has_numbers or vim.api.nvim_win_get_option(outline_winnr, "relativenumber")
if cfg.has_numbers() then
if has_numbers then
width = width + 4
end
@@ -40,7 +42,8 @@ local function get_offset()
else
width = vim.api.nvim_win_get_width(outline_winnr) + 1
end
return { height, width }
return width
end
local function get_height()
@@ -108,17 +111,16 @@ local function show_preview()
state.preview_win = nil
end,
})
local offsets = get_offset()
local height = get_height()
local winheight = math.ceil(height / 2)
state.preview_win = vim.api.nvim_open_win(state.preview_buf, false, {
relative = 'win',
width = 50,
height = winheight,
width = cfg.get_preview_width(),
bufpos = { 0, 0 },
col = offsets[2],
col = get_width_offset(),
-- Position preview window middle-aligned vertically
row = math.ceil((height - winheight) / 2),
row = math.floor((height - winheight) / 2) - 1,
border = cfg.o.preview_window.border,
})
setup_preview_buf()