1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

Select same commit again after pressing "e" to edit a commit

When editing a commit, the index of the current commit can change; for example,
when merge commits are involved, or when working with stacked branches where
"update-ref" commands may be added above the selected commit.

Reselect the current commit after pressing "e"; this requires doing the refresh
blocking on the main thread. (Another option that I considered was to use a
SYNC refresh, and then select the new line with an OnUIThread inside the Then
function. This also works, but results in a very visible lag.)
This commit is contained in:
Stefan Haller
2023-08-03 19:22:51 +02:00
parent c718a73d0a
commit 98e6c119f5
3 changed files with 18 additions and 5 deletions

View File

@ -125,8 +125,8 @@ func isMergeConflictErr(errStr string) bool {
return false
}
func (self *MergeAndRebaseHelper) CheckMergeOrRebase(result error) error {
if err := self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}); err != nil {
func (self *MergeAndRebaseHelper) CheckMergeOrRebaseWithRefreshOptions(result error, refreshOptions types.RefreshOptions) error {
if err := self.c.Refresh(refreshOptions); err != nil {
return err
}
if result == nil {
@ -143,6 +143,10 @@ func (self *MergeAndRebaseHelper) CheckMergeOrRebase(result error) error {
}
}
func (self *MergeAndRebaseHelper) CheckMergeOrRebase(result error) error {
return self.CheckMergeOrRebaseWithRefreshOptions(result, types.RefreshOptions{Mode: types.ASYNC})
}
func (self *MergeAndRebaseHelper) CheckForConflicts(result error) error {
if result == nil {
return nil

View File

@ -392,7 +392,16 @@ func (self *LocalCommitsController) edit(commit *models.Commit) error {
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.EditCommit)
err := self.c.Git().Rebase.EditRebase(commit.Sha)
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebaseWithRefreshOptions(
err,
types.RefreshOptions{Mode: types.BLOCK_UI, Then: func() {
_, index, ok := lo.FindIndexOf(self.c.Model().Commits, func(c *models.Commit) bool {
return c.Sha == commit.Sha
})
if ok {
self.context().SetSelectedLineIdx(index)
}
}})
})
}

View File

@ -44,8 +44,8 @@ var DropTodoCommitWithUpdateRef = NewIntegrationTest(NewIntegrationTestArgs{
Contains("pick").Contains("CI commit 05"),
Contains("update-ref").Contains("branch1").DoesNotContain("*"),
Contains("pick").Contains("CI * commit 04"),
Contains("pick").Contains("CI commit 03").IsSelected(), // wrong line selected
Contains("<-- YOU ARE HERE --- commit 02"),
Contains("pick").Contains("CI commit 03"),
Contains("<-- YOU ARE HERE --- commit 02").IsSelected(),
Contains("CI commit 01"),
).
NavigateToLine(Contains("commit 06")).