Skip to content

Commit

Permalink
fix wrong action preview window position
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed May 13, 2024
1 parent 9a06eaf commit 66161c1
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions lua/lspsaga/codeaction/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,42 @@ local function create_preview_win(content, main_winid)
else
opt.width = content_width < win_conf.width and win_conf.width or content_width
end

local winheight = api.nvim_win_get_height(win_conf.win)
local win_margin = config.ui.border == 'none' and 0 or 2
if win_conf.anchor:find('^S') then
opt.row = util.is_ten and win_conf.row - 3 or win_conf.row[false] - win_conf.height - win_margin
max_height = util.is_ten and win_conf.row or win_conf.row[false] - win_conf.height
elseif win_conf.anchor:find('^N') then
opt.row = util.is_ten and win_conf.row + 3 or win_conf.row[false] + win_conf.height + win_margin
max_height = winheight - opt.row
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_bot_height = north and winheight - row - win_conf.height - margin
or winheight - row - margin
local new_win_height = #content + margin
-- action is NW under cursor and top is enough to show preview
if north then
if valid_top_height > new_win_height then
opt.anchor = 'SW'
opt.row = row
opt.height = math.min(valid_top_height, #content)
elseif valid_bot_height > new_win_height then
opt.anchor = 'NW'
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
opt.anchor = 'NW'
opt.row = row
opt.height = math.min(valid_bot_height, #content)
else
opt.anchor = 'SW'
opt.row = row - win_conf.height - margin
opt.height = math.min(valid_top_height, #content)
end
end

opt.height = math.min(max_height, #content)

if config.ui.title then
opt.title = { { 'Action Preview', 'ActionPreviewTitle' } }
opt.title_pos = 'center'
end
print(vim.inspect(opt))

preview_buf, preview_winid = win
:new_float(opt, false, true)
Expand Down

0 comments on commit 66161c1

Please sign in to comment.