mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
fix(lsp): close floating preview window correctly #34946
Problem:
After 28b7c2d
(found with bisect) the hover preview window does not
close when :edit'ing another file, even when you move the cursor.
Solution:
Change the BufLeave to target the original buffer, not the preview
buffer.
This commit is contained in:
@@ -1418,9 +1418,10 @@ end
|
|||||||
---
|
---
|
||||||
---@param events table list of events
|
---@param events table list of events
|
||||||
---@param winnr integer window id of preview window
|
---@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
|
---@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, {
|
local augroup = api.nvim_create_augroup('nvim.preview_window_' .. winnr, {
|
||||||
clear = true,
|
clear = true,
|
||||||
})
|
})
|
||||||
@@ -1429,13 +1430,13 @@ local function close_preview_autocmd(events, winnr, bufnrs)
|
|||||||
-- the floating window buffer or the buffer that spawned it
|
-- the floating window buffer or the buffer that spawned it
|
||||||
api.nvim_create_autocmd('BufLeave', {
|
api.nvim_create_autocmd('BufLeave', {
|
||||||
group = augroup,
|
group = augroup,
|
||||||
buffer = bufnrs[1],
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
-- When jumping to the quickfix window from the preview window,
|
-- When jumping to the quickfix window from the preview window,
|
||||||
-- do not close the preview window.
|
-- do not close the preview window.
|
||||||
if api.nvim_get_option_value('filetype', { buf = 0 }) ~= 'qf' then
|
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)
|
end)
|
||||||
end,
|
end,
|
||||||
@@ -1444,7 +1445,7 @@ local function close_preview_autocmd(events, winnr, bufnrs)
|
|||||||
if #events > 0 then
|
if #events > 0 then
|
||||||
api.nvim_create_autocmd(events, {
|
api.nvim_create_autocmd(events, {
|
||||||
group = augroup,
|
group = augroup,
|
||||||
buffer = bufnrs[2],
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
close_preview_window(winnr)
|
close_preview_window(winnr)
|
||||||
end,
|
end,
|
||||||
@@ -1690,7 +1691,7 @@ function M.open_floating_preview(contents, syntax, opts)
|
|||||||
'<cmd>bdelete<cr>',
|
'<cmd>bdelete<cr>',
|
||||||
{ silent = true, noremap = true, nowait = true }
|
{ 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
|
-- save focus_id
|
||||||
if opts.focus_id then
|
if opts.focus_id then
|
||||||
|
Reference in New Issue
Block a user