diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index f56fe9207e..9a82b7b2bd 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1340,9 +1340,10 @@ end --- ---@param events table list of events ---@param winnr integer window id of preview window ----@param bufnrs table list of buffers where the preview window will remain visible +---@param floating_bufnr integer floating preview buffer +---@param bufnr integer buffer that opened the floating preview buffer ---@see autocmd-events -local function close_preview_autocmd(events, winnr, bufnrs) +local function close_preview_autocmd(events, winnr, floating_bufnr, bufnr) local augroup = api.nvim_create_augroup('nvim.preview_window_' .. winnr, { clear = true, }) @@ -1351,13 +1352,13 @@ local function close_preview_autocmd(events, winnr, bufnrs) -- the floating window buffer or the buffer that spawned it api.nvim_create_autocmd('BufLeave', { group = augroup, - buffer = bufnrs[1], + buffer = bufnr, callback = function() vim.schedule(function() -- When jumping to the quickfix window from the preview window, -- do not close the preview window. if api.nvim_get_option_value('filetype', { buf = 0 }) ~= 'qf' then - close_preview_window(winnr, bufnrs) + close_preview_window(winnr, { floating_bufnr, bufnr }) end end) end, @@ -1366,7 +1367,7 @@ local function close_preview_autocmd(events, winnr, bufnrs) if #events > 0 then api.nvim_create_autocmd(events, { group = augroup, - buffer = bufnrs[2], + buffer = bufnr, callback = function() close_preview_window(winnr) end, @@ -1613,7 +1614,7 @@ function M.open_floating_preview(contents, syntax, opts) 'bdelete', { silent = true, noremap = true, nowait = true } ) - close_preview_autocmd(opts.close_events, floating_winnr, { floating_bufnr, bufnr }) + close_preview_autocmd(opts.close_events, floating_winnr, floating_bufnr, bufnr) -- save focus_id if opts.focus_id then