Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lua/diffview/scene/views/diff/diff_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ DiffView.update_files = debounce.debounce_trailing(

perf:lap("received new file list")

local prev_cur_file = self.panel.cur_file

local files = {
{ cur_files = self.files.conflicting, new_files = new_files.conflicting },
{ cur_files = self.files.working, new_files = new_files.working },
Expand Down Expand Up @@ -644,7 +646,17 @@ DiffView.update_files = debounce.debounce_trailing(
self.panel:render()
self.panel:redraw()

self:set_file(self.panel.cur_file or self.panel:next_file(), false, not self.initialized or nil)
local next_file = self.panel.cur_file or self.panel:next_file()

-- Only re-open the current entry when something actually changed:
-- first init, cur_file identity changed, or buffers were invalidated.
local needs_reopen = not self.initialized
or next_file ~= prev_cur_file
or not (self.cur_layout and self.cur_layout:is_valid() and self.cur_layout:is_files_loaded())

if needs_reopen then
self:set_file(next_file, false, not self.initialized or nil)
end

-- Position cursor at the requested row on first open.
if not self.initialized and self.options.selected_row then
Expand Down
2 changes: 1 addition & 1 deletion lua/diffview/ui/panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function Panel:resize()
width = math.min(width, max_width)
local ok = pcall(api.nvim_win_set_width, self.winid, width)
if ok and api.nvim_win_get_width(self.winid) ~= old_width then
vim.cmd("vertical wincmd =")
vim.cmd("wincmd =")
-- Re-render so that header lines (path, revision info, etc.) are
-- truncated to the actual panel width rather than left at full length.
self:render()
Expand Down
Loading