diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-07 18:27:18 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-07 18:59:56 +1000 |
commit | 660cc2f3d1d5253817d52e8991f74e836d3db6ba (patch) | |
tree | 6ca6d605851b6f71d27713cf9f5cb5afb2e6eeac /pkg/commands/git.go | |
parent | 469ac116efde8dd107bc227ef8fc0f1927a629cb (diff) |
follow cursor when staging and unstaging a file rename
Diffstat (limited to 'pkg/commands/git.go')
-rw-r--r-- | pkg/commands/git.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 20cbd9fb2..249221c1f 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -279,7 +279,7 @@ func (c *GitCommand) StashSave(message string) error { } // MergeStatusFiles merge status files -func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []*File) []*File { +func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []*File, selectedFile *File) []*File { if len(oldFiles) == 0 { return newFiles } @@ -290,10 +290,15 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []*File) []*File { result := []*File{} for _, oldFile := range oldFiles { for newIndex, newFile := range newFiles { - if oldFile.Name == newFile.Name { + if includesInt(appendedIndexes, newIndex) { + continue + } + // if we just staged B and in doing so created 'A -> B' and we are currently have oldFile: A and newFile: 'A -> B', we want to wait until we come across B so the our cursor isn't jumping anywhere + waitForMatchingFile := selectedFile != nil && newFile.IsRename() && !selectedFile.IsRename() && newFile.Matches(selectedFile) && !oldFile.Matches(selectedFile) + + if oldFile.Matches(newFile) && !waitForMatchingFile { result = append(result, newFile) appendedIndexes = append(appendedIndexes, newIndex) - break } } } |