Skip to content

Commit

Permalink
fix preview window position
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed May 23, 2024
1 parent 898030d commit 59525cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lua/lspsaga/codeaction/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ local function get_action_diff(main_buf, tuple)
end, lines)

api.nvim_buf_delete(tmp_buf, { force = true })
---@diagnostic disable-next-line: missing-fields
local diff = vim.diff(table.concat(lines), table.concat(data), {
algorithm = 'minimal',
ctxlen = 0,
Expand All @@ -79,6 +80,7 @@ local function get_action_diff(main_buf, tuple)

diff = vim.tbl_filter(function(item)
return not item:find('@@%s')
---@diagnostic disable-next-line: param-type-mismatch
end, vim.split(diff, '\n'))
return diff
end
Expand All @@ -104,7 +106,7 @@ 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 0 or 2
local margin = config.ui.border == 'none' and 2 or 4
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
Expand All @@ -113,18 +115,19 @@ local function create_preview_win(content, main_winid)
local new_win_height = #content + margin
-- action is NW under cursor and top is enough to show preview
local east_or_west = win_conf.anchor:sub(2, 2)
new_win_height = math.min(new_win_height, math.max(valid_bot_height, valid_top_height))
if north then
if valid_top_height > new_win_height then
if valid_top_height >= new_win_height then
opt.anchor = 'S' .. east_or_west
opt.row = row
opt.height = math.min(valid_top_height, #content)
elseif valid_bot_height > new_win_height then
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)
end
else
if valid_bot_height > new_win_height then
if valid_bot_height >= new_win_height then
opt.anchor = 'N' .. east_or_west
opt.row = row
opt.height = math.min(valid_bot_height, #content)
Expand All @@ -134,6 +137,7 @@ 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
2 changes: 1 addition & 1 deletion lua/lspsaga/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local default_config = {
show_layout = 'float',
show_normal_height = 10,
jump_num_shortcut = true,
auto_preview = false,
auto_preview = true,
max_width = 0.8,
max_height = 0.6,
max_show_width = 0.9,
Expand Down

0 comments on commit 59525cb

Please sign in to comment.