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/gui | |
parent | 469ac116efde8dd107bc227ef8fc0f1927a629cb (diff) |
follow cursor when staging and unstaging a file rename
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/files_panel.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 6cba05715..0c6d2c9f3 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -410,14 +410,27 @@ func (gui *Gui) handleRefreshFiles(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) refreshStateFiles() error { + // keep track of where the cursor is currently and the current file names + // when we refresh, go looking for a matching name + // move the cursor to there. + selectedFile, _ := gui.getSelectedFile() + // get files to stage files := gui.GitCommand.GetStatusFiles(commands.GetStatusFileOptions{}) - gui.State.Files = gui.GitCommand.MergeStatusFiles(gui.State.Files, files) + gui.State.Files = gui.GitCommand.MergeStatusFiles(gui.State.Files, files, selectedFile) if err := gui.fileWatcher.addFilesToFileWatcher(files); err != nil { return err } + // let's try to find our file again and move the cursor to that + for idx, f := range gui.State.Files { + if selectedFile != nil && f.Matches(selectedFile) { + gui.State.Panels.Files.SelectedLine = idx + break + } + } + gui.refreshSelectedLine(&gui.State.Panels.Files.SelectedLine, len(gui.State.Files)) return nil } |