mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-24 15:30:21 -05:00
Compare user-facing paths when re-finding the selection after a refresh
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>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
77cbb532f2
commit
4766ce009e
@@ -132,6 +132,8 @@ func (self *FileTreeViewModel) SetTree() {
|
||||
// to that.
|
||||
// prevNodes starts from our previously selected node because we don't need to consider anything above that
|
||||
func (self *FileTreeViewModel) findNewSelectedIdx(prevNodes []*FileNode, currNodes []*FileNode) int {
|
||||
// Paths are compared as the user sees them, without the "./" prefix of the
|
||||
// root item, so that they line up with the names of a rename.
|
||||
getPaths := func(node *FileNode) []string {
|
||||
if node == nil {
|
||||
return nil
|
||||
@@ -139,7 +141,7 @@ func (self *FileTreeViewModel) findNewSelectedIdx(prevNodes []*FileNode, currNod
|
||||
if node.File != nil && node.File.IsRename() {
|
||||
return node.File.Names()
|
||||
}
|
||||
return []string{node.path}
|
||||
return []string{node.GetPath()}
|
||||
}
|
||||
|
||||
for _, prevNode := range prevNodes {
|
||||
@@ -150,7 +152,7 @@ func (self *FileTreeViewModel) findNewSelectedIdx(prevNodes []*FileNode, currNod
|
||||
|
||||
// If you started off with a rename selected, and now it's broken in two, we want you to jump to the new file, not the old file.
|
||||
// This is because the new should be in the same position as the rename was meaning less cursor jumping
|
||||
foundOldFileInRename := prevNode.File != nil && prevNode.File.IsRename() && node.path == prevNode.File.PreviousPath
|
||||
foundOldFileInRename := prevNode.File != nil && prevNode.File.IsRename() && node.GetPath() == prevNode.File.PreviousPath
|
||||
foundNode := utils.StringArraysOverlap(paths, selectedPaths) && !foundOldFileInRename
|
||||
if foundNode {
|
||||
return idx
|
||||
|
||||
@@ -41,10 +41,7 @@ func TestSetTreeSelectsNewFileWhenSelectedRenameSplits(t *testing.T) {
|
||||
{
|
||||
name: "with root item",
|
||||
showRootItem: true,
|
||||
/* EXPECTED:
|
||||
expectedPath: "dir/new.go",
|
||||
ACTUAL: */
|
||||
expectedPath: "other.go",
|
||||
},
|
||||
{
|
||||
name: "without root item",
|
||||
|
||||
Reference in New Issue
Block a user