Skip to content

Commit

Permalink
fix(outline): calc width/height for preview win based on columns (#1492)
Browse files Browse the repository at this point in the history
* fix(outline): calc width/height for preview win based on columns

* chore: trigger github action
  • Loading branch information
Alienover authored Oct 8, 2024
1 parent e64351d commit a095521
Showing 1 changed file with 30 additions and 17 deletions.
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

0 comments on commit a095521

Please sign in to comment.