Skip to content

Commit a095521

Browse files
authored
fix(outline): calc width/height for preview win based on columns (#1492)
* fix(outline): calc width/height for preview win based on columns * chore: trigger github action
1 parent e64351d commit a095521

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

lua/lspsaga/symbol/outline.lua

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,24 @@ function ot:toggle_or_jump()
336336
beacon({ pos[1] - 1, 0 }, width)
337337
end
338338

339-
function ot:create_preview_win(lines)
340-
local screen_col = fn.win_screenpos(self.winid)[2]
341-
if config.outline.win_position == 'left' then
342-
screen_col = api.nvim_win_get_width(self.winid)
343-
end
339+
function ot:calc_preview_win_spec(lines)
344340
local max_height = vim.o.lines - fn.winline()
345-
local max_width = math.floor(screen_col * 0.7)
341+
local max_width = math.floor(vim.o.columns * 0.7)
342+
343+
return {
344+
height = math.min(max_height, #lines),
345+
width = math.min(max_width, util.get_max_content_length(lines)),
346+
}
347+
end
348+
349+
function ot:create_preview_win(lines)
350+
local win_spec = self:calc_preview_win_spec(lines)
346351

347352
local float_opt = {
348353
relative = 'editor',
349354
style = 'minimal',
350-
height = math.min(max_height, #lines),
351-
width = math.min(max_width, util.get_max_content_length(lines)),
355+
height = win_spec.height,
356+
width = win_spec.width,
352357
focusable = false,
353358
noautocmd = true,
354359
}
@@ -381,6 +386,21 @@ function ot:create_preview_win(lines)
381386
:wininfo()
382387
end
383388

389+
function ot:update_preview_win(lines)
390+
local win_spec = self:calc_preview_win_spec(lines)
391+
392+
local win_config = api.nvim_win_get_config(self.preview_winid)
393+
394+
win
395+
:from_exist(self.preview_bufnr, self.preview_winid)
396+
:setlines(lines)
397+
:winsetconf(vim.tbl_extend('force', win_config, {
398+
row = fn.winline(),
399+
height = win_spec.height,
400+
width = win_spec.width,
401+
}))
402+
end
403+
384404
function ot:refresh()
385405
api.nvim_create_autocmd('User', {
386406
group = group,
@@ -440,16 +460,9 @@ function ot:preview()
440460
api.nvim_buf_get_lines(self.main_buf, range.start.line, range['end'].line + 1, false)
441461
if not self.preview_winid or not api.nvim_win_is_valid(self.preview_winid) then
442462
self:create_preview_win(lines)
443-
return
463+
else
464+
self:update_preview_win(lines)
444465
end
445-
446-
api.nvim_buf_set_lines(self.preview_bufnr, 0, -1, false, lines)
447-
local win_conf = api.nvim_win_get_config(self.preview_winid)
448-
local row = fn.winline()
449-
win_conf.width = math.ceil(fn.win_screenpos(self.winid)[2] * 0.7)
450-
win_conf.row = row - 1
451-
win_conf.height = math.min(#lines, bit.rshift(vim.o.lines, 1))
452-
api.nvim_win_set_config(self.preview_winid, win_conf)
453466
end,
454467
})
455468

0 commit comments

Comments
 (0)