From 59525cb2887d80dbfa1ce3120ecf723f46562678 Mon Sep 17 00:00:00 2001 From: glepnir Date: Thu, 23 May 2024 15:04:25 +0800 Subject: [PATCH] fix preview window position --- lua/lspsaga/codeaction/preview.lua | 12 ++++++++---- lua/lspsaga/init.lua | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lua/lspsaga/codeaction/preview.lua b/lua/lspsaga/codeaction/preview.lua index d5fb9ab2d..1b388c54e 100644 --- a/lua/lspsaga/codeaction/preview.lua +++ b/lua/lspsaga/codeaction/preview.lua @@ -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, @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/lua/lspsaga/init.lua b/lua/lspsaga/init.lua index ce4ddc2a7..387b63b09 100644 --- a/lua/lspsaga/init.lua +++ b/lua/lspsaga/init.lua @@ -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,