Skip to content

Commit

Permalink
fix preview window height
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed May 23, 2024
1 parent 59525cb commit bf8c54f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lua/lspsaga/codeaction/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ local function create_preview_win(content, main_winid)
opt.width = math.min(max_win_width, content_width)
end
local winheight = api.nvim_win_get_height(win_conf.win)
local margin = config.ui.border == 'none' and 2 or 4
local margin = config.ui.border == 'none' and 0 or 2
local north = win_conf.anchor:sub(1, 1) == 'N'
local row = util.is_ten and win_conf.row or win_conf.row[false]
local valid_top_height = north and row or row - win_conf.height - margin
local valid_top_height = north and row - 1 or row - win_conf.height - margin - 1
local valid_bot_height = north and winheight - row - win_conf.height - margin
or winheight - row - margin
local new_win_height = #content + margin
Expand All @@ -124,7 +124,7 @@ local function create_preview_win(content, main_winid)
elseif valid_bot_height >= new_win_height then
opt.anchor = 'N' .. east_or_west
opt.row = row + win_conf.height + margin
opt.height = math.min(valid_bot_height, #content)
opt.height = math.min(valid_bot_height, #content) - 2
end
else
if valid_bot_height >= new_win_height then
Expand All @@ -137,7 +137,6 @@ local function create_preview_win(content, main_winid)
opt.height = math.min(valid_top_height, #content)
end
end
print(vim.inspect(opt))
preview_buf, preview_winid = win
:new_float(opt, false, true)
:setlines(content)
Expand Down Expand Up @@ -171,7 +170,7 @@ local function action_preview(main_winid, main_buf, tuple)
api.nvim_buf_set_lines(preview_buf, 0, -1, false, diff)
vim.bo[preview_buf].modifiable = false
local win_conf = api.nvim_win_get_config(preview_winid)
win_conf.height = #diff
win_conf.height = math.min(win_conf.height, #diff)
local new_width = util.get_max_content_length(diff)
local main_width = api.nvim_win_get_width(main_winid)
win_conf.width = new_width < main_width and main_width or new_width
Expand Down

0 comments on commit bf8c54f

Please sign in to comment.