From bf8c54fad4ee8d20f02f999e099a760f64b2f07e Mon Sep 17 00:00:00 2001 From: glepnir Date: Thu, 23 May 2024 16:19:16 +0800 Subject: [PATCH] fix preview window height --- lua/lspsaga/codeaction/preview.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lua/lspsaga/codeaction/preview.lua b/lua/lspsaga/codeaction/preview.lua index 1b388c54e..18b199da3 100644 --- a/lua/lspsaga/codeaction/preview.lua +++ b/lua/lspsaga/codeaction/preview.lua @@ -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 @@ -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 @@ -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) @@ -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