fix: reopen closed diff panes from explorer - #499
Open
orestisfl wants to merge 1 commit into
Open
Conversation
Keep explorer and history sessions active when users manually close one or both side-by-side diff panes, provided the panel remains usable. Recreate missing panes on the next file selection while preserving panel placement and the configured original side. Count marked diff windows in the owning tab to avoid deferred WinClosed and BufEnter cleanup races across tabs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closing a diff pane with
:closetears down the whole CodeDiff session, even when the explorer or history panel is still open. The panel disappears along with it, so recovering means re-running:CodeDiff.This keeps explorer and history sessions alive when one or both panes are closed manually. The next file selection rebuilds the missing panes.
Root cause
Both cleanup handlers in
lua/codediff/ui/lifecycle/cleanup.luacounted windows tagged with thecodediff_restorewindow variable and tore the session down atcount <= 1for two-pane layouts. Two problems:count_diff_windows()counted the wrong tab. It usedvim.fn.winnr("$")/win_getid(), which are scoped to the focused tabpage but the user may have switched tabs before the count runs.Changes
cleanup.lua:count_diff_windows(tabpage)now takes the owning tabpage and iteratesnvim_tabpage_list_wins(). The duplicated threshold logic moves intocleanup_threshold(), which returns-1(never auto-cleanup) for side-by-side explorer/history sessions with a usable panel.side_by_side.lua:M.update()no longer bails out when both panes are gone.Testing
New test in
explorer_spec.luacovering both paths: close one pane then select a file, then close both panes and select another.In addition to the added test, I've used this patch as my daily driver for a few days.