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,12 +408,15 @@ 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
if selectedFile != nil {
for idx, f := range gui.State.Files { for idx, f := range gui.State.Files {
if selectedFile != nil && f.Matches(selectedFile) { selectedFileHasMoved := f.Matches(selectedFile) && idx != prevSelectedLineIdx
if selectedFileHasMoved {
gui.State.Panels.Files.SelectedLineIdx = idx gui.State.Panels.Files.SelectedLineIdx = idx
break break
} }
} }
}
gui.refreshSelectedLine(gui.State.Panels.Files, len(gui.State.Files)) gui.refreshSelectedLine(gui.State.Panels.Files, len(gui.State.Files))
return nil return nil