mirror of
https://github.com/neovim/neovim.git
synced 2026-03-28 03:12:00 +00:00
fix(difftool): don't reset quickfix list when closing quickfix window #38088
Closing the quickfix window previously triggered a WinClosed autocmd that deleted all difftool autocmds and pushed an empty quickfix list, making the difftool non-functional. Users who close the quickfix window to gain screen real estate for viewing diffs had no way to continue navigating entries. Remove the qf_win tracking and its associated WinClosed autocmd so that closing the quickfix window no longer tears down the difftool state. Closing either diff window still performs full cleanup as before. The BufWinEnter handler no longer passes with_qf to diff_files, so navigating entries while the quickfix window is closed reuses the existing diff layout without forcing a layout rebuild. Fixes #37388
This commit is contained in:
@@ -28,7 +28,6 @@ local layout = {
|
||||
group = nil,
|
||||
left_win = nil,
|
||||
right_win = nil,
|
||||
qf_win = nil,
|
||||
}
|
||||
|
||||
local util = require('vim._core.util')
|
||||
@@ -42,7 +41,6 @@ local function cleanup_layout(with_qf)
|
||||
end
|
||||
layout.left_win = nil
|
||||
layout.right_win = nil
|
||||
layout.qf_win = nil
|
||||
|
||||
if with_qf then
|
||||
vim.fn.setqflist({})
|
||||
@@ -55,9 +53,8 @@ end
|
||||
local function setup_layout(with_qf)
|
||||
local left_valid = layout.left_win and vim.api.nvim_win_is_valid(layout.left_win)
|
||||
local right_valid = layout.right_win and vim.api.nvim_win_is_valid(layout.right_win)
|
||||
local qf_valid = layout.qf_win and vim.api.nvim_win_is_valid(layout.qf_win)
|
||||
|
||||
if left_valid and right_valid and (not with_qf or qf_valid) then
|
||||
if left_valid and right_valid then
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -68,9 +65,6 @@ local function setup_layout(with_qf)
|
||||
|
||||
if with_qf then
|
||||
vim.cmd('botright copen')
|
||||
layout.qf_win = vim.api.nvim_get_current_win()
|
||||
else
|
||||
layout.qf_win = nil
|
||||
end
|
||||
vim.api.nvim_set_current_win(layout.right_win)
|
||||
|
||||
@@ -89,20 +83,6 @@ local function setup_layout(with_qf)
|
||||
cleanup_layout(with_qf)
|
||||
end,
|
||||
})
|
||||
if with_qf then
|
||||
vim.api.nvim_create_autocmd('WinClosed', {
|
||||
group = layout.group,
|
||||
pattern = tostring(layout.qf_win),
|
||||
callback = function()
|
||||
-- For quickfix also close one of diff windows
|
||||
if layout.left_win and vim.api.nvim_win_is_valid(layout.left_win) then
|
||||
vim.api.nvim_win_close(layout.left_win, true)
|
||||
end
|
||||
|
||||
cleanup_layout(with_qf)
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
--- Diff two files
|
||||
@@ -497,7 +477,7 @@ function M.open(left, right, opt)
|
||||
|
||||
vim.w.lazyredraw = true
|
||||
vim.schedule(function()
|
||||
diff_files(entry.user_data.left, entry.user_data.right, true)
|
||||
diff_files(entry.user_data.left, entry.user_data.right)
|
||||
vim.w.lazyredraw = false
|
||||
end)
|
||||
end,
|
||||
|
||||
@@ -98,4 +98,21 @@ describe('nvim.difftool', function()
|
||||
local ok = pcall(fn.nvim_get_autocmds, { group = 'nvim.difftool.events' })
|
||||
eq(false, ok)
|
||||
end)
|
||||
|
||||
it('does not reset quickfix list when closing quickfix window', function()
|
||||
command(('DiffTool %s %s'):format(testdir_left, testdir_right))
|
||||
local qflist_before = fn.getqflist()
|
||||
assert(#qflist_before > 0, 'quickfix list should not be empty')
|
||||
|
||||
-- Close the quickfix window
|
||||
command('cclose')
|
||||
|
||||
-- Quickfix list should still be intact
|
||||
local qflist_after = fn.getqflist()
|
||||
eq(#qflist_before, #qflist_after)
|
||||
|
||||
-- Autocmds should still be active
|
||||
local autocmds = fn.nvim_get_autocmds({ group = 'nvim.difftool.events' })
|
||||
assert(#autocmds > 0, 'autocmds should still exist after closing quickfix window')
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user