Repository navigation
Keep the outer folder selected when a folder path in the files panel splits up - #6037
Merged
Merged
Conversation
When a rename is selected in the files panel and then splits into its two halves, e.g. because it was unstaged, the selection is meant to move to the new half. This only works with gui.showRootItemInFileTree turned off. With the default setting, the selection lands on the file that follows the rename in the list instead. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
When the selected rename splits into its two halves, e.g. because it was unstaged, the selection is meant to move to the new half. With the default setting of gui.showRootItemInFileTree, it lands on the file that follows the rename in the list instead. findNewSelectedIdx identifies a rename by the names of its two halves. These are user-facing paths, without the "./" prefix that the root item adds to every internal path, but they were compared against internal paths. The comparison never matched while the root item was shown. Compare user-facing paths throughout findNewSelectedIdx. Node.ID already identifies list items by their user-facing path. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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, expanding the directory on the way. With gui.showRootItemInFileTree turned on, the directory stays collapsed and the selection lands on it instead. With the option turned off, the directory does expand, but if another file in it sorts before the rename, that file gets selected. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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>
When a single file is modified inside a nested directory, the file tree compresses the whole chain of directories into one line, such as "pkg/gui/controllers/helpers". Selecting that line shows the diff of the entire working tree. When a second file is then modified in another subdirectory of pkg/gui, the tree splits the line into "pkg/gui" with "context" and "controllers/helpers" below it, and the refresh moves the selection down to "controllers/helpers". Users who keep the top directory selected to see the diff of everything lose that view and have to move the cursor back up after every such refresh. This happens because the selection is re-found by the node's own path, and a compressed node's path is the deepest directory in its chain. The node stood for every directory in that chain, though, and the topmost piece of the split is the one that stays on the same line. Match a compressed directory node against any new node that stands for at least one of the same directories. The list is in depth-first order, so the topmost piece wins and the cursor stays on its line. Files are never compressed, so their handling doesn't change. The reverse case, where two directories fold back into one compressed line, already selected the merged line and still does. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 task
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.
When only one file inside a nested folder has changes, the files panel shows the whole path to it on a single line:
Selecting that line shows the diff of everything below it, in this case the entire working tree. As soon as a second file changes in a different folder, the panel splits that line up:
Until now, the selection moved down to
cin this situation, so the main view suddenly showed only the diff of that folder. Now the selection stays on the outer folder,a/bhere. That is the same line as before, and it still shows the diff of everything. This is most useful if you like to keep the top folder selected to always see the diff of the whole working tree; the same rule applies to folders further down the tree. The reverse case, where two folders fold back into a single line, already kept the selection on that line.Along the way we also fixed two small bugs in how the selection follows a rename after a refresh; see the individual commit messages for details.