Skip to content

fix: restore file tree width after terminal resize - #33

Open
KEY60228 wants to merge 1 commit into
mainfrom
fix/file-tree-width-resize
Open

fix: restore file tree width after terminal resize#33
KEY60228 wants to merge 1 commit into
mainfrom
fix/file-tree-width-resize

Conversation

@KEY60228

Copy link
Copy Markdown
Owner

Problem

The file tree sometimes ends up much narrower than file_tree_width and never recovers.

Root cause: the tree window uses winfixwidth, which excludes it from width redistribution when the terminal grows. So whenever the terminal (tmux pane zoom/unzoom, window resize, font size change) momentarily becomes too narrow to fit the tree, Neovim force-shrinks it — and after the terminal grows back, the tree stays at the shrunken width forever. Each shrink ratchets it further down.

Reproduced with an embedded nvim + attached UI:

initial 200 cols   [tree=30* old=84 new=84]
shrink to 25       [tree=21* old=1  new=1 ]
grow back to 200   [tree=21* old=1  new=167]   <- tree stuck, old pane crushed

Fix

  • ui/file_tree.lua: re-assert the configured file_tree_width on VimResized (augroup cleaned up in close()).
  • ui/init.lua: rebalance the old/new diff panes on VimResized — the same shrink/grow cycle left one pane crushed at winminwidth (width 1) while the other took all the space.
  • file_tree.close(): skip nvim_win_close when the tree is the last window (previously raised E444, e.g. pressing q in the tree after :only); deleting the scratch buffer leaves the window on an empty buffer instead.

Verification

End-to-end test driving a real :ReviewThemStart session in an embedded nvim with an attached UI, resizing via nvim_ui_try_resize:

initial 200        [tree=30* old=84 new=84]
shrink to 25       [tree=21* old=1  new=1 ]
grow to 200        [tree=30* old=84 new=84]   <- recovers now
shrink to 20       [tree=16* old=1  new=1 ]
grow to 180        [tree=30* old=74 new=74]   <- recovers repeatedly
tree closed, resize cycle: no stale-autocmd errors
close-as-last-window: ok (no E444)

🤖 Generated with Claude Code

'winfixwidth' excludes the tree window from width redistribution when
the terminal grows back after a shrink, so any forced shrink (tmux pane
zoom, font size change, window resize) permanently ratcheted the tree
below file_tree_width. Re-assert the configured width on VimResized,
and rebalance the old/new diff panes which the same event could crush
down to 'winminwidth'.

Also guard file_tree.close() against E444 when the tree is the last
window.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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