1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-05 00:59:19 +02:00

do not reset cursor unless previous file has moved position

This commit is contained in:
Jesse Duffield
2020-08-25 08:34:02 +10:00
committed by github-actions[bot]
parent 2598ce1d4b
commit 771e87ebeb

View File

@ -397,6 +397,7 @@ func (gui *Gui) refreshStateFiles() error {
// when we refresh, go looking for a matching name // when we refresh, go looking for a matching name
// move the cursor to there. // move the cursor to there.
selectedFile := gui.getSelectedFile() selectedFile := gui.getSelectedFile()
prevSelectedLineIdx := gui.State.Panels.Files.SelectedLineIdx
// get files to stage // get files to stage
files := gui.GitCommand.GetStatusFiles(commands.GetStatusFileOptions{}) files := gui.GitCommand.GetStatusFiles(commands.GetStatusFileOptions{})
@ -407,10 +408,13 @@ func (gui *Gui) refreshStateFiles() error {
} }
// let's try to find our file again and move the cursor to that // let's try to find our file again and move the cursor to that
for idx, f := range gui.State.Files { if selectedFile != nil {
if selectedFile != nil && f.Matches(selectedFile) { for idx, f := range gui.State.Files {
gui.State.Panels.Files.SelectedLineIdx = idx selectedFileHasMoved := f.Matches(selectedFile) && idx != prevSelectedLineIdx
break if selectedFileHasMoved {
gui.State.Panels.Files.SelectedLineIdx = idx
break
}
} }
} }