1
0

neovim-34946.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From cad0c71adc30ca4d358cec3146495b340b2e068e Mon Sep 17 00:00:00 2001
  2. From: Tronikel <contactdonatas@gmail.com>
  3. Date: Tue, 15 Jul 2025 18:18:50 +0300
  4. Subject: [PATCH] fix: close floating preview window correctly
  5. ---
  6. runtime/lua/vim/lsp/util.lua | 13 +++++++------
  7. 1 file changed, 7 insertions(+), 6 deletions(-)
  8. diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
  9. index db221ddc6889e6..28d00d6cd307f2 100644
  10. --- a/runtime/lua/vim/lsp/util.lua
  11. +++ b/runtime/lua/vim/lsp/util.lua
  12. @@ -1418,9 +1418,10 @@ end
  13. ---
  14. ---@param events table list of events
  15. ---@param winnr integer window id of preview window
  16. ----@param bufnrs table list of buffers where the preview window will remain visible
  17. +---@param floating_bufnr integer floating preview buffer
  18. +---@param bufnr integer buffer that opened the floating preview buffer
  19. ---@see autocmd-events
  20. -local function close_preview_autocmd(events, winnr, bufnrs)
  21. +local function close_preview_autocmd(events, winnr, floating_bufnr, bufnr)
  22. local augroup = api.nvim_create_augroup('nvim.preview_window_' .. winnr, {
  23. clear = true,
  24. })
  25. @@ -1429,13 +1430,13 @@ local function close_preview_autocmd(events, winnr, bufnrs)
  26. -- the floating window buffer or the buffer that spawned it
  27. api.nvim_create_autocmd('BufLeave', {
  28. group = augroup,
  29. - buffer = bufnrs[1],
  30. + buffer = bufnr,
  31. callback = function()
  32. vim.schedule(function()
  33. -- When jumping to the quickfix window from the preview window,
  34. -- do not close the preview window.
  35. if api.nvim_get_option_value('filetype', { buf = 0 }) ~= 'qf' then
  36. - close_preview_window(winnr, bufnrs)
  37. + close_preview_window(winnr, { floating_bufnr, bufnr })
  38. end
  39. end)
  40. end,
  41. @@ -1444,7 +1445,7 @@ local function close_preview_autocmd(events, winnr, bufnrs)
  42. if #events > 0 then
  43. api.nvim_create_autocmd(events, {
  44. group = augroup,
  45. - buffer = bufnrs[2],
  46. + buffer = bufnr,
  47. callback = function()
  48. close_preview_window(winnr)
  49. end,
  50. @@ -1690,7 +1691,7 @@ function M.open_floating_preview(contents, syntax, opts)
  51. '<cmd>bdelete<cr>',
  52. { silent = true, noremap = true, nowait = true }
  53. )
  54. - close_preview_autocmd(opts.close_events, floating_winnr, { floating_bufnr, bufnr })
  55. + close_preview_autocmd(opts.close_events, floating_winnr, floating_bufnr, bufnr)
  56. -- save focus_id
  57. if opts.focus_id then