Skip to content

Restore diff and merge layouts after a foreign split closes - #29

Merged
CoreyKaylor merged 1 commit into
mainfrom
fix/foreign-split-relayout
Nov 5, 2026
Merged

CoreyKaylor merged 1 commit into
mainfrom
fix/foreign-split-relayout

Conversation

@CoreyKaylor

Copy link
Copy Markdown
Owner

Fixes #28.

Problem

Toggling a file tree (Neo-tree, nvim-tree, …) while a DiffBandit view was open left the layout broken. Closing the tree gave its columns to whichever DiffBandit window was next to it, and the views only laid out their widths on open or a content change. With the commit panel open, the panel grew on every toggle (42 → 83 → 124 → 146 columns in a repro) until the diff panes were almost gone. Merge views had the same problem, and they also sized from vim.o.columns, so an open tree was never accounted for.

Fix

  • util/layout.foreign_layout_key(tabpage, owned) builds a key from the editor size plus every window the view doesn't own, with its size. Owned windows count only by id.
  • Two-way sessions and merge views re-run their width layout on WinResized/VimResized when that key changes. The panel and gutters go back to their configured widths, and the content panes split what's left.
  • Resizing DiffBandit's own windows (for example, dragging the separator between panes) leaves the key unchanged, so the user's sizing sticks.
  • Merge views now size from the columns their own windows occupy (Merge:owned_columns) instead of the full editor width.

The folder view already re-runs its layout on every resize and measures only its own windows, so it's unchanged.

Tests

New tests/integration/test_layout.lua:

  • Simulates a tree toggle (topleft 40vnew + close) three times each in a plain diff, a diff with the commit panel, and a 3-way merge, and checks that every window width returns to its starting value. All three cases fail on main.
  • A dragged pane separator survives a redraw.

nvim -l tests/run_all.lua: 20 jobs, 0 failed.

The test uses a plain split as a stand-in for Neo-tree. It hasn't been checked against the real plugin.

Opening and closing a file tree (Neo-tree, nvim-tree, ...) in a DiffBandit
tab handed its columns to whichever DiffBandit window was adjacent, and the
views never laid their widths out again: the commit panel grew on every
toggle and the source panes were squeezed.

Two-way sessions and merge views now re-run their width layout on
WinResized/VimResized when the editor size or a window they do not own
changed (util/layout.foreign_layout_key). Resizes of their own windows, such
as a dragged pane separator, keep the key and stay. Merge views also size
from the columns their windows occupy instead of the full editor width.

Fixes #28
@CoreyKaylor
CoreyKaylor merged commit 35e255b into main Nov 5, 2026
1 check passed
@CoreyKaylor
CoreyKaylor deleted the fix/foreign-split-relayout branch November 5, 2026 23:33
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.

Diff window doesn't resize when toggling Neo-tree

1 participant