Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(outline): calc width/height for preview win based on columns #1492

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions lua/lspsaga/symbol/outline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,24 @@ function ot:toggle_or_jump()
beacon({ pos[1] - 1, 0 }, width)
end

function ot:create_preview_win(lines)
local screen_col = fn.win_screenpos(self.winid)[2]
if config.outline.win_position == 'left' then
screen_col = api.nvim_win_get_width(self.winid)
end
function ot:calc_preview_win_spec(lines)
local max_height = vim.o.lines - fn.winline()
local max_width = math.floor(screen_col * 0.7)
local max_width = math.floor(vim.o.columns * 0.7)

return {
height = math.min(max_height, #lines),
width = math.min(max_width, util.get_max_content_length(lines)),
}
end

function ot:create_preview_win(lines)
local win_spec = self:calc_preview_win_spec(lines)

local float_opt = {
relative = 'editor',
style = 'minimal',
height = math.min(max_height, #lines),
width = math.min(max_width, util.get_max_content_length(lines)),
height = win_spec.height,
width = win_spec.width,
focusable = false,
noautocmd = true,
}
Expand Down Expand Up @@ -381,6 +386,21 @@ function ot:create_preview_win(lines)
:wininfo()
end

function ot:update_preview_win(lines)
local win_spec = self:calc_preview_win_spec(lines)

local win_config = api.nvim_win_get_config(self.preview_winid)

win
:from_exist(self.preview_bufnr, self.preview_winid)
:setlines(lines)
:winsetconf(vim.tbl_extend('force', win_config, {
row = fn.winline(),
height = win_spec.height,
width = win_spec.width,
}))
end

function ot:refresh()
api.nvim_create_autocmd('User', {
group = group,
Expand Down Expand Up @@ -440,16 +460,9 @@ function ot:preview()
api.nvim_buf_get_lines(self.main_buf, range.start.line, range['end'].line + 1, false)
if not self.preview_winid or not api.nvim_win_is_valid(self.preview_winid) then
self:create_preview_win(lines)
return
else
self:update_preview_win(lines)
end

api.nvim_buf_set_lines(self.preview_bufnr, 0, -1, false, lines)
local win_conf = api.nvim_win_get_config(self.preview_winid)
local row = fn.winline()
win_conf.width = math.ceil(fn.win_screenpos(self.winid)[2] * 0.7)
win_conf.row = row - 1
win_conf.height = math.min(#lines, bit.rshift(vim.o.lines, 1))
api.nvim_win_set_config(self.preview_winid, win_conf)
end,
})

Expand Down
Loading