mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-01-26 01:41:35 +03:00
Extract a method for selecting the first branch (and first commit)
We want to do this whenever we switch branches; it wasn't done consistently though. There are many different ways to switch branches, and only some of these would reset the selection of all three panels (branches, commits, and reflog).
This commit is contained in:
@@ -531,7 +531,7 @@ func (self *BranchesController) createNewBranchWithName(newBranchName string) er
|
||||
return err
|
||||
}
|
||||
|
||||
self.context().SetSelection(0)
|
||||
self.c.Helpers().Refs.SelectFirstBranchAndFirstCommit()
|
||||
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, KeepBranchSelectionIndex: true})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@ func NewRefsHelper(
|
||||
}
|
||||
}
|
||||
|
||||
func (self *RefsHelper) SelectFirstBranchAndFirstCommit() {
|
||||
self.c.Contexts().Branches.SetSelection(0)
|
||||
self.c.Contexts().ReflogCommits.SetSelection(0)
|
||||
self.c.Contexts().LocalCommits.SetSelection(0)
|
||||
}
|
||||
|
||||
func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions) error {
|
||||
waitingStatus := options.WaitingStatus
|
||||
if waitingStatus == "" {
|
||||
@@ -40,9 +46,8 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
|
||||
cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
|
||||
|
||||
refresh := func() {
|
||||
self.c.Contexts().Branches.SetSelection(0)
|
||||
self.c.Contexts().ReflogCommits.SetSelection(0)
|
||||
self.c.Contexts().LocalCommits.SetSelection(0)
|
||||
self.SelectFirstBranchAndFirstCommit()
|
||||
|
||||
// loading a heap of commits is slow so we limit them whenever doing a reset
|
||||
self.c.Contexts().LocalCommits.SetLimitCommits(true)
|
||||
|
||||
@@ -348,8 +353,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
|
||||
self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{})
|
||||
}
|
||||
|
||||
self.c.Contexts().LocalCommits.SetSelection(0)
|
||||
self.c.Contexts().Branches.SetSelection(0)
|
||||
self.SelectFirstBranchAndFirstCommit()
|
||||
|
||||
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
|
||||
}
|
||||
@@ -504,8 +508,7 @@ func (self *RefsHelper) moveCommitsToNewBranchStackedOnCurrentBranch(newBranchNa
|
||||
}
|
||||
}
|
||||
|
||||
self.c.Contexts().LocalCommits.SetSelection(0)
|
||||
self.c.Contexts().Branches.SetSelection(0)
|
||||
self.SelectFirstBranchAndFirstCommit()
|
||||
|
||||
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
|
||||
return nil
|
||||
@@ -543,8 +546,7 @@ func (self *RefsHelper) moveCommitsToNewBranchOffOfMainBranch(newBranchName stri
|
||||
}
|
||||
}
|
||||
|
||||
self.c.Contexts().LocalCommits.SetSelection(0)
|
||||
self.c.Contexts().Branches.SetSelection(0)
|
||||
self.SelectFirstBranchAndFirstCommit()
|
||||
|
||||
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
|
||||
return nil
|
||||
|
||||
@@ -368,7 +368,7 @@ func (self *RemotesController) fetchAndCheckout(remote *models.Remote, branchNam
|
||||
err = self.c.Git().Branch.New(branchName, remote.Name+"/"+branchName)
|
||||
if err == nil {
|
||||
self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{})
|
||||
self.c.Contexts().Branches.SetSelection(0)
|
||||
self.c.Helpers().Refs.SelectFirstBranchAndFirstCommit()
|
||||
refreshOptions.KeepBranchSelectionIndex = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user