mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
When the deletion of the selected file is staged and git then reports it as the old half of a rename whose new half sits in a collapsed directory, the selection is meant to move to the rename. With gui.showRootItemInFileTree turned on, the directory stays collapsed and the selection lands on it. With the option turned off, the directory expands, but if another file in it sorts before the rename, that file gets selected. The loop that expands the directory runs before the tree is rebuilt and works on the file list instead of on tree nodes. It compares the rename's previous path, a user-facing path, against the selected node's internal path, so the two never match while the root item is shown. The path it hands to ExpandToPath is user-facing as well, so the directory would stay collapsed either way. And because the loop runs before the old node list is captured, expanding a directory above the selection shifts that list, and the search for the new selection starts from whatever node moved into the selected line. Rebuild the tree first, capture the old node list before anything expands, and then look for the rename among the leaves of the new tree. ExpandToPath gets the leaf's own internal path, so the two kinds of paths never need converting. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>