1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00

do not jump cursor around when fixing merge conflicts

This commit is contained in:
Jesse Duffield 2021-04-02 01:31:23 +11:00
parent 216b5341ae
commit f7772f00c4
2 changed files with 20 additions and 1 deletions

View File

@ -554,9 +554,24 @@ func (gui *Gui) refreshStateFiles() error {
if selectedNode != nil { if selectedNode != nil {
newIdx := gui.findNewSelectedIdx(prevNodes[prevSelectedLineIdx:], gui.State.FileManager.GetAllItems()) newIdx := gui.findNewSelectedIdx(prevNodes[prevSelectedLineIdx:], gui.State.FileManager.GetAllItems())
if newIdx != -1 && newIdx != prevSelectedLineIdx { if newIdx != -1 && newIdx != prevSelectedLineIdx {
newNode := gui.State.FileManager.GetItemAtIndex(newIdx)
// when not in tree mode, we show merge conflict files at the top, so you
// can work through them one by one without having to sift through a large
// set of files. If you have just fixed the merge conflicts of a file, we
// actually don't want to jump to that file's new position, because that
// file will now be ages away amidst the other files without merge
// conflicts: the user in this case would rather work on the next file
// with merge conflicts, which will have moved up to fill the gap left by
// the last file, meaning the cursor doesn't need to move at all.
leaveCursor := !gui.State.FileManager.InTreeMode() && newNode != nil &&
selectedNode.File != nil && selectedNode.File.HasMergeConflicts &&
newNode.File != nil && !newNode.File.HasMergeConflicts
if !leaveCursor {
gui.State.Panels.Files.SelectedLineIdx = newIdx gui.State.Panels.Files.SelectedLineIdx = newIdx
} }
} }
}
gui.refreshSelectedLine(gui.State.Panels.Files, gui.State.FileManager.GetItemsLength()) gui.refreshSelectedLine(gui.State.Panels.Files, gui.State.FileManager.GetItemsLength())
return nil return nil

View File

@ -23,6 +23,10 @@ func NewFileManager(files []*models.File, log *logrus.Entry, showTree bool) *Fil
} }
} }
func (m *FileManager) InTreeMode() bool {
return m.showTree
}
func (m *FileManager) ExpandToPath(path string) { func (m *FileManager) ExpandToPath(path string) {
m.collapsedPaths.ExpandToPath(path) m.collapsedPaths.ExpandToPath(path)
} }