Skip to content

fix: reopen closed diff panes from explorer - #499

Open
orestisfl wants to merge 1 commit into
esmuellert:mainfrom
orestisfl:fix/reopen-closed-diff-panes
Open

fix: reopen closed diff panes from explorer#499
orestisfl wants to merge 1 commit into
esmuellert:mainfrom
orestisfl:fix/reopen-closed-diff-panes

Conversation

@orestisfl

Copy link
Copy Markdown
Contributor

Summary

Closing a diff pane with :close tears 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.lua counted windows tagged with the codediff_restore window variable and tore the session down at count <= 1 for two-pane layouts. Two problems:

  1. The panel isn't considered. For explorer and history the panel is itself an entry point so losing a pane shouldn't be fatal.
  2. count_diff_windows() counted the wrong tab. It used vim.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 iterates nvim_tabpage_list_wins(). The duplicated threshold logic moves into cleanup_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.lua covering 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant